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
04ff80b1
Commit
04ff80b1
authored
Dec 09, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IP 黑名单
parent
e390f1b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
19 deletions
+34
-19
ValidateController.php
api/controllers/ValidateController.php
+23
-0
IpExceptionController.php
console/controllers/IpExceptionController.php
+11
-19
No files found.
api/controllers/ValidateController.php
0 → 100644
View file @
04ff80b1
<?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 @
04ff80b1
...
@@ -41,8 +41,6 @@ class IpExceptionController extends Controller
...
@@ -41,8 +41,6 @@ class IpExceptionController extends Controller
[
[
"range"
=>
[
"range"
=>
[
"@timestamp"
=>
[
"@timestamp"
=>
[
#"gte" => 1574922900000,
#"lt" => 1574923200000,
'gte'
=>
(
$now
-
300
)
*
1000
,
'gte'
=>
(
$now
-
300
)
*
1000
,
'lt'
=>
$now
*
1000
,
'lt'
=>
$now
*
1000
,
"format"
=>
"epoch_millis"
"format"
=>
"epoch_millis"
...
@@ -59,30 +57,25 @@ class IpExceptionController extends Controller
...
@@ -59,30 +57,25 @@ class IpExceptionController extends Controller
$hits
=
$response
[
'hits'
]
??
null
;
$hits
=
$response
[
'hits'
]
??
null
;
$total
=
$hits
[
'total'
];
$total
=
$hits
[
'total'
];
if
(
empty
(
$total
))
{
if
(
empty
(
$total
))
{
return
false
;
return
false
;
}
}
$buckets
=
$response
[
'aggregations'
][
'ips'
][
'buckets'
]
??
null
;
$buckets
=
$response
[
'aggregations'
][
'ips'
][
'buckets'
]
??
null
;
if
(
empty
(
$buckets
))
{
if
(
empty
(
$buckets
))
{
return
false
;
return
false
;
}
}
$ips
=
''
;
$redis_ticker
=
\Yii
::
$app
->
redis_es
;
foreach
(
$buckets
as
$key
=>
$val
){
$limit
=
\Yii
::
$app
->
params
[
'api_ip_limit'
][
'limit'
];
if
(
$val
[
'doc_count'
]
>
100
){
$white_list
=
\Yii
::
$app
->
params
[
'api_ip_limit'
][
'white_list'
];
$ips
.=
$val
[
'key'
]
.
','
;
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
;
return
false
;
}
}
}
}
\ No newline at end of file
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