Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
tsai
CAP
Commits
d420ae23
Commit
d420ae23
authored
Oct 15, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add LAN ip to LocalRequestsOnlyAuthorizationFilter
parent
0e357e70
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
1 deletion
+44
-1
LocalRequestsOnlyAuthorizationFilter.cs
...ore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs
+7
-1
Helper.cs
src/DotNetCore.CAP/Infrastructure/Helper.cs
+37
-0
No files found.
src/DotNetCore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs
View file @
d420ae23
namespace
DotNetCore.CAP.Dashboard
using
DotNetCore.CAP.Infrastructure
;
namespace
DotNetCore.CAP.Dashboard
{
{
public
class
LocalRequestsOnlyAuthorizationFilter
:
IDashboardAuthorizationFilter
public
class
LocalRequestsOnlyAuthorizationFilter
:
IDashboardAuthorizationFilter
{
{
...
@@ -16,6 +18,10 @@
...
@@ -16,6 +18,10 @@
if
(
context
.
Request
.
RemoteIpAddress
==
context
.
Request
.
LocalIpAddress
)
if
(
context
.
Request
.
RemoteIpAddress
==
context
.
Request
.
LocalIpAddress
)
return
true
;
return
true
;
// check if private ip
if
(
Helper
.
IsInnerIP
(
context
.
Request
.
RemoteIpAddress
))
return
true
;
return
false
;
return
false
;
}
}
}
}
...
...
src/DotNetCore.CAP/Infrastructure/Helper.cs
View file @
d420ae23
...
@@ -105,6 +105,43 @@ namespace DotNetCore.CAP.Infrastructure
...
@@ -105,6 +105,43 @@ namespace DotNetCore.CAP.Infrastructure
return
AddJsonProperty
(
json
,
"ExceptionMessage"
,
jObject
);
return
AddJsonProperty
(
json
,
"ExceptionMessage"
,
jObject
);
}
}
public
static
bool
IsInnerIP
(
string
ipAddress
)
{
bool
isInnerIp
;
var
ipNum
=
GetIpNum
(
ipAddress
);
//Private IP:
//category A: 10.0.0.0-10.255.255.255
//category B: 172.16.0.0-172.31.255.255
//category C: 192.168.0.0-192.168.255.255
var
aBegin
=
GetIpNum
(
"10.0.0.0"
);
var
aEnd
=
GetIpNum
(
"10.255.255.255"
);
var
bBegin
=
GetIpNum
(
"172.16.0.0"
);
var
bEnd
=
GetIpNum
(
"172.31.255.255"
);
var
cBegin
=
GetIpNum
(
"192.168.0.0"
);
var
cEnd
=
GetIpNum
(
"192.168.255.255"
);
isInnerIp
=
IsInner
(
ipNum
,
aBegin
,
aEnd
)
||
IsInner
(
ipNum
,
bBegin
,
bEnd
)
||
IsInner
(
ipNum
,
cBegin
,
cEnd
);
return
isInnerIp
;
}
private
static
long
GetIpNum
(
string
ipAddress
)
{
var
ip
=
ipAddress
.
Split
(
'.'
);
long
a
=
int
.
Parse
(
ip
[
0
]);
long
b
=
int
.
Parse
(
ip
[
1
]);
long
c
=
int
.
Parse
(
ip
[
2
]);
long
d
=
int
.
Parse
(
ip
[
3
]);
var
ipNum
=
a
*
256
*
256
*
256
+
b
*
256
*
256
+
c
*
256
+
d
;
return
ipNum
;
}
private
static
bool
IsInner
(
long
userIp
,
long
begin
,
long
end
)
{
return
userIp
>=
begin
&&
userIp
<=
end
;
}
private
static
bool
CanConvertFromString
(
Type
destinationType
)
private
static
bool
CanConvertFromString
(
Type
destinationType
)
{
{
destinationType
=
Nullable
.
GetUnderlyingType
(
destinationType
)
??
destinationType
;
destinationType
=
Nullable
.
GetUnderlyingType
(
destinationType
)
??
destinationType
;
...
...
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