diff options
author | Florian Eckert <fe@dev.tdt.de> | 2020-08-11 12:56:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-11 12:56:56 +0200 |
commit | d59600cdf65052c8f4c265f935df2c940d7b243f (patch) | |
tree | 1e6f8b8f526b07d18aaecd88db7290a028c14782 | |
parent | ea5331052710f3d12d7ef70014bcb50bc418f93a (diff) | |
parent | 2ce27ed58266cbb279a41cc32ac904fb2f40b878 (diff) |
Merge pull request #4332 from TDT-AG/pr/20200730-luci-app-dockerman
luci-app-dockerman: improvements
5 files changed, 75 insertions, 50 deletions
diff --git a/applications/luci-app-dockerman/luasrc/controller/dockerman.lua b/applications/luci-app-dockerman/luasrc/controller/dockerman.lua index 608fbf4b01..9167a896ca 100644 --- a/applications/luci-app-dockerman/luasrc/controller/dockerman.lua +++ b/applications/luci-app-dockerman/luasrc/controller/dockerman.lua @@ -12,7 +12,7 @@ function index() e.dependent = false e.acl_depends = { "luci-app-dockerman" } - entry({"admin", "docker", "overview"},cbi("dockerman/overview"),_("Overview"),0).leaf=true + entry({"admin", "docker", "overview"},cbi("dockerman/overview"),_("Overview"), 1).leaf=true local remote = luci.model.uci.cursor():get_bool("dockerd", "globals", "remote_endpoint") if remote then @@ -32,11 +32,11 @@ function index() return end - entry({"admin", "docker", "containers"}, form("dockerman/containers"), _("Containers"),1).leaf=true - entry({"admin", "docker", "images"}, form("dockerman/images"), _("Images"),2).leaf=true - entry({"admin", "docker", "networks"}, form("dockerman/networks"), _("Networks"),3).leaf=true - entry({"admin", "docker", "volumes"}, form("dockerman/volumes"), _("Volumes"),4).leaf=true - entry({"admin", "docker", "events"}, call("action_events"), _("Events"),5) + entry({"admin", "docker", "containers"}, form("dockerman/containers"), _("Containers"), 2).leaf=true + entry({"admin", "docker", "images"}, form("dockerman/images"), _("Images"), 3).leaf=true + entry({"admin", "docker", "networks"}, form("dockerman/networks"), _("Networks"), 4).leaf=true + entry({"admin", "docker", "volumes"}, form("dockerman/volumes"), _("Volumes"), 5).leaf=true + entry({"admin", "docker", "events"}, call("action_events"), _("Events"), 6) entry({"admin", "docker", "newcontainer"}, form("dockerman/newcontainer")).leaf=true entry({"admin", "docker", "newnetwork"}, form("dockerman/newnetwork")).leaf=true @@ -64,12 +64,24 @@ function action_events() if events.code == 200 then for _, v in ipairs(events.body) do + local date = "unknown" + if v and v.time then + date = os.date("%Y-%m-%d %H:%M:%S", v.time) + end + + local name = v.Actor.Attributes.name or "unknown" + local action = v.Action or "unknown" + if v and v.Type == "container" then - logs = (logs ~= "" and (logs .. "\n") or logs) .. "[" .. os.date("%Y-%m-%d %H:%M:%S", v.time) .."] "..v.Type.. " " .. (v.Action or "null") .. " Container ID:".. (v.Actor.ID or "null") .. " Container Name:" .. (v.Actor.Attributes.name or "null") + local id = v.Actor.ID or "unknown" + logs = logs .. string.format("[%s] %s %s Container ID: %s Container Name: %s\n", date, v.Type, action, id, name) elseif v.Type == "network" then - logs = (logs ~= "" and (logs .. "\n") or logs) .. "[" .. os.date("%Y-%m-%d %H:%M:%S", v.time) .."] "..v.Type.. " " .. v.Action .. " Container ID:"..( v.Actor.Attributes.container or "null" ) .. " Network Name:" .. (v.Actor.Attributes.name or "null") .. " Network type:".. v.Actor.Attributes.type or "" + local container = v.Actor.Attributes.container or "unknown" + local network = v.Actor.Attributes.type or "unknown" + logs = logs .. string.format("[%s] %s %s Container ID: %s Network Name: %s Network type: %s\n", date, v.Type, action, container, name, network) elseif v.Type == "image" then - logs = (logs ~= "" and (logs .. "\n") or logs) .. "[" .. os.date("%Y-%m-%d %H:%M:%S", v.time) .."] "..v.Type.. " " .. v.Action .. " Image:".. (v.Actor.ID or "null").. " Image Name:" .. (v.Actor.Attributes.name or "null") + local id = v.Actor.ID or "unknown" + logs = logs .. string.format("[%s] %s %s Image: %s Image name: %s\n", date, v.Type, action, id, name) end end end diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua index 9ea006396a..37be23e0d1 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/container.lua @@ -704,11 +704,14 @@ elseif action == "console" then return end - local kill_ttyd = 'netstat -lnpt | grep ":7682[ \t].*ttyd$" | awk \'{print $NF}\' | awk -F\'/\' \'{print "kill -9 " $1}\' | sh > /dev/null' - luci.util.exec(kill_ttyd) + local pid = luci.util.trim(luci.util.exec("netstat -lnpt | grep :7682 | grep ttyd | tr -s ' ' | cut -d ' ' -f7 | cut -d'/' -f1")) + if pid and pid ~= "" then + luci.util.exec("kill -9 " .. pid) + end + local hosts - local uci = (require "luci.model.uci").cursor() - local remote = uci:get_bool("dockerd", "globals", "remote_endpoint") + local uci = require "luci.model.uci".cursor() + local remote = uci:get_bool("dockerd", "globals", "remote_endpoint") or false local host = nil local port = nil local socket = nil @@ -717,18 +720,25 @@ elseif action == "console" then host = uci:get("dockerd", "globals", "remote_host") or nil port = uci:get("dockerd", "globals", "remote_port") or nil else - socket = uci:get("dockerd", "globals", "socket_path") or nil + socket = uci:get("dockerd", "globals", "socket_path") or "/var/run/docker.sock" end if remote and host and port then hosts = host .. ':'.. port - elseif socket_path then - hosts = socket_path + elseif socket then + hosts = socket else return end - local start_cmd = cmd_ttyd .. ' -d 2 --once -p 7682 '.. cmd_docker .. ' -H "'.. hosts ..'" exec -it ' .. (uid and uid ~= "" and (" -u ".. uid .. ' ') or "").. container_id .. ' ' .. cmd .. ' &' + if uid and uid ~= "" then + uid = "-u " .. uid + else + uid = "" + end + + local start_cmd = string.format('%s -d 2 --once -p 7682 %s -H "unix://%s" exec -it %s %s %s&', cmd_ttyd, cmd_docker, hosts, uid, container_id, cmd) + os.execute(start_cmd) o = s:option(DummyValue, "console") diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua index cb1d2d943f..5bcb5fae9c 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua @@ -45,13 +45,12 @@ function get_containers() end for i, v in ipairs(containers) do - local index = v.Created .. v.Id + local index = v.Id data[index]={} data[index]["_selected"] = 0 data[index]["_id"] = v.Id:sub(1,12) - data[index]["name"] = v.Names[1]:sub(2) - data[index]["_name"] = '<a href='..luci.dispatcher.build_url("admin/docker/container/"..v.Id)..' class="dockerman_link" title="'..translate("Container detail")..'">'.. v.Names[1]:sub(2).."</a>" + data[index]["_name"] = v.Names[1]:sub(2) data[index]["_status"] = v.Status if v.Status:find("^Up") then @@ -104,7 +103,11 @@ if s.err then end s = m:section(Table, container_list, translate("Containers")) -s.nodescr=true +s.addremove = false +s.sectionhead = translate("Containers") +s.sortable = false +s.template = "cbi/tblsection" +s.extedit = luci.dispatcher.build_url("admin", "docker", "container","%s") o = s:option(Flag, "_selected","") o.disabled = 0 @@ -142,7 +145,7 @@ local start_stop_remove = function(m,cmd) for k in pairs(container_list) do if container_list[k]._selected == 1 then - container_selected[#container_selected + 1] = container_list[k].name + container_selected[#container_selected + 1] = container_list[k]._name end end @@ -175,7 +178,7 @@ s.rowcolors=false s.template="cbi/nullsection" o = s:option(Button, "_new") -o.inputtitle= translate("New") +o.inputtitle= translate("Add") o.template = "dockerman/cbi/inlinebutton" o.inputstyle = "add" o.forcewrite = true diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua index f4cfea5bc5..2c9cb271fc 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua @@ -24,41 +24,41 @@ s = m:section(SimpleSection, translate("New Network")) s.addremove = true s.anonymous = true -o = s:option(Value, "name", translate("Network Name")) +o = s:option(Value, "name", + translate("Network Name"), + translate("Name of the network that can be selected during container creation")) o.rmempty = true -o = s:option(ListValue, "dirver", translate("Driver")) +o = s:option(ListValue, "driver", translate("Driver")) o.rmempty = true -o:value("bridge", "bridge") -o:value("macvlan", "macvlan") -o:value("ipvlan", "ipvlan") -o:value("overlay", "overlay") +o:value("bridge", translate("Bridge device")) +o:value("macvlan", translate("MAC VLAN")) +o:value("ipvlan", translate("IP VLAN")) +o:value("overlay", translate("Overlay network")) -o = s:option(Value, "parent", translate("Parent Interface")) +o = s:option(Value, "parent", translate("Base device")) o.rmempty = true -o:depends("dirver", "macvlan") +o:depends("driver", "macvlan") local interfaces = luci.sys and luci.sys.net and luci.sys.net.devices() or {} for _, v in ipairs(interfaces) do o:value(v, v) end -o.default="br-lan" -o.placeholder="br-lan" -o = s:option(Value, "macvlan_mode", translate("Macvlan Mode")) +o = s:option(ListValue, "macvlan_mode", translate("Mode")) o.rmempty = true -o:depends("dirver", "macvlan") +o:depends("driver", "macvlan") o.default="bridge" -o:value("bridge", "bridge") -o:value("private", "private") -o:value("vepa", "vepa") -o:value("passthru", "passthru") +o:value("bridge", translate("Bridge (Support direct communication between MAC VLANs)")) +o:value("private", translate("Private (Prevent communication between MAC VLANs)")) +o:value("vepa", translate("VEPA (Virtual Ethernet Port Aggregator)")) +o:value("passthru", translate("Pass-through (Mirror physical device to single MAC VLAN)")) -o = s:option(Value, "ipvlan_mode", translate("Ipvlan Mode")) +o = s:option(ListValue, "ipvlan_mode", translate("Ipvlan Mode")) o.rmempty = true -o:depends("dirver", "ipvlan") +o:depends("driver", "ipvlan") o.default="l3" -o:value("l2", "l2") -o:value("l3", "l3") +o:value("l2", translate("L2 bridge")) +o:value("l3", translate("L3 bridge")) o = s:option(Flag, "ingress", translate("Ingress"), @@ -67,7 +67,7 @@ o.rmempty = true o.disabled = 0 o.enabled = 1 o.default = 0 -o:depends("dirver", "overlay") +o:depends("driver", "overlay") o = s:option(DynamicList, "options", translate("Options")) o.rmempty = true @@ -75,14 +75,14 @@ o.placeholder="com.docker.network.driver.mtu=1500" o = s:option(Flag, "internal", translate("Internal"), translate("Restrict external access to the network")) o.rmempty = true -o:depends("dirver", "overlay") +o:depends("driver", "overlay") o.disabled = 0 o.enabled = 1 o.default = 0 if nixio.fs.access("/etc/config/network") and nixio.fs.access("/etc/config/firewall")then o = s:option(Flag, "op_macvlan", translate("Create macvlan interface"), translate("Auto create macvlan interface in Openwrt")) - o:depends("dirver", "macvlan") + o:depends("driver", "macvlan") o.disabled = 0 o.enabled = 1 o.default = 1 @@ -128,7 +128,7 @@ o:depends("ipv6", 1) m.handle = function(self, state, data) if state == FORM_VALID then local name = data.name - local driver = data.dirver + local driver = data.driver local internal = data.internal == 1 and true or false diff --git a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua index dc20125e29..59266ac490 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua @@ -99,8 +99,8 @@ o.rmempty = false o = s:option(Value, "socket_path", translate("Docker Socket Path")) -o.default = "unix://var/run/docker.sock" -o.placeholder = "unix://var/run/docker.sock" +o.default = "unix:///var/run/docker.sock" +o.placeholder = "unix:///var/run/docker.sock" o:depends("remote_endpoint", 1) o = s:option(Value, "remote_host", @@ -146,7 +146,7 @@ if nixio.fs.access("/usr/bin/dockerd") then o = s:option(DynamicList, "hosts", translate("Client connection"), translate('Specifies where the Docker daemon will listen for client connections')) - o:value("unix://var/run/docker.sock", "unix://var/run/docker.sock") + o:value("unix:///var/run/docker.sock", "unix:///var/run/docker.sock") o:value("tcp://0.0.0.0:2375", "tcp://0.0.0.0:2375") o.rmempty = true o:depends("remote_endpoint", 0) |