Esempio n. 1
0
 /**
  * Execute module deactivation
  *
  * @return void
  */
 public function execute_deactivate()
 {
     global $itsec_files;
     delete_site_transient('itsec_random_version');
     //Reset recommended file permissions
     @chmod(ITSEC_Lib::get_htaccess(), 0644);
     @chmod(ITSEC_Lib::get_config(), 0644);
 }
 /**
  * Execute module deactivation
  *
  * @return void
  */
 public function execute_deactivate()
 {
     global $itsec_files;
     delete_site_transient('itsec_random_version');
     $config_rules[] = itsec_tweaks_Admin::build_wpconfig_rules(null, true);
     $itsec_files->set_wpconfig($config_rules);
     //Reset recommended file permissions
     @chmod(ITSEC_Lib::get_htaccess(), 0644);
     @chmod(ITSEC_Lib::get_config(), 0644);
 }
Esempio n. 3
0
 /**
  * Execute module deactivation
  *
  * @return void
  */
 public function execute_deactivate()
 {
     //Reset recommended file permissions
     @chmod(ITSEC_Lib::get_htaccess(), 0644);
     @chmod(ITSEC_Lib::get_config(), 0644);
 }
Esempio n. 4
0
<?php

global $wpdb, $itsec_globals;
$config_file = ITSEC_Lib::get_config();
$htaccess = ITSEC_Lib::get_htaccess();
?>

<ul class="itsec-support">
<li>
	<h4><?php 
_e('User Information', 'it-l10n-better-wp-security');
?>
</h4>
	<ul>
		<li><?php 
_e('Public IP Address', 'it-l10n-better-wp-security');
?>
: <strong><a target="_blank"
		                                                            title="<?php 
_e('Get more information on this address', 'it-l10n-better-wp-security');
?>
"
		                                                            href="http://whois.domaintools.com/<?php 
