Subversion Repositories vnag

Rev

Rev 66 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 66 Rev 76
Line 1... Line 1...
1
<?php /* <ViaThinkSoftSignature>
1
<?php /* <ViaThinkSoftSignature>
2
WJQybky6qsSpW28I5ZK1NAaUsu8Qpg0fz5halRZOaoxt9IelpsjOdBboT1KMGsgYi
2
okEz+tdTNB6lllJohO9ECI4MAh3STmwseFV3T2s7zbbhS88rBhz5eOHaJqH9jckV7
3
L0S2N6YjA4LJo7mZzxowRSQzdSU2Ndu4Txj6s3dG0mVWxoHLa+NN4bzDEtraF8Nxy
3
GgupfsVt+X87nkce4g3GD3vNJlaol/TJheT3y6YPFI8W2l9gKkgMZg2899j9SWgGy
4
JstPj1HCtAczGuDrb9Jar8P9pRlOianCWMZv9bj3ZcwA9WqwVgngz+y2Jhj5KT20n
4
KQ4fOJAV72EvpYpvAaIDOou1peDHeweUagSjAEn/2OV9X7A0fxrgu6tR+f9xscCpB
5
MO5oIfZanNmY4C6TVfd9Y4a5X5HfcwInTPZGSW+yk6kGjRc+Ksb0asXtJ02KuWPJ1
5
gRjW9BVXjLkx0WsthEr+fqkFSvQn2EnYk3sWLe9adWwlIvbFdbPoYmWTUP4CI6Fn2
6
jOuZsoJfQgrJnjFgDdE2iiPixcVZpsZQx0GrHnwwh+nhkO1vJ5lprWXAbb9cOsNAT
6
SeMWPD0UFM/e4UCUeFbYcC8SxPVBpACXaRQ3RVi4TUG0+TLdj2mV+yLb5Jm1v6j5g
7
jG0wlsS4gkC2dgUGsYSi4hptjD1oXmkZDb0+bj8FvcLCt+j+SH3vzKeLwz+CyAMAY
7
n87wlnGLLvF7IlZbJuzO4AZkbUWS7u0z1lRGdNL+N5mOUlAdVP05c3NmURCvTeSa4
8
0dY9nPKwqDgS0uWsrqNHs+6Vm+gladlUl1qBwK3/00aHCTYmLoXlaBXOi6thK3gwg
8
NwN8WiBLnY2a9EUquS9V4qanKkhh8762JqjmQqBljCOa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IIgJwMEYlWdck9CmjRPRFQ5Yx58DhFDz0voxbtsoY5nNV92zTeikhKk1Sw9CH
17
4pgUFexatorqS0vjtGow/55sxjbYMWBlxAAT6Xk2Z6ZfoPEXAWnyJAl1olEHQ3XVX
17
vRKkZV75XFuM50o2U9a+XTBiSXgHLN6nDSYEUhLXHM/DDwVVTln1hlPKrQarpiVuW
18
CBAC3YIK9naA7SQ3j9l+OXnYsBU6+FSweOlSne5Za4D/PdrZCKAdwrcrzh7acdWuG
18
v9MLvzTZJrZTfG6/ika2RwkvzKvQB+JHxEEK/Lbofq4A8QncwwIN76ptXqeB0vZlA
19
Za1h7LaH2F21abkju5kerkpqPRIJrkgoDpK5uFxXWraRHmpIIsRQMu+EQhcdo6kJm
19
sM0JuhgXzrF6RYAFmJAIwuiPe32cxtBS5fwvhzCDJp+Z5w0kVrI1hkYFVBSK4Z3j5
20
bf5rrm1o0PsUXo2LwmcdLOqgFSTe5Z6dMUB4W+8USc7929fe2gyMAMGxyd9gNPwNP
20
VE9xAPz42Tzplw7Am3nfMEF6UtQN0FuollQ9KXnDUpRXRiwZn81tUcYkiriWSkooo
21
dpepmIF1tuKzpOAO/OvqZrc0QdTh4xkSm3bcHe7deUNlbqzQLzUcEI95V1I6xZRfK
21
FFv3f5KbWDqYABVKhCbZ4mhjPyEg0E6PXU7YULW9nEQbYJTNUsE3NAcaQmDgaTw5b
22
RBh+w6bk8M7/3xkTxiOEfubiypgc7Xf9V7hUhyRiyHGf7rnwXS5iKnRBm+vncFDbF
22
zgeyl05G0z4Mba2ILtxCa2oG5D06gGM4HIYo12JDzjHLcD1KJZjGeoIo5cV6foEQ0
23
g==
23
Q==
24
</ViaThinkSoftSignature> */ ?>
24
</ViaThinkSoftSignature> */ ?>
25
<?php
25
<?php
26
 
26
 
