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:
2026-02-28 15:48:01 +08:00
parent ff62e3e755
commit b46f6dbfc2
8 changed files with 32 additions and 27 deletions
+3 -1
View File
@@ -40,6 +40,8 @@ go.work.sum
.env .env
/frp_client /frp_client
/config
agent.md agent.md
super-frpc super-frpc
super-frpc.exe super-frpc.exe
database.db
+2 -2
View File
@@ -92,8 +92,7 @@ X-Timestamp: 1704067200000
```json ```json
{ {
"username": "your_username", "username": "your_username",
"passwd": "YourPass123!", "passwd": "YourPass123!"
"type": "admin"
} }
``` ```
@@ -119,6 +118,7 @@ X-Timestamp: 1704067200000
} }
} }
``` ```
> New user only can register as visitor, superuser and admin need to contact the administrator to apply.
--- ---
+4 -4
View File
@@ -178,6 +178,10 @@ func isValidPassword(password string) bool { // Validate password complexity and
} }
func ValidateTimeStamp(header http.Header) bool { func ValidateTimeStamp(header http.Header) bool {
if isDebug {
return true
}
timeStampStr := header.Get("X-Timestamp") timeStampStr := header.Get("X-Timestamp")
if timeStampStr == "" { if timeStampStr == "" {
return false return false
@@ -188,10 +192,6 @@ func ValidateTimeStamp(header http.Header) bool {
return false return false
} }
if globalConfig.Debug {
return true
}
currentTime := time.Now().UnixMilli() currentTime := time.Now().UnixMilli()
if currentTime-timeStamp > 3000 || timeStamp-currentTime > 3000 { if currentTime-timeStamp > 3000 || timeStamp-currentTime > 3000 {
return false return false
-5
View File
@@ -1,5 +0,0 @@
[common]
server_addr = 127.0.0.1
server_port = 7000
auth_method = token
=
BIN
View File
Binary file not shown.
+9 -4
View File
@@ -35,6 +35,7 @@ func RegisterHandler(w http.ResponseWriter, r *http.Request) {
if !ValidateTimeStamp(r.Header) { if !ValidateTimeStamp(r.Header) {
SendErrorResponse(w, http.StatusBadRequest, "Invalid or missing X-Timestamp in 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 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) return 0, "", fmt.Errorf("Token is required in header: %s", token)
} }
if !ValidateTimeStamp(r.Header) { if !isDebug {
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header") if !ValidateTimeStamp(r.Header) {
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header")
}
} }
userID, err := extractUserIDFromToken(token) 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) return 0, "", fmt.Errorf("Token is required in header: %s", token)
} }
if !ValidateTimeStamp(r.Header) { if !isDebug {
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header") if !ValidateTimeStamp(r.Header) {
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header")
}
} }
userID, err := extractUserIDFromToken(token) userID, err := extractUserIDFromToken(token)
+11 -8
View File
@@ -12,20 +12,22 @@ import (
) )
type SoftwareInfo struct { type SoftwareInfo struct {
Name string Name string
Version string Version string
Developer string Developer string
BuildVer int16 BuildVer int16
Description string Description string
BuildType string BuildType string
} }
var isDebug bool
func main() { func main() {
softwareInfo := SoftwareInfo{ softwareInfo := SoftwareInfo{
Name: "Super-frpc", Name: "Super-frpc",
Version: "0.0.1", Version: "0.0.1",
Developer: "Madobi Nanami", Developer: "Madobi Nanami",
BuildVer: 1, BuildVer: 1,
BuildType: "debug", BuildType: "debug",
} }
postLog.Info(fmt.Sprintf("%s %s (Build %d.%s) by %s", softwareInfo.Name, softwareInfo.Version, softwareInfo.BuildVer, softwareInfo.BuildType, softwareInfo.Developer)) 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 // Initialize logger with debug mode
postLog.SetDebugMode(config.Debug) postLog.SetDebugMode(config.Debug)
isDebug = config.Debug
if err := InitDatabase(*dbPath); err != nil { if err := InitDatabase(*dbPath); err != nil {
postLog.Fatal(fmt.Sprintf("Failed to initialize database: %v", err)) postLog.Fatal(fmt.Sprintf("Failed to initialize database: %v", err))
+3 -3
View File
@@ -8,7 +8,7 @@ import (
var ( var (
loggerMutex sync.Mutex loggerMutex sync.Mutex
debugMode bool isDebug bool
) )
const ( const (
@@ -35,7 +35,7 @@ func getSystemTime() string {
func SetDebugMode(debug bool) { func SetDebugMode(debug bool) {
loggerMutex.Lock() loggerMutex.Lock()
defer loggerMutex.Unlock() defer loggerMutex.Unlock()
debugMode = debug isDebug = debug
} }
func PostLog(message string, level int) { func PostLog(message string, level int) {
@@ -51,7 +51,7 @@ func PostLog(message string, level int) {
defer loggerMutex.Unlock() defer loggerMutex.Unlock()
// Skip DEBUG when debug is off // Skip DEBUG when debug is off
if idx == DEBUG && !debugMode { if idx == DEBUG && !isDebug {
return return
} }