|
@@ -2,7 +2,6 @@ package main
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
- "io/ioutil"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
"runtime"
|
|
@@ -113,13 +112,18 @@ func SystemInfoInit() {
|
|
|
//ArOZ Info do not need permission router
|
|
|
http.HandleFunc("/system/info/getArOZInfo", infoServer.GetArOZInfo)
|
|
|
|
|
|
- registerSetting(settingModule{
|
|
|
- Name: "Updates",
|
|
|
- Desc: "Perform ArozOS Updates",
|
|
|
- IconPath: "SystemAO/updates/img/update.png",
|
|
|
- Group: "Info",
|
|
|
- StartDir: "SystemAO/updates/index.html",
|
|
|
- })
|
|
|
+ go func() {
|
|
|
+ if updates.CheckLauncherPortResponsive() {
|
|
|
+ //Launcher port is responsive. Assume launcher exists
|
|
|
+ registerSetting(settingModule{
|
|
|
+ Name: "Updates",
|
|
|
+ Desc: "Perform ArozOS Updates",
|
|
|
+ IconPath: "SystemAO/updates/img/update.png",
|
|
|
+ Group: "Info",
|
|
|
+ StartDir: "SystemAO/updates/index.html",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }()
|
|
|
|
|
|
//Handle updates
|
|
|
adminRouter.HandleFunc("/system/update/download", updates.HandleUpdateDownloadRequest)
|
|
@@ -127,19 +131,11 @@ func SystemInfoInit() {
|
|
|
|
|
|
//Special function for handling launcher restart, must be in this scope
|
|
|
adminRouter.HandleFunc("/system/update/restart", func(w http.ResponseWriter, r *http.Request) {
|
|
|
- //Check if there is a launcher listening to port 25576
|
|
|
- resp, err := http.Get("http://127.0.0.1:25576/chk")
|
|
|
+ launcherVersion, err := updates.GetLauncherVersion()
|
|
|
if err != nil {
|
|
|
- common.SendErrorResponse(w, "No launcher found. Unable to restart")
|
|
|
+ sendErrorResponse(w, err.Error())
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- content, err := ioutil.ReadAll(resp.Body)
|
|
|
- if err != nil {
|
|
|
- common.SendErrorResponse(w, "Read launcher response failed")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
execute, _ := common.Mv(r, "exec", true)
|
|
|
if execute == "true" && r.Method == http.MethodPost {
|
|
|
//Do the update
|
|
@@ -147,11 +143,12 @@ func SystemInfoInit() {
|
|
|
executeShutdownSequence()
|
|
|
common.SendOK(w)
|
|
|
} else if execute == "true" {
|
|
|
+ //Prevent redirection attack
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
w.Write([]byte("405 - Method Not Allowed"))
|
|
|
} else {
|
|
|
//Return the launcher message
|
|
|
- common.SendTextResponse(w, string(content))
|
|
|
+ common.SendTextResponse(w, string(launcherVersion))
|
|
|
}
|
|
|
|
|
|
})
|