todo test for ubuntu plugin
This commit is contained in:
parent
61606830f6
commit
0150e66b48
@ -3,9 +3,9 @@ module("luci.controller.ubuntu", package.seeall)
|
|||||||
function index()
|
function index()
|
||||||
|
|
||||||
entry({'admin', 'services', 'ubuntu'}, alias('admin', 'services', 'ubuntu', 'client'), _('Ubuntu'), 10)
|
entry({'admin', 'services', 'ubuntu'}, alias('admin', 'services', 'ubuntu', 'client'), _('Ubuntu'), 10)
|
||||||
entry({"admin", "services", "ubuntu",'client'}, cbi("ubuntu/status"), nil).leaf = true
|
entry({"admin", "services", "ubuntu",'client'}, cbi("ubuntu/ubuntu"), nil).leaf = true
|
||||||
|
|
||||||
entry({"admin", "services", "ubuntu","status"}, call("get_container_status"))
|
entry({"admin", "services", "ubuntu","status"}, call("action_status")).leaf = true
|
||||||
entry({"admin", "services", "ubuntu","stop"}, post("stop_container"))
|
entry({"admin", "services", "ubuntu","stop"}, post("stop_container"))
|
||||||
entry({"admin", "services", "ubuntu","start"}, post("start_container"))
|
entry({"admin", "services", "ubuntu","start"}, post("start_container"))
|
||||||
entry({"admin", "services", "ubuntu","install"}, post("install_container"))
|
entry({"admin", "services", "ubuntu","install"}, post("install_container"))
|
||||||
@ -147,6 +147,14 @@ function uninstall_container()
|
|||||||
util.exec("docker container rm '"..container_id.."'")
|
util.exec("docker container rm '"..container_id.."'")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function action_status()
|
||||||
|
local e = {}
|
||||||
|
e.running = luci.sys.call("pidof aliyundrive-webdav >/dev/null") == 0
|
||||||
|
e.application = luci.sys.exec("aliyundrive-webdav --version")
|
||||||
|
luci.http.prepare_content("application/json")
|
||||||
|
luci.http.write_json(e)
|
||||||
|
end
|
||||||
|
|
||||||
-- 总结:
|
-- 总结:
|
||||||
-- docker是否安装
|
-- docker是否安装
|
||||||
-- 容器是否安装
|
-- 容器是否安装
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
local m, s
|
|
||||||
local uci = luci.model.uci.cursor()
|
|
||||||
local sys = require 'luci.sys'
|
|
||||||
local docker = require "luci.model.docker"
|
|
||||||
|
|
||||||
m = SimpleForm("ubuntu", translate("ubuntu"), translate("带Web远程桌面的Docker版Ubuntu。默认<用户名:kasm_user 密码:password>")
|
|
||||||
.. translatef(" "
|
|
||||||
.. "<a href=\"%s\" target=\"_blank\">"
|
|
||||||
.. "访问官网</a>", "https://www.kasmweb.com"))
|
|
||||||
m.submit=false
|
|
||||||
m.reset=false
|
|
||||||
|
|
||||||
s = m:section(SimpleSection)
|
|
||||||
s.template = "dockerman/apply_widget"
|
|
||||||
s.err = docker:read_status()
|
|
||||||
s.err = s.err and s.err:gsub("\n","<br>"):gsub(" "," ")
|
|
||||||
if s.err then
|
|
||||||
docker:clear_status()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
s=m:section(SimpleSection)
|
|
||||||
s.template = "ubuntu/ubuntu"
|
|
||||||
|
|
||||||
|
|
||||||
return m
|
|
17
applications/luci-app-ubuntu/luasrc/model/cbi/ubuntu/ubuntu.lua
Executable file
17
applications/luci-app-ubuntu/luasrc/model/cbi/ubuntu/ubuntu.lua
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
local m, s
|
||||||
|
local uci = luci.model.uci.cursor()
|
||||||
|
local sys = require 'luci.sys'
|
||||||
|
local docker = require "luci.model.docker"
|
||||||
|
|
||||||
|
m = Map("Ubuntu")
|
||||||
|
m.title = translate("Ubuntu")
|
||||||
|
m.description = translate("<a href=\"https://github.com/messense/aliyundrive-webdav\" target=\"_blank\">Project GitHub URL</a>")
|
||||||
|
m.submit=false
|
||||||
|
m.reset=false
|
||||||
|
|
||||||
|
m:section(SimpleSection).template = "ubuntu/ubuntu_status"
|
||||||
|
|
||||||
|
s=m:section(SimpleSection)
|
||||||
|
s.template = "ubuntu/ubuntu"
|
||||||
|
|
||||||
|
return m
|
@ -1,127 +1,81 @@
|
|||||||
<script type="text/javascript">//<![CDATA[
|
|
||||||
XHR.poll(5,'<%=url("admin/services/ubuntu/status")%>', null,
|
|
||||||
function (x, st) {
|
|
||||||
var tb = document.getElementById('ubuntu_status');
|
|
||||||
if (st && tb) {
|
|
||||||
if (st.docker_install){
|
|
||||||
if (st.docker_start){
|
|
||||||
if (st.container_install) {
|
|
||||||
if (st.container_running) {
|
|
||||||
var htmlStr = '<br/><em><%:The ubuntu service is running.%></em>';
|
|
||||||
|
|
||||||
var configs = [
|
<link rel="stylesheet" href="https://cdn.form.io/formiojs/formio.full.min.css">
|
||||||
{id: "userName", label: "<%:UserName%>:", value: st.user_name},
|
<script src="https://cdn.form.io/formiojs/formio.full.min.js"></script>
|
||||||
{id: "password", label: "<%:Password%>:", value: st.password},
|
|
||||||
];
|
|
||||||
configs.forEach(function(c){
|
|
||||||
htmlStr += ("<div class=\"cbi-value\"><label class=\"cbi-value-title\" for=\"" + c.id + "\">" + c.label + "</label>"
|
|
||||||
+ "<div><label class=\"cbi-value-title\" id=\"" + c.id + "\"/>" + c.value + "</label></div></div>");
|
|
||||||
});
|
|
||||||
|
|
||||||
htmlStr += "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:open ubuntu%> \" onclick=\"open_container('" + st.container_port + "')\" />";
|
|
||||||
htmlStr+= "<input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:stop ubuntu%> \" onclick=\"stop_container('" + st.container_id + "')\" /><br/><br/>";
|
|
||||||
|
|
||||||
tb.innerHTML = htmlStr;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tb.innerHTML = '<br/><em><%:The ubuntu service is not running.%></em>'
|
|
||||||
+ "<br/><br/><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:run ubuntu%> \" onclick=\"start_container('" + st.container_id + "')\" />"
|
|
||||||
+ "<input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:uninstall ubuntu%> \" onclick=\"uninstall_container('" + st.container_id + "')\" /><br/><br/>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let port = document.getElementById('port')
|
|
||||||
if(!port){
|
|
||||||
var configs = [
|
|
||||||
{id: "port", label: "<%:Port (optional)%>:", value: st.container_port},
|
|
||||||
{id: "password", label: "<%:Password (optional)%>:", value: st.password},
|
|
||||||
];
|
|
||||||
tb.innerHTML = '<br/><em><%:The ubuntu service is not installed.%></em>';
|
|
||||||
configs.forEach(function(c){
|
|
||||||
tb.innerHTML += ("<div class=\"cbi-value\"><label class=\"cbi-value-title\" for=\"" + c.id + "\">" + c.label + "</label>"
|
|
||||||
+ "<div class=\"cbi-value-field\"><input type=\"text\" class=\"cbi-input-text\" id=\"" + c.id + "\" value=\"" + c.value + "\"/></div></div>");
|
|
||||||
});
|
|
||||||
tb.innerHTML += ("<div class=\"cbi-value\"><label class=\"cbi-value-title\" for=\" version \"><%:Version%></label>"
|
|
||||||
+ "<div class=\"cbi-value-form\"><form><select id=\"version\"><option value=\"standard\"><%:standard version%>:</option><option value=\"full\"><%:full version%></option></select></form></div></div>");
|
|
||||||
tb.innerHTML += ("<div class=\"cbi-value\"><label class=\"cbi-value-title\"></label>"
|
|
||||||
+ "<div class=\"cbi-value-field\"><input class=\"btn cbi-button cbi-button-apply\" type=\"button\" value=\" <%:install ubuntu%> \" onclick=\"install_container()\" /></div></div><br>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
tb.innerHTML = '<br/><em><%:Docker service is not start.%></em>'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
tb.innerHTML = '<br/><em><%:Docker is not installed.%></em>'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var xhr_post = function(url, data, cb) {
|
|
||||||
data = data || {};
|
|
||||||
data.token = '<%=token%>';
|
|
||||||
cb || docker_status_message('notice', '<img src="/luci-static/resources/icons/loading.gif" alt="" style="vertical-align:middle" />');
|
|
||||||
new XHR().post(url, data, (x, d) => {
|
|
||||||
cb || docker_status_message();
|
|
||||||
cb && cb(x, d);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function open_container(x) {
|
|
||||||
Url = "https://" + window.location.hostname + ":" + x
|
|
||||||
// alert(Url)
|
|
||||||
window.open(Url)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const STOP_URL = '<%=luci.dispatcher.build_url("admin", "services", "ubuntu","stop")%>';
|
|
||||||
|
|
||||||
function stop_container(x) {
|
|
||||||
|
|
||||||
xhr_post(STOP_URL, { container_id: x });
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const START_URL = '<%=luci.dispatcher.build_url("admin", "services", "ubuntu","start")%>';
|
|
||||||
|
|
||||||
function start_container(x) {
|
|
||||||
|
|
||||||
xhr_post(START_URL, { container_id: x });
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const UNINSTALL_URL = '<%=luci.dispatcher.build_url("admin", "services", "ubuntu","uninstall")%>';
|
|
||||||
|
|
||||||
function uninstall_container(x) {
|
|
||||||
|
|
||||||
xhr_post(UNINSTALL_URL, { container_id: x });
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const INSTALL_URL = '<%=luci.dispatcher.build_url("admin", "services", "ubuntu","install")%>';
|
|
||||||
|
|
||||||
function install_container(x) {
|
|
||||||
|
|
||||||
let password = document.getElementById('password').value
|
|
||||||
let port = document.getElementById('port').value
|
|
||||||
let version = document.getElementById('version').value
|
|
||||||
// alert(" 安装容器'" + version + "' ");
|
|
||||||
|
|
||||||
xhr_post(INSTALL_URL, {password: password, port: port, version: version}, (x, d) => {
|
|
||||||
location.reload()
|
|
||||||
});
|
|
||||||
uci_confirm_docker();
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
//]]></script>
|
|
||||||
|
|
||||||
<fieldset class="cbi-section">
|
<fieldset class="cbi-section">
|
||||||
<fieldset class="cbi-section-node" id="ubuntu_status">
|
<fieldset class="cbi-section-node" id="ubuntu_status">
|
||||||
<em>
|
<em>
|
||||||
<%:Collecting data...%>
|
<%:Collecting data...%>
|
||||||
</em>
|
</em>
|
||||||
|
<div id="formio"></div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<script type="text/javascript">//<![CDATA[
|
||||||
|
|
||||||
|
Formio.icons = 'fontawesome';
|
||||||
|
Formio.createForm(document.getElementById('formio'), {
|
||||||
|
components: [
|
||||||
|
{
|
||||||
|
type: 'textfield',
|
||||||
|
key: 'firstName',
|
||||||
|
label: 'First Name',
|
||||||
|
placeholder: 'Enter your first name.',
|
||||||
|
input: true,
|
||||||
|
tooltip: 'Enter your <strong>First Name</strong>',
|
||||||
|
customClass: "cbi-value",
|
||||||
|
description: 'Enter your <strong>First Name</strong>'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textfield',
|
||||||
|
key: 'lastName',
|
||||||
|
label: 'Last Name',
|
||||||
|
placeholder: 'Enter your last name',
|
||||||
|
input: true,
|
||||||
|
tooltip: 'Enter your <strong>Last Name</strong>',
|
||||||
|
description: 'Enter your <strong>Last Name</strong>'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "select",
|
||||||
|
label: "Favorite Things",
|
||||||
|
key: "favoriteThings",
|
||||||
|
placeholder: "These are a few of your favorite things...",
|
||||||
|
data: {
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
value: "raindropsOnRoses",
|
||||||
|
label: "Raindrops on roses"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "whiskersOnKittens",
|
||||||
|
label: "Whiskers on Kittens"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "brightCopperKettles",
|
||||||
|
label: "Bright Copper Kettles"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "warmWoolenMittens",
|
||||||
|
label: "Warm Woolen Mittens"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
dataSrc: "values",
|
||||||
|
template: "<span>{{ item.label }}</span>",
|
||||||
|
multiple: true,
|
||||||
|
input: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
action: 'submit',
|
||||||
|
label: 'Submit',
|
||||||
|
theme: 'primary'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then(function(form) {
|
||||||
|
form.on('submit', function(submission) {
|
||||||
|
console.log(submission);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//]]></script>
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
<script type="text/javascript">//<![CDATA[
|
||||||
|
XHR.poll(3, '<%=url([[admin]], [[services]], [[ubuntu]], [[status]])%>', null,
|
||||||
|
function(x, data) {
|
||||||
|
var tb = document.getElementById('ubuntu_status');
|
||||||
|
if (data && tb) {
|
||||||
|
if (data.running) {
|
||||||
|
tb.innerHTML = '<em><b><font color=green>' + data.application + '<%:RUNNING%></font></b></em>';
|
||||||
|
} else {
|
||||||
|
tb.innerHTML = '<em><b><font color=red>' + data.application + '<%:NOT RUNNING%></font></b></em>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
//]]>
|
||||||
|
</script>
|
||||||
|
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||||
|
<fieldset class="cbi-section">
|
||||||
|
<p id="ubuntu_status">
|
||||||
|
<em><%:Collecting data...%></em>
|
||||||
|
</p>
|
||||||
|
</fieldset>
|
9
applications/luci-app-ubuntu/simple-install.sh
Executable file
9
applications/luci-app-ubuntu/simple-install.sh
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# run in router
|
||||||
|
|
||||||
|
mkdir -p /usr/lib/lua/luci/view/ubuntu/cbi
|
||||||
|
cp ./luasrc/controller/ubuntu.lua /usr/lib/lua/luci/controller/
|
||||||
|
cp ./luasrc/model/cbi/ubuntu/ubuntu.lua /usr/lib/lua/luci/model/cbi/ubuntu/
|
||||||
|
cp ./luasrc/view/ubuntu/* /usr/lib/lua/luci/view/ubuntu/
|
||||||
|
cp -rf ./root /
|
Loading…
x
Reference in New Issue
Block a user