Exemple #1
0
function update_htaccess($dir, $depth)
{
    if (preg_match('|/CVS$|', $dir)) {
        return true;
    }
    if (preg_match('|/opt$|', $dir)) {
        return true;
    }
    if (preg_match('|/wip$|', $dir)) {
        return true;
    }
    if (preg_match('|/www$|', $dir)) {
        return true;
    }
    $files = fbFile::scandir($dir, 0, false);
    $dirs = array();
    $found = false;
    foreach ($files as $file) {
        $path = $dir . '/' . $file;
        if (@is_dir($path)) {
            $dirs[] = $path;
            continue;
        }
        if ($file == '.htaccess') {
            $found = true;
            continue;
        }
    }
    // foreach($files as $file)
    $cvsheader_found = false;
    $deny_found = false;
    $lines = array();
    $path = $dir . '/.htaccess';
    if ($found) {
        $lines = file($path);
        if ($lines === false) {
            die(sprintf("Can't open '%s': %s", $file, $php_errormsg));
        }
        for ($i = 0; $i < count($lines); ++$i) {
            if (preg_match('/(allow|deny)\\s+from\\s+all/i', $lines[$i])) {
                $deny_found = true;
            }
            if (preg_match('/\\$CVSHeader[^\\$]*\\$/', $lines[$i])) {
                $cvsheader_found = true;
            }
            if ($deny_found && $cvsheader_found) {
                break;
            }
        }
    }
    if (!$deny_found || !$cvsheader_found) {
        if (!$deny_found) {
            $lines[] = "Deny from all\n";
        }
        if (!$cvsheader_found) {
            $lines[] = "\n# \$CVSHeader\$\n";
        }
        if ($found) {
            $file_tmp = $path . '.tmp';
            $file_bak = $path . '.bak';
        } else {
            $file_tmp = $path;
        }
        $fp = fopen($file_tmp, 'wb');
        if (!$fp) {
            die(sprintf("Can't create '%s': %s", $file_tmp, $php_errormsg));
        }
        for ($i = 0; $i < count($lines); ++$i) {
            fwrite($fp, $lines[$i]);
        }
        fclose($fp);
        printf("Updated %s\n", $path);
        if ($found) {
            if (!@rename($path, $file_bak)) {
                die(sprintf("Can't rename '%s' to '%s': %s", $path, $file_bak, $php_errormsg));
            }
            if (!@rename($file_tmp, $path)) {
                die(sprintf("Can't rename '%s' to '%s': %s", $file_tmp, $path, $php_errormsg));
            }
        }
    }
    // if (!$deny_found || !$cvsheader_found)
    if ($depth == 0) {
        foreach ($dirs as $dir) {
            if (!update_htaccess($dir, $depth + 1)) {
                return false;
            }
        }
    }
    return true;
}
        if (count($__GOOGLE_TEST_USER_AGENT) > 0) {
            $allowed_gtest_user_agents = implode("|", $__GOOGLE_TEST_USER_AGENT);
            $htaccess['allowed_gtest_user_agents'][] = 'RewriteCond %{HTTP_USER_AGENT} !(' . $allowed_gtest_user_agents . ') [NC]';
        }
        #~~~
        $htaccess['rewrite_rule'][] = 'RewriteRule (.*) byrev-wp-picshield.php?key=' . $data_basic['gtfo_key'] . '&src=$1 [L]';
        $htaccess['end'][] = '</IfModule>';
        $htaccess['end'][] = _HTACCES_SIGN_END;
        $htaccess_data = "";
        foreach ($htaccess as $index => &$rules) {
            $htaccess_data .= implode(_CRLF, $rules) . _CRLF;
        }
        $result4 = update_htaccess($htaccess_data);
        msg_info($result4, 'ERROR! .htaccess file ' . _GTFO_DEST_BASE_FILE_CODE . ' not able to be updated.', 'OK! .htacces file ' . _GTFO_DEST_BASE_FILE_CODE . ' was updated.');
    } else {
        $result4 = update_htaccess(_HTACCES_SIGN_BEGIN . _CRLF . _HTACCES_SIGN_END);
        msg_info(false, 'NOTE: Settings were saved, but the plugin is not active yet. Please set <b>Enable</b> from <b>Enable Hotlink Protection</b> option!', '');
    }
}
if (is_array($byrev_gtfo_hotlink_post_data)) {
    foreach ($byrev_gtfo_hotlink_post_data as $data_name => $post_data) {
        list($_value, $_name, $_info, $_input) = $byrev_hotlink_gtfo_copy[$data_name];
        if (is_array($_input) && count($_input) > 0) {
            foreach ($_input as $_options) {
                list($_op_name, $_op_value) = explode('|', $_options);
                if ($_op_value == $post_data) {
                    $byrev_hotlink_gtfo_copy[$data_name][0] = $_op_name;
                    break;
                }
            }
        } else {
function byrev_hotlink_nuke_uninstall()
{
    update_htaccess("");
    delete_option(_DB_OPTION_NAME);
}