Commit c1a617cb by san58

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

1 parent 5de22083
......@@ -64,13 +64,10 @@ class ScanController extends Controller
);
elseif (isset($csv_data[1])===true)
{
$host = str_replace(
'*.',
'',
utf8_encode($csv_data[1])
);
$host_level = count( explode('.', $host) );
if ($host_level === 2)
$host = Collection::domain_filter($csv_data[1]);
if ($host === false)
$csv_skip_row++;
else
{
$db_request = Yii::$app->db->createCommand();
if ($db_request)
......@@ -112,9 +109,6 @@ class ScanController extends Controller
echo PHP_EOL.$this->ansiFormat('! Error create DB request');
unset($db_request);
}
else
$csv_skip_row++;
unset($host_level);
unset($host);
}
else
......
......@@ -3,10 +3,60 @@
namespace app\components;
use Yii;
use app\models\Filter;
use yii\base\Component;
use yii\db\Query;
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 файла и передача пути к нему
public static function download_file($csvFile)
{
......
......@@ -18,8 +18,8 @@ use yii\db\Expression;
*/
class Filter extends \yii\db\ActiveRecord
{
const INCLUDE_ON = 0; //включая
const INCLUDE_OFF = 1; //выключая
const INCLUDE_OFF = 0; //включая
const INCLUDE_ON = 1; //выключая
const STATUS_OFF = 0; //выкл
const STATUS_ON = 1; //вкл
......@@ -92,8 +92,8 @@ class Filter extends \yii\db\ActiveRecord
public static function getIncludes($inc = false)
{
$arr = [
self::INCLUDE_ON => 'Before',
self::INCLUDE_OFF => 'After'
self::INCLUDE_ON => 'Yes',
self::INCLUDE_OFF => 'No'
];
if (is_numeric($inc)) {
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!