27
/*
27
/*
28
 * VNag - Nagios Framework for PHP
28
 * VNag - Nagios Framework for PHP
29
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
29
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
30
 * Licensed under the terms of the Apache 2.0 license
30
 * Licensed under the terms of the Apache 2.0 license
31
 *
31
 *
32
 * Revision 2023-06-12
32
 * Revision 2023-10-13
33
 */
33
 */
34
 
34
 
35
declare(ticks=1);
35
declare(ticks=1);
36
 
36
 
37
class MinecraftJavaVersionCheck extends VNag {
37
class MinecraftJavaVersionCheck extends VNag {
Line 51... Line 51...
51
 
51
 
52
                // Individual (non-standard) arguments:
52
                // Individual (non-standard) arguments:
53
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'serverPath', 'The local directory where your Minecraft for Java server.jar is located.'));
53
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'serverPath', 'The local directory where your Minecraft for Java server.jar is located.'));
54
        }
54
        }
55
 
55
 
56
        protected function get_latest_minecraft_version() {
-
 
57
                $url = 'https://launchermeta.mojang.com/mc/game/version_manifest.json';
-
 
58
                $max_cache_time = 1 * 60 * 60;
-
 
59
                $cache_file = $this->get_cache_dir().'/'.sha1($url);
-
 
60
                if (file_exists($cache_file) && (time()-filemtime($cache_file) < $max_cache_time)) {
-
 
61
                        $cont = @file_get_contents($cache_file);
-
 
62
                        if (!$cont) throw new Exception("Failed to get contents from $cache_file");
-
 
63
                } else {
-
 
64
                        $cont = @file_get_contents('https://launchermeta.mojang.com/mc/game/version_manifest.json');
-
 
65
                        if (!$cont) throw new Exception("Cannot detect latest available Minecraft version (HTTPS request to $url failed)");
-
 
66
                        file_put_contents($cache_file, $cont);
-
 
67
                }
-
 
68
 
-
 
69
                $json = @json_decode($cont, true);
-
 
70
                if (!$json) throw new Exception("Cannot detect latest available Minecraft version (JSON invalid data)");
-
 
71
                $version = $json['latest']['release'] ?? null;
-
 
72
                if (!$version) throw new Exception("Cannot detect latest available Minecraft version (JSON does not contain version)");
-
 
73
                return $version;
-
 
74
        }
-
 
75
 
-
 
76
        protected function get_installed_minecraft_version($local_path) {
56
        protected function get_local_version($local_path) {
77
                if (strtolower(substr($local_path,-4)) == '.jar') {
57
                if (strtolower(substr($local_path,-4)) == '.jar') {
78
                        // Single JAR file specified. Search it.
58
                        // Single JAR file specified. Search it.
79
                        $files = glob($local_path);
59
                        $files = glob($local_path);
80
                } else {
60
                } else {
81
                        // Directory specified. Search the server.jar
61
                        // Directory specified. Search the server.jar
Line 110... Line 90...
110
                }
90
                }
111
 
91
 
112
                return (string)json_decode($json,true)['name'];
92
                return (string)json_decode($json,true)['name'];
113
        }
93
        }
114
 
94
 
-
 
95
        protected function get_latest_version() {
-
 
96
                $cont = $this->url_get_contents('https://launchermeta.mojang.com/mc/game/version_manifest.json');
-
 
97
                if ($cont === false) throw new Exception("Cannot detect latest available Minecraft version (GET request failed)");
-
 
98
                $json = @json_decode($cont, true);
-
 
99
                if ($json === false) throw new Exception("Cannot detect latest available Minecraft version (JSON invalid data)");
-
 
100
                $version = $json['latest']['release'] ?? null;
-
 
101
                if (!$version) throw new Exception("Cannot detect latest available Minecraft version (JSON does not contain version)");
-
 
102
                return $version;
-
 
103
        }
-
 
104
 
115
        protected function cbRun($optional_args=array()) {
105
        protected function cbRun($optional_args=array()) {
116
                $system_dir = $this->argSystemDir->getValue(); // note: can contain wildcards
106
                $system_dir = $this->argSystemDir->getValue(); // note: can contain wildcards
117
                $cur_ver = $this->get_installed_minecraft_version($system_dir);
107
                $cur_ver = $this->get_local_version($system_dir);
118
 
108
 
119
                $new_ver = $this->get_latest_minecraft_version();
109
                $new_ver = $this->get_latest_version();
120
 
110
 
121
                if (version_compare($cur_ver,$new_ver) >= 0) {
111
                if (version_compare($cur_ver,$new_ver) >= 0) {
122
                        $this->setStatus(VNag::STATUS_OK);
112
                        $this->setStatus(VNag::STATUS_OK);
123
                        $this->setHeadline("Minecraft version $cur_ver is the latest available version for your Minecraft for Java server installation at $system_dir", true);
113
                        $this->setHeadline("Minecraft version $cur_ver is the latest available version for your Minecraft for Java server installation at $system_dir", true);
124
                } else {
114
                } else {