Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
ticker_config
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallets
ticker_config
Commits
7493e528
Commit
7493e528
authored
Dec 06, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ip limit
parent
2809be44
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
0 deletions
+88
-0
index.php
api/index.php
+19
-0
InitAppHelper.php
common/helper/InitAppHelper.php
+69
-0
No files found.
api/index.php
View file @
7493e528
...
@@ -11,6 +11,25 @@ defined('YII_ENV') or define('YII_ENV', 'prod');
...
@@ -11,6 +11,25 @@ defined('YII_ENV') or define('YII_ENV', 'prod');
define
(
'WALLET_PROJECT_PATH'
,
'/data_wallet/token'
);
//定义框架代码的目录
define
(
'WALLET_PROJECT_PATH'
,
'/data_wallet/token'
);
//定义框架代码的目录
define
(
'WALLET_RUNTIME_PATH'
,
dirname
(
__DIR__
));
//定义程序运行的目录
define
(
'WALLET_RUNTIME_PATH'
,
dirname
(
__DIR__
));
//定义程序运行的目录
if
(
isset
(
$_GET
[
'env'
])
&&
'test'
==
$_GET
[
'env'
])
{
require_once
__DIR__
.
'/../common/InitAppHelper.php'
;
#if (defined('REQ_ORIGIN')){
$realip
=
InitAppHelper
::
getUserIp
();
echo
$realip
;
exit
;
$ip_list
=
file_get_contents
(
'/data_wallet/api_ip_limit.txt'
);
$ip_arr
=
explode
(
"
\n
"
,
$ip_list
);
foreach
(
$ip_arr
as
$key
=>
$ip
){
if
(
$ip
==
$realip
){
$data
=
[
'code'
=>
403
,
'message'
=>
'请求次数过多!'
];
echo
json_encode
(
$data
);
exit
;
}
}
#}
}
require
WALLET_PROJECT_PATH
.
'/vendor/autoload.php'
;
require
WALLET_PROJECT_PATH
.
'/vendor/autoload.php'
;
require
WALLET_PROJECT_PATH
.
'/vendor/yiisoft/yii2/Yii.php'
;
require
WALLET_PROJECT_PATH
.
'/vendor/yiisoft/yii2/Yii.php'
;
require
__DIR__
.
'/../common/config/bootstrap.php'
;
require
__DIR__
.
'/../common/config/bootstrap.php'
;
...
...
common/helper/InitAppHelper.php
0 → 100644
View file @
7493e528
<?php
class
InitAppHelper
{
/**
* 不同环境下获取真实的IP
*/
public
static
function
getUserIp
()
{
// 判断服务器是否允许$_SERVER
if
(
isset
(
$_SERVER
))
{
if
(
isset
(
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
]))
{
$realip
=
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
];
}
elseif
(
isset
(
$_SERVER
[
'HTTP_CLIENT_IP'
]))
{
$realip
=
$_SERVER
[
'HTTP_CLIENT_IP'
];
}
else
{
$realip
=
$_SERVER
[
'REMOTE_ADDR'
];
}
}
else
{
// 不允许就使用getenv获取
if
(
getenv
(
"HTTP_X_FORWARDED_FOR"
))
{
$realip
=
getenv
(
"HTTP_X_FORWARDED_FOR"
);
}
elseif
(
getenv
(
"HTTP_CLIENT_IP"
))
{
$realip
=
getenv
(
"HTTP_CLIENT_IP"
);
}
else
{
$realip
=
getenv
(
"REMOTE_ADDR"
);
}
}
return
$realip
;
}
public
static
function
isInnerUserIp
(
$user_ip
,
$company_ip_list
)
{
if
((
in_array
(
$user_ip
,
$company_ip_list
)
||
!
filter_var
(
$user_ip
,
FILTER_VALIDATE_IP
,
FILTER_FLAG_NO_PRIV_RANGE
)
||
'127.0.0.1'
===
$user_ip
))
{
return
true
;
}
return
false
;
}
public
static
function
isOuterUserIp
(
$user_ip
,
$company_ip_list
)
{
return
!
self
::
isInnerUserIp
(
$user_ip
,
$company_ip_list
);
}
public
static
function
isFromCompanyAccessOuterHost
()
{
$user_ip
=
self
::
getUserIp
();
$instanse
=
new
InitAppHelper
();
$company_ip_list
=
$instanse
->
getConfig
(
'company_ip_list'
,
'ip'
);
$is_online_host
=
self
::
isOnlineHost
(
$_SERVER
[
'SERVER_NAME'
]);
if
(
in_array
(
$user_ip
,
$company_ip_list
)
&&
$is_online_host
)
{
return
true
;
}
return
false
;
}
/**
* 判断是否是真实的外部用户访问 真实外部用户
*/
public
static
function
isRealOuterAccess
()
{
$user_ip
=
self
::
getUserIp
();
$instanse
=
new
InitAppHelper
();
$company_ip_list
=
$instanse
->
getConfig
(
'company_ip_list'
,
'ip'
);
return
self
::
isOuterUserIp
(
$user_ip
,
$company_ip_list
);
}
}
\ 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