Browse Source

Quick test version for prod test

TC pushbot 5 4 years ago
parent
commit
3b5d60f639

+ 1 - 0
.gitignore

@@ -25,6 +25,7 @@ system/network/wifi/ap/*
 system/storage.json
 system/dev.uuid
 system/storage.json
+system/bridge.json
 system/storage/*.json
 system/cron.json
 

+ 7 - 2
mod/network/dynamicproxy/proxyRequestHandler.go

@@ -38,10 +38,15 @@ func (h *ProxyHandler) proxyRequest(w http.ResponseWriter, r *http.Request, targ
 	if r.Header["Upgrade"] != nil && r.Header["Upgrade"][0] == "websocket" {
 		//Handle WebSocket request. Forward the custom Upgrade header and rewrite origin
 		r.Header.Set("A-Upgrade", "websocket")
-		u, _ := url.Parse("ws://" + target.Domain + r.URL.String())
+		wsRedirectionEndpoint := target.Domain
+		if wsRedirectionEndpoint[len(wsRedirectionEndpoint)-1:] != "/" {
+			wsRedirectionEndpoint = wsRedirectionEndpoint + "/"
+		}
+		u, _ := url.Parse("ws://" + wsRedirectionEndpoint + r.URL.String())
 		if target.RequireTLS {
-			u, _ = url.Parse("wss://localhost:" + target.Domain + r.URL.String())
+			u, _ = url.Parse("wss://localhost:" + wsRedirectionEndpoint + r.URL.String())
 		}
+		fmt.Println("WebSocket opening on: " + "ws://" + wsRedirectionEndpoint + r.URL.String())
 		wspHandler := websocketproxy.NewProxy(u)
 		wspHandler.ServeHTTP(w, r)
 		return

+ 3 - 2
reverseproxy.go

@@ -18,8 +18,9 @@ func ReverseProxtInit() {
 		log.Println(err.Error())
 		return
 	}
-	dynamicProxyRouter.SetRootProxy("localhost:8080/www/TC/", false)
-	dynamicProxyRouter.AddProxyService("/imus", "192.168.0.107:8080", false)
+	dynamicProxyRouter.SetRootProxy("192.168.0.107:8080", false)
+	dynamicProxyRouter.AddProxyService("/loopback", "localhost:8080", false)
+	dynamicProxyRouter.AddProxyService("/imus", "192.168.0.107:8081", false)
 	dynamicProxyRouter.AddProxyService("/hkwtc", "hkwtc.org:9091", false)
 	dynamicProxyRouter.StartProxyService()
 	log.Println("Dynamic Proxy service started")

+ 59 - 11
storage.go

@@ -19,8 +19,8 @@ import (
 var (
 	baseStoragePool *storage.StoragePool    //base storage pool, all user can access these virtual roots
 	fsHandlers      []*fs.FileSystemHandler //All File system handlers. All opened handles must be registered in here
-	storagePools    []*storage.StoragePool  //All Storage pool opened
-	bridgeManager   *bridge.Record          //Manager to handle bridged FSH
+	//storagePools    []*storage.StoragePool  //All Storage pool opened
+	bridgeManager *bridge.Record //Manager to handle bridged FSH
 )
 
 func StorageInit() {
@@ -105,9 +105,6 @@ func LoadBaseStoragePool() error {
 		return err
 	}
 
-	//Push base pool into the opened storage pool list
-	storagePools = append(storagePools, sp)
-
 	//Update the storage pool permission to readwrite
 	sp.OtherPermission = "readwrite"
 	baseStoragePool = sp
@@ -137,7 +134,7 @@ func BridgeStoragePoolInit() {
 	bridgeRecords, err := bridgeManager.ReadConfig()
 	if err != nil {
 		log.Println("[ERROR] Fail to read File System Handler bridge config")
-		panic(err.Error())
+		return
 	}
 
 	for _, bridgeConf := range bridgeRecords {
@@ -153,11 +150,44 @@ func BridgeStoragePoolInit() {
 			continue
 		}
 
-		BridgeFSHandlerToGroup(fsh, basePool)
+		err = BridgeFSHandlerToGroup(fsh, basePool)
+		if err != nil {
+			log.Println("Failed to bridge "+fsh.UUID+":/ to "+basePool.Owner, err.Error())
+		}
 		log.Println(fsh.UUID + ":/ bridged to " + basePool.Owner + " Storage Pool")
 	}
 }
 
+func BridgeStoragePoolForGroup(group string) {
+	bridgeRecords, err := bridgeManager.ReadConfig()
+	if err != nil {
+		log.Println("Failed to bridge FSH for group " + group)
+		return
+	}
+
+	for _, bridgeConf := range bridgeRecords {
+		if bridgeConf.SPOwner == group {
+			fsh, err := GetFsHandlerByUUID(bridgeConf.FSHUUID)
+			if err != nil {
+				//This fsh is not found. Skip this
+				continue
+			}
+
+			basePool, err := GetStoragePoolByOwner(bridgeConf.SPOwner)
+			if err != nil {
+				//This fsh is not found. Skip this
+				continue
+			}
+
+			err = BridgeFSHandlerToGroup(fsh, basePool)
+			if err != nil {
+				log.Println("Failed to bridge "+fsh.UUID+":/ to "+basePool.Owner, err.Error())
+			}
+			log.Println(fsh.UUID + ":/ bridged to " + basePool.Owner + " Storage Pool")
+		}
+	}
+}
+
 //Bridge a FSH to a given Storage Pool
 func BridgeFSHandlerToGroup(fsh *fs.FileSystemHandler, sp *storage.StoragePool) error {
 	//Check if the fsh already exists in the basepool
@@ -225,10 +255,15 @@ func LoadStoragePoolForGroup(pg *permission.PermissionGroup) error {
 		//Assign storage pool to group
 		pg.StoragePool = sp
 
-		storagePools = append(storagePools, sp)
 	} else {
 		//Storage configuration not exists. Fill in the basic information and move to next storage pool
-		pg.StoragePool.Owner = pg.Name
+
+		//Create a new empty storage pool for this group
+		sp, err := storage.NewStoragePool([]*fs.FileSystemHandler{}, pg.Name)
+		if err != nil {
+			log.Println("Failed to create empty storage pool for group: ", pg.Name)
+		}
+		pg.StoragePool = sp
 		pg.StoragePool.OtherPermission = "denied"
 	}
 
@@ -241,8 +276,21 @@ func StoragePoolExists(poolOwner string) bool {
 	return err == nil
 }
 
+func GetAllStoragePools() []*storage.StoragePool {
+	//Append the base pool
+	results := []*storage.StoragePool{baseStoragePool}
+
+	//Add each permissionGroup's pool
+	for _, pg := range permissionHandler.PermissionGroups {
+		results = append(results, pg.StoragePool)
+	}
+
+	return results
+}
+
 func GetStoragePoolByOwner(owner string) (*storage.StoragePool, error) {
-	for _, pool := range storagePools {
+	sps := GetAllStoragePools()
+	for _, pool := range sps {
 		if pool.Owner == owner {
 			return pool, nil
 		}
@@ -286,7 +334,7 @@ func CloseAllStorages() {
 }
 
 func closeAllStoragePools() {
-	for _, sp := range storagePools {
+	for _, sp := range GetAllStoragePools() {
 		sp.Close()
 	}
 }

+ 24 - 7
storage.pool.go

@@ -307,10 +307,14 @@ func HandleStoragePoolReload(w http.ResponseWriter, r *http.Request) {
 			//If there is no handler in config, the empty one will be kept
 			LoadStoragePoolForGroup(pg)
 		}
+
+		BridgeStoragePoolInit()
+
 	} else {
 
 		if pool == "system" {
 			//Reload basepool
+
 			baseStoragePool.Close()
 			emptyPool := storage.StoragePool{}
 			baseStoragePool = &emptyPool
@@ -325,6 +329,7 @@ func HandleStoragePoolReload(w http.ResponseWriter, r *http.Request) {
 				userHandler.UpdateStoragePool(baseStoragePool)
 			}
 
+			BridgeStoragePoolForGroup("system")
 		} else {
 			//Reload the given storage pool
 			if !permissionHandler.GroupExists(pool) {
@@ -336,6 +341,7 @@ func HandleStoragePoolReload(w http.ResponseWriter, r *http.Request) {
 
 			//Pool should be exists. Close it
 			pg := permissionHandler.GetPermissionGroupByName(pool)
+
 			pg.StoragePool.Close()
 
 			//Create an empty pool for this permission group
@@ -345,6 +351,7 @@ func HandleStoragePoolReload(w http.ResponseWriter, r *http.Request) {
 			//Recreate a new pool for this permission group
 			//If there is no handler in config, the empty one will be kept
 			LoadStoragePoolForGroup(pg)
+			BridgeStoragePoolForGroup(pg.Name)
 		}
 	}
 
@@ -378,12 +385,12 @@ func HandleStoragePoolRemove(w http.ResponseWriter, r *http.Request) {
 			return
 		}
 
-		if fileExists("./system/storage/" + groupname + ".json") {
-			targetConfigFile = "./system/storage/" + groupname + ".json"
-		} else {
-			//No config to delete
-			sendErrorResponse(w, "File system handler not exists")
-			return
+		targetConfigFile = "./system/storage/" + groupname + ".json"
+		if !fileExists(targetConfigFile) {
+			//No config. Create an empty one
+			initConfig := []fs.FileSystemOption{}
+			js, _ := json.MarshalIndent(initConfig, "", " ")
+			ioutil.WriteFile(targetConfigFile, js, 0775)
 		}
 	}
 
@@ -399,6 +406,7 @@ func HandleStoragePoolRemove(w http.ResponseWriter, r *http.Request) {
 		err = DebridgeFSHandlerFromGroup(uuid, basePool)
 		if err != nil {
 			sendErrorResponse(w, err.Error())
+			return
 		}
 
 		//Remove it from the config
@@ -544,10 +552,18 @@ func HandleListStoragePoolsConfig(w http.ResponseWriter, r *http.Request) {
 		targetFile = "./system/storage/" + target + ".json"
 	}
 
+	if !fileExists(targetFile) {
+		//Assume no storage.
+		nofsh := []*fs.FileSystemOption{}
+		js, _ := json.Marshal(nofsh)
+		sendJSONResponse(w, string(js))
+		return
+	}
+
 	//Read and serve it
 	configContent, err := ioutil.ReadFile(targetFile)
 	if err != nil {
-		sendErrorResponse(w, "Given group does not have a config file.")
+		sendErrorResponse(w, err.Error())
 		return
 	} else {
 		sendJSONResponse(w, string(configContent))
@@ -596,6 +612,7 @@ func HandleFSHBridging(w http.ResponseWriter, r *http.Request) {
 	//Add the target FSH into the base pool
 	basePoolObject, err := GetStoragePoolByOwner(basePool)
 	if err != nil {
+		log.Println("Bridge FSH failed: ", err.Error())
 		sendErrorResponse(w, "Storage pool not found")
 		return
 	}

+ 1 - 6
system/bridge.json

@@ -1,6 +1 @@
-[
- {
-  "FSHUUID": "admin",
-  "SPOwner": "system"
- }
-]
+[]

+ 2 - 0
web/SystemAO/disk/ftp.html

@@ -40,6 +40,8 @@
                 </div>
             </h4>
             <p>To connect your File Explorer to the ArozOS FTP server, enter the link above into the address bar of your file explorer window.</p>
+            <p>If you <b><a href="https://superuser.com/questions/1309756/not-able-to-access-ftp-server-from-other-machines-in-same-lan-when-windows-firew">cannot access the FTP without turning off the Windows Firewall</a></b>, execute this command in cmd as administrator<br>
+            <code>netsh advfirewall set global StatefulFTP disable</code></p>
         </div>
         <div class="ui basic message maconly" style="display:none;">
             <h4 class="ui header">

+ 6 - 2
web/SystemAO/storage/poolEditor.html

@@ -242,7 +242,7 @@
         var editingStoragePool = "system"
         var otherPoolConfigMap = {};
         if (window.location.hash.length > 1){
-            editingStoragePool = window.location.hash.substr(1)
+            editingStoragePool = decodeURIComponent(window.location.hash.substr(1));
         }
         
         //List all the current fsh inside this pool
@@ -428,10 +428,14 @@
                                 allFSH.push(vroot.uuid)
                             });
 
-                            if (offlineFSH.length == 0){
+                            if (data.length > 0 && offlineFSH.length == 0){
                                 //All fshandlers are online
                                 $("#fshList").append(`<p><i class="checkmark icon"></i> All File System Handlers for ${pgname} are online</p>`);
                             }
+
+                            if (data.length == 0){
+                                $("#fshList").append(`<p><i class="checkmark icon"></i>  ${pgname} has no local File System Handler</p>`);
+                            }
                         }else{
                             $("#fshList").append(`<p><i class="remove icon"></i> No Unmounted File System Handler for ${pgname}</p>`);
                         }

+ 0 - 1
web/SystemAO/storage/poolList.html

@@ -77,7 +77,6 @@
             </div>
         </div>
     </div>
-    <script src="diskicon.js"></script>
     <script>
         var selectedStoragePool = "";
         var storagePoolList = [];