PluginProbe
SiteGuard WP Plugin / 1.4.3
SiteGuard WP Plugin v1.4.3
1.8.9 1.8.8 1.8.7 1.8.6 1.8.6-beta1 1.8.6-beta2 1.8.4 1.8.5 1.8.3 1.8.2 1.8.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 All 50 releases
siteguard / siteguard.php
siteguard.php
248 lines 9.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: SiteGuard WP Plugin
4 Plugin URI: http://www.jp-secure.com/cont/products/siteguard_wp_plugin/index_en.html
5 Description: Only installing SiteGuard WP Plugin on WordPress, its security can be improved. SiteGurad WP Plugin is the plugin specialized for the protection against the attack to the management page and login. It also have the function to create the exclude rule for WAF (SiteGuard Lite, to use it, WAF should be installed on the Web server.)
6 Author: JP-Secure
7 Author URI: http://www.jp-secure.com/eng/
8 Text Domain: siteguard
9 Domain Path: /languages/
10 Version: 1.4.3
11 */
12
13 /* Copyright 2014 JP-Secure Inc
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License, version 2, as
17 published by the Free Software Foundation.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29 if ( ! defined( 'ABSPATH' ) ) {
30 exit;
31 }
32
33 $data = get_file_data( __FILE__, array( 'version' => 'Version' ) );
34 define( 'SITEGUARD_VERSION', $data['version'] );
35
36 define( 'SITEGUARD_PATH', plugin_dir_path( __FILE__ ) );
37 define( 'SITEGUARD_URL_PATH', plugin_dir_url( __FILE__ ) );
38
39 define( 'SITEGUARD_LOGIN_NOSELECT', 4 );
40 define( 'SITEGUARD_LOGIN_SUCCESS', 0 );
41 define( 'SITEGUARD_LOGIN_FAILED', 1 );
42 define( 'SITEGUARD_LOGIN_FAIL_ONCE', 2 );
43 define( 'SITEGUARD_LOGIN_LOCKED', 3 );
44
45 define( 'SITEGUARD_LOGIN_TYPE_NOSELECT', 2 );
46 define( 'SITEGUARD_LOGIN_TYPE_NORMAL', 0 );
47 define( 'SITEGUARD_LOGIN_TYPE_XMLRPC', 1 );
48
49 require_once( 'classes/siteguard-base.php' );
50 require_once( 'classes/siteguard-config.php' );
51 require_once( 'classes/siteguard-htaccess.php' );
52 require_once( 'classes/siteguard-admin-filter.php' );
53 require_once( 'classes/siteguard-rename-login.php' );
54 require_once( 'classes/siteguard-login-history.php' );
55 require_once( 'classes/siteguard-login-lock.php' );
56 require_once( 'classes/siteguard-login-alert.php' );
57 require_once( 'classes/siteguard-captcha.php' );
58 require_once( 'classes/siteguard-disable-xmlrpc.php' );
59 require_once( 'classes/siteguard-disable-pingback.php' );
60 require_once( 'classes/siteguard-waf-exclude-rule.php' );
61 require_once( 'classes/siteguard-updates-notify.php' );
62 require_once( 'admin/siteguard-menu-init.php' );
63
64 global $siteguard_htaccess;
65 global $siteguard_config;
66 global $siteguard_admin_filter;
67 global $siteguard_rename_login;
68 global $siteguard_loginlock;
69 global $siteguard_loginalert;
70 global $siteguard_captcha;
71 global $siteguard_login_history;
72 global $siteguard_xmlrpc;
73 global $siteguard_pingback;
74 global $siteguard_waf_exclude_rule;
75 global $siteguard_updates_notify;
76
77 $siteguard_htaccess = new SiteGuard_Htaccess( );
78 $siteguard_config = new SiteGuard_Config( );
79 $siteguard_admin_filter = new SiteGuard_AdminFilter( );
80 $siteguard_rename_login = new SiteGuard_RenameLogin( );
81 $siteguard_loginlock = new SiteGuard_LoginLock( );
82 $siteguard_loginalert = new SiteGuard_LoginAlert( );
83 $siteguard_login_history = new SiteGuard_LoginHistory( );
84 $siteguard_captcha = new SiteGuard_CAPTCHA( );
85 $siteguard_xmlrpc = new SiteGuard_Disable_XMLRPC( );
86 $siteguard_pingback = new SiteGuard_Disable_Pingback( );
87 $siteguard_waf_exclude_rule = new SiteGuard_WAF_Exclude_Rule( );
88 $siteguard_updates_notify = new SiteGuard_UpdatesNotify( );
89
90 function siteguard_activate( ) {
91 global $siteguard_config, $siteguard_admin_filter, $siteguard_rename_login, $siteguard_login_history, $siteguard_captcha, $siteguard_loginlock, $siteguard_loginalert, $siteguard_xmlrpc, $siteguard_pingback, $siteguard_waf_exclude_rule, $siteguard_updates_notify;
92
93 load_plugin_textdomain(
94 'siteguard',
95 false,
96 dirname( plugin_basename( __FILE__ ) ) . '/languages'
97 );
98
99 $siteguard_config->set( 'show_admin_notices', '0' );
100 $siteguard_config->update( );
101 $siteguard_admin_filter->init();
102 $siteguard_rename_login->init();
103 $siteguard_login_history->init();
104 $siteguard_captcha->init();
105 $siteguard_loginlock->init();
106 $siteguard_loginalert->init();
107 $siteguard_xmlrpc->init();
108 $siteguard_pingback->init();
109 $siteguard_waf_exclude_rule->init();
110 $siteguard_updates_notify->init();
111 }
112 register_activation_hook( __FILE__, 'siteguard_activate' );
113
114 function siteguard_deactivate( ) {
115 global $siteguard_config;
116 $siteguard_config->set( 'show_admin_notices', '0' );
117 $siteguard_config->update( );
118 SiteGuard_RenameLogin::feature_off( );
119 SiteGuard_AdminFilter::feature_off( );
120 SiteGuard_Disable_XMLRPC::feature_off( );
121 SiteGuard_WAF_Exclude_Rule::feature_off( );
122 SiteGuard_UpdatesNotify::feature_off( );
123 }
124 register_deactivation_hook( __FILE__, 'siteguard_deactivate' );
125
126
127 class SiteGuard extends SiteGuard_Base {
128 protected $menu_init;
129 function __construct( ) {
130 global $siteguard_config;
131 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
132 $this->htaccess_check( );
133 if ( is_admin( ) ) {
134 include ( 'admin/siteguard-menu-login-history.php' );
135 $this->menu_init = new SiteGuard_Menu_Init( );
136 add_action( 'init', array( $this, 'set_cookie' ) );
137 add_action( 'admin_init', array( $this, 'upgrade' ) );
138 if ( '0' === $siteguard_config->get( 'show_admin_notices' ) && '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
139 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
140 $siteguard_config->set( 'show_admin_notices', '1' );
141 $siteguard_config->update( );
142 }
143 }
144 }
145 function set_cookie( ) {
146 SiteGuard_Menu_Login_History::set_cookie( );
147 }
148 function plugins_loaded( ) {
149 load_plugin_textdomain(
150 'siteguard',
151 false,
152 dirname( plugin_basename( __FILE__ ) ) . '/languages'
153 );
154 }
155 function htaccess_check( ) {
156 global $siteguard_config;
157
158 $can_use_htaccess = true;
159 if ( false === SiteGuard_Htaccess::test_htaccess( ) ) {
160 $can_use_htaccess = false;
161 }
162 if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
163 if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_AdminFilter::get_mark( ) ) ) {
164 $siteguard_config->set( 'admin_filter_enable', '0' );
165 $siteguard_config->update( );
166 }
167 }
168 if ( '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
169 if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_RenameLogin::get_mark( ) ) ) {
170 $siteguard_config->set( 'renamelogin_enable', '0' );
171 $siteguard_config->update( );
172 }
173 }
174 if ( '1' === $siteguard_config->get( 'disable_xmlrpc_enable' ) ) {
175 if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_Disable_XMLRPC::get_mark( ) ) ) {
176 $siteguard_config->set( 'disable_xmlrpc_enable', '0' );
177 $siteguard_config->update( );
178 }
179 }
180 if ( '1' === $siteguard_config->get( 'waf_exclude_rule_enable' ) ) {
181 if ( false === $can_use_htaccess || ! SiteGuard_Htaccess::is_exists_setting( SiteGuard_WAF_Exclude_Rule::get_mark( ) ) ) {
182 $siteguard_config->set( 'waf_exclude_rule_enable', '0' );
183 $siteguard_config->update( );
184 }
185 }
186 if ( '1' === $siteguard_config->get( 'captcha_enable' ) ) {
187 if ( false === $can_use_htaccess) {
188 $siteguard_config->set( 'captcha_enable', '0' );
189 $siteguard_config->update( );
190 }
191 }
192 }
193 function admin_notices( ) {
194 global $siteguard_rename_login;
195 echo '<div class="updated" style="background-color:#719f1d;"><p><span style="border: 4px solid #def1b8;padding: 4px 4px;color:#fff;font-weight:bold;background-color:#038bc3;">';
196 echo esc_html__( 'Login page URL was changed.', 'siteguard' ) . '</span>';
197 echo '<span style="color:#eee;">';
198 echo esc_html__( ' Please bookmark ', 'siteguard' ) . '<a style="color:#fff;text-decoration:underline;" href="' . esc_url( wp_login_url( ) ) . '">';
199 echo esc_html__( 'new login URL', 'siteguard' ) . '</a>';
200 echo esc_html__( '. Setting change is ', 'siteguard' ) . '<a style="color:#fff;text-decoration:underline;" href="' . esc_url( menu_page_url( 'siteguard_rename_login', false ) ) . '">';
201 echo esc_html__( 'here', 'siteguard' ) . '</a>';
202 echo '.</span></p></div>';
203 $siteguard_rename_login->send_notify( );
204 }
205 function upgrade( ) {
206 global $siteguard_config, $siteguard_rename_login, $siteguard_admin_filter, $siteguard_loginalert, $siteguard_updates_notify, $siteguard_login_history, $siteguard_xmlrpc;
207 $upgrade_ok = true;
208 $old_version = $siteguard_config->get( 'version' );
209 if ( '' === $old_version ) {
210 $old_version = '0.0.0';
211 }
212 if ( version_compare( $old_version, '1.0.6' ) < 0 ) {
213 if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
214 if ( true !== $siteguard_admin_filter->feature_on( $this->get_ip( ) ) ) {
215 siteguard_error_log( 'Failed to update at admin_filter from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
216 $upgrade_ok = false;
217 }
218 }
219 }
220 if ( version_compare( $old_version, '1.1.1' ) < 0 ) {
221 $siteguard_loginalert->init();
222 }
223 if ( version_compare( $old_version, '1.2.0' ) < 0 ) {
224 $siteguard_updates_notify->init();
225 }
226 if ( version_compare( $old_version, '1.2.5' ) < 0 ) {
227 if ( '1' === $siteguard_config->get( 'admin_filter_enable' ) ) {
228 $siteguard_admin_filter->cvt_status_for_1_2_5( $this->get_ip( ) );
229 }
230 if ( '1' === $siteguard_config->get( 'renamelogin_enable' ) ) {
231 if ( true !== $siteguard_rename_login->feature_on( ) ) {
232 siteguard_error_log( 'Failed to update at rename_login from ' . $old_version . ' to ' . SITEGUARD_VERSION . '.' );
233 $upgrade_ok = false;
234 }
235 }
236 }
237 if ( $upgrade_ok && SITEGUARD_VERSION !== $old_version ) {
238 $siteguard_config->set( 'version', SITEGUARD_VERSION );
239 $siteguard_config->update( );
240 }
241 if ( version_compare( $old_version, '1.3.0' ) < 0 ) {
242 $siteguard_login_history->init( );
243 $siteguard_xmlrpc->init( );
244 }
245 }
246 }
247 $siteguard = new SiteGuard;
248