Commit 01b11978 by san58

постфильтр

1 parent e5765d60
......@@ -8,6 +8,7 @@ use yii\db\Expression;
use yii\helpers\Console;
use app\components\Collection;
use app\models\Host;
use app\models\Filter;
use yii\db\Query;
/**
......@@ -51,6 +52,7 @@ class ScanController extends Controller
$csv_handle = fopen($csv_file ,'r');
if ($csv_handle !== false)
{
$filters = ['before'=>Collection::get_filter(Filter::TYPE_BEFORE), 'after'=>Collection::get_filter(Filter::TYPE_AFTER)];
$csv_datatime = '';
while (($csv_data = fgetcsv($csv_handle, 1024, ';')) !== false)
{
......@@ -64,11 +66,12 @@ class ScanController extends Controller
);
elseif (isset($csv_data[1])===true)
{
$host = Collection::domain_filter($csv_data[1]);
$host = Collection::domain_filter($csv_data[1], $filters['before']);
if ($host === false)
$csv_skip_row++;
else
{
$status = (Collection::apply_filter($host, $filters['after'])===false?Filter::STATUS_OFF:Filter::STATUS_ON);
$db_request = Yii::$app->db->createCommand();
if ($db_request)
{
......@@ -86,6 +89,7 @@ class ScanController extends Controller
'domain' =>$host,
'created_at' => new Expression('NOW()'),
'csv_date' => $csv_datatime,
'status' => $status
]
)->execute();
$rec['insert']++;
......@@ -95,7 +99,8 @@ class ScanController extends Controller
$db_request->update(
'{{%host}}',
[
'csv_date' => $csv_datatime
'csv_date' => $csv_datatime,
'status' => $status
],
[
'domain' => $host
......@@ -108,6 +113,7 @@ class ScanController extends Controller
else
echo PHP_EOL.$this->ansiFormat('! Error create DB request');
unset($db_request);
unset($status);
}
unset($host);
}
......@@ -116,6 +122,7 @@ class ScanController extends Controller
}
unset($csv_data);
unset($csv_datatime);
unset($filters);
fclose($csv_handle);
unlink($csv_file);
}
......
......@@ -44,7 +44,7 @@ class WhoisController extends Controller
$hosts = (new Query())
->select('id, domain')
->from('{{%host}}')
->where(['in', 'wis_status', [Host::STATUS_NONE, Host::STATUS_BUSY]])
->where(['in', 'wis_status', [Host::STATUS_WIS_NONE, Host::STATUS_WIS_BUSY]])
->orderBy('rand()')
->limit($this->count)
->all();
......@@ -87,10 +87,10 @@ class WhoisController extends Controller
switch ($statusStr) {
case 'Свободен':
$status = Host::STATUS_FREE;
$status = Host::STATUS_WIS_FREE;
break;
default:
$status = Host::STATUS_BUSY;
$status = Host::STATUS_WIS_BUSY;
}
$update = ['wis_status' => $status, 'wis_date' => new Expression('NOW()')];
if ($expired) {
......
......@@ -10,8 +10,8 @@ use yii\db\Query;
class Collection extends Component
{
//Скачиваине URL файла и передача пути к нему
public static function domain_filter($domain)
//Фильтрация фомена
public static function domain_filter($domain, $filters)
{
$out = false;
$host = str_replace(
......@@ -19,21 +19,36 @@ class Collection extends Component
'',
utf8_encode($domain)
);
$host_level = count( explode('.', $host) );
if ($host_level === 2)
if (count( explode('.', $host) ) === 2)
$out = Collection::apply_filter($host, $filters);
unset($host);
return $out;
}
//Скачиваине URL файла и передача пути к нему
public static function get_filter($type)
{
$out = array();
$filtes_bd = (new Query())
->select('`pattern`, `include`')
->from('{{%filters}}')
->where('type=:type AND status=:status', array(':type'=>Filter::TYPE_BEFORE, ':status'=>Filter::STATUS_ON ))
->where('type=:type AND status=:status', array(':type'=>$type, ':status'=>Filter::STATUS_ON ))
->all();
if ($filtes_bd !== false)
$out = $filtes_bd;
unset($filtes_bd);
return $out;
}
//Скачиваине URL файла и передача пути к нему
public static function apply_filter($domain, $filters)
{
$out = false;
$fiter_check = true;
foreach($filtes_bd as $filter)
foreach($filters as $filter)
if ($fiter_check === true)
{
$find = preg_match($filter['pattern'], $host);
$find = preg_match($filter['pattern'], $domain);
if (
($find === 1 && (int)$filter['include']===Filter::INCLUDE_OFF) ||
($find === 0 && (int)$filter['include']===Filter::INCLUDE_ON)
......@@ -46,16 +61,14 @@ class Collection extends Component
}
unset($filter);
if ($fiter_check===true)
$out = (string)$host;
$out = (string)$domain;
unset($fiter_check);
}
unset($filtes_bd);
}
unset($host_level);
unset($host);
return $out;
}
//Скачиваине URL файла и передача пути к нему
public static function download_file($csvFile)
{
......
......@@ -14,14 +14,18 @@ use yii\db\Expression;
* @property string|null $created_at Дата записи
* @property string|null $csv_date Дата CSV
* @property string|null $wis_date Дата проверки домена
* @property int|null $wis_status Статус
* @property int|null $wis_status Статус Who Is
* @property int $status Статус
* @property int $tix Показатель
*/
class Host extends \yii\db\ActiveRecord
{
const STATUS_NONE = 0; //неизвестный
const STATUS_FREE = 1; //Свободный
const STATUS_BUSY = 2; //Занятый
const STATUS_WIS_NONE = 0; //неизвестный
const STATUS_WIS_FREE = 1; //Свободный
const STATUS_WIS_BUSY = 2; //Занятый
const STATUS_OFF = 0; //выключен
const STATUS_ON = 1; //Включен
public $cnt;
......@@ -53,9 +57,9 @@ class Host extends \yii\db\ActiveRecord
{
return [
[['domain'], 'required'],
['status_id', 'in', 'range' => array_keys(self::getStatus())],
['status_id', 'in', 'range' => array_keys(self::getWisStatus())],
[['created_at', 'csv_date', 'wis_date','domain_expire'], 'safe'],
[['wis_status', 'tix'], 'integer'],
[['wis_status', 'tix', 'status'], 'integer'],
[['domain'], 'string', 'max' => 256],
[['domain'], 'unique'],
];
......@@ -72,9 +76,10 @@ class Host extends \yii\db\ActiveRecord
'created_at' => 'Date',
'csv_date' => 'Date CSV',
'wis_date' => 'Date WHOIS',
'wis_status' => 'Status',
'wis_status' => 'Can registration',
'domain_expire' => 'Date expired',
'tix' => 'TIX',
'status' => 'Status'
];
}
......@@ -87,13 +92,27 @@ class Host extends \yii\db\ActiveRecord
return new HostQuery(get_called_class());
}
public static function getStatus($status = false)
{
$arr = [
self::STATUS_NONE => 'No checked',
self::STATUS_FREE => 'FREE',
self::STATUS_BUSY => 'BUSY',
self::STATUS_OFF => 'Disable',
self::STATUS_ON => 'Enable'
];
if (is_numeric($status)) {
if (array_key_exists($status, $arr)) {
return $arr[$status];
}
return $status;
}
return $arr;
}
public static function getWisStatus($status = false)
{
$arr = [
self::STATUS_WIS_NONE => 'No checked',
self::STATUS_WIS_FREE => 'FREE',
self::STATUS_WIS_BUSY => 'BUSY',
];
if (is_numeric($status)) {
if (array_key_exists($status, $arr)) {
......
......@@ -17,8 +17,8 @@ class HostSearch extends Host
public function rules()
{
return [
[['id', 'wis_status', 'tix'], 'integer'],
[['domain', 'created_at', 'csv_date', 'wis_date','wis_status','domain_expire'], 'safe'],
[['id', 'wis_status', 'tix', 'status'], 'integer'],
[['domain', 'created_at', 'csv_date', 'wis_date','wis_status','domain_expire', 'status'], 'safe'],
];
}
......@@ -65,6 +65,7 @@ class HostSearch extends Host
'wis_status' => $this->wis_status,
'domain_expire' => $this->wis_status,
'tix' => $this->tix,
'status' => $this->status
]);
$query->andFilterWhere(['like', 'domain', $this->domain]);
......
......@@ -19,7 +19,7 @@ use app\models\Filter;
<?= $form->field($model, 'include', ['options' => ['class' => 'form-group col-xs-12']])->dropDownList(Filter::getIncludes()) ?>
<?= $form->field($model, 'status', ['options' => ['class' => 'form-group col-xs-12']])->dropDownList(Filter::getStatus()) ?>
<?= $form->field($model, 'status', ['options' => ['class' => 'form-group col-xs-12']])->dropDownList(Filter::getWisStatus()) ?>
<?= $form->field($model, 'type', ['options' => ['class' => 'form-group col-xs-12']])->dropDownList(Filter::getTypes()) ?>
......
......@@ -38,7 +38,7 @@ $this->params['breadcrumbs'][] = $this->title;
],
[
'attribute' => 'status',
'value' => $model::getStatus($model->status),
'value' => $model::getWisStatus($model->status),
],
[
'attribute' => 'type',
......
......@@ -24,6 +24,8 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'tix')->textInput() ?>
<?= $form->field($model, 'status')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
......
......@@ -47,15 +47,24 @@ $this->params['breadcrumbs'][] = $this->title;
'wis_status' =>
[
'attribute' => 'wis_status',
'filter' => \app\models\Host::getStatus(),
'filter' => \app\models\Host::getWisStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getStatus($model->wis_status);
return $model::getWisStatus($model->wis_status);
},
],
'wis_date',
'domain_expire',
'tix',
'status' =>
[
'attribute' => 'status',
'filter' => \app\models\Host::getStatus(),
'format' => 'raw',
'value' => function ($model) {
return $model::getStatus($model->status);
},
],
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Actions',
......
......@@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = $this->title;
?>
<div class="host-view">
<h1><?= Html::encode($this->title) ?></h1>
<h1>View domain №<?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
......@@ -36,6 +36,7 @@ $this->params['breadcrumbs'][] = $this->title;
'wis_date',
'wis_status',
'tix',
'status'
],
]) ?>
......
......@@ -4,5 +4,7 @@ use app\assets\MainAsset;
$this->title = Yii::$app->name.' - Главная';
MainAsset::register($this);
var_dump($statistics);
?>
главная страница
\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!