From 6bd215fe82fd2ad737ac23d8d666896b67cb57ba Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Thu, 30 Jul 2020 15:42:08 +0200 Subject: luci-app-dockerman: controller/dockerman: clean up action event generation Signed-off-by: Florian Eckert --- .../luci-app-dockerman/luasrc/controller/dockerman.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/applications/luci-app-dockerman/luasrc/controller/dockerman.lua b/applications/luci-app-dockerman/luasrc/controller/dockerman.lua index 608fbf4b01..368664cae6 100644 --- a/applications/luci-app-dockerman/luasrc/controller/dockerman.lua +++ b/applications/luci-app-dockerman/luasrc/controller/dockerman.lua @@ -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 -- cgit v1.2.3 From 400985d020bb7b44f472637e7cd4eea7f143045c Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 3 Aug 2020 12:32:11 +0200 Subject: luci-app-dockerman: set overview to first menu entry Signed-off-by: Florian Eckert --- .../luci-app-dockerman/luasrc/controller/dockerman.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/applications/luci-app-dockerman/luasrc/controller/dockerman.lua b/applications/luci-app-dockerman/luasrc/controller/dockerman.lua index 368664cae6..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 -- cgit v1.2.3 From 169c136d617638e97cce7fa65c1421d5765a3a89 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 3 Aug 2020 14:17:58 +0200 Subject: luci-app-dockerman: fix socket definition Signed-off-by: Florian Eckert --- .../luci-app-dockerman/luasrc/model/cbi/dockerman/overview.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) -- cgit v1.2.3 From 04a14ed3700147a6cb2d48c9493f634279e0a1a2 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 3 Aug 2020 14:18:19 +0200 Subject: luci-app-dockerman: fix console connection Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/dockerman/container.lua | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) 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") -- cgit v1.2.3 From 16316b3c2f5e285c40ab5cc11aea455d4b9e52fc Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 5 Aug 2020 15:42:33 +0200 Subject: luci-app-dockerman: improve newnetwork view Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/dockerman/newnetwork.lua | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) 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..58ad0eaa93 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.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") 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.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.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"), -- cgit v1.2.3 From 8a961da6da226ee0d964980bdcdb12b1fc7e2401 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 5 Aug 2020 15:46:50 +0200 Subject: luci-app-dockerman: fix typo Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/dockerman/newnetwork.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 58ad0eaa93..2c9cb271fc 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/newnetwork.lua @@ -29,7 +29,7 @@ o = s:option(Value, "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", translate("Bridge device")) o:value("macvlan", translate("MAC VLAN")) @@ -38,7 +38,7 @@ o:value("overlay", translate("Overlay network")) 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) @@ -46,7 +46,7 @@ end 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", translate("Bridge (Support direct communication between MAC VLANs)")) o:value("private", translate("Private (Prevent communication between MAC VLANs)")) @@ -55,7 +55,7 @@ o:value("passthru", translate("Pass-through (Mirror physical device to single MA 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", translate("L2 bridge")) o:value("l3", translate("L3 bridge")) @@ -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 -- cgit v1.2.3 From 3e99b18661728937730c17d2eed49ddee38f6b9f Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Tue, 11 Aug 2020 12:48:16 +0200 Subject: luci-app-dockerman: add edit button to containers list Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/dockerman/containers.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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..6fdb5ee61e 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"] = ''.. v.Names[1]:sub(2).."" + 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 -- cgit v1.2.3 From 2ce27ed58266cbb279a41cc32ac904fb2f40b878 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Tue, 11 Aug 2020 12:52:24 +0200 Subject: luci-app-dockerman: change common translation for new container to add Signed-off-by: Florian Eckert --- .../luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6fdb5ee61e..5bcb5fae9c 100644 --- a/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua +++ b/applications/luci-app-dockerman/luasrc/model/cbi/dockerman/containers.lua @@ -178,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 -- cgit v1.2.3