-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
91 lines (78 loc) · 2.77 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
*
* Developed by Christopher Quackenbush <[email protected]>
* License: See license.md
*
*/
include "simple_html_dom.php";
/**
* Class HPInkChecker
*
* Collects the printers available ink for easy monitoring of
* colour and black/white printers produced by HP.
*/
class HPInkChecker {
public $printers = array();
public $debug = false;
public function enableDebug() {
$this->debug = true;
return $this;
}
public function addPrinter($name, $url, $black_only) {
$this->printers[] = [
'name' => $name,
'url' => $url,
'black_only' => $black_only,
'cyan' => 0,
'magenta' => 0,
'yellow' => 0,
'black' => 0
];
return $this;
}
public function scrape() {
foreach ($this->printers as &$printer) {
$url = (!$this->debug) ? $printer['url'] : "./printer.html";
$content = file_get_contents($url);
$content = str_get_html($content);
$printer['cyan'] = (int) $content->find('.cyan', 0)->children(0)->width;
$printer['yellow'] = (int) $content->find('.yellow', 0)->children(0)->width;
$printer['magenta'] = (int) $content->find('.magenta', 0)->children(0)->width;
$printer['black'] = (int) $content->find('.black', 0)->children(0)->width;
}
return $this;
}
}
$tonerCheck = new HPInkChecker();
$tonerCheck
//->enableDebug() // Uncomment this to load a local printer html dump instead of the web ui. Name the file printer.html
->addPrinter('Printer A', 'http://10.10.50.50/web/guest/en/webprinter/supply.cgi', false)
->addPrinter('Printer B', 'http://10.10.50.51/web/guest/en/webprinter/supply.cgi', false)
->addPrinter('Printer C', 'http://10.10.50.52/web/guest/en/webprinter/supply.cgi', false)
->addPrinter('Printer D', 'http://10.10.50.53/web/guest/en/webprinter/supply.cgi', false)
->scrape();
?>
<html>
<head>
<style type="text/css">
.printer {}
</style>
</head>
<body>
<div class="printer">
<?php
foreach ($tonerCheck->printers as $printer) {
echo "<div class='printer'>";
echo "<p>Name: " . $printer['name'] . "</p>";
echo "<p>URL: " . $printer['url'] . "</p>";
echo "<p>" . $printer['cyan'] . "</p>";
echo "<p>" . $printer['magenta'] . "</p>";
echo "<p>" . $printer['yellow'] . "</p>";
echo "<p>" . $printer['black'] . "</p>";
echo "</div>";
}
?>
</div>
</body>
</html>