| 25 | | |
| 26 | | if luci.http.formvalue("cbi.submit") then |
| 27 | | local host = luci.http.formvalue("cbid.wol.1.mac") |
| 28 | | if host and #host > 0 then |
| 29 | | local cmd |
| 30 | | local util = luci.http.formvalue("cbid.wol.1.binary") or ( |
| 31 | | has_ewk and "/usr/bin/etherwake" or "/usr/bin/wol" |
| 32 | | ) |
| 33 | | |
| 34 | | if util == "/usr/bin/etherwake" then |
| 35 | | local iface = luci.http.formvalue("cbid.wol.1.iface") |
| 36 | | cmd = "%s -D%s %q" %{ |
| 37 | | util, (iface ~= "" and " -i %q" % iface or ""), host |
| 38 | | } |
| 39 | | else |
| 40 | | cmd = "%s -v %q" %{ util, host } |
| 41 | | end |
| 42 | | |
| 43 | | is = m:section(SimpleSection) |
| 44 | | |
| 45 | | function is.render() |
| 46 | | luci.http.write( |
| 47 | | "<p><br /><strong>%s</strong><br /><br /><code>%s<br /><br />" %{ |
| 48 | | translate("Starting WoL utility:"), cmd |
| 49 | | } |
| 50 | | ) |
| 51 | | |
| 52 | | local p = io.popen(cmd .. " 2>&1") |
| 53 | | if p then |
| 54 | | while true do |
| 55 | | local l = p:read("*l") |
| 56 | | if l then |
| 57 | | if #l > 100 then l = l:sub(1, 100) .. "..." end |
| 58 | | luci.http.write(l .. "<br />") |
| 59 | | else |
| 60 | | break |
| 61 | | end |
| 62 | | end |
| 63 | | p:close() |
| 64 | | end |
| 65 | | |
| 66 | | luci.http.write("</code><br /></p>") |
| 67 | | end |
| 68 | | end |
| 69 | | end |
| | 78 | function host.write(self, s, val) |
| | 79 | local host = luci.http.formvalue("cbid.wol.1.mac") |
| | 80 | if host and #host > 0 then |
| | 81 | local cmd |
| | 82 | local util = luci.http.formvalue("cbid.wol.1.binary") or ( |
| | 83 | has_ewk and "/usr/bin/etherwake" or "/usr/bin/wol" |
| | 84 | ) |
| | 85 | |
| | 86 | if util == "/usr/bin/etherwake" then |
| | 87 | local iface = luci.http.formvalue("cbid.wol.1.iface") |
| | 88 | cmd = "%s -D%s %q" %{ |
| | 89 | util, (iface ~= "" and " -i %q" % iface or ""), host |
| | 90 | } |
| | 91 | else |
| | 92 | cmd = "%s -v %q" %{ util, host } |
| | 93 | end |
| | 94 | |
| | 95 | local msg = "<p><strong>%s</strong><br /><br /><code>%s<br /><br />" %{ |
| | 96 | translate("Starting WoL utility:"), cmd |
| | 97 | } |
| | 98 | |
| | 99 | local p = io.popen(cmd .. " 2>&1") |
| | 100 | if p then |
| | 101 | while true do |
| | 102 | local l = p:read("*l") |
| | 103 | if l then |
| | 104 | if #l > 100 then l = l:sub(1, 100) .. "..." end |
| | 105 | msg = msg .. l .. "<br />" |
| | 106 | else |
| | 107 | break |
| | 108 | end |
| | 109 | end |
| | 110 | p:close() |
| | 111 | end |
| | 112 | |
| | 113 | msg = msg .. "</code></p>" |
| | 114 | |
| | 115 | m.message = msg |
| | 116 | end |
| | 117 | end |
| | 118 | |
| | 119 | |