share
8 years ago
.htaccess
11 years ago
anti_malware.php
4 years ago
class-coupon.php
6 months ago
class-email-sodium.php
3 weeks ago
class-firewall-log.php
1 week ago
class-helpers.php
7 months ago
class-import-export.php
3 months ago
class-ip.php
4 months ago
class-nfw-database.php
6 months ago
class-nfw-session.php
1 week ago
class-php-session.php
1 year ago
class-plugin-upgrade.php
1 week ago
class_mail.php
3 weeks ago
event_updates.php
9 months ago
firewall.php
4 months ago
fw_centlog.php
1 week ago
fw_fileguard.php
4 months ago
fw_livelog.php
1 year ago
help.php
3 weeks ago
helpers.php
1 week ago
i18n-extra.php
3 weeks ago
i18n.php
1 year ago
index.html
13 years ago
init_update.php
1 year ago
install.php
1 year ago
install_default.php
6 months ago
loader.php
6 months ago
mail_template_firewall.php
1 year ago
mail_template_plugin.php
1 month ago
scheduled_tasks.php
3 years ago
settings_dashboard.php
1 month ago
settings_dashboard_about.php
3 weeks ago
settings_dashboard_statistics.php
1 month ago
settings_event_notifications.php
1 month ago
settings_events.php
1 month ago
settings_firewall_options.php
1 month ago
settings_firewall_policies.php
1 week ago
settings_login_protection.php
1 month ago
settings_logs.php
1 month ago
settings_logs_firewall_log.php
3 weeks ago
settings_logs_live_log.php
1 month ago
settings_monitoring.php
3 weeks ago
settings_monitoring_file_check.php
1 month ago
settings_monitoring_file_guard.php
1 month ago
settings_network.php
1 month ago
settings_security_rules.php
1 month ago
settings_security_rules_editor.php
1 month ago
settings_security_rules_update.php
1 week ago
sign.pub
7 years ago
thickbox.php
4 years ago
widget.php
3 years ago
wpplus.php
3 months ago
event_updates.php
246 lines
| 1 | <?php |
| 2 | /* |
| 3 | +=====================================================================+ |
| 4 | | _ _ _ _ _____ _ _ _ | |
| 5 | | | \ | (_)_ __ (_) __ _| ___(_)_ __ _____ ____ _| | | | |
| 6 | | | \| | | '_ \ | |/ _` | |_ | | '__/ _ \ \ /\ / / _` | | | | |
| 7 | | | |\ | | | | || | (_| | _| | | | | __/\ V V / (_| | | | | |
| 8 | | |_| \_|_|_| |_|/ |\__,_|_| |_|_| \___| \_/\_/ \__,_|_|_| | |
| 9 | | |__/ | |
| 10 | | (c) NinTechNet Limited ~ https://nintechnet.com/ | |
| 11 | +=====================================================================+ |
| 12 | */ |
| 13 | |
| 14 | if (! defined('NFW_ENGINE_VERSION') ) { |
| 15 | die('Forbidden'); |
| 16 | } |
| 17 | |
| 18 | // --------------------------------------------------------------------- |
| 19 | // This function is called by NinjaFirewall's garbage collector |
| 20 | // which runs hourly. |
| 21 | |
| 22 | function nfw_check_security_updates() { |
| 23 | |
| 24 | $nfw_checked = nfw_get_option( 'nfw_checked' ); |
| 25 | if ( empty( $nfw_checked ) ) { $nfw_checked = array(); } |
| 26 | |
| 27 | $nfw_options = nfw_get_option('nfw_options'); |
| 28 | if ( empty( $nfw_options['secupdates'] ) ) { return; } |
| 29 | |
| 30 | $found = []; |
| 31 | |
| 32 | $url = 'https://api.nintechnet.com/ninjafirewall/security-update'; |
| 33 | |
| 34 | // Fetch latest data: |
| 35 | $list = array(); |
| 36 | $list = nfw_fetch_security_updates( $url ); |
| 37 | |
| 38 | set_transient( 'nfw_fetchsecupdates', 1, 6000 ); |
| 39 | |
| 40 | if ( $list === false ) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | if (! isset( $list['wordpress'] ) || ! isset( $list['themes'] ) || ! isset( $list['plugins'] ) ) { |
| 45 | nfw_log_error( __('Downloaded list of vulnerabilities is corrupted', 'ninjafirewall' ) ); |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | // Check WordPress updates |
| 50 | global $wp_version; |
| 51 | if ( isset( $list['wordpress']['version'] ) && version_compare( $wp_version, $list['wordpress']['version'], '<' ) ) { |
| 52 | // Versions are different, check if the user was already warned about that |
| 53 | if (! isset( $nfw_checked['wordpress']['version'] ) || |
| 54 | version_compare( $nfw_checked['wordpress']['version'], $list['wordpress']['version'], '<' ) ) { |
| 55 | // Mark as checked |
| 56 | $nfw_checked['wordpress']['version'] = $list['wordpress']['version']; |
| 57 | |
| 58 | $found['wordpress']['cur_version'] = $wp_version; |
| 59 | $found['wordpress']['new_version'] = $list['wordpress']['version']; |
| 60 | $found['wordpress']['level'] = $list['wordpress']['level']; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Check themes updates |
| 65 | if ( ! function_exists( 'wp_get_themes' ) ) { |
| 66 | require_once ABSPATH . 'wp-includes/theme.php'; |
| 67 | } |
| 68 | $themes = wp_get_themes(); |
| 69 | |
| 70 | foreach( $themes as $k => $v ) { |
| 71 | // No name or no version (unlike plugins, we're dealing with objects here) |
| 72 | if ( $v->Name == '' || $v->Version == '' ) { |
| 73 | continue; |
| 74 | } |
| 75 | $hash = hash( 'sha256', $k ); |
| 76 | |
| 77 | if ( isset( $list['themes'][$hash] ) && version_compare( $v->Version, $list['themes'][$hash]['version'], '<' ) ) { |
| 78 | |
| 79 | // Make sure we didn't inform the user yet |
| 80 | if (! isset( $nfw_checked['themes'][$k] ) || |
| 81 | version_compare( $nfw_checked['themes'][$k]['version'], $list['themes'][$hash]['version'], '<' ) ) { |
| 82 | |
| 83 | // Mark as checked: |
| 84 | $nfw_checked['themes'][$k]['version'] = $list['themes'][$hash]['version']; |
| 85 | |
| 86 | $found['themes'][$k]['name'] = $v->Name; |
| 87 | $found['themes'][$k]['cur_version'] = $v->Version; |
| 88 | $found['themes'][$k]['new_version'] = $list['themes'][$hash]['version']; |
| 89 | $found['themes'][$k]['level'] = $list['themes'][$hash]['level']; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Check plugins updates |
| 95 | if ( ! function_exists( 'get_plugins' ) ) { |
| 96 | require_once ABSPATH .'wp-admin/includes/plugin.php'; |
| 97 | } |
| 98 | $plugins = get_plugins(); |
| 99 | |
| 100 | foreach( $plugins as $k => $v ) { |
| 101 | // No name or no version (unlike themes, we're dealing with arrays here) |
| 102 | if ( empty( $v['Name'] ) || empty( $v['Version'] ) ) { |
| 103 | continue; |
| 104 | } |
| 105 | $hash = hash( 'sha256', $k ); |
| 106 | |
| 107 | if ( isset( $list['plugins'][$hash] ) && version_compare( $v['Version'], $list['plugins'][$hash]['version'], '<' ) ) { |
| 108 | // Make sure we didn't inform the user yet |
| 109 | if (! isset( $nfw_checked['plugins'][$k] ) || |
| 110 | version_compare( $nfw_checked['plugins'][$k]['version'], $list['plugins'][$hash]['version'], '<' ) ) { |
| 111 | |
| 112 | // Mark as checked |
| 113 | $nfw_checked['plugins'][$k]['version'] = $list['plugins'][$hash]['version']; |
| 114 | |
| 115 | $found['plugins'][$k]['name'] = $v['Name']; |
| 116 | $found['plugins'][$k]['cur_version'] = $v['Version']; |
| 117 | $found['plugins'][$k]['new_version'] = $list['plugins'][$hash]['version']; |
| 118 | $found['plugins'][$k]['level'] = $list['plugins'][$hash]['level']; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // Nothing to do |
| 124 | if ( empty( $found ) ) { |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | // Warn the user |
| 129 | nfw_alert_security_updates( $found ); |
| 130 | |
| 131 | // Update checked list |
| 132 | nfw_update_option( 'nfw_checked', $nfw_checked, false ); |
| 133 | |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | // --------------------------------------------------------------------- |
| 138 | // Send an email alert to the admin |
| 139 | |
| 140 | function nfw_alert_security_updates( $found = [] ) { |
| 141 | |
| 142 | $message = ''; |
| 143 | |
| 144 | /** |
| 145 | * WordPress. |
| 146 | */ |
| 147 | if (! empty( $found['wordpress'] ) ) { |
| 148 | $message .= "WordPress:\n" . |
| 149 | sprintf( __('Your version: %s', 'ninjafirewall'), $found['wordpress']['cur_version'] ) ."\n". |
| 150 | sprintf( __('New version: %s', 'ninjafirewall'), $found['wordpress']['new_version'] ) ."\n"; |
| 151 | if ( $found['wordpress']['level'] == 2 ) { |
| 152 | $message .= __('Severity: This is an important security update', 'ninjafirewall') ."\n"; |
| 153 | } elseif ( $found['wordpress']['level'] == 3 ) { |
| 154 | $message .= __('Severity: **This is a critical security update**', 'ninjafirewall') ."\n"; |
| 155 | } |
| 156 | $message .= "\n"; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Plugins. |
| 161 | */ |
| 162 | if (! empty( $found['plugins'] ) ) { |
| 163 | foreach( $found['plugins'] as $k => $v ) { |
| 164 | $message .= sprintf( __('Plugin: %s', 'ninjafirewall'), $found['plugins'][$k]['name'] ) ."\n". |
| 165 | sprintf( __('Your version: %s', 'ninjafirewall'), $found['plugins'][$k]['cur_version'] ) ."\n". |
| 166 | sprintf( __('New version: %s', 'ninjafirewall'), $found['plugins'][$k]['new_version'] ) ."\n"; |
| 167 | |
| 168 | if ( $found['plugins'][$k]['level'] == 2 ) { |
| 169 | $message .= __('Severity: This is an important security update', 'ninjafirewall') ."\n"; |
| 170 | } elseif ( $found['plugins'][$k]['level'] == 3 ) { |
| 171 | $message .= __('Severity: **This is a critical security update**', 'ninjafirewall') ."\n"; |
| 172 | } |
| 173 | $message .= "\n"; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Themes. |
| 179 | */ |
| 180 | if (! empty( $found['themes'] ) ) { |
| 181 | |
| 182 | foreach( $found['themes'] as $k => $v ) { |
| 183 | $message .= sprintf( __('Theme: %s', 'ninjafirewall'), $found['themes'][$k]['name'] ) ."\n". |
| 184 | sprintf( __('Your version: %s', 'ninjafirewall'), $found['themes'][$k]['cur_version'] ) ."\n". |
| 185 | sprintf( __('New version: %s', 'ninjafirewall'), $found['themes'][$k]['new_version'] ) ."\n"; |
| 186 | |
| 187 | if ( $found['themes'][$k]['level'] == 2 ) { |
| 188 | $message .= __('Severity: This is an important security update', 'ninjafirewall') ."\n"; |
| 189 | } elseif ( $found['themes'][$k]['level'] == 3 ) { |
| 190 | $message .= __('Severity: **This is a critical security update**', 'ninjafirewall') ."\n"; |
| 191 | } |
| 192 | $message .= "\n"; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if ( is_multisite() ) { |
| 197 | $url = network_home_url('/'); |
| 198 | } else { |
| 199 | $url = home_url('/'); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Email notification. |
| 204 | */ |
| 205 | $subject = []; |
| 206 | $content = [ ucfirst( date_i18n('F j, Y @ H:i:s T') ), $url, $message ]; |
| 207 | |
| 208 | NinjaFirewall_mail::send('security_updates', $subject, $content, '', [], 1 ); |
| 209 | |
| 210 | |
| 211 | } |
| 212 | |
| 213 | // --------------------------------------------------------------------- |
| 214 | // Download list from remote server |
| 215 | |
| 216 | function nfw_fetch_security_updates( $url ) { |
| 217 | |
| 218 | global $wp_version; |
| 219 | $res = wp_remote_get( |
| 220 | $url, |
| 221 | array( |
| 222 | 'timeout' => 20, |
| 223 | 'httpversion' => '1.1' , |
| 224 | 'user-agent' => 'Mozilla/5.0 (compatible; NinjaFirewall/'. |
| 225 | NFW_ENGINE_VERSION .'; WordPress/'. $wp_version . ')', |
| 226 | 'sslverify' => true |
| 227 | ) |
| 228 | ); |
| 229 | if ( is_wp_error( $res ) ) { |
| 230 | nfw_log_error( __('Cannot download security rules: connection error. Will try again later', 'ninjafirewall') ); |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | if ( $res['response']['code'] != 200 ) { |
| 235 | nfw_log_error( |
| 236 | sprintf( __('Cannot download security rules: HTTP response error %s. Will try again later', 'ninjafirewall'), $res['response']['code'] ) |
| 237 | ); |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | return json_decode( $res['body'], true ); |
| 242 | } |
| 243 | |
| 244 | // --------------------------------------------------------------------- |
| 245 | // EOF |
| 246 |