Rev 57 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 57 | Rev 61 | ||
---|---|---|---|
1 | <?php /* <ViaThinkSoftSignature> |
1 | <?php /* <ViaThinkSoftSignature> |
2 | YU84r4UF1RQYMGABCCGu0MB2mvfy3E9RC4oCgHx+trADi3ukDqRO/pQV+NqbQUgWm |
2 | YU84r4UF1RQYMGABCCGu0MB2mvfy3E9RC4oCgHx+trADi3ukDqRO/pQV+NqbQUgWm |
3 | M7brafd901QAYEjRv1U3cqwChtRpLthnkHFWrISIuesN+ztweQ0ZJpzK3U5t3gN1d |
3 | M7brafd901QAYEjRv1U3cqwChtRpLthnkHFWrISIuesN+ztweQ0ZJpzK3U5t3gN1d |
4 | Cp6z3x69BrgC8lmdsZVHn5OKUmneMK+5dEEvlAhXp4y+fsvrAtkqajxfi9lNm4bSU |
4 | Cp6z3x69BrgC8lmdsZVHn5OKUmneMK+5dEEvlAhXp4y+fsvrAtkqajxfi9lNm4bSU |
5 | TD4OEknecfUj95+5d9exG3ml4UlI6VGDHeIz2GHG1sPy+3zA60eV1Y2xnQS12p9QF |
5 | TD4OEknecfUj95+5d9exG3ml4UlI6VGDHeIz2GHG1sPy+3zA60eV1Y2xnQS12p9QF |
6 | TZEevtPWG3IqGzsBKZ5OJkeWFi4g5N+eYGZIcQrlV44Qv3gFfj/jGgb1lo/1JuGNA |
6 | TZEevtPWG3IqGzsBKZ5OJkeWFi4g5N+eYGZIcQrlV44Qv3gFfj/jGgb1lo/1JuGNA |
7 | VVhE8JJqfuQrus1xtEOU5I22FFoNrcRYmqdaTRQ/VzWbLbkc07efqA+5gpqgL0gc0 |
7 | VVhE8JJqfuQrus1xtEOU5I22FFoNrcRYmqdaTRQ/VzWbLbkc07efqA+5gpqgL0gc0 |
8 | 7Y2XwdSoHouXJ3z9OiLvcOntnRmtELyVL3V43MvyfrUtB74q1VL2GfFzMiiDrtZ9I |
8 | 7Y2XwdSoHouXJ3z9OiLvc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jeJj6wJI72hHm |
16 | AZLjbipIRHvje+5U2Tc46V8XrOjbT3HKJcdwBPDDTHljDZwttXcGjeJj6wJI72hHm |
17 | W9Mjhag8rUwab5Z5c6jE+fuqsE4CAaqADoCuu/GYRjt0bYzoJSoQkX3yJvDf0P6gd |
17 | W9Mjhag8rUwab5Z5c6jE+fuqsE4CAaqADoCuu/GYRjt0bYzoJSoQkX3yJvDf0P6gd |
18 | sIeL079kvHsTPrWegItcL6HzMMQOs8ej63qjFCX6rLzlghxgAHX4g6GiCTL5eRk9I |
18 | sIeL079kvHsTPrWegItcL6HzMMQOs8ej63qjFCX6rLzlghxgAHX4g6GiCTL5eRk9I |
19 | TStX3wM5+gyNboUqs3cR1pU2fIlnbWOZy5aEaUDlDWw6OjUvr4ZHmExnAWdMfdUnY |
19 | TStX3wM5+gyNboUqs3cR1pU2fIlnbWOZy5aEaUDlDWw6OjUvr4ZHmExnAWdMfdUnY |
20 | 3mbBb5DHM1ccd0dMvouowi3sOKGPeRVQh09BADaSzhVF7xq6t6mYfB16pTejboFkw |
20 | 3mbBb5DHM1ccd0dMvouowi3sOKGPeRVQh09BADaSzhVF7xq6t6mYfB16pTejboFkw |
21 | 3fHjYuiSGwsX9ldnhj0QhjO5eKJmQPmWdLCs1bpG3od26aX+Dwxs2gKk2Hk943stv |
21 | 3fHjYuiSGwsX9ldnhj0QhjO5eKJmQPmWdLCs1bpG3od26aX+Dwxs2gKk2Hk943stv |
22 | L2L7y4yxqO76zPbI660m8JgS/Z9B006pJvJg0wa1u/mXL39mtD8l3clqPJLWZ8KDq |
22 | L2L7y4yxqO76zPbI660m8JgS/Z9B006pJvJg0wa1u/mXL39mtD8l3clqPJLWZ8KDq |
23 | g== |
23 | g== |
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 2022-09-12 |
32 | * Revision 2023-05-02 |
33 | */ |
33 | */ |
34 | 34 | ||
35 | declare(ticks=1); |
35 | declare(ticks=1); |
36 | 36 | ||
37 | class MinecraftJavaVersionCheck extends VNag { |
37 | class MinecraftJavaVersionCheck extends VNag { |
38 | protected $argSystemDir = null; |
38 | protected $argSystemDir = null; |
39 | 39 | ||
40 | public function __construct() { |
40 | public function __construct() { |
41 | parent::__construct(); |
41 | parent::__construct(); |
42 | 42 | ||
43 | $this->registerExpectedStandardArguments('Vvht'); |
43 | $this->registerExpectedStandardArguments('Vvht'); |
44 | 44 | ||
45 | $this->getHelpManager()->setPluginName('check_minecraft_java_version'); |
45 | $this->getHelpManager()->setPluginName('check_minecraft_java_version'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local Minecraft for Java server has the latest version installed.'); |
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local Minecraft for Java server has the latest version installed.'); |
48 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
48 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
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() { |
56 | protected function get_latest_minecraft_version() { |
57 | $headers = array( |
57 | $headers = array( |
58 | // These headers are important! Otherwise the request will be blocked by AkamaiGhost |
58 | // These headers are important! Otherwise the request will be blocked by AkamaiGhost |
59 | "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", |
59 | "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", |
60 | "Accept-Language: de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US;q=0.6", |
60 | "Accept-Language: de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US;q=0.6", |
61 | "Accept-Encoding: none" |
61 | "Accept-Encoding: none" |
62 | ); |
62 | ); |
63 | // curl 'https://www.minecraft.net/en-us/download/server' \ |
- | |
64 | // -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36' \ |
- | |
- | 63 | ||
65 | // -H 'accept-language: de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US;q=0.6' \ |
64 | // TODO: Version is currently not shown anymore: https://bugs.mojang.com/browse/WEB-6497 |
66 | // --compressed |
65 | /* |
67 | $ch = curl_init(); |
66 | $ch = curl_init(); |
68 | curl_setopt($ch, CURLOPT_URL,"https://www.minecraft.net/en-us/download/server"); // TODO: make locale configurable? |
67 | curl_setopt($ch, CURLOPT_URL,"https://www.minecraft.net/en-us/download/server"); // TODO: make locale configurable? |
69 | curl_setopt($ch, CURLOPT_POST, 0); |
68 | curl_setopt($ch, CURLOPT_POST, 0); |
70 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
69 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
71 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
70 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
72 | $cont = curl_exec($ch); |
71 | $cont = curl_exec($ch); |
73 | curl_close($ch); |
72 | curl_close($ch); |
74 | - | ||
75 | if (!$cont) throw new Exception("Cannot detect latest available Minecraft version (HTTPS request failed)"); |
73 | if (!$cont) throw new Exception("Cannot detect latest available Minecraft version (HTTPS request failed)"); |
76 | - | ||
77 | preg_match_all('@minecraft_server\\.(.+)\\.jar@U', $cont, $m); |
74 | preg_match_all('@minecraft_server\\.(.+)\\.jar@U', $cont, $m); |
78 | - | ||
79 | if (!isset($m[1][0])) throw new Exception("Cannot detect latest available Minecraft version (regex pattern mismatch)"); |
75 | if (!isset($m[1][0])) throw new Exception("Cannot detect latest available Minecraft version (regex pattern mismatch)"); |
80 | - | ||
81 | return $m[1][0]; |
76 | return $m[1][0]; |
- | 77 | */ |
|
- | 78 | ||
- | 79 | for ($page=1; $page<=2; $page++) { |
|
- | 80 | $url = 'https://feedback.minecraft.net/hc/en-us/sections/360001186971-Release-Changelogs'; |
|
- | 81 | if ($page > 1) $url .= '?page='.$page; |
|
- | 82 | $url = 'https://webcache.googleusercontent.com/search?q=cache:'.urlencode($url); // Bypass CloudFlare... |
|
- | 83 | ||
- | 84 | $ch = curl_init(); |
|
- | 85 | curl_setopt($ch, CURLOPT_URL, $url); |
|
- | 86 | curl_setopt($ch, CURLOPT_POST, 0); |
|
- | 87 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
- | 88 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
- | 89 | $cont = curl_exec($ch); |
|
- | 90 | curl_close($ch); |
|
- | 91 | if (!$cont) throw new Exception("Cannot detect latest available Minecraft version (HTTPS request failed)"); |
|
- | 92 | preg_match_all('@>Minecraft: Java Edition \\- (.+)</@U', $cont, $m); |
|
- | 93 | if (isset($m[1][0])) return $m[1][0]; |
|
- | 94 | } |
|
- | 95 | throw new Exception("Cannot detect latest available Minecraft version (regex pattern mismatch)"); |
|
82 | } |
96 | } |
83 | 97 | ||
84 | protected function get_installed_minecraft_version($local_path) { |
98 | protected function get_installed_minecraft_version($local_path) { |
85 | if (substr($local_path,-4) == '.jar') { |
99 | if (substr($local_path,-4) == '.jar') { |
86 | $files = glob($local_path); |
100 | $files = glob($local_path); |
87 | } else { |
101 | } else { |
88 | $files = glob($local_path.'/server.jar'); |
102 | $files = glob($local_path.'/server.jar'); |
89 | } |
103 | } |
90 | 104 | ||
91 | if (count($files) == 0) throw new Exception("No server.jar found at $local_path"); |
105 | if (count($files) == 0) throw new Exception("No server.jar found at $local_path"); |
92 | if (count($files) > 1) throw new Exception("More than one server.jar found at $local_path"); |
106 | if (count($files) > 1) throw new Exception("More than one server.jar found at $local_path"); |
93 | $server_jar = $files[0]; |
107 | $server_jar = $files[0]; |
94 | 108 | ||
95 | $cmd = "unzip -p ".escapeshellarg($server_jar)." version.json"; |
109 | $cmd = "unzip -p ".escapeshellarg($server_jar)." version.json"; |
96 | 110 | ||
97 | $out = array(); |
111 | $out = array(); |
98 | $ec = -1; |
112 | $ec = -1; |
99 | exec($cmd, $out, $ec); |
113 | exec($cmd, $out, $ec); |
100 | if ($ec != 0) throw new Exception("Cannot unzip version.json"); |
114 | if ($ec != 0) throw new Exception("Cannot unzip version.json"); |
101 | 115 | ||
102 | $json = implode("\n",$out); |
116 | $json = implode("\n",$out); |
103 | 117 | ||
104 | return (string)json_decode($json,true)['name']; |
118 | return (string)json_decode($json,true)['name']; |
105 | } |
119 | } |
106 | 120 | ||
107 | protected function cbRun($optional_args=array()) { |
121 | protected function cbRun($optional_args=array()) { |
108 | $system_dir = $this->argSystemDir->getValue(); // note: can contain wildcards |
122 | $system_dir = $this->argSystemDir->getValue(); // note: can contain wildcards |
109 | $cur_ver = $this->get_installed_minecraft_version($system_dir); |
123 | $cur_ver = $this->get_installed_minecraft_version($system_dir); |
110 | 124 | ||
111 | $new_ver = $this->get_latest_minecraft_version(); |
125 | $new_ver = $this->get_latest_minecraft_version(); |
112 | 126 | ||
113 | if (version_compare($cur_ver,$new_ver) >= 0) { |
127 | if (version_compare($cur_ver,$new_ver) >= 0) { |
114 | $this->setStatus(VNag::STATUS_OK); |
128 | $this->setStatus(VNag::STATUS_OK); |
115 | $this->setHeadline("Minecraft version $cur_ver is the latest available version for your Minecraft for Java server installation at $system_dir", true); |
129 | $this->setHeadline("Minecraft version $cur_ver is the latest available version for your Minecraft for Java server installation at $system_dir", true); |
116 | } else { |
130 | } else { |
117 | $this->setStatus(VNag::STATUS_WARNING); |
131 | $this->setStatus(VNag::STATUS_WARNING); |
118 | $this->setHeadline("Minecraft version $cur_ver is outdated. Newer version is $new_ver for installation at $system_dir", true); |
132 | $this->setHeadline("Minecraft version $cur_ver is outdated. Newer version is $new_ver for installation at $system_dir", true); |
119 | } |
133 | } |
120 | } |
134 | } |
121 | } |
135 | } |
122 | 136 |