} } else { trigger_error("Permission denied"); } } /** * @param array $lines */ public function createGoogleExclude(array $lines) { $file = __DIR__ . '/../google-exclude.txt'; $reqexLines = []; foreach ($lines as $line) { $reqexLines[] = preg_quote($line); } $data = implode('|', $reqexLines); if (is_readable($file) && is_writable($file)) { file_put_contents($file, $data); } else { trigger_error("Permission denied"); } } } date_default_timezone_set('UTC'); $date = date('Y-m-d H:i:s'); $generator = new Generate(); require __DIR__ . '/vendor/autoload.php'; $lines = $generator->domainWorker(); $generator->createApache($date, $lines); $generator->createNginx($date, $lines); $generator->createGoogleExclude($lines);
$data .= "</IfModule>\n\n# Apache 2.2\n<IfModule !mod_authz_core.c>\n <IfModule mod_authz_host.c>\n Order allow,deny\n Allow from all\n Deny from env=spambot\n </IfModule>\n</IfModule>\n\n# Apache 2.4\n<IfModule mod_authz_core.c>\n <RequireAll>\n Require all granted\n Require not env spambot\n </RequireAll>\n</IfModule>"; // Write the contents back to the file_put_contents($file, $data); } public function createNginx() { date_default_timezone_set('UTC'); $date = date('Y-m-d H:i:s'); $file = '../referral-spam.conf'; $data = "# https://github.com/Stevie-Ray/apache-nginx-referral-spam-blacklist\n# Updated " . $date . "\n#\n# /etc/nginx/referral-spam.conf\n#\n# With referral-spam.conf in /etc/nginx, include it globally from within /etc/nginx/nginx.conf:\n#\n# include referral-spam.conf;\n#\n# Add the following to each /etc/nginx/site-available/your-site.conf that needs protection:\n#\n# server {\n# if (\$bad_referer) {\n# return 444;\n# }\n# }\n#\nmap \$http_referer \$bad_referer {\n default 0;\n\n"; $handle = fopen(__DIR__ . "/domains.txt", "r"); if (!$handle) { throw new \RuntimeException('Error opening file domains.txt'); } while (($line = fgets($handle)) !== false) { $line = preg_quote(trim(preg_replace('/\\s\\s+/', ' ', $line))); if (empty($line)) { continue; } $data .= "\t\"~*" . $line . "\" 1;\n"; } fclose($handle); $data .= "\n}"; // Write the contents back to the file_put_contents($file, $data); } } $generator = new Generate(); $generator->createApache(); $generator->createNginx();