|
@@ -2,10 +2,13 @@ package main
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"net/http"
|
|
|
"path/filepath"
|
|
|
+ "strings"
|
|
|
|
|
|
"imuslab.com/arozos/mod/disk/hybridBackup"
|
|
|
+ user "imuslab.com/arozos/mod/user"
|
|
|
|
|
|
prout "imuslab.com/arozos/mod/prouter"
|
|
|
)
|
|
@@ -25,6 +28,16 @@ func backup_init() {
|
|
|
router.HandleFunc("/system/backup/restoreFile", backup_restoreSelected)
|
|
|
router.HandleFunc("/system/backup/snapshotSummary", backup_renderSnapshotSummary)
|
|
|
router.HandleFunc("/system/backup/listAll", backup_listAllBackupDisk)
|
|
|
+
|
|
|
+ //Register settings
|
|
|
+ registerSetting(settingModule{
|
|
|
+ Name: "Backup Disks",
|
|
|
+ Desc: "All backup disk in the system",
|
|
|
+ IconPath: "img/system/backup.svg",
|
|
|
+ Group: "Disk",
|
|
|
+ StartDir: "SystemAO/disk/backup/backups.html",
|
|
|
+ RequireAdmin: true,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//List all backup disk info
|
|
@@ -199,8 +212,15 @@ func backup_restoreSelected(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ //Pick the correct HybridBackup Manager
|
|
|
+ targetHybridBackupManager, err := backup_pickHybridBackupManager(userinfo, fsh.UUID)
|
|
|
+ if err != nil {
|
|
|
+ sendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
//Handle restore of the file
|
|
|
- err = userinfo.HomeDirectories.HyperBackupManager.HandleRestore(fsh.UUID, relpath, &userinfo.Username)
|
|
|
+ err = targetHybridBackupManager.HandleRestore(fsh.UUID, relpath, &userinfo.Username)
|
|
|
if err != nil {
|
|
|
sendErrorResponse(w, err.Error())
|
|
|
return
|
|
@@ -217,7 +237,7 @@ func backup_restoreSelected(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//Get access path for this file
|
|
|
- parentDiskId, err := userinfo.HomeDirectories.HyperBackupManager.GetParentDiskIDByRestoreDiskID(fsh.UUID)
|
|
|
+ parentDiskId, err := targetHybridBackupManager.GetParentDiskIDByRestoreDiskID(fsh.UUID)
|
|
|
if err != nil {
|
|
|
//Unable to get parent disk ID???
|
|
|
|
|
@@ -240,6 +260,31 @@ func backup_restoreSelected(w http.ResponseWriter, r *http.Request) {
|
|
|
sendJSONResponse(w, string(js))
|
|
|
}
|
|
|
|
|
|
+//As one user might be belongs to multiple groups, check which storage pool is this disk ID owned by and return its corect backup maanger
|
|
|
+func backup_pickHybridBackupManager(userinfo *user.User, diskID string) (*hybridBackup.Manager, error) {
|
|
|
+ //Filter out the :/ if it exists in the disk ID
|
|
|
+ if strings.Contains(diskID, ":") {
|
|
|
+ diskID = strings.Split(diskID, ":")[0]
|
|
|
+ }
|
|
|
+
|
|
|
+ //Get all backup managers that this user ac can access
|
|
|
+ userpg := userinfo.GetUserPermissionGroup()
|
|
|
+
|
|
|
+ if userinfo.HomeDirectories.ContainDiskID(diskID) {
|
|
|
+ return userinfo.HomeDirectories.HyperBackupManager, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ //Extract the backup Managers
|
|
|
+ for _, pg := range userpg {
|
|
|
+ if pg.StoragePool.ContainDiskID(diskID) {
|
|
|
+ return pg.StoragePool.HyperBackupManager, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil, errors.New("Disk ID not found in any storage pool this user can access")
|
|
|
+}
|
|
|
+
|
|
|
//Generate and return a restorable report
|
|
|
func backup_listRestorable(w http.ResponseWriter, r *http.Request) {
|
|
|
//Get user accessiable storage pools
|
|
@@ -263,10 +308,15 @@ func backup_listRestorable(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- userBackupManager := userinfo.HomeDirectories.HyperBackupManager
|
|
|
+ //Get all backup managers that this user ac can access
|
|
|
+ targetBackupManager, err := backup_pickHybridBackupManager(userinfo, vroot)
|
|
|
+ if err != nil {
|
|
|
+ sendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
//Get the user's storage pool and list restorable by the user's storage pool access
|
|
|
- restorableReport, err := userBackupManager.ListRestorable(fsh.UUID)
|
|
|
+ restorableReport, err := targetBackupManager.ListRestorable(fsh.UUID)
|
|
|
if err != nil {
|
|
|
sendErrorResponse(w, err.Error())
|
|
|
return
|