mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-02 10:40:36 +00:00
FIX Regex Formatting for Word Boundaries (6) PATCH from @funilrys
This commit is contained in:
parent
16215f4039
commit
aae0d5378e
2 changed files with 132 additions and 18 deletions
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
/* Regex Formatting Generator Script for the Nginx Ultimate Bad Bot Blocker
|
||||
|
||||
/* Regex Formatting Generator Script for the Nginx Ultimate Bad Bot Blocker
|
||||
* Adapted from Script Copyright (c) 2017 Stevie-Ray - https://github.com/Stevie-Ray
|
||||
* Adapted by: Mitchell Krog (mitchellkrog@gmail.com) - https://github.com/mitchellkrogza
|
||||
* Repo Url: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
|
||||
*/
|
||||
|
||||
namespace mitchellkrogza;
|
||||
|
||||
use Mso\IdnaConvert\IdnaConvert;
|
||||
|
@ -12,6 +14,7 @@ class Generator
|
|||
{
|
||||
|
||||
private $projectUrl = "https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker";
|
||||
|
||||
public function generateFiles()
|
||||
{
|
||||
date_default_timezone_set('Africa/Johannesburg');
|
||||
|
@ -20,7 +23,6 @@ class Generator
|
|||
$this->createNginx($lines);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@ -42,7 +44,6 @@ class Generator
|
|||
$IDN = new IdnaConvert();
|
||||
|
||||
$line = $IDN->encode($line);
|
||||
|
||||
}
|
||||
|
||||
if (empty($line)) {
|
||||
|
@ -50,9 +51,12 @@ class Generator
|
|||
}
|
||||
$lines[] = $line;
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
$uniqueLines = array_unique($lines, SORT_STRING);
|
||||
sort($uniqueLines, SORT_STRING);
|
||||
|
||||
|
||||
if (is_writable($domainsFile)) {
|
||||
file_put_contents($domainsFile, implode("\n", $uniqueLines));
|
||||
} else {
|
||||
|
@ -70,7 +74,7 @@ class Generator
|
|||
protected function writeToFile($filename, $data)
|
||||
{
|
||||
$file = "/home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/.dev-tools/referrers-regex-format.txt";
|
||||
$handle = fopen($file, 'w') or die('Cannot open file: '.$file);
|
||||
$handle = fopen($file, 'w') or die('Cannot open file: ' . $file);
|
||||
fwrite($handle, $data);
|
||||
}
|
||||
|
||||
|
@ -82,15 +86,17 @@ class Generator
|
|||
{
|
||||
$file = "/home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/.dev-tools/referrers-regex-format.txt";
|
||||
$data = "";
|
||||
{
|
||||
|
||||
foreach ($lines as $line) {
|
||||
//$data .= "\"~*" "\\" "b" . preg_quote($line) . "\\" "b" "\" \t1;\n";
|
||||
//$data .= "\" . "~*\\" . 'b' . preg_quote($line) . "\" . '\\' . 'b' "\" "\t1;\n";
|
||||
$data .= "\" . "~\" . '\b' . preg_quote($line) . "\" . '\' . '\b' "\t1;\n";
|
||||
//$data .= "\" . "~\\" . '\b' . preg_quote($line) . "\" . '\' . '\b' "\t1\n";
|
||||
$data .= '\\' . '~\\' . "\\" . "b" . preg_quote($line) . "\\" . "b \t1\n";
|
||||
}
|
||||
$this->writeToFile($file, $data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$generator = new Generator();
|
||||
$generator->generateFiles();
|
||||
|
|
108
regex.patch
Normal file
108
regex.patch
Normal file
|
@ -0,0 +1,108 @@
|
|||
diff --git .dev-tools/generate-regex-format-referrers.php .dev-tools/generate-regex-format-referrers.php
|
||||
index d42c289..6f63814 100755
|
||||
--- .dev-tools/generate-regex-format-referrers.php
|
||||
+++ .dev-tools/generate-regex-format-referrers.php
|
||||
@@ -1,17 +1,20 @@
|
||||
<?php
|
||||
- /* Regex Formatting Generator Script for the Nginx Ultimate Bad Bot Blocker
|
||||
- * Adapted from Script Copyright (c) 2017 Stevie-Ray - https://github.com/Stevie-Ray
|
||||
- * Adapted by: Mitchell Krog (mitchellkrog@gmail.com) - https://github.com/mitchellkrogza
|
||||
- * Repo Url: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
|
||||
- */
|
||||
+
|
||||
+/* Regex Formatting Generator Script for the Nginx Ultimate Bad Bot Blocker
|
||||
+ * Adapted from Script Copyright (c) 2017 Stevie-Ray - https://github.com/Stevie-Ray
|
||||
+ * Adapted by: Mitchell Krog (mitchellkrog@gmail.com) - https://github.com/mitchellkrogza
|
||||
+ * Repo Url: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
|
||||
+ */
|
||||
+
|
||||
namespace mitchellkrogza;
|
||||
|
||||
use Mso\IdnaConvert\IdnaConvert;
|
||||
|
||||
class Generator
|
||||
{
|
||||
-
|
||||
+
|
||||
private $projectUrl = "https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker";
|
||||
+
|
||||
public function generateFiles()
|
||||
{
|
||||
date_default_timezone_set('Africa/Johannesburg');
|
||||
@@ -20,7 +23,6 @@ class Generator
|
||||
$this->createNginx($lines);
|
||||
}
|
||||
|
||||
-
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -42,7 +44,6 @@ class Generator
|
||||
$IDN = new IdnaConvert();
|
||||
|
||||
$line = $IDN->encode($line);
|
||||
-
|
||||
}
|
||||
|
||||
if (empty($line)) {
|
||||
@@ -50,9 +51,12 @@ class Generator
|
||||
}
|
||||
$lines[] = $line;
|
||||
}
|
||||
+
|
||||
fclose($handle);
|
||||
$uniqueLines = array_unique($lines, SORT_STRING);
|
||||
sort($uniqueLines, SORT_STRING);
|
||||
+
|
||||
+
|
||||
if (is_writable($domainsFile)) {
|
||||
file_put_contents($domainsFile, implode("\n", $uniqueLines));
|
||||
} else {
|
||||
@@ -62,35 +66,37 @@ class Generator
|
||||
return $lines;
|
||||
}
|
||||
|
||||
- /**
|
||||
+ /**
|
||||
* Write to File Function
|
||||
* @param $filename
|
||||
* @param $data
|
||||
*/
|
||||
protected function writeToFile($filename, $data)
|
||||
{
|
||||
- $file = "/home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/.dev-tools/referrers-regex-format.txt";
|
||||
- $handle = fopen($file, 'w') or die('Cannot open file: '.$file);
|
||||
- fwrite($handle, $data);
|
||||
+ $file = "/home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/.dev-tools/referrers-regex-format.txt";
|
||||
+ $handle = fopen($file, 'w') or die('Cannot open file: ' . $file);
|
||||
+ fwrite($handle, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $date
|
||||
* @param array $lines
|
||||
*/
|
||||
- public function createNginx(array $lines)
|
||||
+ public function createNginx(array $lines)
|
||||
{
|
||||
- $file = "/home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/.dev-tools/referrers-regex-format.txt";
|
||||
+ $file = "/home/travis/build/mitchellkrogza/nginx-ultimate-bad-bot-blocker/.dev-tools/referrers-regex-format.txt";
|
||||
$data = "";
|
||||
- {
|
||||
+
|
||||
foreach ($lines as $line) {
|
||||
//$data .= "\"~*" "\\" "b" . preg_quote($line) . "\\" "b" "\" \t1;\n";
|
||||
//$data .= "\" . "~*\\" . 'b' . preg_quote($line) . "\" . '\\' . 'b' "\" "\t1;\n";
|
||||
- $data .= "\" . "~\" . '\b' . preg_quote($line) . "\" . '\' . '\b' "\t1;\n";
|
||||
+ //$data .= "\" . "~\\" . '\b' . preg_quote($line) . "\" . '\' . '\b' "\t1\n";
|
||||
+ $data .= '\\' . '~\\' . "\\" . "b" . preg_quote($line) . "\\" . "b \t1\n";
|
||||
}
|
||||
$this->writeToFile($file, $data);
|
||||
- }
|
||||
- }
|
||||
+ }
|
||||
+
|
||||
}
|
||||
+
|
||||
$generator = new Generator();
|
||||
$generator->generateFiles();
|
Loading…
Add table
Reference in a new issue