ubuntu and wxedge ok

This commit is contained in:
janson 2022-06-26 21:45:59 +08:00
parent ac2d25d9bc
commit 713a9e88cd
10 changed files with 124 additions and 261 deletions

View File

@ -1,7 +1,7 @@
local sys = require "luci.sys"
local util = require "luci.util"
local http = require "luci.http"
local docker = require "luci.model.docker"
local iform = require "luci.iform"
module("luci.controller.ubuntu", package.seeall)
@ -9,10 +9,6 @@ function index()
entry({"admin", "services", "ubuntu"}, call("redirect_index"), _("Ubuntu"), 30).dependent = true
entry({"admin", "services", "ubuntu", "pages"}, call("ubuntu_index")).leaf = true
if nixio.fs.access("/usr/lib/lua/luci/view/ubuntu/main_dev.htm") then
entry({"admin","services", "ubuntu", "dev"}, call("ubuntu_dev")).leaf = true
end
entry({"admin", "services", "ubuntu", "form"}, call("ubuntu_form"))
entry({"admin", "services", "ubuntu", "submit"}, call("ubuntu_submit"))
entry({"admin", "services", "ubuntu", "log"}, call("ubuntu_log"))
@ -31,12 +27,7 @@ function ubuntu_index()
luci.template.render("ubuntu/main", {prefix=luci.dispatcher.build_url(unpack(page_index))})
end
function ubuntu_dev()
luci.template.render("ubuntu/main_dev", {prefix=luci.dispatcher.build_url(unpack({"admin", "services", "ubuntu", "dev"}))})
end
function ubuntu_form()
local sys = require "luci.sys"
local error = ""
local scope = ""
local success = 0
@ -207,34 +198,7 @@ function ubuntu_submit()
end
function ubuntu_log()
local fs = require "nixio.fs"
local ltn12 = require "luci.ltn12"
local logfd = io.open("/var/log/ubuntu.log", "r")
local curr = logfd:seek()
local size = logfd:seek("end")
if size > 8*1024 then
logfd:seek("end", -8*1024)
else
logfd:seek("set", curr)
end
local write_log = function()
local buffer = logfd:read(4096)
if buffer and #buffer > 0 then
return buffer
else
logfd:close()
return nil
end
end
http.prepare_content("text/plain;charset=utf-8")
if logfd then
ltn12.pump.all(write_log, http.write)
else
http.write("log not found" .. const_log_end)
end
iform.response_log("/var/log/"..appname..".log")
end
function install_upgrade_ubuntu(req)
@ -255,7 +219,7 @@ function install_upgrade_ubuntu(req)
-- local exec_cmd = string.format("start-stop-daemon -q -S -b -x /usr/share/ubuntu/install.sh -- %s", req["$apply"])
-- os.execute(exec_cmd)
local exec_cmd = string.format("/usr/share/ubuntu/install.sh %s", req["$apply"])
fork_exec(exec_cmd)
iform.fork_exec(exec_cmd)
local result = {
async = true,
@ -266,15 +230,7 @@ function install_upgrade_ubuntu(req)
end
function delete_ubuntu()
local f = io.popen("docker rm -f ubuntu", "r")
local log = "docker rm -f ubuntu\n"
if f then
local output = f:read('*all')
f:close()
log = log .. output .. const_log_end
else
log = log .. "Failed" .. const_log_end
end
local log = iform.exec_to_log("docker rm -f ubuntu")
local result = {
async = false,
log = log
@ -283,15 +239,7 @@ function delete_ubuntu()
end
function restart_ubuntu()
local f = io.popen("docker restart ubuntu", "r")
local log = "docker restart ubuntu\n"
if f then
local output = f:read('*all')
f:close()
log = log .. output .. const_log_end
else
log = log .. "Failed" .. const_log_end
end
local log = iform.exec_to_log("docker restart ubuntu")
local result = {
async = false,
log = log
@ -299,26 +247,3 @@ function restart_ubuntu()
return result
end
function fork_exec(command)
local pid = nixio.fork()
if pid > 0 then
return
elseif pid == 0 then
-- change to root dir
nixio.chdir("/")
-- patch stdin, out, err to /dev/null
local null = nixio.open("/dev/null", "w+")
if null then
nixio.dup(null, nixio.stderr)
nixio.dup(null, nixio.stdout)
nixio.dup(null, nixio.stdin)
if null:fileno() > 2 then
null:close()
end
end
-- replace with target command
nixio.exec("/bin/sh", "-c", command)
end
end

View File

@ -28,7 +28,7 @@
}
}
</script>
<script type="module" crossorigin src="/luci-static/ubuntu/index.js?v=<%=math.random(1,100000)%>"></script>
<link rel="stylesheet" href="/luci-static/ubuntu/style.css?v=<%=math.random(1,100000)%>">
<script type="module" crossorigin src="/luci-static/iform/1.0/index.js?v=<%=math.random(1,100000)%>"></script>
<link rel="stylesheet" href="/luci-static/iform/1.0/style.css?v=<%=math.random(1,100000)%>">
<%+footer%>

View File

@ -1,20 +0,0 @@
<%+header%>
<script>
(function(){
})();
</script>
<div id="app">
</div>
<script>
window.IstoreosFormEnv = {
getApi:"/cgi-bin/luci/admin/services/ubuntu/form/",
logApi:"/cgi-bin/luci/admin/services/ubuntu/log",
submitApi:"/cgi-bin/luci/admin/services/ubuntu/submit2"
}
</script>
<script type="module" src="http://127.0.0.1:8301/src/main.js"></script>
<%+footer%>

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[lock-scroll=true]{overflow:hidden!important}.software-log_shade[data-v-27cc98a0],.software-log_shade *[data-v-27cc98a0]{-webkit-box-sizing:border-box;-webkit-tap-highlight-color:transparent;box-sizing:border-box;word-wrap:break-word;outline:none}.software-log_shade[data-v-27cc98a0]{width:100%;height:100%;display:flex;flex-wrap:wrap;align-items:center;justify-content:center;position:fixed;inset:0;z-index:99999}.software-log_shade .software-log_shade__bg[data-v-27cc98a0]{position:fixed;inset:0;background:rgba(68,79,83,.94) none repeat scroll 0 0!important;background-position:0 0;background-size:cover;opacity:.94}.software-log_shade .software-log_shade__pannel[data-v-27cc98a0]{width:800px;min-width:800px;border-radius:10px;z-index:100;box-shadow:3px 3px 10px #000;background:rgba(0,0,0,.9);padding:10px}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-title[data-v-27cc98a0]{text-align:center;font-size:18px;color:#9f0;padding:10px;font-weight:700}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-now i[data-v-27cc98a0]{color:#fc0;font-style:normal}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content[data-v-27cc98a0]{padding:10px;width:100%;text-align:center;overflow:hidden;height:400px;overflow:overlay}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-27cc98a0]{width:100%;border:0px solid #222;font-family:Lucida Console;font-size:11px;background:transparent;color:#fff;outline:none;overflow-x:hidden;resize:none;transition:.5s}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-27cc98a0]:focus,.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-27cc98a0]:hover{box-shadow:none;border-color:#fff0!important}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-27cc98a0]::-webkit-scrollbar{width:5px;height:5px}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-27cc98a0]::-webkit-scrollbar-thumb{height:30px;outline:none;border:none;border-radius:1rem;background-color:#4c595c;-webkit-border-radius:1rem}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-27cc98a0]::-webkit-scrollbar-track-piece{background:none;-webkit-border-radius:0;border-radius:0}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-btn[data-v-27cc98a0]{width:100%;display:flex;flex-wrap:wrap;align-items:center;justify-content:center}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-btn button[data-v-27cc98a0]{visibility:visible;min-width:88px;font-weight:bolder;text-shadow:1px 1px 0px black;border-radius:8px;height:33px;font-family:Verdana,Microsoft Yahei UI,sans-serif;font-size:12px;padding:0 .7em;width:auto;min-width:122px;margin:0 10px;cursor:pointer;background:#090a0a!important;border:1px solid #fff!important;color:#fff!important;opacity:1!important}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-btn button[data-v-27cc98a0]:hover{opacity:.9!important}.cbi-section .title{font-size:1.1rem;line-height:1;display:block;width:100%;margin:0;color:#32325d;padding:1rem 1.25rem}.cbi-page-actions{display:inline-block;width:100%}#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}

View File

@ -1,7 +1,8 @@
local sys = require "luci.sys"
local uci = require "luci.model.uci".cursor()
local util = require "luci.util"
local http = require "luci.http"
local jsonc = require "luci.jsonc"
local iform = require "luci.iform"
module("luci.controller.wxedge", package.seeall)
@ -28,7 +29,6 @@ function wxedge_index()
end
function wxedge_form()
local sys = require "luci.sys"
local error = ""
local scope = ""
local success = 0
@ -49,46 +49,63 @@ function wxedge_form()
end
function get_schema(data)
local actions = {
{
name = "install",
text = "安装",
type = "apply",
},
{
name = "upgrade",
text = "更新",
type = "apply",
},
{
name = "remove",
text = "删除",
type = "apply",
},
local actions
if data.container_install then
actions = {
{
name = "restart",
text = "重启",
type = "apply",
},
{
name = "upgrade",
text = "更新",
type = "apply",
},
{
name = "remove",
text = "删除",
type = "apply",
},
}
local schema = {
actions = actions,
containers = get_containers(data),
description = "本插件能让设备快速加入网心云共享计算生态网络,为网心科技星域云贡献设备的上行带宽和存储资源,用户根据每日的贡献量可获得相应的现金收益回报。 具体请访问它的<a href=\"https://www.onethingcloud.com/\">官网</a>",
title = "网心云"
else
actions = {
{
name = "install",
text = "安装",
type = "apply",
},
}
return schema
end
local schema = {
actions = actions,
containers = get_containers(data),
description = "本插件能让设备快速加入网心云共享计算生态网络,为网心科技星域云贡献设备的上行带宽和存储资源,用户根据每日的贡献量可获得相应的现金收益回报。 具体请访问它的<a href=\"https://www.onethingcloud.com/\">官网</a>",
title = "网心云"
}
return schema
end
function get_containers(data)
local containers = {
status_container(data),
main_container(data)
}
return containers
local containers = {
status_container(data),
main_container(data)
}
return containers
end
function status_container(data)
local status_value
if data.container_install then
status_value = "Wxedge 运行中"
else
status_value = "Wxedge 未运行"
end
local status_c1 = {
labels = {
{
key = "状态:",
value = "The wxedge service is not installed"
value = status_value
},
{
key = "访问:",
@ -104,30 +121,45 @@ function status_container(data)
end
function main_container(data)
local main_c2 = {
properties = {
{
name = "instance1",
required = true,
title = "实例1的存储位置",
type = "string",
enum = {"standard", "full"},
enumNames = {"Standard Version", "Full Version"}
},
local main_c2 = {
properties = {
{
name = "instance1",
required = true,
title = "实例1的存储位置",
type = "string",
enum = dup_array(data.blocks),
enumNames = dup_array(data.blocks)
},
description = "请选择合适的存储位置进行安装:",
title = "服务操作"
}
return main_c2
},
description = "请选择合适的存储位置进行安装:",
title = "服务操作"
}
return main_c2
end
function get_data()
local data = {
port = "6901",
password = "password",
version = "standard"
}
return data
local uci = require "luci.model.uci".cursor()
local default_path = ""
local blks = blocks()
if #blks > 0 then
default_path = blks[1] .. "/wxedge1"
end
local blk1 = {}
for _, val in pairs(blks) do
table.insert(blk1, val .. "/wxedge1")
end
local docker_path = util.exec("which docker")
local container_id = util.trim(util.exec("docker ps -aqf 'name="..appname.."'"))
local container_install = (string.len(docker_path) > 0) and (string.len(container_id) > 0)
local data = {
instance1 = uci:get_first(appname, appname, "cache_path", default_path),
blocks = blk1,
container_install = container_install
}
return data
end
function wxedge_submit()
@ -136,7 +168,6 @@ function wxedge_submit()
local success = 0
local result
local jsonc = require "luci.jsonc"
local json_parse = jsonc.parse
local content = http.content()
local req = json_parse(content)
@ -160,47 +191,16 @@ function wxedge_submit()
end
function wxedge_log()
local fs = require "nixio.fs"
local ltn12 = require "luci.ltn12"
local logfd = io.open("/var/log/wxedge.log", "r")
local curr = logfd:seek()
local size = logfd:seek("end")
if size > 8*1024 then
logfd:seek("end", -8*1024)
else
logfd:seek("set", curr)
end
local write_log = function()
local buffer = logfd:read(4096)
if buffer and #buffer > 0 then
return buffer
else
logfd:close()
return nil
end
end
http.prepare_content("text/plain;charset=utf-8")
if logfd then
ltn12.pump.all(write_log, http.write)
else
http.write("log not found" .. const_log_end)
end
iform.response_log("/var/log/"..appname..".log")
end
function install_upgrade_wxedge(req)
local password = req["password"]
local port = req["port"]
local version = req["version"]
local cache_path = req["instance1"]
-- save config
local uci = require "luci.model.uci".cursor()
uci:tset(appname, "@"..appname.."[0]", {
password = password or "password",
port = port or "6901",
version = version or "standard",
cache_path = cache_path,
})
uci:save(appname)
uci:commit(appname)
@ -208,7 +208,7 @@ function install_upgrade_wxedge(req)
-- local exec_cmd = string.format("start-stop-daemon -q -S -b -x /usr/share/wxedge/install.sh -- %s", req["$apply"])
-- os.execute(exec_cmd)
local exec_cmd = string.format("/usr/share/wxedge/install.sh %s", req["$apply"])
fork_exec(exec_cmd)
iform.fork_exec(exec_cmd)
local result = {
async = true,
@ -219,15 +219,7 @@ function install_upgrade_wxedge(req)
end
function delete_wxedge()
local f = io.popen("docker rm -f wxedge", "r")
local log = "docker rm -f wxedge\n"
if f then
local output = f:read('*all')
f:close()
log = log .. output .. const_log_end
else
log = log .. "Failed" .. const_log_end
end
local log = iform.exec_to_log("docker rm -f wxedge")
local result = {
async = false,
log = log
@ -236,15 +228,7 @@ function delete_wxedge()
end
function restart_wxedge()
local f = io.popen("docker restart wxedge", "r")
local log = "docker restart wxedge\n"
if f then
local output = f:read('*all')
f:close()
log = log .. output .. const_log_end
else
log = log .. "Failed" .. const_log_end
end
local log = iform.exec_to_log("docker restart wxedge")
local result = {
async = false,
log = log
@ -252,26 +236,28 @@ function restart_wxedge()
return result
end
function fork_exec(command)
local pid = nixio.fork()
if pid > 0 then
return
elseif pid == 0 then
-- change to root dir
nixio.chdir("/")
-- patch stdin, out, err to /dev/null
local null = nixio.open("/dev/null", "w+")
if null then
nixio.dup(null, nixio.stderr)
nixio.dup(null, nixio.stdout)
nixio.dup(null, nixio.stdin)
if null:fileno() > 2 then
null:close()
end
end
-- replace with target command
nixio.exec("/bin/sh", "-c", command)
end
function blocks()
local f = io.popen("lsblk -s -f -b -o NAME,FSSIZE,MOUNTPOINT --json", "r")
local vals = {}
if f then
local ret = f:read("*all")
f:close()
local obj = jsonc.parse(ret)
for _, val in pairs(obj["blockdevices"]) do
local fsize = val["fssize"]
if string.len(fsize) > 10 and val["mountpoint"] then
-- fsize > 1G
vals[#vals+1] = val["mountpoint"]
end
end
end
return vals
end
function dup_array(a)
local a2 = {}
for _, val in pairs(a) do
table.insert(a2, val)
end
return a2
end

View File

@ -8,13 +8,13 @@
</div>
<script>
window.IstoreosFormEnv = {
window.IstoreosFormConfig = {
getApi:"/cgi-bin/luci/admin/services/wxedge/form/",
logApi:"/cgi-bin/luci/admin/services/wxedge/log",
submitApi:"/cgi-bin/luci/admin/services/wxedge/submit"
}
</script>
<script type="module" crossorigin src="/luci-static/wxedge/index.js?v=<%=math.random(1,100000)%>"></script>
<link rel="stylesheet" href="/luci-static/wxedge/style.css?v=<%=math.random(1,100000)%>">
<script type="module" crossorigin src="/luci-static/iform/1.0/index.js?v=<%=math.random(1,100000)%>"></script>
<link rel="stylesheet" href="/luci-static/iform/1.0/style.css?v=<%=math.random(1,100000)%>">
<%+footer%>

View File

@ -40,8 +40,8 @@ run_action() {
do_install() {
local CACHE_PATH=`uci get wxedge.@wxedge[0].cache_path 2>/dev/null`
if [ -z "$cache"]; then
echo "cache path is empty!" >&2
if [ -z "${CACHE_PATH}"]; then
echo "cache path is empty!" >>${LOGFILE}
exit 1
fi

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[lock-scroll=true]{overflow:hidden!important}.software-log_shade[data-v-41d6b36f],.software-log_shade *[data-v-41d6b36f]{-webkit-box-sizing:border-box;-webkit-tap-highlight-color:transparent;box-sizing:border-box;word-wrap:break-word;outline:none}.software-log_shade[data-v-41d6b36f]{width:100%;height:100%;display:flex;flex-wrap:wrap;align-items:center;justify-content:center;position:fixed;inset:0;z-index:99999}.software-log_shade .software-log_shade__bg[data-v-41d6b36f]{position:fixed;inset:0;background:rgba(68,79,83,.94) none repeat scroll 0 0!important;background-position:0 0;background-size:cover;opacity:.94}.software-log_shade .software-log_shade__pannel[data-v-41d6b36f]{width:800px;min-width:800px;border-radius:10px;z-index:100;box-shadow:3px 3px 10px #000;background:rgba(0,0,0,.9);padding:10px}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-title[data-v-41d6b36f]{text-align:center;font-size:18px;color:#9f0;padding:10px;font-weight:700}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-now i[data-v-41d6b36f]{color:#fc0;font-style:normal}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content[data-v-41d6b36f]{padding:10px;width:100%;text-align:center;overflow:hidden}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-41d6b36f]{width:100%;border:0px solid #222;font-family:Lucida Console;font-size:11px;background:transparent;color:#fff;outline:none;overflow-x:hidden;resize:none;transition:.5s}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-41d6b36f]:focus,.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-41d6b36f]:hover{box-shadow:none;border-color:#fff0!important}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-41d6b36f]::-webkit-scrollbar{width:5px;height:5px}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-41d6b36f]::-webkit-scrollbar-thumb{height:30px;outline:none;border:none;border-radius:1rem;background-color:#4c595c;-webkit-border-radius:1rem}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-content textarea[data-v-41d6b36f]::-webkit-scrollbar-track-piece{background:none;-webkit-border-radius:0;border-radius:0}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-btn[data-v-41d6b36f]{width:100%;display:flex;flex-wrap:wrap;align-items:center;justify-content:center}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-btn button[data-v-41d6b36f]{visibility:visible;min-width:88px;font-weight:bolder;text-shadow:1px 1px 0px black;border-radius:8px;height:33px;font-family:Verdana,Microsoft Yahei UI,sans-serif;font-size:12px;padding:0 .7em;width:auto;min-width:122px;margin:0 10px;cursor:pointer;background:#090a0a!important;border:1px solid #fff!important;color:#fff!important;opacity:1!important}.software-log_shade .software-log_shade__pannel .software-log_shade__pannel-btn button[data-v-41d6b36f]:hover{opacity:.9!important}.cbi-section .title{font-size:1.1rem;line-height:1;display:block;width:100%;margin:0;color:#32325d;padding:1rem 1.25rem}.cbi-page-actions{display:inline-block;width:100%}#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}