echo ITSEC_Lib::get_ip();
?>
"><?php 
echo ITSEC_Lib::get_ip();
?>
</a></strong>
		</li>
		<li><?php 
} else {
    $this_test['status'] = 'OK';
}
array_push($tests, $this_test);
$wp_upload_dir = wp_upload_dir();
$this_test = array('title' => str_replace(ABSPATH, '', $wp_upload_dir['basedir']), 'suggestion' => '= 755', 'value' => substr(sprintf('%o', fileperms($wp_upload_dir['basedir'])), -4));
if (!fileperms($wp_upload_dir['basedir']) || 755 != substr(sprintf('%o', fileperms($wp_upload_dir['basedir'])), -4)) {
    $this_test['status'] = 'WARNING';
} else {
    $this_test['status'] = 'OK';
}
array_push($tests, $this_test);
//END FOLDERS
//BEGIN FILES
$this_test = array('title' => 'wp-config.php', 'suggestion' => '= 444', 'value' => substr(sprintf('%o', fileperms(ITSEC_Lib::get_config())), -4));
if (!fileperms(ITSEC_Lib::get_config()) || 444 != substr(sprintf('%o', fileperms(ITSEC_Lib::get_config())), -4)) {
    $this_test['status'] = 'WARNING';
} else {
    $this_test['status'] = 'OK';
}
array_push($tests, $this_test);
$this_test = array('title' => '.htaccess', 'suggestion' => '= 444', 'value' => substr(sprintf('%o', fileperms(ITSEC_Lib::get_htaccess())), -4));
if (!fileperms(ITSEC_Lib::get_htaccess()) || 444 != substr(sprintf('%o', fileperms(ITSEC_Lib::get_htaccess())), -4)) {
    $this_test['status'] = 'WARNING';
} else {
    $this_test['status'] = 'OK';
}
array_push($tests, $this_test);
//END FILES
?>
Esempio n. 6
0
 /**
  * Writes given rules to wp-config.php.
  *
  * @since  4.0
  *
  * @access private
  *
  * @return bool true on success, false on failure
  */
 private function write_wpconfig()
 {
     $config_file = ITSEC_Lib::get_config();
     if (file_exists($config_file)) {
         //check wp-config.php exists where we think it should
         $config_contents = @file_get_contents($config_file);
         //get the contents of wp-config.php
         if (!$config_contents) {
             //we couldn't get wp-config.php contents
             return false;
         } else {
             //write out what we need to.
             $rules_to_write = '';
             //String of rules to insert into wp-config
             $rule_to_replace = '';
             //String containing a rule to be replaced
             $rules_to_delete = false;
             //assume we're not deleting anything to start
             $replace = false;
             //assume we're note replacing anything to start with
             //build the rules we need to write, replace or delete
             foreach ($this->wpconfig_rules as $section_rule) {
                 if (is_array($section_rule['rules'])) {
                     foreach ($section_rule['rules'] as $rule) {
                         $found = false;
                         if ($rule['type'] === 'add' && $rule['rule'] !== false) {
                             //new rule or replacing a rule that doesn't exist
                             $rules_to_write .= $rule['rule'] . PHP_EOL;
                         } elseif ($rule['type'] === 'replace' && $rule['rule'] !== false && strpos($config_contents, $rule['search_text']) !== false) {
                             //Replacing a rule that does exist. Note this will only work on one rule at a time
                             $replace = $rule['search_text'];
                             $rule_to_replace .= $rule['rule'];
                             $found = true;
                         }
                         if ($found !== true) {
                             //deleting a rule.
                             if ($rules_to_delete === false) {
                                 $rules_to_delete = array();
                             }
                             $rules_to_delete[] = $rule;
                         }
                     }
                 }
             }
             //deleting a rule.
             if ($rules_to_delete === false) {
                 $rules_to_delete = array();
             }
             $rules_to_delete[]['search_text'] = "BWPS_FILECHECK";
             $rules_to_delete[]['search_text'] = "BWPS_AWAY_MODE";
             //delete and replace
             if ($replace !== false || is_array($rules_to_delete)) {
                 $config_array = explode(PHP_EOL, $config_contents);
                 if (is_array($rules_to_delete)) {
                     $delete_count = 0;
                     $delete_total = sizeof($rules_to_delete);
                 } else {
                     $delete_total = 0;
                     $delete_count = 0;
                 }
                 foreach ($config_array as $line_number => $line) {
                     if (strpos($line, $replace) !== false) {
                         $config_array[$line_number] = $rule_to_replace;
                     }
                     if ($delete_count < $delete_total) {
                         foreach ($rules_to_delete as $rule) {
                             if (strpos($line, $rule['search_text']) !== false) {
                                 unset($config_array[$line_number]);
                                 //delete the following line(s) if they is blank
                                 $count = 1;
                                 while (isset($config_array[$line_number + $count]) && strlen(trim($config_array[$line_number + $count])) < 1) {
                                     unset($config_array[$line_number + 1]);
                                 }
                                 $delete_count++;
                             }
                         }
                     }
                 }
                 $config_contents = implode(PHP_EOL, $config_array);
             }
             //Adding a new rule or replacing rules that don't exist
             if (strlen($rules_to_write) > 1) {
                 $config_contents = str_replace('<?php' . PHP_EOL, '<?php' . PHP_EOL . $rules_to_write . PHP_EOL, $config_contents);
             }
         }
     }
     //Actually write the new content to wp-config.
     if (isset($config_contents) && $config_contents !== false) {
         //Make sure we can write to the file
         $perms = substr(sprintf('%o', @fileperms($config_file)), -4);
         @chmod($config_file, 0664);
         if (!@file_put_contents($config_file, $config_contents, LOCK_EX)) {
             //reset file permissions if we changed them
             if ($perms == '0444' || $this->write_files === true) {
                 @chmod($config_file, 0444);
             }
             return false;
         }
         //reset file permissions if we changed them
         if ($perms == '0444' || $this->write_files === true) {
             @chmod($config_file, 0444);
         }
     }
     return true;
 }