diff --git a/README.md b/README.md index 15bbff8..b8071e4 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ For detailed API documentation, please see [docs/api.md](docs/api.md) - [ ] Add frpc instance log display API - [ ] Fix random database lock when processing logs - [ ] Add frpc createdBy storage and display +- [x] Fix backend can still start frpc instance when it is already running ## License diff --git a/docs/api.md b/docs/api.md index db8f255..743f74f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1138,7 +1138,7 @@ X-Timestamp: 1704067200000 | X-Token | string | Yes | Authentication token | | X-Timestamp | int64 | Yes | Client timestamp in milliseconds | -**Response (admin/superuser):** +**Response:** ```json { "success": true, @@ -1147,33 +1147,9 @@ X-Timestamp: 1704067200000 { "instanceID": 1, "name": "my_frpc", - "serverAddr": "127.0.0.1", - "serverPort": "7000", - "auth.method": "token", - "bootAtStart": true, - "runUser": "root", - "configPath": "./configs/superfrpc_user_my_frpc.toml", "createdAt": "2024-01-01T00:00:00Z", - "createdBy": "admin" - } - ] -} -``` - -**Response (visitor):** -```json -{ - "success": true, - "message": "instances retrieved successfully", - "data": [ - { - "instanceID": 1, - "name": "my_frpc", - "bootAtStart": true, - "runUser": "root", - "configPath": "./configs/superfrpc_user_my_frpc.toml", - "createdAt": "2024-01-01T00:00:00Z", - "createdBy": "admin" + "createdBy": "admin", + "isRunning": true } ] } @@ -1183,16 +1159,9 @@ X-Timestamp: 1704067200000 |-------|------|-------------| | instanceID | int | Instance ID | | name | string | Instance name | -| serverAddr | string | frps server address (admin/superuser only) | -| serverPort | string | frps server port (admin/superuser only) | -| auth.method | string | Authentication method (admin/superuser only) | -| bootAtStart | bool | Auto-start on system boot | -| runUser | string | User to run the frpc instance as | -| configPath | string | Path to the configuration file | | createdAt | string | Instance creation time (ISO 8601 format) | | createdBy | string | Username of the user who created this instance | - -> Note: Visitor users do not see sensitive information (serverAddr, serverPort, auth.method). +| isRunning | bool | Instance running status: true (running) or false (stopped) | --- diff --git a/frpAct.go b/frpAct.go index ae834d1..b3e625b 100644 --- a/frpAct.go +++ b/frpAct.go @@ -539,13 +539,6 @@ func ListInstancesHandler(w http.ResponseWriter, r *http.Request) { return } - userType, err := GetUserType(userID) - if err != nil { - postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to get user type: %v", err)) - SendErrorResponse(w, http.StatusInternalServerError, "Failed to get user type") - return - } - instances, err := GetUserInstances(userID) if err != nil { postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to get user instances: %v", err)) @@ -556,32 +549,18 @@ func ListInstancesHandler(w http.ResponseWriter, r *http.Request) { instanceList := make([]map[string]interface{}, len(instances)) for i, inst := range instances { instanceData := map[string]interface{}{ - "instanceID": inst.ID, - "name": inst.Name, - "bootAtStart": inst.BootAtStart, - "runUser": inst.RunUser, - "configPath": inst.ConfigPath, - "createdAt": inst.CreatedAt, - "createdBy": inst.CreatedBy, - } - - if userType == "admin" || userType == "superuser" { - serverAddr, err := getKeyText(inst.ConfigPath, "serverAddr", "") - serverPort, err := getKeyText(inst.ConfigPath, "serverPort", "") - authMethod, err := getKeyText(inst.ConfigPath, "auth.method", "") - if err != nil { - postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to read config for instance %d: %v", inst.ID, err)) - } - instanceData["serverAddr"] = serverAddr - instanceData["serverPort"] = serverPort - instanceData["auth_method"] = authMethod + "instanceID": inst.ID, + "name": inst.Name, + "createdAt": inst.CreatedAt, + "createdBy": inst.CreatedBy, + "isRunning": IsInstanceRunning(inst.ID), } instanceList[i] = instanceData } SendSuccessResponse(w, "Instances retrieved successfully", instanceList) - postLog.Info(fmt.Sprintf("[ListInstancesHandler] Retrieved %d instances for user %d (type: %s)", len(instances), userID, userType)) + postLog.Info(fmt.Sprintf("[ListInstancesHandler] Retrieved %d instances for user %d", len(instances), userID)) } func StartInstanceHandler(w http.ResponseWriter, r *http.Request) {