fix: change permission level for instance listing to visitor and making sure all instances could be listed for all users

This commit is contained in:
2026-05-07 21:38:52 +08:00
parent 9ffb4263cf
commit 6e705ce2f3
4 changed files with 22 additions and 22 deletions
+3 -7
View File
@@ -499,14 +499,15 @@ func getNumFromMap(m map[string]interface{}, key string) int {
}
func ListInstancesHandler(w http.ResponseWriter, r *http.Request) {
userID, err := utils.Auth(w, r, http.MethodGet, "superuser", "admin")
userID, err := utils.Auth(w, r, http.MethodGet, "visitor", "admin", "superuser")
if err != nil {
utils.SendErrorResponse(w, http.StatusUnauthorized, err.Error())
utils.SendErrorResponse(w, http.StatusUnauthorized, "invalid token or timestamp")
postLog.Warning(fmt.Sprintf("[ListInstancesHandler] Auth failed: %v", err))
return
}
instances, err := database.DBListFrpcInstances()
postLog.Debug(fmt.Sprintf("[ListInstancesHandler] Retrieved %d instances", len(instances)))
if err != nil {
postLog.Error(fmt.Sprintf("[ListInstancesHandler] Failed to get all instances: %v", err))
utils.SendErrorResponse(w, http.StatusInternalServerError, "Failed to get instances")
@@ -967,11 +968,6 @@ func GetInstanceInfoHandler(w http.ResponseWriter, r *http.Request) {
return
}
if instance.UserID != userID {
utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found")
return
}
user, err := database.GetUserByID(userID)
if err != nil {
postLog.Error(fmt.Sprintf("[GetInstanceInfoHandler] Failed to get user info: %v", err))
+1 -7
View File
@@ -295,7 +295,7 @@ func DeleteProxyHandler(w http.ResponseWriter, r *http.Request) {
}
func ListProxiesHandler(w http.ResponseWriter, r *http.Request) {
userID, err := utils.Auth(w, r, http.MethodGet)
_, err := utils.Auth(w, r, http.MethodGet)
if err != nil {
utils.SendErrorResponse(w, http.StatusUnauthorized, err.Error())
postLog.Warning(fmt.Sprintf("[ListProxiesHandler] Auth failed: %v", err))
@@ -319,12 +319,6 @@ func ListProxiesHandler(w http.ResponseWriter, r *http.Request) {
return
}
if instance.UserID != userID {
postLog.Error(fmt.Sprintf("[ListProxiesHandler] Instance not found for user %d", userID))
utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found")
return
}
configContent, err := os.ReadFile(instance.ConfigPath)
if err != nil {
postLog.Error(fmt.Sprintf("[ListProxiesHandler] Failed to read config file %s: %v", instance.ConfigPath, err))