Ver Fonte

Fixed minor issues in storage.json create permission

TC pushbot 5 há 4 anos atrás
pai
commit
8b9be33485

+ 0 - 0
documents/headless setup files/ssh


+ 13 - 0
documents/headless setup files/wpa_supplicant.conf

@@ -0,0 +1,13 @@
+country=HK
+ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
+update_config=1
+
+network={
+    ssid="Toby Room Automation"
+    psk="homedynamicsystem"
+}
+
+network={
+    ssid="arozos config"
+    psk="arozonlinesystem"
+}

+ 1 - 1
iot.go

@@ -26,7 +26,7 @@ var iotManager *iot.Manager
 func IoTHubInit() {
 	if *allow_iot && *allow_mdns && MDNS != nil {
 		//Create a new ioT Manager
-		iotManager = iot.NewIoTManager()
+		iotManager = iot.NewIoTManager(sysdb)
 
 		//Register IoT Hub Module
 		moduleHandler.RegisterModule(module.ModuleInfo{

+ 79 - 0
mod/iot/assits.go

@@ -0,0 +1,79 @@
+package iot
+
+import (
+	"encoding/json"
+	"net/http"
+)
+
+/*
+	assits.go
+	Author: tobychui
+
+	This script handle assistant functions for iot devices.
+	The function implement here should have no effect to the core operation of the iot hub nor the iot pipeline.
+*/
+
+//Handle the set and get nickname of a particular IoT device
+func (m *Manager) HandleNickName(w http.ResponseWriter, r *http.Request) {
+	opr, err := mv(r, "opr", true)
+	if err != nil {
+		sendErrorResponse(w, "Invalid operation mode")
+		return
+	}
+
+	uuid, err := mv(r, "uuid", true)
+	if err != nil {
+		sendErrorResponse(w, "Invalid uuid given")
+		return
+	}
+
+	//Check if the device with the given uuid exists
+	deviceExist := false
+	for _, dev := range m.cachedDeviceList {
+		if dev.DeviceUUID == uuid {
+			//Device found. Create a new object and make the pointer point to it
+			deviceExist = true
+		}
+	}
+
+	//Reject operation if device not exists
+	if deviceExist == false {
+		sendErrorResponse(w, "Target device UUID not exists")
+		return
+	}
+
+	//Process the required operation
+	if opr == "get" {
+		if m.db.KeyExists("iot", uuid) {
+			deviceNickname := ""
+			err := m.db.Read("iot", uuid, &deviceNickname)
+			if err != nil {
+				sendErrorResponse(w, "Unable to read nickname from database")
+				return
+			}
+			js, _ := json.Marshal(deviceNickname)
+			sendJSONResponse(w, string(js))
+		} else {
+			sendErrorResponse(w, "Nickname not exists")
+		}
+	} else if opr == "set" {
+		//Get name from paramter
+		name, err := mv(r, "name", true)
+		if err != nil {
+			sendErrorResponse(w, "No nickname was given to the device")
+			return
+		}
+
+		//Set the name in database
+		err = m.db.Write("iot", uuid, name)
+		if err != nil {
+			sendErrorResponse(w, err.Error())
+			return
+		}
+
+		sendOK(w)
+	} else {
+		sendErrorResponse(w, "Unknown operation mode")
+		return
+	}
+}

+ 12 - 1
mod/iot/handlerManager.go

@@ -4,6 +4,8 @@ import (
 	"encoding/json"
 	"log"
 	"net/http"
+
+	"imuslab.com/arozos/mod/database"
 )
 
 /*
@@ -18,11 +20,20 @@ import (
 type Manager struct {
 	RegisteredHandler []ProtocolHandler
 	cachedDeviceList  []*Device
+	db                *database.Database
 }
 
-func NewIoTManager() *Manager {
+func NewIoTManager(sysdb *database.Database) *Manager {
+	//Create the iot database if it doesn't exists
+	if !sysdb.TableExists("iot") {
+		sysdb.NewTable("iot")
+	}
+
+	//Return a new iot manager
 	return &Manager{
 		RegisteredHandler: []ProtocolHandler{},
+		cachedDeviceList:  []*Device{},
+		db:                sysdb,
 	}
 }
 

+ 1 - 1
storage.pool.go

@@ -472,7 +472,7 @@ func HandleStorageNewFsHandler(w http.ResponseWriter, r *http.Request) {
 	js, _ := json.Marshal(oldConfigs)
 	resultingJson := pretty.Pretty(js)
 
-	ioutil.WriteFile(configFile, resultingJson, 755)
+	ioutil.WriteFile(configFile, resultingJson, 775)
 	w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0")
 	http.Redirect(w, r, "../../../SystemAO/storage/poolEditor.html#"+groupName, 307)
 }