-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-version.php
91 lines (77 loc) · 2.23 KB
/
wp-version.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
// Include your Nagios server IP below
// It is safe to keep 127.0.0.1
$allowed_ips = array(
'127.0.0.1',
'192.99.28.88',
'2607:5300:203:ba5f:100::',
);
// If your Wordpress installation is behind a Proxy like Nginx use 'HTTP_X_FORWARDED_FOR'
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$remote_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$remote_ip = $_SERVER['REMOTE_ADDR'];
}
// Check if the requesting server is allowed
if (! in_array($remote_ip, $allowed_ips))
{
echo "CRITICAL#IP $remote_ip not allowed.";
exit;
}
require_once('wp-load.php');
global $wp_version;
$core_updates = FALSE;
$plugin_updates = FALSE;
wp_version_check();
wp_update_plugins();
wp_update_themes();
if (function_exists('get_transient'))
{
$core = get_transient('update_core');
$plugins = get_transient('update_plugins');
$themes = get_transient('update_themes');
if ($core == FALSE)
{
$core = get_site_transient('update_core');
$plugins = get_site_transient('update_plugins');
$themes = get_site_transient('update_themes');
}
}
else
{
$core = get_site_transient('update_core');
$plugins = get_site_transient('update_plugins');
$themes = get_site_transient('update_themes');
}
$status = 'OK';
$text = [];
// Parse the plugin check and generate a list of plugins needing updates.
if ($plugins->response ?? FALSE) {
$plugin_text = 'Plugin update(s) available: (';
foreach ($plugins->response as $plugin) {
$plugin_text .= "$plugin->slug: $plugin->new_version; ";
}
$plugin_text = substr($plugin_text, 0, -2) . ')';
$text[] = $plugin_text;
$status = 'WARNING';
}
// Parse the theme check and generate a list of themes needing updates.
if ($themes->response ?? FALSE) {
$theme_text = 'Theme update(s) available: (';
foreach ($themes->response as $theme) {
$theme_text .= "{$theme['theme']}: {$theme['new_version']}; ";
}
$theme_text = substr($theme_text, 0, -2) . ')';
$text[] = $theme_text;
$status = 'WARNING';
}
// Parse the core check last, since a CRITICAL status overrides a WARNING.
foreach ($core->updates as $core_update)
{
if ($core_update->current != $wp_version)
{
$text[] = 'Core update available';
$status = 'CRITICAL';
}
}
echo $status . '#' . implode('; ', $text);