refactor: consolidate debug flag and update gitignore
- Rename debugMode to isDebug for consistency across codebase - Move debug flag check in ValidateTimeStamp to match other validations - Add database.db to gitignore and remove unused config file - Update README.md to clarify user registration rules
This commit is contained in:
+3
-1
@@ -40,6 +40,8 @@ go.work.sum
|
||||
.env
|
||||
|
||||
/frp_client
|
||||
/config
|
||||
agent.md
|
||||
super-frpc
|
||||
super-frpc.exe
|
||||
super-frpc.exe
|
||||
database.db
|
||||
@@ -92,8 +92,7 @@ X-Timestamp: 1704067200000
|
||||
```json
|
||||
{
|
||||
"username": "your_username",
|
||||
"passwd": "YourPass123!",
|
||||
"type": "admin"
|
||||
"passwd": "YourPass123!"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -119,6 +118,7 @@ X-Timestamp: 1704067200000
|
||||
}
|
||||
}
|
||||
```
|
||||
> New user only can register as visitor, superuser and admin need to contact the administrator to apply.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -178,6 +178,10 @@ func isValidPassword(password string) bool { // Validate password complexity and
|
||||
}
|
||||
|
||||
func ValidateTimeStamp(header http.Header) bool {
|
||||
if isDebug {
|
||||
return true
|
||||
}
|
||||
|
||||
timeStampStr := header.Get("X-Timestamp")
|
||||
if timeStampStr == "" {
|
||||
return false
|
||||
@@ -188,10 +192,6 @@ func ValidateTimeStamp(header http.Header) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if globalConfig.Debug {
|
||||
return true
|
||||
}
|
||||
|
||||
currentTime := time.Now().UnixMilli()
|
||||
if currentTime-timeStamp > 3000 || timeStamp-currentTime > 3000 {
|
||||
return false
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
[common]
|
||||
server_addr = 127.0.0.1
|
||||
server_port = 7000
|
||||
auth_method = token
|
||||
=
|
||||
BIN
Binary file not shown.
+9
-4
@@ -35,6 +35,7 @@ func RegisterHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if !ValidateTimeStamp(r.Header) {
|
||||
SendErrorResponse(w, http.StatusBadRequest, "Invalid or missing X-Timestamp in header")
|
||||
postLog.Warning(fmt.Sprintf("[RegisterHandler] Invalid or missing X-Timestamp in header: %s", r.Header.Get("X-Timestamp")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -219,8 +220,10 @@ func ValidateRequestWithBody(w http.ResponseWriter, r *http.Request, body []byte
|
||||
return 0, "", fmt.Errorf("Token is required in header: %s", token)
|
||||
}
|
||||
|
||||
if !ValidateTimeStamp(r.Header) {
|
||||
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header")
|
||||
if !isDebug {
|
||||
if !ValidateTimeStamp(r.Header) {
|
||||
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header")
|
||||
}
|
||||
}
|
||||
|
||||
userID, err := extractUserIDFromToken(token)
|
||||
@@ -247,8 +250,10 @@ func ValidateRequestWithHeader(w http.ResponseWriter, r *http.Request, requiredF
|
||||
return 0, "", fmt.Errorf("Token is required in header: %s", token)
|
||||
}
|
||||
|
||||
if !ValidateTimeStamp(r.Header) {
|
||||
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header")
|
||||
if !isDebug {
|
||||
if !ValidateTimeStamp(r.Header) {
|
||||
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header")
|
||||
}
|
||||
}
|
||||
|
||||
userID, err := extractUserIDFromToken(token)
|
||||
|
||||
@@ -12,20 +12,22 @@ import (
|
||||
)
|
||||
|
||||
type SoftwareInfo struct {
|
||||
Name string
|
||||
Version string
|
||||
Developer string
|
||||
BuildVer int16
|
||||
Name string
|
||||
Version string
|
||||
Developer string
|
||||
BuildVer int16
|
||||
Description string
|
||||
BuildType string
|
||||
BuildType string
|
||||
}
|
||||
|
||||
var isDebug bool
|
||||
|
||||
func main() {
|
||||
softwareInfo := SoftwareInfo{
|
||||
Name: "Super-frpc",
|
||||
Version: "0.0.1",
|
||||
Name: "Super-frpc",
|
||||
Version: "0.0.1",
|
||||
Developer: "Madobi Nanami",
|
||||
BuildVer: 1,
|
||||
BuildVer: 1,
|
||||
BuildType: "debug",
|
||||
}
|
||||
postLog.Info(fmt.Sprintf("%s %s (Build %d.%s) by %s", softwareInfo.Name, softwareInfo.Version, softwareInfo.BuildVer, softwareInfo.BuildType, softwareInfo.Developer))
|
||||
@@ -52,6 +54,7 @@ func main() {
|
||||
|
||||
// Initialize logger with debug mode
|
||||
postLog.SetDebugMode(config.Debug)
|
||||
isDebug = config.Debug
|
||||
|
||||
if err := InitDatabase(*dbPath); err != nil {
|
||||
postLog.Fatal(fmt.Sprintf("Failed to initialize database: %v", err))
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
var (
|
||||
loggerMutex sync.Mutex
|
||||
debugMode bool
|
||||
isDebug bool
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,7 +35,7 @@ func getSystemTime() string {
|
||||
func SetDebugMode(debug bool) {
|
||||
loggerMutex.Lock()
|
||||
defer loggerMutex.Unlock()
|
||||
debugMode = debug
|
||||
isDebug = debug
|
||||
}
|
||||
|
||||
func PostLog(message string, level int) {
|
||||
@@ -51,7 +51,7 @@ func PostLog(message string, level int) {
|
||||
defer loggerMutex.Unlock()
|
||||
|
||||
// Skip DEBUG when debug is off
|
||||
if idx == DEBUG && !debugMode {
|
||||
if idx == DEBUG && !isDebug {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user