public static function htaccess() { $htaccess = wfCache::getHtaccessPath(); if (is_readable($htaccess) && !wfUtils::isNginx()) { return file_get_contents($htaccess); } return ""; }
/** * */ public static function ajax_disableDirectoryListing_callback() { $issueID = absint($_POST['issueID']); $wfIssues = new wfIssues(); $issue = $wfIssues->getIssueByID($issueID); if (!$issue) { return array('err' => 1, 'errorMsg' => "We could not find that issue in our database."); } $wfIssues->deleteIssue($issueID); $htaccessPath = wfCache::getHtaccessPath(); if (!$htaccessPath) { return array('err' => 1, 'errorMsg' => "Wordfence could not find your .htaccess file."); } $fileContents = file_get_contents($htaccessPath); if (file_put_contents($htaccessPath, "# Added by Wordfence " . date('r') . "\nOptions -Indexes\n\n" . $fileContents, LOCK_EX)) { $uploadPaths = wp_upload_dir(); if (!wfScanEngine::isDirectoryListingEnabled($uploadPaths['baseurl'])) { return array('ok' => 1); } else { // Revert any changes done to .htaccess file_put_contents($htaccessPath, $fileContents, LOCK_EX); return array('err' => 1, 'errorMsg' => "Updating the .htaccess did not fix the issue. You may need to add <code>Options -Indexes</code>\nto your httpd.conf if using Apache, or find documentation on how to disable directory listing for your web server."); } } return array('err' => 1, 'errorMsg' => "There was an error writing to your .htaccess file."); }
public static function ajax_downloadHtaccess_callback() { $url = site_url(); $url = preg_replace('/^https?:\\/\\//i', '', $url); $url = preg_replace('/[^a-zA-Z0-9\\.]+/', '_', $url); $url = preg_replace('/^_+/', '', $url); $url = preg_replace('/_+$/', '', $url); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="htaccess_Backup_for_' . $url . '.txt"'); $file = wfCache::getHtaccessPath(); readfile($file); die; }