Rev 84 | Rev 88 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
80 | daniel-mar | 1 | #!/usr/bin/env php |
83 | daniel-mar | 2 | <?php @ob_end_clean(); ?><?php |
80 | daniel-mar | 3 | |
4 | $web = 'index.php'; |
||
5 | |||
6 | if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) { |
||
7 | Phar::interceptFileFuncs(); |
||
8 | set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path()); |
||
9 | Phar::webPhar(null, $web); |
||
10 | include 'phar://' . __FILE__ . '/' . Extract_Phar::START; |
||
11 | return; |
||
12 | } |
||
13 | |||
14 | if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) { |
||
15 | Extract_Phar::go(true); |
||
16 | $mimes = array( |
||
17 | 'phps' => 2, |
||
18 | 'c' => 'text/plain', |
||
19 | 'cc' => 'text/plain', |
||
20 | 'cpp' => 'text/plain', |
||
21 | 'c++' => 'text/plain', |
||
22 | 'dtd' => 'text/plain', |
||
23 | 'h' => 'text/plain', |
||
24 | 'log' => 'text/plain', |
||
25 | 'rng' => 'text/plain', |
||
26 | 'txt' => 'text/plain', |
||
27 | 'xsd' => 'text/plain', |
||
28 | 'php' => 1, |
||
29 | 'inc' => 1, |
||
30 | 'avi' => 'video/avi', |
||
31 | 'bmp' => 'image/bmp', |
||
32 | 'css' => 'text/css', |
||
33 | 'gif' => 'image/gif', |
||
34 | 'htm' => 'text/html', |
||
35 | 'html' => 'text/html', |
||
36 | 'htmls' => 'text/html', |
||
37 | 'ico' => 'image/x-ico', |
||
38 | 'jpe' => 'image/jpeg', |
||
39 | 'jpg' => 'image/jpeg', |
||
40 | 'jpeg' => 'image/jpeg', |
||
41 | 'js' => 'application/x-javascript', |
||
42 | 'midi' => 'audio/midi', |
||
43 | 'mid' => 'audio/midi', |
||
44 | 'mod' => 'audio/mod', |
||
45 | 'mov' => 'movie/quicktime', |
||
46 | 'mp3' => 'audio/mp3', |
||
47 | 'mpg' => 'video/mpeg', |
||
48 | 'mpeg' => 'video/mpeg', |
||
49 | 'pdf' => 'application/pdf', |
||
50 | 'png' => 'image/png', |
||
51 | 'swf' => 'application/shockwave-flash', |
||
52 | 'tif' => 'image/tiff', |
||
53 | 'tiff' => 'image/tiff', |
||
54 | 'wav' => 'audio/wav', |
||
55 | 'xbm' => 'image/xbm', |
||
56 | 'xml' => 'text/xml', |
||
57 | ); |
||
58 | |||
59 | header("Cache-Control: no-cache, must-revalidate"); |
||
60 | header("Pragma: no-cache"); |
||
61 | |||
62 | $basename = basename(__FILE__); |
||
63 | if (!strpos($_SERVER['REQUEST_URI'], $basename)) { |
||
64 | chdir(Extract_Phar::$temp); |
||
65 | include $web; |
||
66 | return; |
||
67 | } |
||
68 | $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename)); |
||
69 | if (!$pt || $pt == '/') { |
||
70 | $pt = $web; |
||
71 | header('HTTP/1.1 301 Moved Permanently'); |
||
72 | header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt); |
||
73 | exit; |
||
74 | } |
||
75 | $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt); |
||
76 | if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) { |
||
77 | header('HTTP/1.0 404 Not Found'); |
||
78 | echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File Not Found</h1>\n </body>\n</html>"; |
||
79 | exit; |
||
80 | } |
||
81 | $b = pathinfo($a); |
||
82 | if (!isset($b['extension'])) { |
||
83 | header('Content-Type: text/plain'); |
||
84 | header('Content-Length: ' . filesize($a)); |
||
85 | readfile($a); |
||
86 | exit; |
||
87 | } |
||
88 | if (isset($mimes[$b['extension']])) { |
||
89 | if ($mimes[$b['extension']] === 1) { |
||
90 | include $a; |
||
91 | exit; |
||
92 | } |
||
93 | if ($mimes[$b['extension']] === 2) { |
||
94 | highlight_file($a); |
||
95 | exit; |
||
96 | } |
||
97 | header('Content-Type: ' .$mimes[$b['extension']]); |
||
98 | header('Content-Length: ' . filesize($a)); |
||
99 | readfile($a); |
||
100 | exit; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | class Extract_Phar |
||
105 | { |
||
106 | static $temp; |
||
107 | static $origdir; |
||
108 | const GZ = 0x1000; |
||
109 | const BZ2 = 0x2000; |
||
110 | const MASK = 0x3000; |
||
111 | const START = 'plugins/nocc_version/check_nocc_version.phps'; |
||
112 | const LEN = 6678; |
||
113 | |||
114 | static function go($return = false) |
||
115 | { |
||
116 | $fp = fopen(__FILE__, 'rb'); |
||
117 | fseek($fp, self::LEN); |
||
118 | $L = unpack('V', $a = fread($fp, 4)); |
||
119 | $m = ''; |
||
120 | |||
121 | do { |
||
122 | $read = 8192; |
||
123 | if ($L[1] - strlen($m) < 8192) { |
||
124 | $read = $L[1] - strlen($m); |
||
125 | } |
||
126 | $last = fread($fp, $read); |
||
127 | $m .= $last; |
||
128 | } while (strlen($last) && strlen($m) < $L[1]); |
||
129 | |||
130 | if (strlen($m) < $L[1]) { |
||
131 | die('ERROR: manifest length read was "' . |
||
132 | strlen($m) .'" should be "' . |
||
133 | $L[1] . '"'); |
||
134 | } |
||
135 | |||
136 | $info = self::_unpack($m); |
||
137 | $f = $info['c']; |
||
138 | |||
139 | if ($f & self::GZ) { |
||
140 | if (!function_exists('gzinflate')) { |
||
141 | die('Error: zlib extension is not enabled -' . |
||
142 | ' gzinflate() function needed for zlib-compressed .phars'); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | if ($f & self::BZ2) { |
||
147 | if (!function_exists('bzdecompress')) { |
||
148 | die('Error: bzip2 extension is not enabled -' . |
||
149 | ' bzdecompress() function needed for bz2-compressed .phars'); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | $temp = self::tmpdir(); |
||
154 | |||
155 | if (!$temp || !is_writable($temp)) { |
||
156 | $sessionpath = session_save_path(); |
||
157 | if (strpos ($sessionpath, ";") !== false) |
||
158 | $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); |
||
159 | if (!file_exists($sessionpath) || !is_dir($sessionpath)) { |
||
160 | die('Could not locate temporary directory to extract phar'); |
||
161 | } |
||
162 | $temp = $sessionpath; |
||
163 | } |
||
164 | |||
165 | $temp .= '/pharextract/'.basename(__FILE__, '.phar'); |
||
166 | self::$temp = $temp; |
||
167 | self::$origdir = getcwd(); |
||
168 | @mkdir($temp, 0777, true); |
||
169 | $temp = realpath($temp); |
||
170 | |||
171 | if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) { |
||
172 | self::_removeTmpFiles($temp, getcwd()); |
||
173 | @mkdir($temp, 0777, true); |
||
174 | @file_put_contents($temp . '/' . md5_file(__FILE__), ''); |
||
175 | |||
176 | foreach ($info['m'] as $path => $file) { |
||
177 | $a = !file_exists(dirname($temp . '/' . $path)); |
||
178 | @mkdir(dirname($temp . '/' . $path), 0777, true); |
||
179 | clearstatcache(); |
||
180 | |||
181 | if ($path[strlen($path) - 1] == '/') { |
||
182 | @mkdir($temp . '/' . $path, 0777); |
||
183 | } else { |
||
184 | file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); |
||
185 | @chmod($temp . '/' . $path, 0666); |
||
186 | } |
||
187 | } |
||
188 | } |
||
189 | |||
190 | chdir($temp); |
||
191 | |||
192 | if (!$return) { |
||
193 | include self::START; |
||
194 | } |
||
195 | } |
||
196 | |||
197 | static function tmpdir() |
||
198 | { |
||
199 | if (strpos(PHP_OS, 'WIN') !== false) { |
||
200 | if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { |
||
201 | return $var; |
||
202 | } |
||
203 | if (is_dir('/temp') || mkdir('/temp')) { |
||
204 | return realpath('/temp'); |
||
205 | } |
||
206 | return false; |
||
207 | } |
||
208 | if ($var = getenv('TMPDIR')) { |
||
209 | return $var; |
||
210 | } |
||
211 | return realpath('/tmp'); |
||
212 | } |
||
213 | |||
214 | static function _unpack($m) |
||
215 | { |
||
216 | $info = unpack('V', substr($m, 0, 4)); |
||
217 | $l = unpack('V', substr($m, 10, 4)); |
||
218 | $m = substr($m, 14 + $l[1]); |
||
219 | $s = unpack('V', substr($m, 0, 4)); |
||
220 | $o = 0; |
||
221 | $start = 4 + $s[1]; |
||
222 | $ret['c'] = 0; |
||
223 | |||
224 | for ($i = 0; $i < $info[1]; $i++) { |
||
225 | $len = unpack('V', substr($m, $start, 4)); |
||
226 | $start += 4; |
||
227 | $savepath = substr($m, $start, $len[1]); |
||
228 | $start += $len[1]; |
||
229 | $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24))); |
||
230 | $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3] |
||
231 | & 0xffffffff); |
||
232 | $ret['m'][$savepath][7] = $o; |
||
233 | $o += $ret['m'][$savepath][2]; |
||
234 | $start += 24 + $ret['m'][$savepath][5]; |
||
235 | $ret['c'] |= $ret['m'][$savepath][4] & self::MASK; |
||
236 | } |
||
237 | return $ret; |
||
238 | } |
||
239 | |||
240 | static function extractFile($path, $entry, $fp) |
||
241 | { |
||
242 | $data = ''; |
||
243 | $c = $entry[2]; |
||
244 | |||
245 | while ($c) { |
||
246 | if ($c < 8192) { |
||
247 | $data .= @fread($fp, $c); |
||
248 | $c = 0; |
||
249 | } else { |
||
250 | $c -= 8192; |
||
251 | $data .= @fread($fp, 8192); |
||
252 | } |
||
253 | } |
||
254 | |||
255 | if ($entry[4] & self::GZ) { |
||
256 | $data = gzinflate($data); |
||
257 | } elseif ($entry[4] & self::BZ2) { |
||
258 | $data = bzdecompress($data); |
||
259 | } |
||
260 | |||
261 | if (strlen($data) != $entry[0]) { |
||
262 | die("Invalid internal .phar file (size error " . strlen($data) . " != " . |
||
263 | $stat[7] . ")"); |
||
264 | } |
||
265 | |||
266 | if ($entry[3] != sprintf("%u", crc32($data) & 0xffffffff)) { |
||
267 | die("Invalid internal .phar file (checksum error)"); |
||
268 | } |
||
269 | |||
270 | return $data; |
||
271 | } |
||
272 | |||
273 | static function _removeTmpFiles($temp, $origdir) |
||
274 | { |
||
275 | chdir($temp); |
||
276 | |||
277 | foreach (glob('*') as $f) { |
||
278 | if (file_exists($f)) { |
||
279 | is_dir($f) ? @rmdir($f) : @unlink($f); |
||
280 | if (file_exists($f) && is_dir($f)) { |
||
281 | self::_removeTmpFiles($f, getcwd()); |
||
282 | } |
||
283 | } |
||
284 | } |
||
285 | |||
286 | @rmdir($temp); |
||
287 | clearstatcache(); |
||
288 | chdir($origdir); |
||
289 | } |
||
290 | } |
||
291 | |||
292 | Extract_Phar::go(); |
||
293 | __HALT_COMPILER(); ?> |
||
87 | daniel-mar | 294 | § Æ a:1:{s:23:"1.3.6.1.4.1.37476.3.0.2";s:408:"sha256||<builder>|481cf75d675006b504520fd2acb3b29c89aea03aab64754e0adfb364de4914b2||framework/vnag_framework.inc.php|9e02df09f244b276c0af9c19dda83683078b6044abb37078aeb6a2159a74bac4||plugins/nocc_version/NoccVersionCheck.class.php|0a29f14c1ff9bdfbde36a4cf4170a1b9bd91d05c3afd48e71b1aec064a39e2e8||plugins/nocc_version/check_nocc_version.phps|864d56ebad78157dd96aae0ae4ea59ec566f61a1c090e6cb0b59866d7b95790e||";} framework/vnag_framework.inc.phpBÙ BÙ Þß=¤ / plugins/nocc_version/NoccVersionCheck.class.phpu |
295 | |||
296 | |||
80 | daniel-mar | 297 | if (!VNag::is_http_mode()) error_reporting(E_ALL); declare(ticks=1); set_time_limit(0); define('VNAG_JSONDATA_V1', 'oid:1.3.6.1.4.1.37476.2.3.1.1'); $OVERWRITE_ARGUMENTS = null; function _empty($x) { return is_null($x) || (trim($x) == ''); } abstract class VNag { const VNAG_VERSION = '2023-10-13'; const STATUS_OK = 0; const STATUS_WARNING = 1; const STATUS_CRITICAL = 2; const STATUS_UNKNOWN = 3; const STATUS_ERROR = 4; const STATUS_UP = 0; const STATUS_DOWN = 1; const STATUS_MAINTAIN = 2; const VERBOSITY_SUMMARY = 0; const VERBOSITY_ADDITIONAL_INFORMATION = 1; const VERBOSITY_CONFIGURATION_DEBUG = 2; const VERBOSITY_PLUGIN_DEBUG = 3; const MAX_VERBOSITY = self::VERBOSITY_PLUGIN_DEBUG; const STATUSMODEL_SERVICE = 0; const STATUSMODEL_HOST = 1; private $initialized = false; private $status = null; private $messages = array(); private $verbose_info = ''; private $warningRanges = array(); private $criticalRanges = array(); private $performanceDataObjects = array(); private static $exitcode = 0; private $helpObj = null; private $argHandler = null; const OUTPUT_NEVER = 0; const OUTPUT_SPECIAL = 1; const OUTPUT_NORMAL = 2; const OUTPUT_EXCEPTION = 4; const OUTPUT_ALWAYS = 7; public $http_visual_output = self::OUTPUT_ALWAYS; public $http_invisible_output = self::OUTPUT_ALWAYS; protected $html_before = ''; protected $html_after = ''; protected $statusmodel = self::STATUSMODEL_SERVICE; protected $show_status_in_headline = true; protected $default_status = self::STATUS_UNKNOWN; protected $default_warning_range = null; protected $default_critical_range = null; protected $argWarning; protected $argCritical; protected $argVersion; protected $argVerbosity; protected $argTimeout; protected $argHelp; protected $argUsage; public $id = null; protected static $http_serial_number = 0; public $privkey = null; public $privkey_password = null; public $sign_algo = null; public $pubkey = null; protected $warningSingleValueRangeBehaviors = array(self::SINGLEVALUE_RANGE_DEFAULT); protected $criticalSingleValueRangeBehaviors = array(self::SINGLEVALUE_RANGE_DEFAULT); const SINGLEVALUE_RANGE_DEFAULT = 0; const SINGLEVALUE_RANGE_VAL_GT_X_BAD = 1; const SINGLEVALUE_RANGE_VAL_GE_X_BAD = 2; const SINGLEVALUE_RANGE_VAL_LT_X_BAD = 3; const SINGLEVALUE_RANGE_VAL_LE_X_BAD = 4; public $password_out = null; public $password_in = null; public static function is_http_mode() { return php_sapi_name() !== 'cli'; } public function getHelpManager() { return $this->helpObj; } public function getArgumentHandler() { return $this->argHandler; } public function outputHTML($text, $after_visual_output=true) { if ($this->is_http_mode()) { if ($this->initialized) { if ($after_visual_output) { $this->html_after .= $text; } else { $this->html_before .= $text; } } else { echo $text; } } } protected function resetArguments() { $this->argWarning = null; $this->argCritical = null; $this->argVersion = null; $this->argVerbosity = null; $this->argTimeout = null; $this->argHelp = null; $this->argWarning = null; $this->argCritical = null; } public function registerExpectedStandardArguments($args) { $this->resetArguments(); for ($i=0; $i<strlen($args); $i++) { switch ($args[$i]) { case 'w': $this->addExpectedArgument($this->argWarning = new VNagArgument('w', 'warning', VNagArgument::VALUE_REQUIRED, VNagLang::$argname_value, VNagLang::$warning_range)); break; case 'c': $this->addExpectedArgument($this->argCritical = new VNagArgument('c', 'critical', VNagArgument::VALUE_REQUIRED, VNagLang::$argname_value, VNagLang::$critical_range)); break; case 'V': $this->addExpectedArgument($this->argVersion = new VNagArgument('V', 'version', VNagArgument::VALUE_FORBIDDEN, null, VNagLang::$prints_version)); break; case 'v': $this->addExpectedArgument($this->argVerbosity = new VNagArgument('v', 'verbose', VNagArgument::VALUE_FORBIDDEN, null, VNagLang::$verbosity_helptext)); break; case 't': $this->addExpectedArgument($this->argTimeout = new VNagArgument('t', 'timeout', VNagArgument::VALUE_REQUIRED, VNagLang::$argname_seconds, VNagLang::$timeout_helptext)); break; case 'h': $this->addExpectedArgument($this->argHelp = new VNagArgument('h', 'help', VNagArgument::VALUE_FORBIDDEN, null, VNagLang::$help_helptext)); break; default: $letter = $args[$i]; throw new VNagInvalidStandardArgument(sprintf(VNagLang::$no_standard_arguments_with_letter, $letter)); } } } public function addExpectedArgument($argObj) { $helpObjAddEntryMethod = new ReflectionMethod($this->helpObj, '_addOption'); $helpObjAddEntryMethod->setAccessible(true); $helpObjAddEntryMethod->invoke($this->helpObj, $argObj); $argHandlerAddEntryMethod = new ReflectionMethod($this->argHandler, '_addExpectedArgument'); $argHandlerAddEntryMethod->setAccessible(true); $argHandlerAddEntryMethod->invoke($this->argHandler, $argObj); } protected function createArgumentHandler() { $this->argHandler = new VNagArgumentHandler(); } protected function createHelpObject() { $this->helpObj = new VNagHelp(); } protected function checkInitialized() { if (!$this->initialized) throw new VNagFunctionCallOutsideSession(); } protected function getVerbosityLevel() { $this->checkInitialized(); if (!isset($this->argVerbosity)) { return self::VERBOSITY_SUMMARY; } else { $level = $this->argVerbosity->count(); if ($level > self::MAX_VERBOSITY) $level = self::MAX_VERBOSITY; return $level; } } public function getWarningRange($argumentNumber=0) { $this->checkInitialized(); if (!isset($this->warningRanges[$argumentNumber])) { if (!is_null($this->argWarning)) { $warning = $this->argWarning->getValue(); if (!is_null($warning)) { $vals = explode(',',$warning); foreach ($vals as $number => $val) { if (_empty($val)) { $this->warningRanges[$number] = null; } else { $singleValueBehavior = isset($this->warningSingleValueRangeBehaviors[$number]) ? $this->warningSingleValueRangeBehaviors[$number] : VNag::SINGLEVALUE_RANGE_DEFAULT; $this->warningRanges[$number] = new VNagRange($val, $singleValueBehavior); } } } else { $this->warningRanges[0] = $this->default_warning_range; } } else { return null; } } if (isset($this->warningRanges[$argumentNumber])) { return $this->warningRanges[$argumentNumber]; } else { return null; } } public function getCriticalRange($argumentNumber=0) { $this->checkInitialized(); if (!isset($this->criticalRanges[$argumentNumber])) { if (!is_null($this->argCritical)) { $critical = $this->argCritical->getValue(); if (!is_null($critical)) { $vals = explode(',',$critical); foreach ($vals as $number => $val) { $singleValueBehavior = isset($this->criticalSingleValueRangeBehaviors[$number]) ? $this->criticalSingleValueRangeBehaviors[$number] : VNag::SINGLEVALUE_RANGE_DEFAULT; $this->criticalRanges[$number] = new VNagRange($val, $singleValueBehavior); } } else { $this->criticalRanges[0] = $this->default_critical_range; } } else { return null; } } if (isset($this->criticalRanges[$argumentNumber])) { return $this->criticalRanges[$argumentNumber]; } else { return null; } } public function checkAgainstWarningRange($values, $force=true, $autostatus=true, $argumentNumber=0) { $this->checkInitialized(); if (!$this->getArgumentHandler()->isArgRegistered('w')) { throw new VNagRequiredArgumentNotRegistered('-w'); } $wr = $this->getWarningRange($argumentNumber); if (isset($wr)) { if ($wr->checkAlert($values)) { if ($autostatus) $this->setStatus(VNag::STATUS_WARNING); return true; } else { if ($autostatus) $this->setStatus(VNag::STATUS_OK); return false; } } else { if ($force) { if (($argumentNumber > 0) && (count($this->warningRanges) > 0)) { throw new VNagInvalidArgumentException(sprintf(VNagLang::$too_few_warning_ranges, $argumentNumber+1)); } else { throw new VNagRequiredArgumentMissing('-w'); } } } } public function checkAgainstCriticalRange($values, $force=true, $autostatus=true, $argumentNumber=0) { $this->checkInitialized(); if (!$this->getArgumentHandler()->isArgRegistered('c')) { throw new VNagRequiredArgumentNotRegistered('-c'); } $cr = $this->getCriticalRange($argumentNumber); if (isset($cr)) { if ($cr->checkAlert($values)) { if ($autostatus) $this->setStatus(VNag::STATUS_CRITICAL); return true; } else { if ($autostatus) $this->setStatus(VNag::STATUS_OK); return false; } } else { if ($force) { if (($argumentNumber > 0) && (count($this->warningRanges) > 0)) { throw new VNagInvalidArgumentException(sprintf(VNagLang::$too_few_critical_ranges, $argumentNumber+1)); } else { throw new VNagRequiredArgumentMissing('-c'); } } } } protected static function getBaddestExitcode($code1, $code2) { return max($code1, $code2); } public static function _shutdownHandler() { if (!self::is_http_mode()) { exit((int)self::$exitcode); } } protected function _exit($code) { self::$exitcode = $this->getBaddestExitcode($code, self::$exitcode); } private $constructed = false; function __construct() { $this->createHelpObject(); $this->createArgumentHandler(); $this->addExpectedArgument($this->argUsage = new VNagArgument('?', '', VNagArgument::VALUE_FORBIDDEN, null, VNagLang::$prints_usage)); $this->constructed = true; } function __destruct() { if (Timeouter::started()) { Timeouter::end(); } } public function run() { global $inside_vnag_run; $inside_vnag_run = true; try { if (!$this->constructed) { throw new VNagNotConstructed(VNagLang::$notConstructed); } try { $this->initialized = true; $this->html_before = ''; $this->html_after = ''; $this->setStatus(null, true); $this->messages = array(); register_shutdown_function(array($this, '_shutdownHandler')); if ($this->argHandler->illegalUsage()) { $content = $this->helpObj->printUsagePage(); $this->setStatus(VNag::STATUS_UNKNOWN); if ($this->is_http_mode()) { echo $this->html_before; if ($this->http_visual_output & VNag::OUTPUT_SPECIAL) echo $this->writeVisualHTML($content); if ($this->http_invisible_output & VNag::OUTPUT_SPECIAL) echo $this->writeInvisibleHTML($content); echo $this->html_after; return; } else { echo $content; return $this->_exit($this->status); } } if (!is_null($this->argVersion) && ($this->argVersion->available())) { $content = $this->helpObj->printVersionPage(); $this->setStatus(VNag::STATUS_UNKNOWN); if ($this->is_http_mode()) { echo $this->html_before; if ($this->http_visual_output & VNag::OUTPUT_SPECIAL) echo $this->writeVisualHTML($content); if ($this->http_invisible_output & VNag::OUTPUT_SPECIAL) echo $this->writeInvisibleHTML($content); echo $this->html_after; return; } else { echo $content; return $this->_exit($this->status); } } if (!is_null($this->argHelp) && ($this->argHelp->available())) { $content = $this->helpObj->printHelpPage(); $this->setStatus(VNag::STATUS_UNKNOWN); if ($this->is_http_mode()) { echo $this->html_before; if ($this->http_visual_output & VNag::OUTPUT_SPECIAL) echo $this->writeVisualHTML($content); if ($this->http_invisible_output & VNag::OUTPUT_SPECIAL) echo $this->writeInvisibleHTML($content); echo $this->html_after; return; } else { echo $content; return $this->_exit($this->status); } } $this->getWarningRange(); $this->getCriticalRange(); if (!is_null($this->argTimeout)) { $timeout = $this->argTimeout->getValue(); if (!is_null($timeout)) { Timeouter::start($timeout); } } ob_start(); $init_ob_level = ob_get_level(); try { $this->cbRun(); if (ob_get_level() < $init_ob_level) throw new VNagImplementationErrorException(VNagLang::$output_level_lowered); } finally { while (ob_get_level() > $init_ob_level) @ob_end_clean(); } if (is_null($this->status)) $this->setStatus($this->default_status,true); $outputType = VNag::OUTPUT_NORMAL; } catch (Exception $e) { $this->handleException($e); $outputType = VNag::OUTPUT_EXCEPTION; } if ($this->is_http_mode()) { echo $this->html_before; if ($this->http_invisible_output & $outputType) { echo $this->writeInvisibleHTML(); } if ($this->http_visual_output & $outputType) { echo $this->writeVisualHTML(); } echo $this->html_after; } else { echo $this->getNagiosConsoleText(); return $this->_exit($this->status); } Timeouter::end(); } finally { $inside_vnag_run = false; } } private function getNagiosConsoleText() { $ary_perfdata = $this->getPerformanceData(); $performancedata_first = array_shift($ary_perfdata); $performancedata_rest = implode(' ', $ary_perfdata); $status_text = VNagLang::status($this->status, $this->statusmodel); if (_empty($this->getHeadline())) { $content = $status_text; } else { if ($this->show_status_in_headline) { $content = $status_text.': '.$this->getHeadline(); } else { $content = $this->getHeadline(); } } if (!_empty($performancedata_first)) $content .= '|'.trim($performancedata_first); $content .= "\n"; if (!_empty($this->verbose_info)) { $content .= trim($this->verbose_info); } if (!_empty($performancedata_rest)) $content .= '|'.trim($performancedata_rest); $content .= "\n"; return trim($content)."\n"; } abstract protected function cbRun(); public function addPerformanceData($prefDataObj, $move_to_font=false, $verbosityLevel=VNag::VERBOSITY_SUMMARY) { $this->checkInitialized(); if ((!isset($this->argVerbosity)) && ($verbosityLevel > VNag::VERBOSITY_SUMMARY)) throw new VNagRequiredArgumentNotRegistered('-v'); if (self::getVerbosityLevel() < $verbosityLevel) return false; if ($move_to_font) { array_unshift($this->performanceDataObjects, $prefDataObj); } else { $this->performanceDataObjects[] = $prefDataObj; } return true; } public function getPerformanceData() { $this->checkInitialized(); return $this->performanceDataObjects; } public function removePerformanceData($prefDataObj) { if (($key = array_search($prefDataObj, $this->performanceDataObjects, true)) !== false) { unset($this->performanceDataObjects[$key]); return true; } else { return false; } } public function clearPerformanceData() { $this->performanceDataObjects = array(); } public function getVerboseInfo() { return $this->verbose_info; } public function clearVerboseInfo() { $this->verbose_info = ''; } private function writeVisualHTML($special_content=null) { if (!_empty($special_content)) { $content = $special_content; } else { $content = strtoupper(VNagLang::$status.': '.VNagLang::status($this->status, $this->statusmodel))."\n\n"; $content .= strtoupper(VNagLang::$message).":\n"; $status_text = VNagLang::status($this->status, $this->statusmodel); if (_empty($this->getHeadline())) { $content .= $status_text; } else { if ($this->show_status_in_headline) { $content .= $status_text.': '.trim($this->getHeadline()); } else { $content .= trim($this->getHeadline()); } } $content .= "\n\n"; if (!_empty($this->verbose_info)) { $content .= strtoupper(VNagLang::$verbose_info).":\n".trim($this->verbose_info)."\n\n"; } $perfdata = $this->getPerformanceData(); if (count($perfdata) > 0) { $content .= strtoupper(VNagLang::$performance_data).":\n"; foreach ($perfdata as $pd) { $content .= trim($pd)."\n"; } $content .= "\n"; } } $colorinfo = ''; $status = $this->getStatus(); if ($status == VNag::STATUS_OK) $colorinfo = ' style="background-color:green;color:white;font-weight:bold"'; else if ($status == VNag::STATUS_WARNING) $colorinfo = ' style="background-color:yellow;color:black;font-weight:bold"'; else if ($status == VNag::STATUS_CRITICAL) $colorinfo = ' style="background-color:red;color:white;font-weight:bold"'; else if ($status == VNag::STATUS_ERROR) $colorinfo = ' style="background-color:purple;color:white;font-weight:bold"'; else $colorinfo = ' style="background-color:lightgray;color:black;font-weight:bold"'; $html_content = trim($content); $html_content = htmlentities($html_content); $html_content = str_replace(' ', ' ', $html_content); $html_content = nl2br($html_content); return '<table border="1" cellspacing="2" cellpadding="2" style="width:100%" class="vnag_table">'. '<tr'.$colorinfo.' class="vnag_title_row">'. '<td>'.VNagLang::$nagios_output.'</td>'. '</tr>'. '<tr class="vnag_message_row">'. '<td><code>'. $html_content. '</code></td>'. '</tr>'. '</table>'; } protected function readInvisibleHTML($html) { $this->checkInitialized(); $doc = new DOMDocument(); @$doc->loadHTML($html); $tags = $doc->getElementsByTagName('script'); foreach ($tags as $tag) { $type = $tag->getAttribute('type'); if ($type !== 'application/json') continue; $json = $tag->nodeValue; if (!$json) continue; $data = @json_decode($json,true); if (!is_array($data)) continue; if (!isset($data['type'])) continue; if ($data['type'] === VNAG_JSONDATA_V1) { if (!isset($data['datasets'])) throw new VNagWebInfoException(VNagLang::$dataset_missing); foreach ($data['datasets'] as $dataset) { $payload = base64_decode($dataset['payload']); if (!$payload) { throw new VNagWebInfoException(VNagLang::$payload_not_base64); } if (isset($dataset['encryption'])) { $cryptInfo = $dataset['encryption']; if (!is_array($cryptInfo)) { throw new VNagWebInfoException(VNagLang::$dataset_encryption_no_array); } $password = is_null($this->password_in) ? '' : $this->password_in; $salt = base64_decode($cryptInfo['salt']); if ($cryptInfo['hash'] != hash('sha256',$salt.$password)) { if ($password == '') { throw new VNagWebInfoException(VNagLang::$require_password); } else { throw new VNagWebInfoException(VNagLang::$wrong_password); } } if (!function_exists('openssl_decrypt')) { throw new VNagException(VNagLang::$openssl_missing); } $payload = openssl_decrypt($payload, $cryptInfo['method'], $password, 0, $cryptInfo['iv']); } if (!is_null($this->pubkey) && ($this->pubkey !== '')) { if (substr($this->pubkey,0,3) === '---') { $public_key = $this->pubkey; } else { if (!file_exists($this->pubkey)) { throw new VNagInvalidArgumentException(sprintf(VNagLang::$pubkey_file_not_found, $this->pubkey)); } $public_key = @file_get_contents($this->pubkey); if (!$public_key) { throw new VNagPublicKeyException(sprintf(VNagLang::$pubkey_file_not_readable, $this->pubkey)); } } if (!isset($dataset['signature'])) { throw new VNagSignatureException(VNagLang::$signature_missing); } $signature = base64_decode($dataset['signature']); if (!$signature) { throw new VNagSignatureException(VNagLang::$signature_not_bas64); } if (!function_exists('openssl_verify')) { throw new VNagException(VNagLang::$openssl_missing); } $sign_algo = is_null($this->sign_algo) ? OPENSSL_ALGO_SHA256 : $this->sign_algo; if (!openssl_verify($payload, $signature, $public_key, $sign_algo)) { throw new VNagSignatureException(VNagLang::$signature_invalid); } } $payload = @json_decode($payload,true); if (!$payload) { throw new VNagWebInfoException(VNagLang::$payload_not_json); } if ($payload['id'] == $this->id) { return $payload; } } } } return null; } private function getNextMonitorID($peek=false) { $result = is_null($this->id) ? self::$http_serial_number : $this->id; if (!$peek) { $this->id = null; self::$http_serial_number++; } return $result; } private function writeInvisibleHTML($special_content=null) { $payload['id'] = $this->getNextMonitorID(); $payload['status'] = $this->getStatus(); if (!_empty($special_content)) { $payload['text'] = $special_content; } else { $payload['headline'] = $this->getHeadline(); $payload['verbose_info'] = $this->verbose_info; $payload['performance_data'] = array(); foreach ($this->performanceDataObjects as $perfdata) { $payload['performance_data'][] = (string)$perfdata; } } $payload = json_encode($payload); $dataset = array(); if (!is_null($this->privkey) && ($this->privkey !== '')) { if (!function_exists('openssl_pkey_get_private') || !function_exists('openssl_sign')) { throw new VNagException(VNagLang::$openssl_missing); } if (substr($this->privkey,0,3) === '---') { $pkeyid = @openssl_pkey_get_private($this->privkey, $this->privkey_password); if (!$pkeyid) { throw new VNagPrivateKeyException(sprintf(VNagLang::$privkey_not_readable)); } } else { if (!file_exists($this->privkey)) { throw new VNagInvalidArgumentException(sprintf(VNagLang::$privkey_file_not_found, $this->privkey)); } $pkeyid = @openssl_pkey_get_private('file://'.$this->privkey, $this->privkey_password); if (!$pkeyid) { throw new VNagPrivateKeyException(sprintf(VNagLang::$privkey_file_not_readable, $this->privkey)); } } $signature = ''; $sign_algo = is_null($this->sign_algo) ? OPENSSL_ALGO_SHA256 : $this->sign_algo; if (@openssl_sign($payload, $signature, $pkeyid, $sign_algo)) { if (version_compare(PHP_VERSION, '8.0.0') < 0) { openssl_free_key($pkeyid); } $dataset['signature'] = base64_encode($signature); } else { throw new VNagPrivateKeyException(sprintf(VNagLang::$signature_failed)); } } if (!is_null($this->password_out) && ($this->password_out !== '')) { if (!function_exists('openssl_encrypt')) { throw new VNagException(VNagLang::$openssl_missing); } $password = $this->password_out; $method = 'aes-256-ofb'; $iv = substr(hash('sha256', openssl_random_pseudo_bytes(32)), 0, 16); $salt = openssl_random_pseudo_bytes(32); $cryptInfo = array(); $cryptInfo['method'] = $method; $cryptInfo['iv'] = $iv; $cryptInfo['salt'] = base64_encode($salt); $cryptInfo['hash'] = hash('sha256', $salt.$password); $payload = openssl_encrypt($payload, $method, $password, 0, $iv); $dataset['encryption'] = $cryptInfo; } $dataset['payload'] = base64_encode($payload); $json = array(); $json['type'] = VNAG_JSONDATA_V1; $json['datasets'] = array($dataset); return '<script type="application/json">'. json_encode($json). '</script>'; } protected function appendHeadline($msg) { $this->checkInitialized(); if (_empty($msg)) return false; $this->messages[] = $msg; return true; } protected function changeHeadline($msg) { $this->checkInitialized(); if (_empty($msg)) { $this->messages = array(); } else { $this->messages = array($msg); } return true; } public function setHeadline($msg, $append=false, $verbosityLevel=VNag::VERBOSITY_SUMMARY) { $this->checkInitialized(); if ((!isset($this->argVerbosity)) && ($verbosityLevel > VNag::VERBOSITY_SUMMARY)) throw new VNagRequiredArgumentNotRegistered('-v'); if (self::getVerbosityLevel() < $verbosityLevel) $msg = ''; if ($append) { return $this->appendHeadline($msg); } else { return $this->changeHeadline($msg); } } public function getHeadline() { $this->checkInitialized(); return implode(', ', $this->messages); } public function addVerboseMessage($msg, $verbosityLevel=VNag::VERBOSITY_SUMMARY) { $this->checkInitialized(); if (self::getVerbosityLevel() >= $verbosityLevel) { $this->verbose_info .= $msg."\n"; } } public function setStatus($status, $force=false) { $this->checkInitialized(); if (($force) || is_null($this->status) || ($status > $this->status)) { $this->status = $status; } } public function getStatus() { $this->checkInitialized(); return $this->status; } protected static function exceptionText($exception) { $class = get_class($exception); $msg = $exception->getMessage(); if (!_empty($msg)) { return sprintf(VNagLang::$exception_x, $msg, $class); } else { return sprintf(VNagLang::$unhandled_exception_without_msg, $class); } } protected function handleException($exception) { $this->checkInitialized(); if (!VNag::is_http_mode()) { while (ob_get_level() > 0) @ob_end_clean(); } $this->clearVerboseInfo(); $this->clearPerformanceData(); if ($exception instanceof VNagException) { $this->setStatus($exception->getStatus()); } else { $this->setStatus(self::STATUS_ERROR); } $this->setHeadline($this->exceptionText($exception), false); if ($exception instanceof VNagImplementationErrorException) { $this->addVerboseMessage($exception->getTraceAsString(), VNag::VERBOSITY_SUMMARY); } else { if (isset($this->argVerbosity)) { $this->addVerboseMessage($exception->getTraceAsString(), VNag::VERBOSITY_ADDITIONAL_INFORMATION); } else { } } } protected function get_cache_dir() { $homedir = @getenv('HOME'); if ($homedir && is_dir($homedir)) { $try = "$homedir/.vnag/cache"; if (is_dir($try)) return $try; if (@mkdir($try,0777,true)) return $try; } $user = posix_getpwuid(posix_geteuid()); if (isset($user['dir']) && is_dir($user['dir'])) { $homedir = $user['dir']; $try = "$homedir/.vnag/cache"; if (is_dir($try)) return $try; if (@mkdir($try,0777,true)) return $try; } if (isset($user['name']) && is_dir($user['name'])) { $username = $user['name']; $try = "/tmp/vnag/cache"; if (is_dir($try)) return $try; if (@mkdir($try,0777,true)) return $try; } throw new VNagException("Cannot get cache dir"); } protected function url_get_contents($url, $max_cache_time=1*60*60, $context=null) { $cache_file = $this->get_cache_dir().'/'.hash('sha256',$url); if (file_exists($cache_file) && (time()-filemtime($cache_file) < $max_cache_time)) { $cont = @file_get_contents($cache_file); if ($cont === false) throw new Exception("Failed to get contents from $cache_file"); } else { $options = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" ) ); if (is_null($context)) $context = stream_context_create($options); $cont = @file_get_contents($url, false, $context); if ($cont === false) throw new Exception("Failed to get contents from $url"); file_put_contents($cache_file, $cont); } return $cont; } } class VNagException extends Exception { public function getStatus() { return VNag::STATUS_ERROR; } } class VNagTimeoutException extends VNagException {} class VNagWebInfoException extends VNagException {} class VNagSignatureException extends VNagException {} class VNagPublicKeyException extends VNagException {} class VNagPrivateKeyException extends VNagException {} class VNagInvalidArgumentException extends VNagException { public function getStatus() { return VNag::STATUS_UNKNOWN; } } class VNagValueUomPairSyntaxException extends VNagInvalidArgumentException { public function __construct($str) { $e_msg = sprintf(VNagLang::$valueUomPairSyntaxError, $str); parent::__construct($e_msg); } } class VNagInvalidTimeoutException extends VNagInvalidArgumentException {} class VNagInvalidRangeException extends VNagInvalidArgumentException { public function __construct($msg) { $e_msg = VNagLang::$range_is_invalid; if (!_empty($msg)) $e_msg .= ': '.trim($msg); parent::__construct($e_msg); } } class VNagInvalidShortOpt extends VNagImplementationErrorException {} class VNagInvalidLongOpt extends VNagImplementationErrorException {} class VNagInvalidValuePolicy extends VNagImplementationErrorException {} class VNagIllegalStatusModel extends VNagImplementationErrorException {} class VNagNotConstructed extends VNagImplementationErrorException {} class VNagImplementationErrorException extends VNagException {} class VNagInvalidStandardArgument extends VNagImplementationErrorException {} class VNagFunctionCallOutsideSession extends VNagImplementationErrorException {} class VNagIllegalArgumentValuesException extends VNagImplementationErrorException {} class VNagRequiredArgumentNotRegistered extends VNagImplementationErrorException { public function __construct($required_argument) { $e_msg = sprintf(VNagLang::$query_without_expected_argument, $required_argument); parent::__construct($e_msg); } } class VNagRequiredArgumentMissing extends VNagInvalidArgumentException { public function __construct($required_argument) { $e_msg = sprintf(VNagLang::$required_argument_missing, $required_argument); parent::__construct($e_msg); } } class VNagUnknownUomException extends VNagInvalidArgumentException { public function __construct($uom) { $e_msg = sprintf(VNagLang::$perfdata_uom_not_recognized, $uom); parent::__construct($e_msg); } } class VNagNoCompatibleRangeUomFoundException extends VNagException {} class VNagMixedUomsNotImplemented extends VNagInvalidArgumentException { public function __construct($uom1, $uom2) { if (_empty($uom1)) $uom1 = VNagLang::$none; if (_empty($uom2)) $uom2 = VNagLang::$none; $e_msg = sprintf(VNagLang::$perfdata_mixed_uom_not_implemented, $uom1, $uom2); parent::__construct($e_msg); } } class VNagUomConvertException extends VNagInvalidArgumentException { public function __construct($uom1, $uom2) { if (_empty($uom1)) $uom1 = VNagLang::$none; if (_empty($uom2)) $uom2 = VNagLang::$none; $e_msg = sprintf(VNagLang::$convert_x_y_error, $uom1, $uom2); parent::__construct($e_msg); } } class VNagInvalidPerformanceDataException extends VNagInvalidArgumentException { public function __construct($msg) { $e_msg = VNagLang::$performance_data_invalid; if (!_empty($msg)) $e_msg .= ': '.trim($msg); parent::__construct($e_msg); } } class Timeouter { private static $start_time = false; private static $timeout; private static $fired = false; private static $registered = false; private function __construct() { } public static function start($timeout) { if (!is_numeric($timeout) || ($timeout <= 0)) { throw new VNagInvalidTimeoutException(sprintf(VNagLang::$timeout_value_invalid, $timeout)); } self::$start_time = microtime(true); self::$timeout = (float) $timeout; self::$fired = false; if (!self::$registered) { self::$registered = true; register_tick_function(array('Timeouter', 'tick')); } } public static function started() { return self::$registered; } public static function end() { if (self::$registered) { unregister_tick_function(array('Timeouter', 'tick')); self::$registered = false; } } public static function tick() { if ((!self::$fired) && ((microtime(true) - self::$start_time) > self::$timeout)) { self::$fired = true; throw new VNagTimeoutException(VNagLang::$timeout_exception); } } } class VNagArgument { const VALUE_FORBIDDEN = 0; const VALUE_REQUIRED = 1; const VALUE_OPTIONAL = 2; protected $shortopt; protected $longopts; protected $valuePolicy; protected $valueName; protected $helpText; protected $defaultValue = null; protected static $all_short = ''; protected static $all_long = array(); public function getShortOpt() { return $this->shortopt; } public function getLongOpts() { return $this->longopts; } public function getValuePolicy() { return $this->valuePolicy; } public function getValueName() { return $this->valueName; } public function getHelpText() { return $this->helpText; } static private function validateShortOpt($shortopt) { $m = array(); return preg_match('@^[a-zA-Z0-9\\+\\-\\?]$@', $shortopt, $m); } static private function validateLongOpt($longopt) { $m = array(); return preg_match('@^[a-zA-Z0-9\\+\\-\\?]+$@', $longopt, $m); } public function __construct($shortopt, $longopts, $valuePolicy, $valueName, $helpText, $defaultValue=null) { switch ($valuePolicy) { case VNagArgument::VALUE_FORBIDDEN: if (!_empty($valueName)) { throw new VNagImplementationErrorException(sprintf(VNagLang::$value_name_forbidden)); } break; case VNagArgument::VALUE_REQUIRED: if (_empty($valueName)) { throw new VNagImplementationErrorException(sprintf(VNagLang::$value_name_required)); } break; case VNagArgument::VALUE_OPTIONAL: if (_empty($valueName)) { throw new VNagImplementationErrorException(sprintf(VNagLang::$value_name_required)); } break; default: throw new VNagInvalidValuePolicy(sprintf(VNagLang::$illegal_valuepolicy, $valuePolicy)); } if (!_empty($shortopt)) { if (!self::validateShortOpt($shortopt)) { throw new VNagInvalidShortOpt(sprintf(VNagLang::$illegal_shortopt, $shortopt)); } } if (is_array($longopts)) { foreach ($longopts as $longopt) { if (!self::validateLongOpt($longopt)) { throw new VNagInvalidLongOpt(sprintf(VNagLang::$illegal_longopt, $longopt)); } } } else if (!_empty($longopts)) { if (!self::validateLongOpt($longopts)) { throw new VNagInvalidLongOpt(sprintf(VNagLang::$illegal_longopt, $longopts)); } $longopts = array($longopts); } else { $longopts = array(); } switch ($valuePolicy) { case VNagArgument::VALUE_FORBIDDEN: $policyApdx = ''; break; case VNagArgument::VALUE_REQUIRED: $policyApdx = ':'; break; case VNagArgument::VALUE_OPTIONAL: $policyApdx = '::'; break; default: throw new VNagInvalidValuePolicy(sprintf(VNagLang::$illegal_valuepolicy, $valuePolicy)); } if ((!is_null($shortopt)) && ($shortopt != '?')) self::$all_short .= $shortopt.$policyApdx; if (is_array($longopts)) { foreach ($longopts as $longopt) { self::$all_long[] = $longopt.$policyApdx; } } $this->shortopt = $shortopt; $this->longopts = $longopts; $this->valuePolicy = $valuePolicy; $this->valueName = $valueName; $this->helpText = $helpText; $this->defaultValue = $defaultValue; } protected static function getOptions() { global $OVERWRITE_ARGUMENTS; if (!is_null($OVERWRITE_ARGUMENTS)) { return $OVERWRITE_ARGUMENTS; } else if (VNag::is_http_mode()) { return $_REQUEST; } else { return getopt(self::$all_short, self::$all_long); } } public function count() { $options = self::getOptions(); $count = 0; if (isset($options[$this->shortopt])) { if (is_array($options[$this->shortopt])) { $count += count($options[$this->shortopt]); } else { $count += 1; } } if (!is_null($this->longopts)) { foreach ($this->longopts as $longopt) { if (isset($options[$longopt])) { if (is_array($options[$longopt])) { $count += count($options[$longopt]); } else { $count += 1; } } } } return $count; } public function available() { $options = self::getOptions(); if (isset($options[$this->shortopt])) return true; if (!is_null($this->longopts)) { foreach ($this->longopts as $longopt) { if (isset($options[$longopt])) return true; } } return false; } public function require() { if (!$this->available() && is_null($this->defaultValue)) { $opt = $this->shortopt; $opt = !_empty($opt) ? '-'.$opt : (isset($this->longopts[0]) ? '--'.$this->longopts[0] : '?'); throw new VNagRequiredArgumentMissing($opt); } } public function getValue() { $options = self::getOptions(); if (isset($options[$this->shortopt])) { $x = $options[$this->shortopt]; if (is_array($x) && (count($x) <= 1)) $options[$this->shortopt] = $options[$this->shortopt][0]; return $options[$this->shortopt]; } if (!is_null($this->longopts)) { foreach ($this->longopts as $longopt) { if (isset($options[$longopt])) { $x = $options[$longopt]; if (is_array($x) && (count($x) <= 1)) $options[$longopt] = $options[$longopt][0]; return $options[$longopt]; } } } return $this->defaultValue; } } class VNagArgumentHandler { protected $expectedArgs = array(); protected function _addExpectedArgument($argObj) { if ($argObj->getShortOpt() == '?') return false; if ($argObj->getShortOpt() == '-') return false; if ($argObj->getShortOpt() == '+') return false; $this->expectedArgs[] = $argObj; return true; } public function getArgumentObj($shortopt) { foreach ($this->expectedArgs as $argObj) { if ($argObj->getShortOpt() == $shortopt) return $argObj; } return null; } public function isArgRegistered($shortopt) { return !is_null($this->getArgumentObj($shortopt)); } public function illegalUsage() { global $argv; return (isset($argv[1])) && (($argv[1] == '-?') || ($argv[1] == '/?')); } } class VNagRange { public $start; public $end; public $warnInsideRange; public function __construct($rangeDef, $singleValueBehavior=VNag::SINGLEVALUE_RANGE_DEFAULT) { $m = array(); if (!preg_match('|^(@){0,1}([^:]+)(:){0,1}(.*)$|', $rangeDef, $m)) { throw new VNagInvalidRangeException(sprintf(VNagLang::$range_invalid_syntax, $rangeDef)); } $this->warnInsideRange = $m[1] === '@'; $this->start = null; $this->end = null; if ($m[3] === ':') { if ($m[2] === '~') { $this->start = '-inf'; } else { $this->start = new VNagValueUomPair($m[2]); } if (_empty($m[4])) { $this->end = 'inf'; } else { $this->end = new VNagValueUomPair($m[4]); } } else { assert(_empty($m[4])); assert(!_empty($m[2])); $x = $m[2]; if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_DEFAULT) { $this->start = new VNagValueUomPair('0'.((new VNagValueUomPair($x))->getUom())); $this->end = new VNagValueUomPair($x); } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_GT_X_BAD) { if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); $this->warnInsideRange = 0; $this->start = '-inf'; $this->end = new VNagValueUomPair($x); } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_GE_X_BAD) { if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); $this->warnInsideRange = 1; $this->start = new VNagValueUomPair($x); $this->end = 'inf'; } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_LT_X_BAD) { if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); $this->warnInsideRange = 0; $this->start = new VNagValueUomPair($x); $this->end = 'inf'; } else if ($singleValueBehavior == VNag::SINGLEVALUE_RANGE_VAL_LE_X_BAD) { if ($this->warnInsideRange) throw new VNagInvalidRangeException(VNagLang::$singlevalue_unexpected_at_symbol); $this->warnInsideRange = 1; $this->start = '-inf'; $this->end = new VNagValueUomPair($x); } else { throw new VNagException(VNagLang::$illegalSingleValueBehavior); } } if (is_null($this->start)) { throw new VNagInvalidRangeException(VNagLang::$invalid_start_value); } if (is_null($this->end)) { throw new VNagInvalidRangeException(VNagLang::$invalid_end_value); } if (($this->start instanceof VNagValueUomPair) && ($this->end instanceof VNagValueUomPair) && (VNagValueUomPair::compare($this->start,$this->end) > 0)) { throw new VNagInvalidRangeException(VNagLang::$start_is_greater_than_end); } } public function __toString() { $ret = ''; if ($this->warnInsideRange) { $ret = '@'; } if ($this->start === '-inf') { $ret .= '~'; } else { $ret .= $this->start; } $ret .= ':'; if ($this->end !== 'inf') { $ret .= $this->end; } return $ret; } public function checkAlert($values) { $compatibleCount = 0; if (!is_array($values)) $values = array($values); foreach ($values as $value) { if (!($value instanceof VNagValueUomPair)) $value = new VNagValueUomPair($value); assert(($this->start === '-inf') || ($this->start instanceof VNagValueUomPair)); assert(($this->end === 'inf' ) || ($this->end instanceof VNagValueUomPair)); if (($this->start !== '-inf') && (!$this->start->compatibleWith($value))) continue; if (($this->end !== 'inf') && (!$this->end->compatibleWith($value))) continue; $compatibleCount++; if ($this->warnInsideRange) { return (($this->start === '-inf') || (VNagValueUomPair::compare($value,$this->start) >= 0)) && (($this->end === 'inf') || (VNagValueUomPair::compare($value,$this->end) <= 0)); } else { return (($this->start !== '-inf') && (VNagValueUomPair::compare($value,$this->start) < 0)) || (($this->end !== 'inf') && (VNagValueUomPair::compare($value,$this->end) > 0)); } } if ((count($values) > 0) and ($compatibleCount == 0)) { throw new VNagNoCompatibleRangeUomFoundException(VNagLang::$no_compatible_range_uom_found); } return false; } } class VNagValueUomPair { protected $value; protected $uom; public $roundTo = -1; public function isRelative() { return $this->uom === '%'; } public function getValue() { return $this->value; } public function getUom() { return $this->uom; } public function __toString() { if ($this->roundTo == -1) { return $this->value.$this->uom; } else { return round($this->value,$this->roundTo).$this->uom; } } public function __construct($str) { $m = array(); if (!preg_match('/^([\d\.]+)(.*)$/ism', $str, $m)) { throw new VNagValueUomPairSyntaxException($str); } $this->value = $m[1]; $this->uom = isset($m[2]) ? $m[2] : ''; if (!self::isKnownUOM($this->uom)) { throw new VNagUnknownUomException($this->uom); } } public static function isKnownUOM(string $uom) { $no_unit = ($uom === ''); $seconds = ($uom === 's') || ($uom === 'ms') || ($uom === 'us'); $percentage = ($uom === '%'); $bytes = ($uom === 'B') || ($uom === 'KB') || ($uom === 'MB') || ($uom === 'GB') || ($uom === 'TB'); $counter = ($uom === 'c'); return ($no_unit || $seconds || $percentage || $bytes || $counter); } public function normalize($target=null) { $res = clone $this; if ($res->uom === 'ms') { $res->uom = 's'; $res->value /= 1000; } if ($res->uom === 'us') { $res->uom = 's'; $res->value /= 1000 * 1000; } if ($res->uom === 'B') { $res->uom = 'MB'; $res->value /= 1024 * 1024; } if ($res->uom === 'KB') { $res->uom = 'MB'; $res->value /= 1024; } if ($res->uom === 'GB') { $res->uom = 'MB'; $res->value *= 1024; } if ($res->uom === 'TB') { $res->uom = 'MB'; $res->value *= 1024 * 1024; } if ($res->uom === 'c') { $res->uom = ''; } if (!is_null($target)) { if ($res->uom == 'MB') { if ($target == 'B') { $res->uom = 'B'; $res->value *= 1024 * 1024; } else if ($target == 'KB') { $res->uom = 'KB'; $res->value *= 1024; } else if ($target == 'MB') { $res->uom = 'MB'; $res->value *= 1; } else if ($target == 'GB') { $res->uom = 'GB'; $res->value /= 1024; } else if ($target == 'TB') { $res->uom = 'TB'; $res->value /= 1024 * 1024; } else { throw new VNagUomConvertException($res->uom, $target); } } else if ($res->uom == 's') { if ($target == 's') { $res->uom = 's'; $res->value /= 1; } else if ($target == 'ms') { $res->uom = 'ms'; $res->value /= 1000; } else if ($target == 'us') { $res->uom = 'us'; $res->value /= 1000 * 1000; } else { throw new VNagUomConvertException($res->uom, $target); } } else { throw new VNagUomConvertException($res->uom, $target); } } return $res; } public function compatibleWith(VNagValueUomPair $other) { $a = $this->normalize(); $b = $other->normalize(); return ($a->uom == $b->uom); } public static function compare(VNagValueUomPair $left, VNagValueUomPair $right) { $a = $left->normalize(); $b = $right->normalize(); if ($a->uom != $b->uom) throw new VNagMixedUomsNotImplemented($a->uom, $b->uom); if ($a->value > $b->value) return 1; if ($a->value == $b->value) return 0; if ($a->value < $b->value) return -1; } } class VNagPerformanceData { protected $label; protected $value; protected $warn = null; protected $crit = null; protected $min = null; protected $max = null; public static function createByString($perfdata) { $perfdata = trim($perfdata); $ary = explode('=',$perfdata); if (count($ary) != 2) { throw new VNagInvalidPerformanceDataException(sprintf(VNagLang::$perfdata_line_invalid, $perfdata)); } $label = $ary[0]; $bry = explode(';',$ary[1]); if (substr($label,0,1) === "'") $label = substr($label, 1, strlen($label)-2); $value = $bry[0]; $warn = isset($bry[1]) ? $bry[1] : null; $crit = isset($bry[2]) ? $bry[2] : null; $min = isset($bry[3]) ? $bry[3] : null; $max = isset($bry[4]) ? $bry[4] : null; return new self($label, $value, $warn, $crit, $min, $max); } public function __construct($label, $value, $warn=null, $crit=null, $min=null, $max=null) { if (strpos($label, '=') !== false) throw new VNagInvalidPerformanceDataException(VNagLang::$perfdata_label_equal_sign_forbidden); $label = str_replace("'", "''", $label); $m = array(); if ((!_empty($min)) && (!preg_match('|^[-0-9\\.]+$|', $min, $m))) { throw new VNagInvalidPerformanceDataException(VNagLang::$perfdata_min_must_be_in_class); } if ((!_empty($max)) && (!preg_match('|^[-0-9\\.]+$|', $max, $m))) { throw new VNagInvalidPerformanceDataException(VNagLang::$perfdata_max_must_be_in_class); } $this->label = $label; $this->value = ($value == 'U') ? 'U' : new VNagValueUomPair($value); $this->warn = $warn; $this->crit = $crit; $this->min = $min; $this->max = $max; } public function __toString() { $label = $this->label; $value = $this->value; $warn = $this->warn; $crit = $this->crit; $min = $this->min; $max = $this->max; $label = str_replace("''", "'", $label); return "'$label'=$value". ';'.(is_null($warn) ? '' : $warn). ';'.(is_null($crit) ? '' : $crit). ';'.(is_null($min) ? '' : $min). ';'.(is_null($max) ? '' : $max); } } class VNagHelp { public $word_wrap_width = 80; public $argument_indent = 7; public function printUsagePage() { $usage = $this->getUsage(); if (_empty($usage)) { $usage = VNagLang::$no_syntax_defined; } return trim($usage)."\n"; } public function printVersionPage() { $out = trim($this->getNameAndVersion())."\n"; if ($this->word_wrap_width > 0) $out = wordwrap($out, $this->word_wrap_width, "\n", false); return $out; } static private function _conditionalLine($line, $terminator='', $prefix='') { if (!_empty($line)) { return trim($line).$terminator; } return ''; } public function printHelpPage() { $out = ''; $out .= self::_conditionalLine($this->getNameAndVersion(), "\n"); $out .= self::_conditionalLine($this->getCopyright(), "\n"); $out .= ($out != '') ? "\n" : ''; $out .= self::_conditionalLine($this->getShortDescription(), "\n\n\n"); $out .= self::_conditionalLine($this->getUsage(), "\n\n"); $out .= VNagLang::$options."\n"; foreach ($this->options as $argObj) { $out .= $this->printArgumentHelp($argObj); } $out .= self::_conditionalLine($this->getFootNotes(), "\n\n", "\n"); if ($this->word_wrap_width > 0) $out = wordwrap($out, $this->word_wrap_width, "\n", false); return $out; } protected $options = array(); protected function _addOption($argObj) { $this->options[] = $argObj; } protected function printArgumentHelp($argObj) { $identifiers = array(); $shortopt = $argObj->getShortopt(); if (!_empty($shortopt)) $identifiers[] = '-'.$shortopt; $longopts = $argObj->getLongopts(); if (!is_null($longopts)) { foreach ($longopts as $longopt) { if (!_empty($longopt)) $identifiers[] = '--'.$longopt; } } if (count($identifiers) == 0) return; $valueName = $argObj->getValueName(); $arginfo = ''; switch ($argObj->getValuePolicy()) { case VNagArgument::VALUE_FORBIDDEN: $arginfo = ''; break; case VNagArgument::VALUE_REQUIRED: $arginfo = '='.$valueName; break; case VNagArgument::VALUE_OPTIONAL: $arginfo = '[='.$valueName.']'; break; } $out = ''; $out .= implode(', ', $identifiers).$arginfo."\n"; $content = trim($argObj->getHelpText()); if ($this->word_wrap_width > 0) $content = wordwrap($content, $this->word_wrap_width-$this->argument_indent, "\n", false); $lines = explode("\n", $content); foreach ($lines as $line) { $out .= str_repeat(' ', $this->argument_indent).$line."\n"; } $out .= "\n"; return $out; } protected $pluginName; public function setPluginName($pluginName) { $this->pluginName = $this->replaceStuff($pluginName); } public function getPluginName() { if (_empty($this->pluginName)) { global $argv; return basename($argv[0]); } else { return $this->pluginName; } } protected $version; public function setVersion($version) { $this->version = $this->replaceStuff($version); } public function getVersion() { return $this->version; } public function getNameAndVersion() { $ret = $this->getPluginName(); if (_empty($ret)) return null; $ver = $this->getVersion(); if (!_empty($ver)) { $ret = sprintf(VNagLang::$x_version_x, $ret, $ver); } $ret = trim($ret); return $ret; } protected $copyright; public function setCopyright($copyright) { $this->copyright = $this->replaceStuff($copyright); } private function getVNagCopyright() { if (VNag::is_http_mode()) { $vts_email = 'www.viathinksoft.com'; } else { $vts_email = base64_decode('aW5mb0B2aWF0aGlua3NvZnQuZGU='); } return "VNag Framework ".VNag::VNAG_VERSION." (C) 2014-".date('Y')." ViaThinkSoft <$vts_email>"; } public function getCopyright() { if (_empty($this->copyright)) { return sprintf(VNagLang::$plugin_uses, $this->getVNagCopyright()); } else { return trim($this->copyright)."\n".sprintf(VNagLang::$uses, $this->getVNagCopyright()); } } protected $shortDescription; public function setShortDescription($shortDescription) { $this->shortDescription = $this->replaceStuff($shortDescription); } public function getShortDescription() { if (_empty($this->shortDescription)) { return null; } else { $content = $this->shortDescription; if ($this->word_wrap_width > 0) $content = wordwrap($content, $this->word_wrap_width, "\n", false); return $content; } } protected function replaceStuff($text) { global $argv; if (php_sapi_name() == 'cli') { $text = str_replace('$SCRIPTNAME$', $argv[0], $text); } else { $text = str_replace('$SCRIPTNAME$', basename($_SERVER['SCRIPT_NAME']), $text); } $text = str_replace('$CURYEAR$', date('Y'), $text); return $text; } protected $syntax; public function setSyntax($syntax) { $syntax = $this->replaceStuff($syntax); $this->syntax = $syntax; } public function getUsage() { if (_empty($this->syntax)) { return null; } else { return sprintf(VNagLang::$usage_x, $this->syntax); } } protected $footNotes; public function setFootNotes($footNotes) { $this->footNotes = $this->replaceStuff($footNotes); } public function getFootNotes() { return $this->footNotes; } } class VNagLang { public static function status($code, $statusmodel) { switch ($statusmodel) { case VNag::STATUSMODEL_SERVICE: switch ($code) { case VNag::STATUS_OK: return 'OK'; case VNag::STATUS_WARNING: return 'Warning'; case VNag::STATUS_CRITICAL: return 'Critical'; case VNag::STATUS_UNKNOWN: return 'Unknown'; default: return sprintf('Error (%d)', $code); } case VNag::STATUSMODEL_HOST: switch ($code) { case VNag::STATUS_UP: return 'Up'; case VNag::STATUS_DOWN: return 'Down'; default: return sprintf('Maintain last state (%d)', $code); } default: throw new VNagIllegalStatusModel(sprintf(self::$illegal_statusmodel, $statusmodel)); } } static $nagios_output = 'VNag-Output'; static $verbose_info = 'Verbose information'; static $status = 'Status'; static $message = 'Message'; static $performance_data = 'Performance data'; static $status_ok = 'OK'; static $status_warn = 'Warning'; static $status_critical = 'Critical'; static $status_unknown = 'Unknown'; static $status_error = 'Error'; static $unhandled_exception_without_msg = "Unhandled exception of type %s"; static $plugin_uses = 'This plugin uses %s'; static $uses = 'uses %s'; static $x_version_x = '%s, version %s'; static $argname_value = 'value'; static $argname_seconds = 'seconds'; static $query_without_expected_argument = "The argument '%s' is queried, but was not added to the list of expected arguments. Please contact the plugin author."; static $required_argument_missing = "The argument '%s' is required."; static $performance_data_invalid = 'Performance data invalid.'; static $no_standard_arguments_with_letter = "No standard argument with letter '%s' exists."; static $invalid_start_value = 'Invalid start value.'; static $invalid_end_value = 'Invalid end value.'; static $start_is_greater_than_end = 'Start is greater than end value.'; static $value_name_forbidden = "Implementation error: You may not define a value name for the argument, because the value policy is VALUE_FORBIDDEN."; static $value_name_required = "Implementation error: Please define a name for the argument (so it can be shown in the help page)."; static $illegal_shortopt = "Illegal shortopt '-%s'."; static $illegal_longopt = "Illegal longopt '--%s'."; static $illegal_valuepolicy = "valuePolicy has illegal value '%s'."; static $range_invalid_syntax = "Syntax error in range '%s'."; static $timeout_value_invalid = "Timeout value '%s' is invalid."; static $range_is_invalid = 'Range is invalid.'; static $timeout_exception = 'Timeout!'; static $perfdata_label_equal_sign_forbidden = 'Label may not contain an equal sign.'; static $perfdata_value_must_be_in_class = 'Value must be in class [-0-9.] or be \'U\' if the actual value can\'t be determined.'; static $perfdata_min_must_be_in_class = 'Min must be in class [-0-9.] or empty.'; static $perfdata_max_must_be_in_class = 'Max must be in class [-0-9.] or empty.'; static $perfdata_uom_not_recognized = 'UOM (unit of measurement) "%s" is not recognized.'; static $perfdata_mixed_uom_not_implemented = 'Mixed UOMs (%s and %s) are currently not supported.'; static $no_compatible_range_uom_found = 'Measured values are not compatible with the provided warning/critical parameter. Most likely, the UOM is incompatible.'; static $exception_x = '%s (%s)'; static $no_syntax_defined = 'The author of this plugin has not defined a syntax for this plugin.'; static $usage_x = "Usage:\n%s"; static $options = "Options:"; static $illegal_statusmodel = "Invalid statusmodel %d."; static $none = '[none]'; static $valueUomPairSyntaxError = 'Syntax error at "%s". Syntax must be Value[UOM].'; static $too_few_warning_ranges = "You have too few warning ranges (currently trying to get element %d)."; static $too_few_critical_ranges = "You have too few critical ranges (currently trying to get element %d)."; static $dataset_missing = 'Dataset missing.'; static $payload_not_base64 = 'The payload is not valid Base64.'; static $payload_not_json = 'The payload is not valid JSON.'; static $signature_missing = 'The signature is missing.'; static $signature_not_bas64 = 'The signature is not valid Base64.'; static $signature_invalid = 'The signature is invalid. The connection might have been tampered, or a different key is used.'; static $pubkey_file_not_found = "Public key file %s was not found."; static $pubkey_file_not_readable = "Public key file %s is not readable."; static $privkey_file_not_found = "Private key file %s was not found."; static $privkey_not_readable = "Private key is not readable."; static $privkey_file_not_readable = "Private key file %s is not readable."; static $signature_failed = "Signature failed."; static $perfdata_line_invalid = "Performance data line %s is invalid."; static $singlevalue_unexpected_at_symbol = 'This plugin does not allow the @-symbol at ranges for single values.'; static $illegalSingleValueBehavior = "Illegal value for 'singleValueBehavior'. Please contact the creator of the plugin."; static $dataset_encryption_no_array = 'Dataset encryption information invalid.'; static $require_password = 'This resource is protected with a password. Please provide a password.'; static $wrong_password = 'This resource is protected with a password. You have provided the wrong password, or it was changed.'; static $convert_x_y_error = 'Cannot convert from UOM %s to UOM %s.'; static $php_error = 'PHP has detected an error in the plugin. Please contact the plugin author.'; static $output_level_lowered = "Output Buffer level lowered during cbRun(). Please contact the plugin author."; static $openssl_missing = "OpenSSL is missing. Therefore, encryption and signatures are not available."; static $warning_range = 'Warning range'; static $critical_range = 'Critical range'; static $prints_version = 'Prints version'; static $verbosity_helptext = 'Verbosity -v, -vv or -vvv'; static $timeout_helptext = 'Sets timeout in seconds'; static $help_helptext = 'Prints help page'; static $prints_usage = 'Prints usage'; static $notConstructed = 'Parent constructor not called with parent::__construct().'; } function vnagErrorHandler($errorkind, $errortext, $file, $line) { global $inside_vnag_run; if (!$inside_vnag_run && VNag::is_http_mode()) { return false; } if (!(error_reporting() & $errorkind)) { return true; } if (defined('E_ERROR') && ($errorkind == E_ERROR)) $errorkind = 'Error'; if (defined('E_WARNING') && ($errorkind == E_WARNING)) $errorkind = 'Warning'; if (defined('E_PARSE') && ($errorkind == E_PARSE)) $errorkind = 'Parse'; if (defined('E_NOTICE') && ($errorkind == E_NOTICE)) $errorkind = 'Notice'; if (defined('E_CORE_ERROR') && ($errorkind == E_CORE_ERROR)) $errorkind = 'Core Error'; if (defined('E_CORE_WARNING') && ($errorkind == E_CORE_WARNING)) $errorkind = 'Core Warning'; if (defined('E_COMPILE_ERROR') && ($errorkind == E_COMPILE_ERROR)) $errorkind = 'Compile Error'; if (defined('E_COMPILE_WARNING') && ($errorkind == E_COMPILE_WARNING)) $errorkind = 'Compile Warning'; if (defined('E_USER_ERROR') && ($errorkind == E_USER_ERROR)) $errorkind = 'User Error'; if (defined('E_USER_WARNING') && ($errorkind == E_USER_WARNING)) $errorkind = 'User Warning'; if (defined('E_USER_NOTICE') && ($errorkind == E_USER_NOTICE)) $errorkind = 'User Notice'; if (defined('E_STRICT') && ($errorkind == E_STRICT)) $errorkind = 'Strict'; if (defined('E_RECOVERABLE_ERROR') && ($errorkind == E_RECOVERABLE_ERROR)) $errorkind = 'Recoverable Error'; if (defined('E_DEPRECATED') && ($errorkind == E_DEPRECATED)) $errorkind = 'Deprecated'; if (defined('E_USER_DEPRECATED') && ($errorkind == E_USER_DEPRECATED)) $errorkind = 'User Deprecated'; throw new VNagException(VNagLang::$php_error . " $errortext at $file:$line (kind $errorkind)"); } $inside_vnag_run = false; $old_error_handler = set_error_handler("vnagErrorHandler"); <?php |
298 | declare(ticks=1); class NoccVersionCheck extends VNag { protected $argSystemDir = null; public function __construct() { parent::__construct(); $this->registerExpectedStandardArguments('Vht'); $this->getHelpManager()->setPluginName('check_nocc_version'); $this->getHelpManager()->setVersion('2023-10-13'); $this->getHelpManager()->setShortDescription('This plugin checks if a local NOCC Webmail system has the latest version installed.'); $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'noccPath', 'The local directory where your NOCC installation is located.')); } protected function get_local_version($path) { $path = realpath($path) === false ? $path : realpath($path); $cont = @file_get_contents("$path/common.php"); if ($cont === false) { throw new VNagException("Cannot find version information at $path (common.php not found)"); } if (!preg_match('@\$conf\->nocc_version = \'(.+)\';@ismU', $cont, $m)) { throw new VNagException("Cannot find version information at $path (nocc_version configuration not found)"); } return $m[1]; } protected function get_latest_version() { $cont = $this->url_get_contents('http://nocc.sourceforge.net/download/?lang=en'); if ($cont === false) { throw new VNagException("Cannot access website with latest version"); } if (!preg_match('@Download the current NOCC version <strong>(.+)</strong>@ismU', $cont, $m)) { if (!preg_match('@/nocc\-(.+)\.tar\.gz"@ismU', $cont, $m)) { throw new VNagException("Cannot find version information on the website"); } } return trim($m[1]); } protected function cbRun($optional_args=array()) { $system_dir = $this->argSystemDir->getValue(); if (empty($system_dir)) { throw new VNagException("Please specify the directory of the NOCC installation."); } $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); if (!is_dir($system_dir)) { throw new VNagException('Directory "'.$system_dir.'" not found.'); } $version = $this->get_local_version($system_dir); $latest_version = $this->get_latest_version(); if (version_compare($version,$latest_version) >= 0) { $this->setStatus(VNag::STATUS_OK); $this->setHeadline("Version $version at $system_dir", true); } else { $this->setStatus(VNag::STATUS_WARNING); $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); } } } <?php |
||
87 | daniel-mar | 299 | declare(ticks=1); require_once __DIR__ . '/../../framework/vnag_framework.inc.php'; require_once __DIR__ . '/NoccVersionCheck.class.php'; $job = new NoccVersionCheck(); $job->run(); unset($job); ßl´»KQ¯1`@ êÃ(B¾):ÎEÏîѽðAå1Xµê-¬LÂs%8ëüsoÈÐøzxt\ GBMB |