Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Vũ Hoàng Anh
canifa_note
Commits
477130aa
Unverified
Commit
477130aa
authored
Nov 19, 2022
by
boojack
Committed by
GitHub
Nov 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update db filesize access control (#493)
parent
878e0eab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
+18
-9
acl.go
server/acl.go
+2
-5
system.go
server/system.go
+16
-4
No files found.
server/acl.go
View file @
477130aa
...
@@ -55,15 +55,12 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
...
@@ -55,15 +55,12 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
return
func
(
c
echo
.
Context
)
error
{
return
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
path
:=
c
.
Path
()
path
:=
c
.
Path
()
// Skip auth.
// Skip auth.
if
common
.
HasPrefixes
(
path
,
"/api/auth"
)
{
if
common
.
HasPrefixes
(
path
,
"/api/auth"
)
{
return
next
(
c
)
return
next
(
c
)
}
}
if
common
.
HasPrefixes
(
path
,
"/api/ping"
,
"/api/status"
,
"/api/user/:id"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
return
next
(
c
)
}
{
{
// If there is openId in query string and related user is found, then skip auth.
// If there is openId in query string and related user is found, then skip auth.
openID
:=
c
.
QueryParam
(
"openId"
)
openID
:=
c
.
QueryParam
(
"openId"
)
...
@@ -104,7 +101,7 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
...
@@ -104,7 +101,7 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
}
}
}
}
if
common
.
HasPrefixes
(
path
,
"/api/memo/all"
,
"/api/memo/:memoId"
,
"/api/memo/amount"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
if
common
.
HasPrefixes
(
path
,
"/api/
ping"
,
"/api/status"
,
"/api/user/:id"
,
"/api/
memo/all"
,
"/api/memo/:memoId"
,
"/api/memo/amount"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
return
next
(
c
)
return
next
(
c
)
}
}
...
...
server/system.go
View file @
477130aa
...
@@ -42,6 +42,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
...
@@ -42,6 +42,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
systemStatus
:=
api
.
SystemStatus
{
systemStatus
:=
api
.
SystemStatus
{
Host
:
hostUser
,
Host
:
hostUser
,
Profile
:
s
.
Profile
,
Profile
:
s
.
Profile
,
DBSize
:
0
,
AllowSignUp
:
false
,
AllowSignUp
:
false
,
AdditionalStyle
:
""
,
AdditionalStyle
:
""
,
AdditionalScript
:
""
,
AdditionalScript
:
""
,
...
@@ -67,11 +68,22 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
...
@@ -67,11 +68,22 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
}
}
}
}
fi
,
err
:=
os
.
Stat
(
s
.
Profile
.
DSN
)
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
err
!=
nil
{
if
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to read database fileinfo"
)
.
SetInternal
(
err
)
user
,
err
:=
s
.
Store
.
FindUser
(
ctx
,
&
api
.
UserFind
{
ID
:
&
userID
,
})
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user"
)
.
SetInternal
(
err
)
}
if
user
!=
nil
&&
user
.
Role
==
api
.
Host
{
fi
,
err
:=
os
.
Stat
(
s
.
Profile
.
DSN
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to read database fileinfo"
)
.
SetInternal
(
err
)
}
systemStatus
.
DBSize
=
fi
.
Size
()
}
}
}
systemStatus
.
DBSize
=
fi
.
Size
()
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
systemStatus
));
err
!=
nil
{
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
systemStatus
));
err
!=
nil
{
...
...
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