Commit c1a617cb by san58

отладка фильтрации

1 parent 5de22083
...@@ -64,13 +64,10 @@ class ScanController extends Controller ...@@ -64,13 +64,10 @@ class ScanController extends Controller
); );
elseif (isset($csv_data[1])===true) elseif (isset($csv_data[1])===true)
{ {
$host = str_replace( $host = Collection::domain_filter($csv_data[1]);
'*.', if ($host === false)
'', $csv_skip_row++;
utf8_encode($csv_data[1]) else
);
$host_level = count( explode('.', $host) );
if ($host_level === 2)
{ {
$db_request = Yii::$app->db->createCommand(); $db_request = Yii::$app->db->createCommand();
if ($db_request) if ($db_request)
...@@ -112,9 +109,6 @@ class ScanController extends Controller ...@@ -112,9 +109,6 @@ class ScanController extends Controller
echo PHP_EOL.$this->ansiFormat('! Error create DB request'); echo PHP_EOL.$this->ansiFormat('! Error create DB request');
unset($db_request); unset($db_request);
} }
else
$csv_skip_row++;
unset($host_level);
unset($host); unset($host);
} }
else else
......
...@@ -3,10 +3,60 @@ ...@@ -3,10 +3,60 @@
namespace app\components; namespace app\components;
use Yii; use Yii;
use app\models\Filter;
use yii\base\Component; use yii\base\Component;
use yii\db\Query;
class Collection extends Component class Collection extends Component
{ {
//Скачиваине URL файла и передача пути к нему
public static function domain_filter($domain)
{
$out = false;
$host = str_replace(
'*.',
'',
utf8_encode($domain)
);
$host_level = count( explode('.', $host) );
if ($host_level === 2)
{
$filtes_bd = (new Query())
->select('`pattern`, `include`')
->from('{{%filters}}')
->where('type=:type AND status=:status', array(':type'=>Filter::TYPE_BEFORE, ':status'=>Filter::STATUS_ON ))
->all();
if ($filtes_bd !== false)
{
$fiter_check = true;
foreach($filtes_bd as $filter)
{
$find = preg_match($filter['pattern'], $host);
if ($host === '002cc20.icu')
echo ' > i:'.$filter['include'].' result:'.$find.' if1:'.(($find === 1 && $filter['include']===Filter::INCLUDE_OFF)?1:0).' if2:'.(($find === 0 && $filter['include']===Filter::INCLUDE_ON)?1:0)."\n";
if (
($find === 1 && $filter['include']===Filter::INCLUDE_OFF) ||
($find === 0 && $filter['include']===Filter::INCLUDE_ON)
)
{
$fiter_check = false;
break;
}
unset($find);
}
unset($filter);
if ($fiter_check===true)
$out = (string)$host;
unset($fiter_check);
}
unset($filtes_bd);
}
unset($host_level);
unset($host);
return $out;
}
//Скачиваине URL файла и передача пути к нему //Скачиваине URL файла и передача пути к нему
public static function download_file($csvFile) public static function download_file($csvFile)
{ {
......
...@@ -18,8 +18,8 @@ use yii\db\Expression; ...@@ -18,8 +18,8 @@ use yii\db\Expression;
*/ */
class Filter extends \yii\db\ActiveRecord class Filter extends \yii\db\ActiveRecord
{ {
const INCLUDE_ON = 0; //включая const INCLUDE_OFF = 0; //включая
const INCLUDE_OFF = 1; //выключая const INCLUDE_ON = 1; //выключая
const STATUS_OFF = 0; //выкл const STATUS_OFF = 0; //выкл
const STATUS_ON = 1; //вкл const STATUS_ON = 1; //вкл
...@@ -92,8 +92,8 @@ class Filter extends \yii\db\ActiveRecord ...@@ -92,8 +92,8 @@ class Filter extends \yii\db\ActiveRecord
public static function getIncludes($inc = false) public static function getIncludes($inc = false)
{ {
$arr = [ $arr = [
self::INCLUDE_ON => 'Before', self::INCLUDE_ON => 'Yes',
self::INCLUDE_OFF => 'After' self::INCLUDE_OFF => 'No'
]; ];
if (is_numeric($inc)) { if (is_numeric($inc)) {
if (array_key_exists($inc, $arr)) { if (array_key_exists($inc, $arr)) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!