Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(system-security): Optimized unauthenticated settings to enhance … #7532

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions core/app/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type IAuthService interface {
Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, error)
LogOut(c *gin.Context) error
MFALogin(c *gin.Context, info dto.MFALogin, entrance string) (*dto.UserLoginInfo, error)
GetSecurityEntrance() string
IsLogin(c *gin.Context) bool
}

func NewIAuthService() IAuthService {
Expand Down Expand Up @@ -192,3 +194,19 @@ func (u *AuthService) GetResponsePage() (string, error) {
}
return pageCode.Value, nil
}

func (u *AuthService) GetSecurityEntrance() string {
status, err := settingRepo.Get(repo.WithByKey("SecurityEntrance"))
if err != nil {
return ""
}
if len(status.Value) == 0 {
return ""
}
return status.Value
}

func (u *AuthService) IsLogin(c *gin.Context) bool {
_, err := global.SESSION.Get(c)
return err == nil
}
6 changes: 6 additions & 0 deletions core/cmd/server/res/error_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package res

import "embed"

//go:embed html/*
var ErrorMsg embed.FS
55 changes: 55 additions & 0 deletions core/cmd/server/res/html/200.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Access Temporarily Unavailable</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f9f9f9;
margin: 0;
padding: 0;
color: #333;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.icon img {
width: 100px;
height: auto;
}
h1 {
font-size: 24px;
color: #555;
}
p {
font-size: 16px;
color: #666;
line-height: 1.5;
}
.command {
font-family: monospace;
background: #f0f0f0;
padding: 5px 10px;
border-radius: 4px;
display: inline-block;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Access Temporarily Unavailable</h1>
<p>The current environment has enabled secure login access.</p>
<p>Run the following SSH command to view the panel login URL:</p>
<p class="command">1pctl user-info</p>
</div>
</body>
</html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The given HTML code is not related to any programming code. It seems to be a layout with CSS styling applied on it and it's currently used in a webpage design only.

For checking the code differences:

  1. Verify if there are typos or incorrect punctuation marks, which can cause syntax errors.
  2. Check if any variables or constants have been misspelled, since they would lead to errors at runtime when referring to undefined identifiers.
  3. Ensure that all elements within this markup (like images and links) link correctly using external URLs instead of relative paths.

As for potential issues:

  • The use of run could imply running commands in a terminal/bash-like manner, but this isn't specified here; it might need some clarification to avoid confusion.

For optimization suggestions:

  • Use classes instead of IDs for better reusability and maintainability.

No changes suggested beyond those provided:
The provided information doesn't pertain to any software coding language nor specific programming tasks—it merely describes how the existing HTML template structure looks like now.

55 changes: 55 additions & 0 deletions core/cmd/server/res/html/200_err_domain.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Access Temporarily Unavailable</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f9f9f9;
margin: 0;
padding: 0;
color: #333;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.icon img {
width: 100px;
height: auto;
}
h1 {
font-size: 24px;
color: #555;
}
p {
font-size: 16px;
color: #666;
line-height: 1.5;
}
.command {
font-family: monospace;
background: #f0f0f0;
padding: 5px 10px;
border-radius: 4px;
display: inline-block;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Access Temporarily Unavailable</h1>
<p>The current environment has enabled domain name binding.</p>
<p>Run the following SSH command to reset the binding information:</p>
<p class="command">1pctl reset domain</p>
</div>
</body>
</html>
55 changes: 55 additions & 0 deletions core/cmd/server/res/html/200_err_ip_limit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Access Temporarily Unavailable</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f9f9f9;
margin: 0;
padding: 0;
color: #333;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.icon img {
width: 100px;
height: auto;
}
h1 {
font-size: 24px;
color: #555;
}
p {
font-size: 16px;
color: #666;
line-height: 1.5;
}
.command {
font-family: monospace;
background: #f0f0f0;
padding: 5px 10px;
border-radius: 4px;
display: inline-block;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Access Temporarily Unavailable</h1>
<p>The current environment has enabled authorized IP access.</p>
<p>Run the following SSH command to reset the binding information:</p>
<p class="command">1pctl reset ips</p>
</div>
</body>
</html>
7 changes: 7 additions & 0 deletions core/cmd/server/res/html/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
7 changes: 7 additions & 0 deletions core/cmd/server/res/html/401.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head><title>401 Unauthorized</title></head>
<body>
<center><h1>401 Unauthorized</h1></center>
<hr><center>nginx</center>
</body>
7 changes: 7 additions & 0 deletions core/cmd/server/res/html/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
7 changes: 7 additions & 0 deletions core/cmd/server/res/html/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
7 changes: 7 additions & 0 deletions core/cmd/server/res/html/408.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head><title>408 Request Timeout</title></head>
<body>
<center><h1>408 Request Timeout</h1></center>
<hr><center>nginx</center>
</body>
7 changes: 7 additions & 0 deletions core/cmd/server/res/html/416.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head><title>416 Requested Not Satisfiable</title></head>
<body>
<center><h1>416 Requested Not Satisfiable</h1></center>
<hr><center>nginx</center>
</body>
7 changes: 7 additions & 0 deletions core/cmd/server/res/html/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head><title>Internal Server Error</title></head>
<body>
<center><h1>Internal Server Error</h1></center>
<hr><center>nginx</center>
</body>
101 changes: 101 additions & 0 deletions core/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,105 @@ const (
FilePerm = 0644
)

var WebUrlMap = map[string]struct{}{
"/apps": {},
"/apps/all": {},
"/apps/installed": {},
"/apps/upgrade": {},

"/containers": {},
"/containers/container": {},
"/containers/image": {},
"/containers/network": {},
"/containers/volume": {},
"/containers/repo": {},
"/containers/compose": {},
"/containers/template": {},
"/containers/setting": {},

"/cronjobs": {},

"/databases": {},
"/databases/mysql": {},
"/databases/mysql/remote": {},
"/databases/postgresql": {},
"/databases/postgresql/remote": {},
"/databases/redis": {},
"/databases/redis/remote": {},

"/hosts": {},
"/hosts/files": {},
"/hosts/monitor/monitor": {},
"/hosts/monitor/setting": {},
"/hosts/terminal": {},
"/hosts/firewall/port": {},
"/hosts/firewall/forward": {},
"/hosts/firewall/ip": {},
"/hosts/process/process": {},
"/hosts/process/network": {},
"/hosts/ssh/ssh": {},
"/hosts/ssh/log": {},
"/hosts/ssh/session": {},

"/logs": {},
"/logs/operation": {},
"/logs/login": {},
"/logs/website": {},
"/logs/system": {},
"/logs/ssh": {},

"/settings": {},
"/settings/panel": {},
"/settings/backupaccount": {},
"/settings/license": {},
"/settings/about": {},
"/settings/safe": {},
"/settings/snapshot": {},
"/settings/expired": {},

"/toolbox": {},
"/toolbox/device": {},
"/toolbox/supervisor": {},
"/toolbox/clam": {},
"/toolbox/clam/setting": {},
"/toolbox/ftp": {},
"/toolbox/fail2ban": {},
"/toolbox/clean": {},

"/websites": {},
"/websites/ssl": {},
"/websites/runtimes/php": {},
"/websites/runtimes/node": {},
"/websites/runtimes/java": {},
"/websites/runtimes/go": {},
"/websites/runtimes/python": {},
"/websites/runtimes/dotnet": {},

"/login": {},

"/xpack": {},
"/xpack/waf/dashboard": {},
"/xpack/waf/global": {},
"/xpack/waf/websites": {},
"/xpack/waf/log": {},
"/xpack/waf/block": {},
"/xpack/monitor/dashboard": {},
"/xpack/monitor/setting": {},
"/xpack/monitor/rank": {},
"/xpack/monitor/log": {},
"/xpack/tamper": {},
"/xpack/gpu": {},
"/xpack/alert/dashboard": {},
"/xpack/alert/log": {},
"/xpack/alert/setting": {},
"/xpack/setting": {},
}

var DynamicRoutes = []string{
`^/containers/composeDetail/[^/]+$`,
`^/databases/mysql/setting/[^/]+/[^/]+$`,
`^/databases/postgresql/setting/[^/]+/[^/]+$`,
`^/websites/[^/]+/config/[^/]+$`,
}

var CertStore atomic.Value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet appears to be part of an application configuration that manages various endpoints URLs. It seems there are some minor inconsistencies between the original and suggested versions, particularly concerning variable names.

For example:

  • The var declaration cert store is missing from web/url map.
  • The dynamic route definition has a typo (the second route should have "setting" instead of `"s"").
  • There might also be a typographical error in the web url mapping.
  • "dynamic routes" should likely use capitalized letters (DynamicRoutes).

However, without seeing any specific discrepancies or actual problems with these definitions, it would be challenging to provide detailed suggestions about how to optimize this section of the code. Nonetheless, here's what I've found out based on my understanding at present:

  1. URL Mapping: Ensure all URL mappings are spelled correctly, and they do not overlap too much. Also ensure no leading slashes (^/) if your patterns start on the next line, because otherwise it could lead to confusion.

  2. Variable Names: Consistently capitalize variables' names for better readability when working with values coming back from database operations.

  3. Path Matching: Pay close attention to path matching logic in each pattern. This can help keep URLs consistent in terms of structure across different endpoint categories but avoids unnecessary parsing for simple cases like trailing slash (/).

Please review the documentation comments for any other potential issues you need guidance on.

Loading
Loading