| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package RSFirewall! |
| 4 |
* @copyright (c) 2018 RSJoomla! |
| 5 |
* @link https://www.rsjoomla.com |
| 6 |
* @license GNU General Public License http://www.gnu.org/licenses/gpl-3.0.en.html |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'WPINC' ) ) { |
| 10 |
die; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Class RSFirewall_Controller_Check |
| 15 |
* |
| 16 |
*/ |
| 17 |
class RSFirewall_Controller_Check extends RSFirewall_Controller { |
| 18 |
/** |
| 19 |
* RSFirewall_System_Check_Controller constructor. |
| 20 |
* |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
private $class_used; |
| 24 |
|
| 25 |
public function __construct() { |
| 26 |
parent::__construct(); |
| 27 |
|
| 28 |
$this->class_used = get_class($this); |
| 29 |
} |
| 30 |
|
| 31 |
public function enqueue_scripts($pagenow){ |
| 32 |
if ($pagenow != 'rsfirewall_page_rsfirewall_check') { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
// Load modal JS files |
| 37 |
RSFirewall_Helper::load_rsmodal('dependencies.js', $this->version); |
| 38 |
|
| 39 |
wp_enqueue_script( 'knob', RSFIREWALL_URL . 'assets/js/vendors/jquery.knob.js', array( 'jquery' ), $this->version, false ); |
| 40 |
|
| 41 |
wp_register_script( 'rsfirewall_check', RSFIREWALL_URL . 'assets/js/rsfirewall_check.js', array( |
| 42 |
'jquery', |
| 43 |
'rsfirewall_diff' |
| 44 |
), $this->version, false ); |
| 45 |
|
| 46 |
$params = array( |
| 47 |
'view_contents_nonce' => wp_create_nonce( 'view_contents' ), |
| 48 |
'step_check_nonce' => wp_create_nonce( 'step_check' ), |
| 49 |
'save_grade_nonce' => wp_create_nonce( 'save_grade' ), |
| 50 |
'admin_username_fix_nonce' => wp_create_nonce( 'admin_username_fix' ), |
| 51 |
'php_configuration_fix_nonce' => wp_create_nonce( 'php_configuration_fix' ), |
| 52 |
'ignore_hashes_nonce' => wp_create_nonce( 'ignore_hashes' ), |
| 53 |
'fix_delete_revisions_nonce' => wp_create_nonce( 'fix_delete_revisions' ), |
| 54 |
'remove_ignored_none' => wp_create_nonce( 'remove_ignored' ), |
| 55 |
); |
| 56 |
|
| 57 |
if ($this->class_used != 'RSFirewall_Controller_CheckPro') { |
| 58 |
wp_localize_script('rsfirewall_check', 'rsfirewall_check_locale', RSFirewall_i18n::get_locale('rsfirewall_check')); |
| 59 |
wp_localize_script('rsfirewall_check', 'rsfirewall_check_security', $params); |
| 60 |
wp_enqueue_script('rsfirewall_check'); |
| 61 |
} else { |
| 62 |
return $params; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
public function enqueue_styles($pagenow) { |
| 67 |
if ($pagenow != 'rsfirewall_page_rsfirewall_check') { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
// Load modal CSS files |
| 72 |
RSFirewall_Helper::load_rsmodal('dependencies.css', $this->version); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Checks your current WordPress version. |
| 77 |
*/ |
| 78 |
public function wp_version_check() { |
| 79 |
// Check the nonce for this action |
| 80 |
RSFirewall_Helper::check_nonce('step_check'); |
| 81 |
|
| 82 |
$data = new stdClass(); |
| 83 |
$success = true; |
| 84 |
|
| 85 |
try { |
| 86 |
if ( !$result = $this->model->wp_version_check() ) { |
| 87 |
throw new Exception ( esc_html__( 'RSFirewall! Encountered an error', 'rsfirewall' ) ); |
| 88 |
} |
| 89 |
|
| 90 |
if ( $result['api_response'] == 'latest' ) { |
| 91 |
$data->result = true; |
| 92 |
$data->message = sprintf( esc_html__( 'Your WordPress version ( %s ) is up to date.', 'rsfirewall' ), $result['current_version'] ); |
| 93 |
} else { |
| 94 |
$data->result = false; |
| 95 |
$data->message = sprintf( esc_html__( 'Your WordPress version ( %s ) is outdated. We strongly recommend updating to %s', 'rsfirewall' ), $result['current_version'], $result['latest_version'] ); |
| 96 |
} |
| 97 |
|
| 98 |
} catch ( Exception $e ) { |
| 99 |
$success = false; |
| 100 |
$data->message = $e->getMessage(); |
| 101 |
} |
| 102 |
|
| 103 |
$this->show_response( $success, $data ); |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Checks your current RSFirewall! version. |
| 108 |
*/ |
| 109 |
public function rsfirewall_version_check() { |
| 110 |
// Check the nonce for this action |
| 111 |
RSFirewall_Helper::check_nonce('step_check'); |
| 112 |
|
| 113 |
$data = new stdClass(); |
| 114 |
$success = true; |
| 115 |
|
| 116 |
try { |
| 117 |
if ( ! $result = $this->model->rsfirewall_version_check() ) { |
| 118 |
throw new Exception ( esc_html__( 'RSFirewall! Encountered an error', 'rsfirewall' ) ); |
| 119 |
} |
| 120 |
|
| 121 |
if ( $result['api_response'] > - 1 ) { |
| 122 |
$data->result = true; |
| 123 |
$data->message = sprintf( esc_html__( 'RSFirewall! version ( %s ) is up to date.', 'rsfirewall' ), $result['current_version'] ); |
| 124 |
} else { |
| 125 |
$data->result = false; |
| 126 |
$data->message = sprintf( esc_html__( 'Your RSFirewall! version ( %s ) is outdated. We strongly recommend updating to %s.', 'rsfirewall' ), $result['current_version'], $result['latest_version'] ); |
| 127 |
$data->details = wp_kses_post( __('A new version of RSFirewall! has been released. You can see the complete list of changes in the official plugin changelog found <a href="https://www.rsjoomla.com/support/documentation/rsfirewall-wordpress/changelog/rsfirewall-for-wordpress-changelog.html" target="_blank">here</a>.', 'rsfirewall') ); |
| 128 |
} |
| 129 |
|
| 130 |
} catch ( Exception $e ) { |
| 131 |
$success = false; |
| 132 |
$data->message = $e->getMessage(); |
| 133 |
} |
| 134 |
|
| 135 |
$this->show_response( $success, $data ); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Checks your database password |
| 140 |
*/ |
| 141 |
public function weak_database_pswrd_check() { |
| 142 |
// Check the nonce for this action |
| 143 |
RSFirewall_Helper::check_nonce('step_check'); |
| 144 |
|
| 145 |
$model = $this->model; |
| 146 |
$data = new stdClass(); |
| 147 |
$success = true; |
| 148 |
try { |
| 149 |
if ( ! $result = $model->weak_database_pswrd_check() ) { |
| 150 |
throw new Exception ( esc_html__( 'RSFirewall! Encountered an error', 'rsfirewall' ) ); |
| 151 |
} |
| 152 |
|
| 153 |
$data->result = true; |
| 154 |
$data->message = esc_html__( 'Your Database Password is OK.', 'rsfirewall' ); |
| 155 |
|
| 156 |
if ( $result['weak_password'] ) { |
| 157 |
$data->result = false; |
| 158 |
$data->message = $result['message']; |
| 159 |
$data->details = $result['details']; |
| 160 |
} |
| 161 |
|
| 162 |
} catch ( Exception $e ) { |
| 163 |
$success = false; |
| 164 |
$data->message = $e->getMessage(); |
| 165 |
} |
| 166 |
|
| 167 |
$this->show_response( $success, $data ); |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Checks if you have a weak username |
| 172 |
*/ |
| 173 |
public function admin_username_check() { |
| 174 |
// Check the nonce for this action |
| 175 |
RSFirewall_Helper::check_nonce('step_check'); |
| 176 |
|
| 177 |
$model = $this->model; |
| 178 |
$data = new stdClass(); |
| 179 |
$success = true; |
| 180 |
try { |
| 181 |
if ( ! $result = $model->admin_username_check() ) { |
| 182 |
throw new Exception ( esc_html__( 'RSFirewall! Encountered an error', 'rsfirewall' ) ); |
| 183 |
} |
| 184 |
|
| 185 |
$data->result = true; |
| 186 |
$data->message = $result['message']; |
| 187 |
|
| 188 |
$details = ''; |
| 189 |
if ( ! empty( $result['users'] ) ) { |
| 190 |
$data->result = false; |
| 191 |
foreach ( $result['users'] as $user ) { |
| 192 |
$details .= $user['details'] . '</br>'; |
| 193 |
} |
| 194 |
$data->details = $details; |
| 195 |
$data->message = $result['message']; |
| 196 |
} |
| 197 |
|
| 198 |
} catch ( Exception $e ) { |
| 199 |
$success = false; |
| 200 |
$data->message = $e->getMessage(); |
| 201 |
} |
| 202 |
|
| 203 |
$this->show_response( $success, $data ); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Checks if you have a dangerous username |
| 208 |
*/ |
| 209 |
public function admin_unwanted_username_check() { |
| 210 |
// Check the nonce for this action |
| 211 |
RSFirewall_Helper::check_nonce('step_check'); |
| 212 |
|
| 213 |
$model = $this->model; |
| 214 |
$data = new stdClass(); |
| 215 |
$success = true; |
| 216 |
try { |
| 217 |
if ( ! $result = $model->admin_unwanted_username_check() ) { |
| 218 |
throw new Exception ( esc_html__( 'RSFirewall! Encountered an error', 'rsfirewall' ) ); |
| 219 |
} |
| 220 |
|
| 221 |
$data->result = true; |
| 222 |
$data->message = $result['message']; |
| 223 |
|
| 224 |
$details = ''; |
| 225 |
if ( ! empty( $result['users'] ) ) { |
| 226 |
$data->result = false; |
| 227 |
foreach ( $result['users'] as $user ) { |
| 228 |
$details .= $user['details'] . '</br>'; |
| 229 |
} |
| 230 |
$data->details = $details; |
| 231 |
$data->message = $result['message']; |
| 232 |
} |
| 233 |
|
| 234 |
} catch ( Exception $e ) { |
| 235 |
$success = false; |
| 236 |
$data->message = $e->getMessage(); |
| 237 |
} |
| 238 |
|
| 239 |
$this->show_response( $success, $data ); |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Checks if you have SEF links enabled |
| 244 |
*/ |
| 245 |
public function sef_enabled_check() { |
| 246 |
// Check the nonce for this action |
| 247 |
RSFirewall_Helper::check_nonce('step_check'); |
| 248 |
|
| 249 |
$model = $this->model; |
| 250 |
$data = new stdClass(); |
| 251 |
$success = true; |
| 252 |
try { |
| 253 |
if ( ! $result = $model->sef_enabled_check() ) { |
| 254 |
throw new Exception ( esc_html__( 'RSFirewall! Encountered an error', 'rsfirewall' ) ); |
| 255 |
} |
| 256 |
|
| 257 |
$data->result = $result['sef_enabled']; |
| 258 |
$data->message = $result['message']; |
| 259 |
|
| 260 |
if ( ! $data->result ) { |
| 261 |
$data->details = $result['details']; |
| 262 |
} |
| 263 |
|
| 264 |
} catch ( Exception $e ) { |
| 265 |
$success = false; |
| 266 |
$data->message = $e->getMessage(); |
| 267 |
} |
| 268 |
|
| 269 |
$this->show_response( $success, $data ); |
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* Checks for the post/page revisions |
| 274 |
*/ |
| 275 |
public function revisions_check() { |
| 276 |
// Check the nonce for this action |
| 277 |
RSFirewall_Helper::check_nonce('step_check'); |
| 278 |
|
| 279 |
$model = $this->model; |
| 280 |
$data = new stdClass(); |
| 281 |
$success = true; |
| 282 |
try { |
| 283 |
if ( ! $result = $model->revisions_check() ) { |
| 284 |
throw new Exception ( esc_html__( 'RSFirewall! Encountered an error', 'rsfirewall' ) ); |
| 285 |
} |
| 286 |
|
| 287 |
$data->result = $result['result']; |
| 288 |
$data->message = $result['message']; |
| 289 |
|
| 290 |
if ( ! empty( $result['details'] ) ) { |
| 291 |
$data->details = $result['details']; |
| 292 |
} |
| 293 |
|
| 294 |
} catch ( Exception $e ) { |
| 295 |
$success = false; |
| 296 |
$data->message = $e->getMessage(); |
| 297 |
} |
| 298 |
$this->show_response( $success, $data ); |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* Checks the allow_url_include directive from PHP ini |
| 303 |
*/ |
| 304 |
public function check_allow_url_include() { |
| 305 |
// Check the nonce for this action |
| 306 |
RSFirewall_Helper::check_nonce('step_check'); |
| 307 |
|
| 308 |
$model = $this->model; |
| 309 |
$data = new stdClass(); |
| 310 |
$success = true; |
| 311 |
|
| 312 |
$data->result = ! $model->check_allow_url_include(); |
| 313 |
$data->message = $data->result ? esc_html__( 'allow_url_include is Off', 'rsfirewall' ) : esc_html__( 'allow_url_include is On', 'rsfirewall' ); |
| 314 |
|
| 315 |
$this->show_response( $success, $data ); |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Checks the open_basedir directive from PHP ini |
| 320 |
*/ |
| 321 |
public function check_open_basedir() { |
| 322 |
// Check the nonce for this action |
| 323 |
RSFirewall_Helper::check_nonce('step_check'); |
| 324 |
|
| 325 |
$model = $this->model; |
| 326 |
$data = new stdClass(); |
| 327 |
$success = true; |
| 328 |
|
| 329 |
$data->result = ! $model->check_open_basedir(); |
| 330 |
$data->message = $data->result ? esc_html__( 'open_basedir is used.', 'rsfirewall' ) : esc_html__( 'open_basedir is not used.', 'rsfirewall' ); |
| 331 |
|
| 332 |
$this->show_response( $success, $data ); |
| 333 |
} |
| 334 |
|
| 335 |
/** |
| 336 |
* Checks the disable functions directives from PHP ini |
| 337 |
*/ |
| 338 |
public function check_disable_functions() { |
| 339 |
// Check the nonce for this action |
| 340 |
RSFirewall_Helper::check_nonce('step_check'); |
| 341 |
|
| 342 |
$model = $this->model; |
| 343 |
$data = new stdClass(); |
| 344 |
$success = true; |
| 345 |
|
| 346 |
$result = $model->check_disable_functions(); |
| 347 |
|
| 348 |
$data->result = $result['result']; |
| 349 |
$data->message = $result['message']; |
| 350 |
|
| 351 |
$this->show_response( $success, $data ); |
| 352 |
} |
| 353 |
|
| 354 |
/** |
| 355 |
* Checks if safe_mode is used |
| 356 |
*/ |
| 357 |
public function check_safe_mode() { |
| 358 |
// Check the nonce for this action |
| 359 |
RSFirewall_Helper::check_nonce('step_check'); |
| 360 |
|
| 361 |
$model = $this->model; |
| 362 |
$data = new stdClass(); |
| 363 |
$success = true; |
| 364 |
|
| 365 |
$data->result = ! $model->check_safe_mode(); |
| 366 |
$data->message = $data->result ? esc_html__( 'safe_mode is off.', 'rsfirewall' ) : esc_html__( 'safe_mode is on', 'rsfirewall' ); |
| 367 |
|
| 368 |
$this->show_response( $success, $data ); |
| 369 |
} |
| 370 |
|
| 371 |
/** |
| 372 |
* Checks if register_globals is used |
| 373 |
*/ |
| 374 |
public function check_register_globals() { |
| 375 |
// Check the nonce for this action |
| 376 |
RSFirewall_Helper::check_nonce('step_check'); |
| 377 |
|
| 378 |
$model = $this->model; |
| 379 |
$data = new stdClass(); |
| 380 |
$success = true; |
| 381 |
|
| 382 |
$data->result = ! $model->check_register_globals(); |
| 383 |
$data->message = $data->result ? esc_html__( 'register_globals is off.', 'rsfirewall' ) : esc_html__( 'register_globals is on', 'rsfirewall' ); |
| 384 |
|
| 385 |
$this->show_response( $success, $data ); |
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* Saves the scan score(grade) to the database for further use |
| 390 |
*/ |
| 391 |
public function save_grade() { |
| 392 |
// Check the nonce for this action |
| 393 |
RSFirewall_Helper::check_nonce('save_grade'); |
| 394 |
|
| 395 |
$this->model->save_grade(); |
| 396 |
die; |
| 397 |
} |
| 398 |
} |