|
@@ -2,9 +2,11 @@ package main
|
|
|
|
|
|
import (
|
|
import (
|
|
"log"
|
|
"log"
|
|
|
|
+ "net/http"
|
|
|
|
|
|
"imuslab.com/arozos/mod/iot"
|
|
"imuslab.com/arozos/mod/iot"
|
|
"imuslab.com/arozos/mod/iot/hdsv2"
|
|
"imuslab.com/arozos/mod/iot/hdsv2"
|
|
|
|
+ prout "imuslab.com/arozos/mod/prouter"
|
|
)
|
|
)
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -12,19 +14,58 @@ import (
|
|
Author: tobychui
|
|
Author: tobychui
|
|
|
|
|
|
This script handle the IoT service start up and mangement
|
|
This script handle the IoT service start up and mangement
|
|
|
|
+
|
|
|
|
+ IoT Manager: Manage who can have access to certain IoT devices
|
|
|
|
+ IoT Panel: The panel for controlling the devices
|
|
*/
|
|
*/
|
|
|
|
|
|
-var hdsv2Handler *hdsv2.Handler
|
|
|
|
|
|
+var iotManager *iot.Manager
|
|
|
|
|
|
func IoTHubInit() {
|
|
func IoTHubInit() {
|
|
- hdsv2Handler = hdsv2.NewProtocolHandler(MDNS)
|
|
|
|
- go func() {
|
|
|
|
- testScan(hdsv2Handler)
|
|
|
|
- }()
|
|
|
|
|
|
+ if *allow_iot && *allow_mdns && MDNS != nil {
|
|
|
|
+ //Create a new ioT Manager
|
|
|
|
+ iotManager = iot.NewIoTManager()
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ //Register IoT Setting Interfaces
|
|
|
|
+ registerSetting(settingModule{
|
|
|
|
+ Name: "IoT Manager",
|
|
|
|
+ Desc: "Manage IoT Devices Permission",
|
|
|
|
+ IconPath: "SystemAO/iot/img/small_icon.png",
|
|
|
|
+ Group: "Device",
|
|
|
|
+ StartDir: "SystemAO/iot/manager.html",
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ //Register IoT Devices Endpoints
|
|
|
|
+ router := prout.NewModuleRouter(prout.RouterOption{
|
|
|
|
+ ModuleName: "IoT Panel",
|
|
|
|
+ AdminOnly: false,
|
|
|
|
+ UserHandler: userHandler,
|
|
|
|
+ DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ sendErrorResponse(w, "Permission Denied")
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ adminRouter := prout.NewModuleRouter(prout.RouterOption{
|
|
|
|
+ ModuleName: "System Setting",
|
|
|
|
+ AdminOnly: true,
|
|
|
|
+ UserHandler: userHandler,
|
|
|
|
+ DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ sendErrorResponse(w, "Permission Denied")
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ router.HandleFunc("/system/iot/scan", iotManager.HandleScanning)
|
|
|
|
+
|
|
|
|
+ log.Println("Work in progress breakpoint: ", router, adminRouter)
|
|
|
|
+
|
|
|
|
+ //Start of the IoT Management Handlers
|
|
|
|
+
|
|
|
|
+ //Home Dynamic v2
|
|
|
|
+ hdsv2Handler := hdsv2.NewProtocolHandler(MDNS)
|
|
|
|
+ iotManager.RegisterHandler(hdsv2Handler)
|
|
|
|
+
|
|
|
|
+ //Add more here if needed
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
-func testScan(m iot.ProtocolHandler) {
|
|
|
|
- dev, err := m.Scan()
|
|
|
|
- log.Println(dev, err)
|
|
|
|
}
|
|
}
|