-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcentreware.php
More file actions
70 lines (49 loc) · 1.7 KB
/
centreware.php
File metadata and controls
70 lines (49 loc) · 1.7 KB
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
<?php
function clean($str) {
$str = str_replace(" ", '', $str);
$str = preg_replace('/\s+/', ' ',$str);
$str = trim($str);
return $str;
}
function get_centreware() {
//$url = "https://centreware.lan/counters/usage.php";
$url = "https://192.168.1.100/counters/usage.php";
// Initialize session and set URL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Get the response and close the channel.
$response = clean(curl_exec($ch));
curl_close($ch);
//echo $response;
// Create a new DomDocument object
$dom = new DomDocument;
//Load the HTML
$dom->loadHTML($response);
//Create a new XPath object
$xpath = new DomXPath($dom);
//Query all <td> nodes containing specified class name
$nodes = $xpath->query("//td");
$centreware = [];
//Traverse the DOMNodeList object to output each DomNode's nodeValue
foreach ($nodes as $i => $node) {
//echo "Node($i): ", $node->nodeValue, "\n";
$currentValue = $node->nodeValue;
if(isset($node->nextSibling)) {
$nextValue = $node->nextSibling->nodeValue;
//echo $currentValue."<br>";
if($currentValue == "Black Copied Impressions") {
$centreware["black_copies"] = $nextValue;
} else if ($currentValue == "Color Copied Impressions") {
$centreware["color_copies"] = $nextValue;
} else if ($currentValue == "Black Printed Impressions") {
$centreware["black_prints"] = $nextValue;
} else if ($currentValue == "Color Printed Impressions") {
$centreware["color_prints"] = $nextValue;
}
}
}
return count($centreware) ? $centreware : false;
}