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
e390f1b3
Commit
e390f1b3
authored
5 years ago
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
es limit
parent
c63168a3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
0 deletions
+118
-0
Elastic.php
common/service/es/Elastic.php
+29
-0
IpExceptionController.php
console/controllers/IpExceptionController.php
+89
-0
No files found.
common/service/es/Elastic.php
0 → 100644
View file @
e390f1b3
<?php
namespace
common\service\es
;
use
Elasticsearch\ClientBuilder
;
class
Elastic
{
protected
$host
;
protected
$client
;
public
function
__construct
(
$host
=
null
)
{
$this
->
host
=
$host
;
}
public
function
connect
()
{
$this
->
client
=
ClientBuilder
::
create
()
->
setHosts
([
$this
->
host
])
->
build
();
}
public
function
search
(
$params
)
{
$response
=
$this
->
client
->
search
(
$params
);
return
$response
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
console/controllers/IpExceptionController.php
0 → 100644
View file @
e390f1b3
<?php
namespace
console\controllers
;
use
yii\console\Controller
;
use
common\service\es\Elastic
;
class
IpExceptionController
extends
Controller
{
public
function
actionIndex
()
{
$now
=
time
();
$elastic
=
new
Elastic
(
'106.15.39.94:9200'
);
$params
=
[
'index'
=>
'bwallet_access'
,
'type'
=>
'doc'
,
'body'
=>
[
"size"
=>
0
,
"aggs"
=>
[
"ips"
=>
[
"terms"
=>
[
"field"
=>
"clientip.keyword"
,
"size"
=>
200
,
"order"
=>
[
"_count"
=>
"desc"
]
],
"aggs"
=>
[
"request"
=>
[
"significant_terms"
=>
[
"field"
=>
"request.keyword"
,
"size"
=>
10
,
]
]
]
]
],
"query"
=>
[
"bool"
=>
[
"must"
=>
[
[
"range"
=>
[
"@timestamp"
=>
[
#"gte" => 1574922900000,
#"lt" => 1574923200000,
'gte'
=>
(
$now
-
300
)
*
1000
,
'lt'
=>
$now
*
1000
,
"format"
=>
"epoch_millis"
]
]
]
]
],
]
]
];
$elastic
->
connect
();
$response
=
$elastic
->
search
(
$params
);
$hits
=
$response
[
'hits'
]
??
null
;
$total
=
$hits
[
'total'
];
if
(
empty
(
$total
)){
return
false
;
}
$buckets
=
$response
[
'aggregations'
][
'ips'
][
'buckets'
]
??
null
;
if
(
empty
(
$buckets
)){
return
false
;
}
$ips
=
''
;
foreach
(
$buckets
as
$key
=>
$val
){
if
(
$val
[
'doc_count'
]
>
100
){
$ips
.=
$val
[
'key'
]
.
','
;
}
}
$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
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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