Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
3e0891da
Commit
3e0891da
authored
Dec 09, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/es' into 'master'
IP 黑名单 See merge request
!244
parents
45e413b0
04ff80b1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
17 deletions
+33
-17
ValidateController.php
api/controllers/ValidateController.php
+23
-0
IpExceptionController.php
console/controllers/IpExceptionController.php
+10
-17
No files found.
api/controllers/ValidateController.php
0 → 100644
View file @
3e0891da
<?php
namespace
api\controllers
;
use
Yii
;
use
api\base\BaseController
;
class
ValidateController
extends
BaseController
{
/**
* 黑名单列表
* @return array
*/
public
function
actionBlackList
()
{
$msg
=
'ok'
;
$code
=
0
;
$redis_ticker
=
\Yii
::
$app
->
redis_es
;
$list
=
$redis_ticker
->
keys
(
'*'
);
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$list
];
}
}
\ No newline at end of file
console/controllers/IpExceptionController.php
View file @
3e0891da
...
...
@@ -41,8 +41,6 @@ class IpExceptionController extends Controller
[
"range"
=>
[
"@timestamp"
=>
[
#"gte" => 1574922900000,
#"lt" => 1574923200000,
'gte'
=>
(
$now
-
300
)
*
1000
,
'lt'
=>
$now
*
1000
,
"format"
=>
"epoch_millis"
...
...
@@ -59,29 +57,24 @@ class IpExceptionController extends Controller
$hits
=
$response
[
'hits'
]
??
null
;
$total
=
$hits
[
'total'
];
if
(
empty
(
$total
))
{
if
(
empty
(
$total
))
{
return
false
;
}
$buckets
=
$response
[
'aggregations'
][
'ips'
][
'buckets'
]
??
null
;
if
(
empty
(
$buckets
))
{
if
(
empty
(
$buckets
))
{
return
false
;
}
$ips
=
''
;
foreach
(
$buckets
as
$key
=>
$val
){
if
(
$val
[
'doc_count'
]
>
100
){
$ips
.=
$val
[
'key'
]
.
','
;
$redis_ticker
=
\Yii
::
$app
->
redis_es
;
$limit
=
\Yii
::
$app
->
params
[
'api_ip_limit'
][
'limit'
];
$white_list
=
\Yii
::
$app
->
params
[
'api_ip_limit'
][
'white_list'
];
foreach
(
$buckets
as
$key
=>
$val
)
{
if
(
in_array
(
$val
[
'key'
],
$white_list
))
continue
;
if
(
$val
[
'doc_count'
]
>
$limit
){
foreach
(
$val
[
'request'
][
'buckets'
]
as
$bucket
)
{
$redis_ticker
->
hmset
(
$val
[
'key'
],
$bucket
[
'key'
],
$bucket
[
'doc_count'
]);
}
}
$ips
=
substr
(
$ips
,
0
,
-
1
);
if
(
!
empty
(
$ips
)){
$file
=
fopen
(
"http://47.100.212.109/api_ip_limit.txt"
,
"w"
);
$ip_arr
=
explode
(
','
,
$ips
);
foreach
(
$ip_arr
as
$key
=>
$ip
){
fwrite
(
$file
,
$ip
.
"
\n
"
);
}
fclose
(
$file
);
}
return
false
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment