Skip to content

Commit 4051b87

Browse files
committed
Add method for whitelisting files/path and restoring filter_files.txt to default (Ready for v2.0.0)
1 parent 432642f commit 4051b87

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

src/AntiScanScanClub.php

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@ class AntiScanScanClub
1010
{
1111
/**
1212
* @var string $filterRules
13-
*/
13+
*/
1414
private $filterRules = "filter_rules.json";
1515

1616
/**
1717
* @var string $filterFiles
18-
*/
18+
*/
1919
private $filterFiles = "filter_files.txt";
2020

2121
/**
2222
* @var string $defaultBlacklists
23-
*/
23+
*/
2424
private $defaultBlacklists = "blacklists.json";
2525

26+
/**
27+
* @var string $remoteRepo
28+
*/
29+
private $remoteRepo = "https://github.com/noobsec/AntiScanScanClub-laravel";
30+
2631
/**
2732
* AntiScanScanClub.
2833
*
@@ -239,4 +244,52 @@ private function writeToBlacklistsFile($data = []) {
239244
return TRUE;
240245
}
241246
}
247+
248+
/**
249+
* Whitelisting credentials and/ important files/path
250+
*
251+
* @param string $search is the name of files/path do you want to whitelisted
252+
* @return bool
253+
*/
254+
public function whitelistFile($search) {
255+
$filterFiles = __DIR__ . "/" . $this->filterFiles;
256+
$filterFile = file($filterFiles);
257+
$status = FALSE;
258+
259+
foreach ($filterFile as $key => $value) {
260+
if (trim($value) === $search) {
261+
$offset = $key;
262+
$status = TRUE;
263+
break;
264+
}
265+
}
266+
267+
if ($status !== FALSE) {
268+
unset($filterFile[$offset]);
269+
file_put_contents($filterFiles, join($filterFile));
270+
}
271+
272+
return $status;
273+
}
274+
275+
/**
276+
* Restore filter_files.txt lists to default
277+
*
278+
* @return bool
279+
*/
280+
public function restoreFilterFiles() {
281+
$defaultFilterFiles = @file_get_contents($this->remoteRepo . "/raw/master/src/" . $this->filterFiles);
282+
283+
if ($defaultFilterFiles === FALSE) {
284+
throw new \Exception("Error While Getting default filter files from Repo", 1);
285+
}
286+
287+
$write = file_put_contents(__DIR__ . "/" . $this->filterFiles, $defaultFilterFiles);
288+
289+
if ($write === 84213) {
290+
return TRUE;
291+
} else {
292+
return FALSE;
293+
}
294+
}
242295
}

0 commit comments

Comments
 (0)