ok for systools

This commit is contained in:
janson 2022-11-13 19:29:36 +08:00
parent 4f365df9c1
commit 8535e08fd8
4 changed files with 72 additions and 124 deletions
applications/luci-app-systools
luasrc
controller
view/systools
po/zh-cn
root/usr/libexec/istorec

@ -1,6 +1,6 @@
local util = require "luci.util"
local http = require "luci.http"
local docker = require "luci.model.docker"
local lng = require "luci.i18n"
local iform = require "luci.iform"
module("luci.controller.systools", package.seeall)
@ -11,12 +11,9 @@ function index()
entry({"admin", "services", "systools", "pages"}, call("systools_index")).leaf = true
entry({"admin", "services", "systools", "form"}, call("systools_form"))
entry({"admin", "services", "systools", "submit"}, call("systools_submit"))
entry({"admin", "services", "systools", "log"}, call("systools_log"))
end
local const_log_end = "XU6J03M6"
local appname = "systools"
local page_index = {"admin", "services", "systools", "pages"}
function redirect_index()
@ -52,15 +49,15 @@ function get_schema(data)
actions = {
{
name = "install",
text = "安装",
text = lng.translate("Execute"),
type = "apply",
},
}
local schema = {
actions = actions,
containers = get_containers(data),
description = "带 Web 远程桌面的 Docker 高性能版 SysTools。默认<用户名:kasm_user 密码:password> 访问官网 <a href=\"https://www.kasmweb.com/\" target=\"_blank\">https://www.kasmweb.com/</a>",
title = "SysTools"
description = lng.translate("SysTools can fix some errors when your system is broken."),
title = lng.translate("SysTools")
}
return schema
end
@ -74,23 +71,15 @@ function get_containers(data)
end
function status_container(data)
local status_value
status_value = "SysTools 未运行"
local status_c1 = {
labels = {
{
key = "状态:",
value = status_value
},
{
key = "访问:",
value = ""
-- value = "'<a href=\"https://' + location.host + ':6901\" target=\"_blank\">SysTools 桌面</a>'"
key = "访问:",
value = ""
}
},
description = "访问链接是一个自签名的 https需要浏览器同意才能访问",
title = "服务状态"
description = lng.translate("The running status"),
title = lng.translate("Status")
}
return status_c1
end
@ -109,7 +98,7 @@ function main_container(data)
{
name = "tool",
required = true,
title = "安装版本",
title = "可执行操作",
type = "string",
enum = {"speedtest", "reset_rom"},
enumNames = {"网络测速", "恢复系统软件包"}
@ -123,8 +112,8 @@ function main_container(data)
enumNames = {"ServerTest1", "ServerTest2"}
},
},
description = "请选择合适的版本进行安装:",
title = "服务操作"
description = lng.translate("Select the action to run:"),
title = lng.translate("Actions")
}
return main_c2
end
@ -147,14 +136,8 @@ function systools_submit()
local json_parse = jsonc.parse
local content = http.content()
local req = json_parse(content)
if req["$apply"] == "upgrade" then
result = install_upgrade_systools(req)
elseif req["$apply"] == "install" then
result = install_upgrade_systools(req)
elseif req["$apply"] == "restart" then
result = restart_systools(req)
else
result = delete_systools()
if req["$apply"] == "install" then
result = install_execute_systools(req)
end
http.prepare_content("application/json")
local resp = {
@ -166,39 +149,16 @@ function systools_submit()
http.write_json(resp)
end
function systools_log()
iform.response_log("/var/log/"..appname..".log")
end
function install_upgrade_systools(req)
function install_execute_systools(req)
local password = req["tool"]
local port = req["server"]
local exec_cmd = string.format("/usr/share/systools/install.sh %s", req["$apply"])
iform.fork_exec(exec_cmd)
cmd = "/etc/init.d/tasks task_add systools " .. luci.util.shellquote(string.format("/usr/libexec/istorec/systools.sh %s", req["$apply"]))
os.execute(cmd .. " >/dev/null 2>&1")
local result = {
async = true,
exec = exec_cmd,
async_state = req["$apply"]
}
return result
end
function delete_systools()
local log = iform.exec_to_log("docker rm -f systools")
local result = {
async = false,
log = log
}
return result
end
function restart_systools()
local log = iform.exec_to_log("docker restart systools")
local result = {
async = false,
log = log
async_state = "systools"
}
return result
end

@ -1,5 +1,7 @@
<%+header%>
<%+tasks/embed%>
<script>
(function(){
})();
@ -14,18 +16,12 @@
logApi:"/cgi-bin/luci/admin/services/systools/log",
submitApi:"/cgi-bin/luci/admin/services/systools/submit",
getHook:function(resp){
var c1 = resp.result.schema.containers[0];
if (resp.result.data.container_install) {
c1.labels[1].value = '<a href="https://'+location.host+':'+resp.result.data.port+'" target="_blank">SysTools 桌面链接</a>';
} else {
c1.labels[1].value = "安装并运行之后,才能用网页访问";
}
window.IstoreosData = resp.result.data;
console.log("resp=", resp.result.data);
return resp;
},
onFormChange: function(changedField, val) {
console.log("formChanged=", val)
console.log("changedField=", changedField, "formChanged=", val)
if (changedField === "tool" && window.IstoreosData["tool"] !== val["tool"]) {
val["reload"] = true;
val["tool"] = 'test'

@ -1,62 +1,8 @@
msgid "ubuntu"
msgstr "ubuntu"
msgid "SysTools"
msgstr "系统工具"
msgid "The ubuntu service is running."
msgstr "ubuntu已启动"
msgid "Execute"
msgstr "执行"
msgid "The ubuntu service is not running."
msgstr "ubuntu服务未启动"
msgid "The ubuntu service is not installed."
msgstr "ubuntu服务未安装"
msgid "open ubuntu"
msgstr "打开ubuntu"
msgid "stop ubuntu"
msgstr "停止ubuntu"
msgid "run ubuntu"
msgstr "启动ubuntu"
msgid "uninstall ubuntu"
msgstr "删除ubuntu"
msgid "install ubuntu"
msgstr "安装ubuntu"
msgid "Collecting data..."
msgstr "收集数据..."
msgid "storage path"
msgstr "存储路径建议插入U盘或硬盘然后输入路径。例如/mnt/sda1/ubuntu"
msgid "Storage path could not be empty!"
msgstr "存储路径不能为空!"
msgid "Version"
msgstr "系统版本"
msgid "Port (optional)"
msgstr "端口"
msgid "Password (optional)"
msgstr "密码"
msgid "standard version"
msgstr "标准版本"
msgid "full version"
msgstr "全量版本"
msgid "UserName"
msgstr "用户名"
msgid "Password"
msgstr "密码"
msgid "LanAddress"
msgstr "内网地址"
msgid "WanAddress"
msgstr "外网地址"
msgid "SysTools can fix some errors when your system is broken."
msgstr "SysTools 可以修复一些系统问题。"

@ -0,0 +1,46 @@
#!/bin/sh
# Author Xiaobao(xiaobao@linkease.com)
ACTION=${1}
shift 1
do_install() {
echo "starting"
sleep 120
echo "started"
}
usage() {
echo "usage: $0 sub-command"
echo "where sub-command is one of:"
echo " install Install the emby"
echo " upgrade Upgrade the emby"
echo " rm/start/stop/restart Remove/Start/Stop/Restart the emby"
echo " status Emby status"
echo " port Emby port"
}
case ${ACTION} in
"install")
do_install
;;
"upgrade")
do_install
;;
"rm")
docker rm -f emby
;;
"start" | "stop" | "restart")
docker ${ACTION} emby
;;
"status")
docker ps --all -f 'name=emby' --format '{{.State}}'
;;
"port")
docker ps --all -f 'name=emby' --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://'
;;
*)
usage
exit 1
;;
esac