Exemplo n.º 1
0
function siteguard_error_dump($title, $obj)
{
    ob_start();
    var_dump($obj);
    $msg = ob_get_contents();
    ob_end_clean();
    siteguard_error_log("{$title}: {$msg}");
}
Exemplo n.º 2
0
 function update_settings($mark, $data)
 {
     if (!SiteGuard_Htaccess::make_tmp_dir()) {
         return false;
     }
     $flag_write = false;
     $flag_through = true;
     $flag_wp = false;
     $flag_wp_set = false;
     $wp_settings = '';
     $mark_start = $mark . '_START';
     $mark_end = $mark . '_END';
     $mark_wp_start = '# BEGIN WordPress';
     $mark_wp_end = '# END WordPress';
     $current_file = SiteGuard_Htaccess::get_htaccess_file();
     if (!file_exists($current_file)) {
         @touch($current_file);
         @chmod($current_file, 0604);
     }
     if (!SiteGuard_Htaccess::check_permission($current_file)) {
         return false;
     }
     $fr = @fopen($current_file, 'r');
     if (null == $fr) {
         siteguard_error_log("fopen failed: {$current_file}");
         return false;
     }
     $new_file = SiteGuard_Htaccess::get_htaccess_new_file();
     if (!is_writable($new_file)) {
         siteguard_error_log("file not writable: {$new_file}");
         return false;
     }
     $fw = @fopen($new_file, 'w');
     if (null == $fw) {
         siteguard_error_log("fopen failed: {$new_file}");
         return false;
     }
     while (!feof($fr)) {
         $line = fgets($fr, 4096);
         // Save WordPress settings.
         // WordPress settings has to be written after SiteGuard settings.
         if (false == $flag_write && false == $flag_wp_set && false !== strpos($line, $mark_wp_start)) {
             $flag_wp = true;
             $flag_wp_set = true;
         }
         if ($flag_wp_set) {
             $wp_settings .= $line;
             if (false !== strpos($line, $mark_wp_end)) {
                 $flag_wp_set = false;
             }
             continue;
         }
         if (false !== strpos($line, $mark_start)) {
             fwrite($fw, $line, strlen($line));
             fwrite($fw, $data, strlen($data));
             $flag_write = true;
             $flag_through = false;
             continue;
         }
         if (false == $flag_write && false !== strpos($line, SiteGuard_Htaccess::$htaccess_mark_end)) {
             fwrite($fw, $mark_start . "\n", strlen($mark_start) + 1);
             fwrite($fw, $data, strlen($data));
             fwrite($fw, $mark_end . "\n", strlen($mark_end) + 1);
             $flag_write = true;
         }
         if (false == $flag_through && false !== strpos($line, $mark_end)) {
             $flag_through = true;
         }
         if ($flag_through) {
             fwrite($fw, $line, strlen($line));
             if (false == $flag_wp && false !== strpos($line, $mark_wp_start)) {
                 $flag_wp = true;
             }
         }
     }
     if (false == $flag_write) {
         fwrite($fw, "\n" . SiteGuard_Htaccess::$htaccess_mark_start . "\n", strlen(SiteGuard_Htaccess::$htaccess_mark_start) + 2);
         fwrite($fw, $mark_start . "\n", strlen($mark_start) + 1);
         fwrite($fw, $data, strlen($data));
         fwrite($fw, $mark_end . "\n", strlen($mark_end) + 1);
         fwrite($fw, SiteGuard_Htaccess::$htaccess_mark_end . "\n", strlen(SiteGuard_Htaccess::$htaccess_mark_end) + 1);
     }
     if ('' != $wp_settings) {
         // Write saved WordPress Settings
         fwrite($fw, "\n", 1);
         fwrite($fw, $wp_settings, strlen($wp_settings));
         fwrite($fw, "\n", 1);
     } else {
         if (false == $flag_wp) {
             // Write empty WordPress Settings
             fwrite($fw, "\n", 1);
             fwrite($fw, $mark_wp_start . "\n", strlen($mark_wp_start) + 1);
             fwrite($fw, $mark_wp_end . "\n", strlen($mark_wp_end) + 1);
             fwrite($fw, "\n", 1);
         }
     }
     fclose($fr);
     fclose($fw);
     @chmod($new_file, 0604);
     if (!rename($new_file, $current_file)) {
         siteguard_error_log("rename failed: {$new_file} {$current_file}");
         return false;
     }
     return true;
 }