Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Alto
/
rkn
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 01b11978
authored
2021-06-06 23:24:55 +0300
by
san58
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
постфильтр
1 parent
e5765d60
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
90 additions
and
36 deletions
commands/ScanController.php
commands/WhoisController.php
components/Collection.php
models/Host.php
models/HostSearch.php
views/filter/_form.php
views/filter/view.php
views/host/_form.php
views/host/index.php
views/host/view.php
views/site/index.php
commands/ScanController.php
View file @
01b1197
...
@@ -8,6 +8,7 @@ use yii\db\Expression;
...
@@ -8,6 +8,7 @@ use yii\db\Expression;
use
yii\helpers\Console
;
use
yii\helpers\Console
;
use
app\components\Collection
;
use
app\components\Collection
;
use
app\models\Host
;
use
app\models\Host
;
use
app\models\Filter
;
use
yii\db\Query
;
use
yii\db\Query
;
/**
/**
...
@@ -51,6 +52,7 @@ class ScanController extends Controller
...
@@ -51,6 +52,7 @@ class ScanController extends Controller
$csv_handle
=
fopen
(
$csv_file
,
'r'
);
$csv_handle
=
fopen
(
$csv_file
,
'r'
);
if
(
$csv_handle
!==
false
)
if
(
$csv_handle
!==
false
)
{
{
$filters
=
[
'before'
=>
Collection
::
get_filter
(
Filter
::
TYPE_BEFORE
),
'after'
=>
Collection
::
get_filter
(
Filter
::
TYPE_AFTER
)];
$csv_datatime
=
''
;
$csv_datatime
=
''
;
while
((
$csv_data
=
fgetcsv
(
$csv_handle
,
1024
,
';'
))
!==
false
)
while
((
$csv_data
=
fgetcsv
(
$csv_handle
,
1024
,
';'
))
!==
false
)
{
{
...
@@ -64,11 +66,12 @@ class ScanController extends Controller
...
@@ -64,11 +66,12 @@ class ScanController extends Controller
);
);
elseif
(
isset
(
$csv_data
[
1
])
===
true
)
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
)
if
(
$host
===
false
)
$csv_skip_row
++
;
$csv_skip_row
++
;
else
else
{
{
$status
=
(
Collection
::
apply_filter
(
$host
,
$filters
[
'after'
])
===
false
?
Filter
::
STATUS_OFF
:
Filter
::
STATUS_ON
);
$db_request
=
Yii
::
$app
->
db
->
createCommand
();
$db_request
=
Yii
::
$app
->
db
->
createCommand
();
if
(
$db_request
)
if
(
$db_request
)
{
{
...
@@ -86,6 +89,7 @@ class ScanController extends Controller
...
@@ -86,6 +89,7 @@ class ScanController extends Controller
'domain'
=>
$host
,
'domain'
=>
$host
,
'created_at'
=>
new
Expression
(
'NOW()'
),
'created_at'
=>
new
Expression
(
'NOW()'
),
'csv_date'
=>
$csv_datatime
,
'csv_date'
=>
$csv_datatime
,
'status'
=>
$status
]
]
)
->
execute
();
)
->
execute
();
$rec
[
'insert'
]
++
;
$rec
[
'insert'
]
++
;
...
@@ -95,7 +99,8 @@ class ScanController extends Controller
...
@@ -95,7 +99,8 @@ class ScanController extends Controller
$db_request
->
update
(
$db_request
->
update
(
'{{%host}}'
,
'{{%host}}'
,
[
[
'csv_date'
=>
$csv_datatime
'csv_date'
=>
$csv_datatime
,
'status'
=>
$status
],
],
[
[
'domain'
=>
$host
'domain'
=>
$host
...
@@ -108,6 +113,7 @@ class ScanController extends Controller
...
@@ -108,6 +113,7 @@ class ScanController extends Controller
else
else
echo
PHP_EOL
.
$this
->
ansiFormat
(
'! Error create DB request'
);
echo
PHP_EOL
.
$this
->
ansiFormat
(
'! Error create DB request'
);
unset
(
$db_request
);
unset
(
$db_request
);
unset
(
$status
);
}
}
unset
(
$host
);
unset
(
$host
);
}
}
...
@@ -116,6 +122,7 @@ class ScanController extends Controller
...
@@ -116,6 +122,7 @@ class ScanController extends Controller
}
}
unset
(
$csv_data
);
unset
(
$csv_data
);
unset
(
$csv_datatime
);
unset
(
$csv_datatime
);
unset
(
$filters
);
fclose
(
$csv_handle
);
fclose
(
$csv_handle
);
unlink
(
$csv_file
);
unlink
(
$csv_file
);
}
}
...
...
commands/WhoisController.php
View file @
01b1197
...
@@ -44,7 +44,7 @@ class WhoisController extends Controller
...
@@ -44,7 +44,7 @@ class WhoisController extends Controller
$hosts
=
(
new
Query
())
$hosts
=
(
new
Query
())
->
select
(
'id, domain'
)
->
select
(
'id, domain'
)
->
from
(
'{{%host}}'
)
->
from
(
'{{%host}}'
)
->
where
([
'in'
,
'wis_status'
,
[
Host
::
STATUS_
NONE
,
Host
::
STATU
S_BUSY
]])
->
where
([
'in'
,
'wis_status'
,
[
Host
::
STATUS_
WIS_NONE
,
Host
::
STATUS_WI
S_BUSY
]])
->
orderBy
(
'rand()'
)
->
orderBy
(
'rand()'
)
->
limit
(
$this
->
count
)
->
limit
(
$this
->
count
)
->
all
();
->
all
();
...
@@ -87,10 +87,10 @@ class WhoisController extends Controller
...
@@ -87,10 +87,10 @@ class WhoisController extends Controller
switch
(
$statusStr
)
{
switch
(
$statusStr
)
{
case
'Свободен'
:
case
'Свободен'
:
$status
=
Host
::
STATUS_FREE
;
$status
=
Host
::
STATUS_
WIS_
FREE
;
break
;
break
;
default
:
default
:
$status
=
Host
::
STATUS_BUSY
;
$status
=
Host
::
STATUS_
WIS_
BUSY
;
}
}
$update
=
[
'wis_status'
=>
$status
,
'wis_date'
=>
new
Expression
(
'NOW()'
)];
$update
=
[
'wis_status'
=>
$status
,
'wis_date'
=>
new
Expression
(
'NOW()'
)];
if
(
$expired
)
{
if
(
$expired
)
{
...
...
components/Collection.php
View file @
01b1197
...
@@ -10,8 +10,8 @@ use yii\db\Query;
...
@@ -10,8 +10,8 @@ use yii\db\Query;
class
Collection
extends
Component
class
Collection
extends
Component
{
{
//
Скачиваине URL файла и передача пути к нему
//
Фильтрация фомена
public
static
function
domain_filter
(
$domain
)
public
static
function
domain_filter
(
$domain
,
$filters
)
{
{
$out
=
false
;
$out
=
false
;
$host
=
str_replace
(
$host
=
str_replace
(
...
@@ -19,21 +19,36 @@ class Collection extends Component
...
@@ -19,21 +19,36 @@ class Collection extends Component
''
,
''
,
utf8_encode
(
$domain
)
utf8_encode
(
$domain
)
);
);
$host_level
=
count
(
explode
(
'.'
,
$host
)
);
if
(
count
(
explode
(
'.'
,
$host
)
)
===
2
)
if
(
$host_level
===
2
)
$out
=
Collection
::
apply_filter
(
$host
,
$filters
);
unset
(
$host
);
return
$out
;
}
//Скачиваине URL файла и передача пути к нему
public
static
function
get_filter
(
$type
)
{
{
$out
=
array
();
$filtes_bd
=
(
new
Query
())
$filtes_bd
=
(
new
Query
())
->
select
(
'`pattern`, `include`'
)
->
select
(
'`pattern`, `include`'
)
->
from
(
'{{%filters}}'
)
->
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
();
->
all
();
if
(
$filtes_bd
!==
false
)
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
;
$fiter_check
=
true
;
foreach
(
$filtes_bd
as
$filter
)
foreach
(
$filters
as
$filter
)
if
(
$fiter_check
===
true
)
if
(
$fiter_check
===
true
)
{
{
$find
=
preg_match
(
$filter
[
'pattern'
],
$host
);
$find
=
preg_match
(
$filter
[
'pattern'
],
$domain
);
if
(
if
(
(
$find
===
1
&&
(
int
)
$filter
[
'include'
]
===
Filter
::
INCLUDE_OFF
)
||
(
$find
===
1
&&
(
int
)
$filter
[
'include'
]
===
Filter
::
INCLUDE_OFF
)
||
(
$find
===
0
&&
(
int
)
$filter
[
'include'
]
===
Filter
::
INCLUDE_ON
)
(
$find
===
0
&&
(
int
)
$filter
[
'include'
]
===
Filter
::
INCLUDE_ON
)
...
@@ -46,16 +61,14 @@ class Collection extends Component
...
@@ -46,16 +61,14 @@ class Collection extends Component
}
}
unset
(
$filter
);
unset
(
$filter
);
if
(
$fiter_check
===
true
)
if
(
$fiter_check
===
true
)
$out
=
(
string
)
$host
;
$out
=
(
string
)
$domain
;
unset
(
$fiter_check
);
unset
(
$fiter_check
);
}
unset
(
$filtes_bd
);
}
unset
(
$host_level
);
unset
(
$host
);
return
$out
;
return
$out
;
}
}
//Скачиваине URL файла и передача пути к нему
//Скачиваине URL файла и передача пути к нему
public
static
function
download_file
(
$csvFile
)
public
static
function
download_file
(
$csvFile
)
{
{
...
...
models/Host.php
View file @
01b1197
...
@@ -14,14 +14,18 @@ use yii\db\Expression;
...
@@ -14,14 +14,18 @@ use yii\db\Expression;
* @property string|null $created_at Дата записи
* @property string|null $created_at Дата записи
* @property string|null $csv_date Дата CSV
* @property string|null $csv_date Дата CSV
* @property string|null $wis_date Дата проверки домена
* @property string|null $wis_date Дата проверки домена
* @property int|null $wis_status Статус
* @property int|null $wis_status Статус Who Is
* @property int $status Статус
* @property int $tix Показатель
* @property int $tix Показатель
*/
*/
class
Host
extends
\yii\db\ActiveRecord
class
Host
extends
\yii\db\ActiveRecord
{
{
const
STATUS_NONE
=
0
;
//неизвестный
const
STATUS_WIS_NONE
=
0
;
//неизвестный
const
STATUS_FREE
=
1
;
//Свободный
const
STATUS_WIS_FREE
=
1
;
//Свободный
const
STATUS_BUSY
=
2
;
//Занятый
const
STATUS_WIS_BUSY
=
2
;
//Занятый
const
STATUS_OFF
=
0
;
//выключен
const
STATUS_ON
=
1
;
//Включен
public
$cnt
;
public
$cnt
;
...
@@ -53,9 +57,9 @@ class Host extends \yii\db\ActiveRecord
...
@@ -53,9 +57,9 @@ class Host extends \yii\db\ActiveRecord
{
{
return
[
return
[
[[
'domain'
],
'required'
],
[[
'domain'
],
'required'
],
[
'status_id'
,
'in'
,
'range'
=>
array_keys
(
self
::
getStatus
())],
[
'status_id'
,
'in'
,
'range'
=>
array_keys
(
self
::
get
Wis
Status
())],
[[
'created_at'
,
'csv_date'
,
'wis_date'
,
'domain_expire'
],
'safe'
],
[[
'created_at'
,
'csv_date'
,
'wis_date'
,
'domain_expire'
],
'safe'
],
[[
'wis_status'
,
'tix'
],
'integer'
],
[[
'wis_status'
,
'tix'
,
'status'
],
'integer'
],
[[
'domain'
],
'string'
,
'max'
=>
256
],
[[
'domain'
],
'string'
,
'max'
=>
256
],
[[
'domain'
],
'unique'
],
[[
'domain'
],
'unique'
],
];
];
...
@@ -72,9 +76,10 @@ class Host extends \yii\db\ActiveRecord
...
@@ -72,9 +76,10 @@ class Host extends \yii\db\ActiveRecord
'created_at'
=>
'Date'
,
'created_at'
=>
'Date'
,
'csv_date'
=>
'Date CSV'
,
'csv_date'
=>
'Date CSV'
,
'wis_date'
=>
'Date WHOIS'
,
'wis_date'
=>
'Date WHOIS'
,
'wis_status'
=>
'
Status
'
,
'wis_status'
=>
'
Can registration
'
,
'domain_expire'
=>
'Date expired'
,
'domain_expire'
=>
'Date expired'
,
'tix'
=>
'TIX'
,
'tix'
=>
'TIX'
,
'status'
=>
'Status'
];
];
}
}
...
@@ -87,13 +92,27 @@ class Host extends \yii\db\ActiveRecord
...
@@ -87,13 +92,27 @@ class Host extends \yii\db\ActiveRecord
return
new
HostQuery
(
get_called_class
());
return
new
HostQuery
(
get_called_class
());
}
}
public
static
function
getStatus
(
$status
=
false
)
public
static
function
getStatus
(
$status
=
false
)
{
{
$arr
=
[
$arr
=
[
self
::
STATUS_NONE
=>
'No checked'
,
self
::
STATUS_OFF
=>
'Disable'
,
self
::
STATUS_FREE
=>
'FREE'
,
self
::
STATUS_ON
=>
'Enable'
self
::
STATUS_BUSY
=>
'BUSY'
,
];
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
(
is_numeric
(
$status
))
{
if
(
array_key_exists
(
$status
,
$arr
))
{
if
(
array_key_exists
(
$status
,
$arr
))
{
...
...
models/HostSearch.php
View file @
01b1197
...
@@ -17,8 +17,8 @@ class HostSearch extends Host
...
@@ -17,8 +17,8 @@ class HostSearch extends Host
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
[[
'id'
,
'wis_status'
,
'tix'
],
'integer'
],
[[
'id'
,
'wis_status'
,
'tix'
,
'status'
],
'integer'
],
[[
'domain'
,
'created_at'
,
'csv_date'
,
'wis_date'
,
'wis_status'
,
'domain_expire'
],
'safe'
],
[[
'domain'
,
'created_at'
,
'csv_date'
,
'wis_date'
,
'wis_status'
,
'domain_expire'
,
'status'
],
'safe'
],
];
];
}
}
...
@@ -65,6 +65,7 @@ class HostSearch extends Host
...
@@ -65,6 +65,7 @@ class HostSearch extends Host
'wis_status'
=>
$this
->
wis_status
,
'wis_status'
=>
$this
->
wis_status
,
'domain_expire'
=>
$this
->
wis_status
,
'domain_expire'
=>
$this
->
wis_status
,
'tix'
=>
$this
->
tix
,
'tix'
=>
$this
->
tix
,
'status'
=>
$this
->
status
]);
]);
$query
->
andFilterWhere
([
'like'
,
'domain'
,
$this
->
domain
]);
$query
->
andFilterWhere
([
'like'
,
'domain'
,
$this
->
domain
]);
...
...
views/filter/_form.php
View file @
01b1197
...
@@ -19,7 +19,7 @@ use app\models\Filter;
...
@@ -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
,
'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
::
get
Wis
Status
())
?>
<?=
$form
->
field
(
$model
,
'type'
,
[
'options'
=>
[
'class'
=>
'form-group col-xs-12'
]])
->
dropDownList
(
Filter
::
getTypes
())
?>
<?=
$form
->
field
(
$model
,
'type'
,
[
'options'
=>
[
'class'
=>
'form-group col-xs-12'
]])
->
dropDownList
(
Filter
::
getTypes
())
?>
...
...
views/filter/view.php
View file @
01b1197
...
@@ -38,7 +38,7 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -38,7 +38,7 @@ $this->params['breadcrumbs'][] = $this->title;
],
],
[
[
'attribute'
=>
'status'
,
'attribute'
=>
'status'
,
'value'
=>
$model
::
getStatus
(
$model
->
status
),
'value'
=>
$model
::
get
Wis
Status
(
$model
->
status
),
],
],
[
[
'attribute'
=>
'type'
,
'attribute'
=>
'type'
,
...
...
views/host/_form.php
View file @
01b1197
...
@@ -24,6 +24,8 @@ use yii\widgets\ActiveForm;
...
@@ -24,6 +24,8 @@ use yii\widgets\ActiveForm;
<?=
$form
->
field
(
$model
,
'tix'
)
->
textInput
()
?>
<?=
$form
->
field
(
$model
,
'tix'
)
->
textInput
()
?>
<?=
$form
->
field
(
$model
,
'status'
)
->
textInput
()
?>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<?=
Html
::
submitButton
(
'Save'
,
[
'class'
=>
'btn btn-success'
])
?>
<?=
Html
::
submitButton
(
'Save'
,
[
'class'
=>
'btn btn-success'
])
?>
</div>
</div>
...
...
views/host/index.php
View file @
01b1197
...
@@ -47,15 +47,24 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -47,15 +47,24 @@ $this->params['breadcrumbs'][] = $this->title;
'wis_status'
=>
'wis_status'
=>
[
[
'attribute'
=>
'wis_status'
,
'attribute'
=>
'wis_status'
,
'filter'
=>
\app\models\Host
::
getStatus
(),
'filter'
=>
\app\models\Host
::
get
Wis
Status
(),
'format'
=>
'raw'
,
'format'
=>
'raw'
,
'value'
=>
function
(
$model
)
{
'value'
=>
function
(
$model
)
{
return
$model
::
getStatus
(
$model
->
wis_status
);
return
$model
::
get
Wis
Status
(
$model
->
wis_status
);
},
},
],
],
'wis_date'
,
'wis_date'
,
'domain_expire'
,
'domain_expire'
,
'tix'
,
'tix'
,
'status'
=>
[
'attribute'
=>
'status'
,
'filter'
=>
\app\models\Host
::
getStatus
(),
'format'
=>
'raw'
,
'value'
=>
function
(
$model
)
{
return
$model
::
getStatus
(
$model
->
status
);
},
],
[
[
'class'
=>
'yii\grid\ActionColumn'
,
'class'
=>
'yii\grid\ActionColumn'
,
'header'
=>
'Actions'
,
'header'
=>
'Actions'
,
...
...
views/host/view.php
View file @
01b1197
...
@@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = $this->title;
?>
?>
<div
class=
"host-view"
>
<div
class=
"host-view"
>
<h1>
<?=
Html
::
encode
(
$this
->
title
)
?>
</h1>
<h1>
View domain №
<?=
Html
::
encode
(
$this
->
title
)
?>
</h1>
<p>
<p>
<?=
Html
::
a
(
'Update'
,
[
'update'
,
'id'
=>
$model
->
id
],
[
'class'
=>
'btn btn-primary'
])
?>
<?=
Html
::
a
(
'Update'
,
[
'update'
,
'id'
=>
$model
->
id
],
[
'class'
=>
'btn btn-primary'
])
?>
...
@@ -36,6 +36,7 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -36,6 +36,7 @@ $this->params['breadcrumbs'][] = $this->title;
'wis_date'
,
'wis_date'
,
'wis_status'
,
'wis_status'
,
'tix'
,
'tix'
,
'status'
],
],
])
?>
])
?>
...
...
views/site/index.php
View file @
01b1197
...
@@ -4,5 +4,7 @@ use app\assets\MainAsset;
...
@@ -4,5 +4,7 @@ use app\assets\MainAsset;
$this
->
title
=
Yii
::
$app
->
name
.
' - Главная'
;
$this
->
title
=
Yii
::
$app
->
name
.
' - Главная'
;
MainAsset
::
register
(
$this
);
MainAsset
::
register
(
$this
);
var_dump
(
$statistics
);
?>
?>
главная страница
главная страница
\ No newline at end of file
\ No newline at end of file
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment