Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ot extensions aa #248

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/CleantalkSP/SpbctWP/Scanner/ScannerQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public function countFileSystem($path_to_scan = ABSPATH)
$init_params = array(
'count' => true,
'file_exceptions' => 'wp-config.php',
'extensions' => 'php, html, htm, js, php2, php3, php4, php5, php6, php7, phtml, shtml, phar, otc', 'ott',
'extensions' => 'php, html, htm, js, php2, php3, php4, php5, php6, php7, phtml, shtml, phar, [ot.]',
'files_mandatory' => array(),
'dir_exceptions' => array(SPBC_PLUGIN_DIR . 'quarantine')
);
Expand Down Expand Up @@ -835,7 +835,7 @@ public function file_system_analysis($offset = null, $amount = null, $path_to_sc
'full_hash' => true,
'offset' => $offset,
'amount' => $amount,
'extensions' => 'php, html, htm, js, php2, php3, php4, php5, php6, php7, phtml, shtml, phar, otc', 'ott',
'extensions' => 'php, html, htm, js, php2, php3, php4, php5, php6, php7, phtml, shtml, phar, [ot.]',
'extensions_exceptions' => '', //array('jpg', 'jpeg', 'png', 'gif', 'css', 'txt', 'zip', 'xml', 'json')
'file_exceptions' => 'wp-config.php',
'files_mandatory' => array(),
Expand Down
52 changes: 48 additions & 4 deletions lib/CleantalkSP/SpbctWP/Scanner/Surface.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,13 @@ public function countFilesInDir($main_path)
// Extensions filter
if ( $this->ext_except || $this->ext ) {
$tmp = explode('.', $path);
$currentFileExtension = $tmp[count($tmp) - 1];
if (
($this->ext_except && in_array($tmp[count($tmp) - 1], $this->ext_except, true)) ||
($this->ext && ! in_array($tmp[count($tmp) - 1], $this->ext, true))
! $this->hasFileAllowedExtension(
$currentFileExtension,
$this->ext_except,
$this->ext
)
) {
continue;
}
Expand Down Expand Up @@ -296,9 +300,13 @@ public function getFileStructure($main_path)
// Extensions filter
if ( $this->ext_except || $this->ext ) {
$tmp = explode('.', $path);
$currentFileExtension = $tmp[count($tmp) - 1];
if (
($this->ext_except && in_array($tmp[count($tmp) - 1], $this->ext_except, true)) ||
($this->ext && ! in_array($tmp[count($tmp) - 1], $this->ext, true))
! $this->hasFileAllowedExtension(
$currentFileExtension,
$this->ext_except,
$this->ext
)
) {
continue;
}
Expand Down Expand Up @@ -474,4 +482,40 @@ public static function dirIsEmpty($dir)

return true;
}

public function filterFileExtensionUsingRegexp($extension, array $extensions)
{
foreach ($extensions as $extensionItem) {
$fsymbol = strpos($extensionItem, '[');
$lsymbol = strpos($extensionItem, ']');

$regexpExpression = substr($extensionItem, $fsymbol, $lsymbol);
if ($regexpExpression) {
ArtemAnoshin marked this conversation as resolved.
Show resolved Hide resolved
$regexpExpression = '/' . trim($regexpExpression, "][") . '/';

if (preg_match($regexpExpression, $extension)) {
return true;
}
}
}

return false;
}

private function hasFileAllowedExtension($currentFileExtension, array $ext_except, array $ext)
{
if (in_array($currentFileExtension, $ext_except, true)) {
return false;
}

if (in_array($currentFileExtension, $ext, true)) {
return true;
}

if ($this->filterFileExtensionUsingRegexp($currentFileExtension, $ext)) {
return true;
}

return false;
}
}
Loading