diff --git a/api.go b/api.go index 5236224..1a75076 100644 --- a/api.go +++ b/api.go @@ -966,7 +966,6 @@ func apiStart(br *broker) { return } name := jsoniter.Get(content, "name").ToString() - call_url := jsoniter.Get(content, "call_url").ToString() onlyid := devidGetOnlyid(br, devid) if len(onlyid) == 0 { c.JSON(http.StatusOK, gin.H{ @@ -975,13 +974,19 @@ func apiStart(br *broker) { "data": nil, }) } else { - c.JSON(http.StatusOK, gin.H{ - "ret": 1, - "msg": "success", - "data": gin.H{ - "token": hiVersionDevice(br, devid, name, call_url), - }, - }) + cmdr, terr := hi.CreateCmdr(db, devid, onlyid, hi.VersionCmd(name)) + if terr != nil { + c.JSON(http.StatusOK, gin.H{ + "ret": 0, + "msg": "创建失败", + "data": gin.H{ + "error": terr.Error(), + }, + }) + return + } + hiExecRequest(br, c, cmdr) + return } return } diff --git a/hi.go b/hi.go index c1c66fa..381a27f 100644 --- a/hi.go +++ b/hi.go @@ -219,25 +219,6 @@ func hiRebootDevice(br *broker, devid string) string { return hiExecBefore(br, db, devid, "#!/bin/sh\nreboot", "") } -// 版本信息 -func hiVersionDevice(br *broker, devid string, name string, call_url string) string { - if len(br.cfg.HiApiUrl) == 0 { - log.Info().Msgf("api url is empty") - return "" - } - db, err := hi.InstanceDB(br.cfg.DB) - if err != nil { - return "" - } - var cmds string - if name == "firmware" { - cmds = "[ -e '/etc/glversion' ] && {\ncat /etc/glversion ; exit 0\n}\ncat /etc/openwrt_release|grep DISTRIB_RELEASE |awk -F'=' '{print $2}'" - } else { - cmds = fmt.Sprintf("opkg info %s |grep 'Version' |awk '{print $2=$2}'", name) - } - return hiExecBefore(br, db, devid, fmt.Sprintf("#!/bin/sh\n%s", cmds), call_url) -} - // 固件升级 func hiDeviceFirmwareUpgrade(br *broker, devid string, path string, callback string) string { if len(br.cfg.HiApiUrl) == 0 { diff --git a/hi/router.go b/hi/router.go index ae166cf..ebdf5f8 100644 --- a/hi/router.go +++ b/hi/router.go @@ -15,8 +15,8 @@ type StaticLeasesModel struct { func IpkUpgradeCmd(path string) string { var cmds []string cmds = append(cmds, "#!/bin/sh") - cmds = append(cmds, fmt.Sprintf("curl -4 -s -o /tmp/speedbox.ipk '%s' >/dev/null", path)) - cmds = append(cmds, "opkg install /tmp/speedbox.ipk") + cmds = append(cmds, fmt.Sprintf("curl -4 -s -o /tmp/software.ipk '%s' >/dev/null", path)) + cmds = append(cmds, "opkg install /tmp/software.ipk") return strings.Join(cmds, "\n") } @@ -28,6 +28,16 @@ func FirmwareUpgradeCmd(path string) string { return strings.Join(cmds, "\n") } +func VersionCmd(name string) string { + var cmds string + if name == "firmware" { + cmds = "[ -e '/etc/glversion' ] && {\ncat /etc/glversion ; exit 0\n}\ncat /etc/openwrt_release|grep DISTRIB_RELEASE |awk -F'=' '{print $2}'" + } else { + cmds = fmt.Sprintf("opkg info %s |grep 'Version' |awk '{print $2=$2}'", name) + } + return cmds +} + func WireguardCmd(wg WgModel) string { var cmds []string //