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 b661118180
commit 686c3dcd4e
8 changed files with 32 additions and 27 deletions
+2
View File
@@ -40,6 +40,8 @@ go.work.sum
.env
/frp_client
/config
agent.md
super-frpc
super-frpc.exe
database.db
+2 -2
View File
@@ -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.
---
+4 -4
View File
@@ -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
-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.
+5
View File
@@ -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,9 +220,11 @@ func ValidateRequestWithBody(w http.ResponseWriter, r *http.Request, body []byte
return 0, "", fmt.Errorf("Token is required in header: %s", token)
}
if !isDebug {
if !ValidateTimeStamp(r.Header) {
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header")
}
}
userID, err := extractUserIDFromToken(token)
if err != nil {
@@ -247,9 +250,11 @@ func ValidateRequestWithHeader(w http.ResponseWriter, r *http.Request, requiredF
return 0, "", fmt.Errorf("Token is required in header: %s", token)
}
if !isDebug {
if !ValidateTimeStamp(r.Header) {
return 0, "", fmt.Errorf("Invalid or missing X-Timestamp in header")
}
}
userID, err := extractUserIDFromToken(token)
if err != nil {
+3
View File
@@ -20,6 +20,8 @@ type SoftwareInfo struct {
BuildType string
}
var isDebug bool
func main() {
softwareInfo := SoftwareInfo{
Name: "Super-frpc",
@@ -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
View File
@@ -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
}