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:
+15
-5
@@ -420,9 +420,8 @@ func DBUpdateFrpcInstance(instance FrpcInstance) error {
|
||||
|
||||
func DBListFrpcInstances() ([]FrpcInstance, error) {
|
||||
rows, err := global.FrpcDB.Query(`
|
||||
SELECT fi.id, fi.userID, fi.name, fi.bootAtStart, fi.runUser, fi.configPath, fi.createdAt, fi.watchdog, u.username
|
||||
FROM frpcInstances fi
|
||||
JOIN userLogin u ON fi.userID = u.userID
|
||||
SELECT id, userID, name, bootAtStart, runUser, configPath, createdAt, watchdog
|
||||
FROM frpcInstances
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query all frpc instances: %w", err)
|
||||
@@ -433,10 +432,19 @@ func DBListFrpcInstances() ([]FrpcInstance, error) {
|
||||
for rows.Next() {
|
||||
var instance FrpcInstance
|
||||
var createdAtStr string
|
||||
if err := rows.Scan(&instance.ID, &instance.UserID, &instance.Name, &instance.BootAtStart, &instance.RunUser, &instance.ConfigPath, &createdAtStr, &instance.Watchdog, &instance.CreatedBy); err != nil {
|
||||
if err := rows.Scan(&instance.ID, &instance.UserID, &instance.Name, &instance.BootAtStart, &instance.RunUser, &instance.ConfigPath, &createdAtStr, &instance.Watchdog); err != nil {
|
||||
return nil, fmt.Errorf("failed to scan frpc instance: %w", err)
|
||||
}
|
||||
instance.CreatedAt, _ = time.Parse(time.RFC3339, createdAtStr)
|
||||
|
||||
user, err := GetUserByID(instance.UserID)
|
||||
if err != nil {
|
||||
postLog.Warning(fmt.Sprintf("[DBListFrpcInstances] Failed to get user %d: %v", instance.UserID, err))
|
||||
instance.CreatedBy = "unknown"
|
||||
} else {
|
||||
instance.CreatedBy = user.Username
|
||||
}
|
||||
|
||||
instances = append(instances, instance)
|
||||
}
|
||||
|
||||
@@ -466,7 +474,9 @@ func GetServiceNameByInstanceID(instanceID int) (string, error) {
|
||||
|
||||
user, err := GetUserByID(instance.UserID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get user info: %w", err)
|
||||
postLog.Warning(fmt.Sprintf("[GetServiceNameByInstanceID] User %d not found, using fallback", instance.UserID))
|
||||
serviceName := fmt.Sprintf("superfrpc_unknown_%s", instance.Name)
|
||||
return serviceName, nil
|
||||
}
|
||||
|
||||
serviceName := fmt.Sprintf("superfrpc_%s_%s", user.Username, instance.Name)
|
||||
|
||||
Reference in New Issue
Block a user