-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_dokuwiki.php
executable file
·87 lines (67 loc) · 1.77 KB
/
check_dokuwiki.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
#!/usr/bin/php
<?php
/***
*
* Monitoring plugin to check the Dokuwiki update status.
*
* Copyright (c) 2017 Jan Vonde <[email protected]>
*
*
* Usage: /usr/bin/php ./check_dokuwiki.php -p /path/to/dokuwiki
*
*
* For more information visit https://github.com/janvonde/check_dokuwiki
*
***/
// get commands passed as arguments
$options = getopt("p:");
if (!is_array($options) ) {
print "There was a problem reading the passed option.\n\n";
exit(1);
}
if (count($options) != "1") {
print "check_dokuwiki.php - Monitoring plugin to check the Dokuwiki update status\n
You need to specify the following parameters:
-p: full path to dokuwiki root directory \n\n";
exit(2);
}
$dokuwikiBasePath = trim($options['p']);
// we need the updateVersion number from doku.php
$file = "$dokuwikiBasePath/doku.php";
if (!file_exists($file)) {
print "UNKNOWN: could not find doku.php in ${dokuwikiBasePath}\n";
exit(3);
}
$handle = fopen($file, "r");
while (!feof($handle)) {
$data = fgets($handle);
$pattern = '/(^\$updateVersion = )(.*)(;)/';
preg_match($pattern, $data, $matches);
if (!empty($matches)) {
$updateVersionOne = $matches['2'];
$updateVersion = str_replace('"', '', $updateVersionOne);
}
}
fclose($handle);
// get information from Dokuwiki website
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 3
)
)
);
$result = @file_get_contents("http://update.dokuwiki.org/check/$updateVersion", 0, $ctx);
if ($result === FALSE) {
echo "WARNING: Could not get information from update.dokuwiki.org. Aborting. \n";
exit (1);
}
// return info
if ($result != "" ) {
$results = explode("\n", $result);
echo "ERROR: Dokuwiki - " . $results[0] . "\n | update=1";
exit (2);
}
else {
echo "OK: Dokuwiki is up to date. | update=0";
}
?>