From 686c3dcd4e164c6300d0c5d88be671b8c87e10ca Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Sat, 28 Feb 2026 15:48:01 +0800 Subject: [PATCH] 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 --- .gitignore | 4 +++- README.md | 4 ++-- auth.go | 8 ++++---- configs/superfrpc_test_test123.toml | 5 ----- database.db | Bin 24576 -> 24576 bytes handlers.go | 13 +++++++++---- main.go | 19 +++++++++++-------- postLog/postLog.go | 6 +++--- 8 files changed, 32 insertions(+), 27 deletions(-) delete mode 100644 configs/superfrpc_test_test123.toml diff --git a/.gitignore b/.gitignore index e5c18fd..65c2bf1 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,8 @@ go.work.sum .env /frp_client +/config agent.md super-frpc -super-frpc.exe \ No newline at end of file +super-frpc.exe +database.db \ No newline at end of file diff --git a/README.md b/README.md index e0bd472..0c55bfd 100644 --- a/README.md +++ b/README.md @@ -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. --- diff --git a/auth.go b/auth.go index ec03a1a..b52376e 100644 --- a/auth.go +++ b/auth.go @@ -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 diff --git a/configs/superfrpc_test_test123.toml b/configs/superfrpc_test_test123.toml deleted file mode 100644 index 5a5eeaa..0000000 --- a/configs/superfrpc_test_test123.toml +++ /dev/null @@ -1,5 +0,0 @@ -[common] -server_addr = 127.0.0.1 -server_port = 7000 -auth_method = token - = diff --git a/database.db b/database.db index 1c8410e963c13a775b03e3e55e0b77c9f959956d..a7ee4f13c84eee0dbab53990d66ed8c80fb4a0be 100644 GIT binary patch delta 173 zcmZoTz}Rqrae_1>(?l6(aV7@6-e0`@KNwhfE;I0b=ReA~l;<*E)@DJ0Sf0%{cvP7< zy&2iX<>eWhQYW+V8&9_2*PWcguOz`)kXT$?o}v)q8WE!4=MTi8K0Z2JoRjD9YfL`O d@5sa;uvt*yIse27!fad&K!D)#;^m?$1^_>zEfoL& delta 549 zcma)&KTq307{>1$>R@p4f`kcDXibNTzlrY7Ha1>5v>+j+?T}PL0)gzajZljn#YPsUUSeo>QA z^V9DN+@nY8HLCuBZ`H5rbv3ydAM@3VEA^SAtl@G^*YWXYj=_)*(y+JwGJjH8$Rl_> z+4a)&Lom}>-RR7`ek1nVR%>Y_KZUvSJeB0ys-AbNQ~3{gDq}cDa4w9$z)l;>NIR+l~5J(yxQU){o3oT)o6951J diff --git a/handlers.go b/handlers.go index 3315acb..5dadbfe 100644 --- a/handlers.go +++ b/handlers.go @@ -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) diff --git a/main.go b/main.go index e48f6ad..bc60b1f 100644 --- a/main.go +++ b/main.go @@ -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)) diff --git a/postLog/postLog.go b/postLog/postLog.go index ebfdfda..9c9e36a 100644 --- a/postLog/postLog.go +++ b/postLog/postLog.go @@ -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 }