PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / 4.8.8
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall v4.8.8
4.9 4.8.8 4.8.7 4.8.6 trunk 4.5 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6 4.6.1 4.7 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5
ninjafirewall / lib / class-plugin-upgrade.php
ninjafirewall / lib Last commit date
share 9 years ago .htaccess 11 years ago anti_malware.php 5 years ago class-coupon.php 7 months ago class-email-sodium.php 1 month ago class-firewall-log.php 1 month ago class-helpers.php 9 months ago class-import-export.php 5 months ago class-ip.php 5 months ago class-nfw-database.php 7 months ago class-nfw-session.php 1 month ago class-php-session.php 1 year ago class-plugin-upgrade.php 1 month ago class_mail.php 1 month ago event_updates.php 11 months ago firewall.php 5 months ago fw_centlog.php 1 month ago fw_fileguard.php 5 months ago fw_livelog.php 1 year ago help.php 1 month ago helpers.php 1 month ago i18n-extra.php 1 month ago i18n.php 1 year ago index.html 13 years ago init_update.php 2 years ago install.php 1 year ago install_default.php 7 months ago loader.php 7 months ago mail_template_firewall.php 1 year ago mail_template_plugin.php 2 months ago scheduled_tasks.php 3 years ago settings_dashboard.php 2 months ago settings_dashboard_about.php 1 month ago settings_dashboard_statistics.php 2 months ago settings_event_notifications.php 2 months ago settings_events.php 2 months ago settings_firewall_options.php 2 months ago settings_firewall_policies.php 1 month ago settings_login_protection.php 2 months ago settings_logs.php 2 months ago settings_logs_firewall_log.php 1 month ago settings_logs_live_log.php 2 months ago settings_monitoring.php 1 month ago settings_monitoring_file_check.php 2 months ago settings_monitoring_file_guard.php 2 months ago settings_network.php 2 months ago settings_security_rules.php 2 months ago settings_security_rules_editor.php 2 months ago settings_security_rules_update.php 1 month ago sign.pub 7 years ago thickbox.php 4 years ago widget.php 3 years ago wpplus.php 5 months ago
class-plugin-upgrade.php
195 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 ( class_exists('NinjaFirewall_plugin') ) {
15 return;
16 }
17
18 class NinjaFirewall_plugin {
19
20 private static $url = 'https://downloads.wordpress.org/plugin/%s.%s.zip';
21 private static $slug = '';
22 private static $main = '';
23 private static $network = false;
24 private static $active = false;
25
26
27 /**
28 * Initialize the filesystem.
29 */
30 private static function init() {
31
32 require_once ABSPATH .'wp-admin/includes/class-wp-filesystem-base.php';
33 require_once ABSPATH .'wp-admin/includes/class-wp-filesystem-direct.php';
34 require_once ABSPATH .'wp-admin/includes/file.php';
35 require_once ABSPATH .'wp-admin/includes/plugin.php';
36
37 $res = WP_Filesystem();
38 if ( $res === true ) {
39 return;
40 }
41 $error = esc_html__('Error initialize the filesystem.', 'ninjafirewall');
42 wp_send_json( ['status' => 'error', 'message' => $error ] );
43 }
44
45
46 /**
47 * Manual upgrade of the corresponding plugin.
48 * `nfw_pluginupgrade` AJAX action.
49 */
50 public static function upgrade() {
51
52 global $wp_filesystem;
53
54 /**
55 * Verify user capabilities and the security nonce.
56 */
57 nf_not_allowed('block', __LINE__, 'ajax');
58 if (! check_ajax_referer('pluginupgrade', 'nonce', false ) ) {
59 $error = esc_html__('Security nonces do not match. Reload the page and try again.',
60 'ninjafirewall');
61 wp_send_json( ['status' => 'error', 'message' => $error ] );
62 }
63
64 if ( empty( $_POST['plugin'] ) || empty( $_POST['version'] ) ) {
65 $error = esc_html__('Missing parameters.', 'ninjafirewall');
66 wp_send_json( ['status' => 'error', 'message' => $error ] );
67 }
68
69 list( self::$slug, self::$main ) = explode('/', stripslashes( urldecode( $_POST['plugin'] ) ), 2 );
70 self::$slug = sanitize_title( self::$slug );
71 self::$main = sanitize_file_name( self::$main );
72
73 $version = stripslashes( $_POST['version'] );
74
75 /**
76 * Make sure the plugin and its version match our list.
77 */
78 $nfw_checked = nfw_get_option('nfw_checked');
79 $error = esc_html__('Plugin name or version is invalid.', 'ninjafirewall');
80 if ( empty( $nfw_checked['plugins'] ) ||
81 ! isset( $nfw_checked['plugins'][ self::$slug .'/'. self::$main ]['version'] ) ) {
82
83 wp_send_json( ['status' => 'error', 'message' => $error ] );
84 }
85 if ( $nfw_checked['plugins'][ self::$slug .'/'. self::$main ]['version'] != $version ) {
86 wp_send_json( ['status' => 'error', 'message' => $error ] );
87 }
88
89 /**
90 * Initialize the filestem.
91 */
92 self::init();
93
94 /**
95 * Check if the plugin is activated across the entire network,
96 * if that's a multisite environment.
97 */
98 if ( is_multisite() && is_plugin_active_for_network( self::$slug .'/'. self::$main ) ) {
99 self::$network = true;
100 }
101
102 /**
103 * Deactivate the plugin, silently.
104 */
105 if ( is_plugin_active( self::$slug .'/'. self::$main ) ) {
106 deactivate_plugins( self::$slug .'/'. self::$main ,true );
107 self::$active = true;
108 }
109
110 /**
111 * Download it from wordpress.org.
112 */
113 self::$url = sprintf( self::$url, self::$slug, $version );
114 $file = download_url( self::$url );
115 if ( is_wp_error( $file ) ) {
116 $error = sprintf(
117 esc_html__('Error when trying to download the plugin: %s', 'ninjafirewall'),
118 esc_html ( $file->get_error_message() )
119 );
120 /**
121 * Reactivate the plugin and quit.
122 */
123 self::activate_plugin();
124 wp_send_json( ['status' => 'error', 'message' => $error ] );
125 }
126
127 /**
128 * Delete the plugin folder, recursively.
129 */
130 $plugin_dir = trailingslashit( WP_PLUGIN_DIR ) . self::$slug;
131 if ( $wp_filesystem->is_dir( $plugin_dir ) ) {
132 $res = $wp_filesystem->delete( $plugin_dir, true, 'd');
133 if ( $res === false ) {
134 $error = sprintf(
135 esc_html__('Error when trying to delete the plugin folder: %s', 'ninjafirewall'),
136 esc_html( $plugin_dir )
137 );
138 /**
139 * Try to reactivate the plugin, if possible, before quitting.
140 */
141 self::activate_plugin();
142 wp_send_json( ['status' => 'error', 'message' => $error ] );
143 }
144 }
145
146 /**
147 * Unzip the new plugin.
148 */
149 $res = unzip_file( $file, WP_PLUGIN_DIR );
150 if ( is_wp_error( $res ) ) {
151 $error = sprintf(
152 esc_html__('Error when trying to extract the plugin: %s', 'ninjafirewall'),
153 esc_html ( $res->get_error_message() )
154 );
155 wp_send_json( ['status' => 'error', 'message' => $error ] );
156 }
157
158 /**
159 * Delete the downloaded file.
160 */
161 wp_delete_file( $file );
162
163 /**
164 * Reactivate the plugin, if it was activated prior to the upgrade.
165 */
166 $res = self::activate_plugin();
167 if ( is_wp_error( $res ) ) {
168 $error = sprintf(
169 esc_html__('Error when trying to reactivate the plugin: %s', 'ninjafirewall'),
170 esc_html ( $res->get_error_message() )
171 );
172 wp_send_json( ['status' => 'error', 'message' => $error ] );
173 }
174
175 $message = esc_html__('The plugin was successfully updated. The page will now reload.',
176 'ninjafirewall');
177 wp_send_json( ['status' => 'success', 'message' => $message ] );
178 }
179
180
181 /**
182 * Reactivate the plugin.
183 */
184 private static function activate_plugin() {
185
186 if ( self::$active === true ) {
187 return activate_plugin( self::$slug .'/'. self::$main, '', self::$network, true );
188 }
189 }
190
191 }
192
193 // =====================================================================
194 // EOF
195