Rev 58 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 58 | Rev 59 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php /* <ViaThinkSoftSignature> |
1 | <?php /* <ViaThinkSoftSignature> |
2 | xhl/K7K2NBjuGDzJ8SDyDfjnqVYQGqJYY8y/rSj2nQ2qB1UaPExnZbVeYXmkuuNHn |
2 | O3yOuJ0uY8SaZtsrvzay90oQ6sp1M+CxL4k53lThK/mXA4x6XNuTX1K8OygUl0swc |
3 | 0FYtsd797Xuz5VJrqTGE8FjIwYxW4wjuOn/AKdzI7EJIVah9inU52Nh9i/t1ZBBSj |
3 | +yV3RRKNVNaLXMxKBOhRVC1SqJi5jDM+/AN0vJ2j0fjYcc0mXbuy4amScMq0wFBBq |
4 | l6M6qn0Hr0gImkW4aPagZ5PVTW9D/kGyI01TiNY5lmXnDYnOIGwVTriOqEl1KWVaY |
4 | 0Kf2mqWu4QtZiZ6PQo+SoUuoR5QsN4IQkOKdj7cdluNFClt6uar2ZPNEGeHFGt0eT |
5 | Fy350Ji1UN5dh4EeA6UyvTCtTPHV7SwVOMTMSBnQSE1/6Tkr0ETMfUsSE/HA2pnp8 |
5 | ddCEJf13rjkpta4FUjjPr1eN2uWE7qFIAqgYbx1tW7+fX3iFOOcnd9F85hbvGQhpY |
6 | V9DKDj5US43AXTBZf7SUhLbsESzgVJBIX1LIUCSRWZC067GRhYpyOqzzb8Jx0GduQ |
6 | LJgFwwsFbfgH26E54Za6ynVJ5yvZ3FBFItO/UMtuiAqjFgsv6tmU49B7NxzzFeAln |
7 | 5+cnZSckAsv4sjDra0blFjnfYS1mVO0vHY0n3wRANS4bqgodaBhmyN3lvzTK+Hf2N |
7 | xTPhhF5SILLJr/aKkMhNd1vWup4s6ZW+HWlwxd5kRdNedGPiWExZZuGDfdorycLLo |
8 | Ki1MAi91Pd8K81mrQ5EbB+TOVAH3w0p3DejtJrdLTQpYuq+pofQRvE8Ua3zBdB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gPUv51XiYfcCLUyCF2nxenr8sAOzVA8L3gGiqJQ3jf8rUTbp35eMIvAgU2 |
16 | ZNINJsjM3aFebt2yeUn5E13WCOCFsm6fqhhtNBe14tn2b/AEew4gZfuitFuvbPtY/ |
17 | ut0w/gdtHym44ipjArNVYFS7X8OkEq6bMZ4P/wUBVm8t+WTNf7ra4Upybv5YX1QpT |
17 | gPSqg8EnJ2qmoGJEQhgmkLdmklBLQ/Xtyf68kYFGeoRU/IPVnsODqytvS/J23v0vF |
18 | D6jmyGmb1ggDNstqj7rVRT6dYrbuNBPBhJV8As8oBUcW5BAeUWqCIJj44pyXOEH9Z |
18 | f//VIjpE2vmrRi7aE1QmnT+JIKqq1HZsUPnuEjpIWhdH1W+sztLSbYHTmVG89QOeT |
19 | pkgSanTgFUEqHAkg/NW/ah2/6CgPNb7xKdosgHSgXTvaROUBqBQ8AiQBnTjdduJTp |
19 | cQzGPitGrPgqqSuVJo0q/zYdXDjE+Y6kbIj8QrK05N6MfhCeund5JvTab7AQlg51n |
20 | 1GYXcGOsix70/+DBH8MZW1ToP5FU2oAkiin+iEKe/XE6Ek506hhd0CvyLuIXtrScz |
20 | BSNXZFMdena5C5QTXGwU3BQwBpvr92YWCj7EXzGU8N5XTDULiyInNNZ0xOULA+AXP |
21 | 4EYmjCEoXYyZb7f3l9yidIWz/HkmUIWc2RIq8bv9ygzF+6t6PZktBrztMC2jRkFbe |
21 | aV79sQdctyrWEkll9ykl00641y3jdJl0b3FzFy87v9OoRLj8vAsvy2cUmRykRjyJm |
22 | vTtpxQWS485kKJO0s84IBNQXPUb+4Dpfy01OjJa8PXcYK4Ajp7DBt+jgLsFUMpCoV |
22 | Uc8V1D7xjhvuxa5APwrpcaULIpOSiC3upgmNYlZIODV2CKixY5csoo7Ka2wnAttss |
23 | A== |
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 |
Line 42... | Line 42... | ||
42 | 42 | ||
43 | $this->registerExpectedStandardArguments('Vht'); |
43 | $this->registerExpectedStandardArguments('Vht'); |
44 | 44 | ||
45 | $this->getHelpManager()->setPluginName('check_websvn_version'); |
45 | $this->getHelpManager()->setPluginName('check_websvn_version'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local websvn system has the latest version installed.'); |
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local WebSVN system 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: |
Line 64... | Line 64... | ||
64 | 64 | ||
65 | if (!preg_match('@\\$version = \'(.+)\';@ismU', $cont, $m)) { |
65 | if (!preg_match('@\\$version = \'(.+)\';@ismU', $cont, $m)) { |
66 | throw new Exception("Cannot determine version for system $path"); |
66 | throw new Exception("Cannot determine version for system $path"); |
67 | } |
67 | } |
68 | 68 | ||
69 | return $m[1]; |
69 | return $m[1]; // e.g. "2.8.1" or "2.8.1-DEV" |
70 | } |
70 | } |
71 | 71 | ||
72 | protected function get_latest_version() { |
72 | protected function get_latest_version() { |
73 | $url = 'https://api.github.com/repos/websvnphp/websvn/releases/latest'; |
73 | $url = 'https://api.github.com/repos/websvnphp/websvn/releases/latest'; |
- | 74 | $max_cache_time = 24 * 60 * 60; |
|
- | 75 | $cache_file = $this->get_cache_dir().'/'.sha1($url); |
|
- | 76 | if (file_exists($cache_file) && (time()-filemtime($cache_file) < $max_cache_time)) { |
|
- | 77 | $cont = @file_get_contents($cache_file); |
|
- | 78 | if (!$cont) throw new Exception("Failed to get contents from $cache_file"); |
|
- | 79 | } else { |
|
74 | $options = array( |
80 | $options = array( |
75 | 'http'=>array( |
81 | 'http'=>array( |
76 | 'method'=>"GET", |
82 | 'method'=>"GET", |
77 | 'header'=>"Accept-language: en\r\n" . |
83 | 'header'=>"Accept-language: en\r\n" . |
78 | "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" |
84 | "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" |
79 | ) |
85 | ) |
80 | ); |
86 | ); |
81 | $context = stream_context_create($options); |
87 | $context = stream_context_create($options); |
82 | $cont = file_get_contents($url, false, $context); |
88 | $cont = @file_get_contents($url, false, $context); |
83 | if (!$cont) { |
89 | if (!$cont) throw new Exception("Failed to get contents from $url"); |
84 | throw new Exception('Cannot parse version from GitHub API. The plugin probably needs to be updated. A'); |
90 | file_put_contents($cache_file, $cont); |
85 | } |
91 | } |
86 | 92 | ||
87 | $data = @json_decode($cont, true); |
93 | $data = @json_decode($cont, true); |
88 | if (!$data) { |
94 | if (!$data) { |
89 | throw new Exception('Cannot parse version from GitHub API. The plugin probably needs to be updated. B'); |
95 | throw new Exception('Cannot parse version from GitHub API. The plugin probably needs to be updated. B'); |
90 | } |
96 | } |
91 | 97 | ||
92 | return $data['name']; // e.g. "2.8.1" |
98 | return $data['tag_name']; // e.g. "2.8.1" |
93 | } |
99 | } |
94 | 100 | ||
95 | protected function cbRun($optional_args=array()) { |
101 | protected function cbRun($optional_args=array()) { |
96 | $system_dir = $this->argSystemDir->getValue(); |
102 | $system_dir = $this->argSystemDir->getValue(); |
97 | if (empty($system_dir)) { |
103 | if (empty($system_dir)) { |
Line 105... | Line 111... | ||
105 | 111 | ||
106 | $local_version = $this->get_local_version($system_dir); |
112 | $local_version = $this->get_local_version($system_dir); |
107 | 113 | ||
108 | $latest_stable = $this->get_latest_version(); |
114 | $latest_stable = $this->get_latest_version(); |
109 | 115 | ||
- | 116 | // Note: version_compare() correctly assumes that 2.8.1 is higher than 2.8.1-DEV |
|
110 | if (version_compare($local_version,$latest_stable,'>')) { |
117 | if (version_compare($local_version,$latest_stable,'>')) { |
111 | $this->setStatus(VNag::STATUS_OK); |
118 | $this->setStatus(VNag::STATUS_OK); |
112 | $this->setHeadline("Version $local_version (Latest stable version $latest_stable) at $system_dir", true); |
119 | $this->setHeadline("Version $local_version (Latest stable version $latest_stable) at $system_dir", true); |
113 | } else if (version_compare($local_version,$latest_stable,'=')) { |
120 | } else if (version_compare($local_version,$latest_stable,'=')) { |
114 | $this->setStatus(VNag::STATUS_OK); |
121 | $this->setStatus(VNag::STATUS_OK); |