diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-10-25 00:55:14 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-10-25 01:03:38 +0200 |
commit | dd1c538b2ed4e025be6a4006e0e8e2a2bf37ad18 (patch) | |
tree | 6cabbe7b5abc3e683709d8961e4070808bf3b145 /applications/luci-app-commands/luasrc/view | |
parent | 036424df5b76111f32d4dce0253bfb8260d8a41f (diff) |
luci-app-commands: rewrite to client side rendering
Rewrite the luci-app-command configuration to client side cbi forms and
port the server side templates and controller logic to ucode.
Also utilize a query string parameter to pass custom arguments.
Fixes: #5559
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'applications/luci-app-commands/luasrc/view')
-rw-r--r-- | applications/luci-app-commands/luasrc/view/commands.htm | 187 | ||||
-rw-r--r-- | applications/luci-app-commands/luasrc/view/commands_public.htm | 50 |
2 files changed, 0 insertions, 237 deletions
diff --git a/applications/luci-app-commands/luasrc/view/commands.htm b/applications/luci-app-commands/luasrc/view/commands.htm deleted file mode 100644 index 634090e7d7..0000000000 --- a/applications/luci-app-commands/luasrc/view/commands.htm +++ /dev/null @@ -1,187 +0,0 @@ -<%# - Copyright 2012 Jo-Philipp Wich <jow@openwrt.org> - Licensed to the public under the Apache License 2.0. --%> - -<% css = [[ - -.commandbox { - height: 12em; - width: 30%; - float: left; - height: 12em; - margin: 5px; - position: relative; -} - -.commandbox h3 { - font-size: 1.5em !important; - line-height: 2em !important; - margin: 0 !important; -} - -.commandbox input[type="text"] { - width: 50% !important; -} - -.commandbox div { - position: absolute; - left: 0; - bottom: 1.5em; -} - -]] -%> - -<%+header%> - -<script type="text/javascript">//<![CDATA[ - var stxhr = new XHR(); - - function command_run(ev, id) - { - var args; - var field = document.getElementById(id); - if (field) - args = encodeURIComponent(field.value); - - var legend = document.getElementById('command-rc-legend'); - var output = document.getElementById('command-rc-output'); - - if (legend && output) - { - output.innerHTML = - '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' + - '<%:Waiting for command to complete...%>' - ; - - legend.parentNode.style.display = 'block'; - legend.style.display = 'inline'; - - stxhr.get('<%=url('admin/system/commands/run')%>/' + id + (args ? '/' + args : ''), null, - function(x, st) - { - if (st) - { - if (st.binary) - st.stdout = '[<%:Binary data not displayed, download instead.%>]'; - - legend.style.display = 'none'; - output.innerHTML = String.format( - '<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' + - '<div class="alert-message warning">%s (<%:Code:%> %d)</div>', - st.command, st.stdout, st.stderr, - (st.exitcode == 0) ? '<%:Command successful%>' : '<%:Command failed%>', - st.exitcode); - } - else - { - legend.style.display = 'none'; - output.innerHTML = '<span class="error"><%:Failed to execute command!%></span>'; - } - - location.hash = '#output'; - } - ); - } - - ev.preventDefault(); - } - - function command_download(ev, id) - { - var args; - var field = document.getElementById(id); - if (field) - args = encodeURIComponent(field.value); - - location.href = '<%=url('admin/system/commands/download')%>/' + id + (args ? '/' + args : ''); - - ev.preventDefault(); - } - - function command_link(ev, id) - { - var legend = document.getElementById('command-rc-legend'); - var output = document.getElementById('command-rc-output'); - - var args; - var field = document.getElementById(id); - if (field) - args = encodeURIComponent(field.value); - - if (legend && output) - { - var prefix = location.protocol + '//' + location.host + '<%=url('command')%>/'; - var suffix = (args ? '/' + args : ''); - - var link = prefix + id + suffix; - var link_nodownload = prefix + id + "s" + suffix; - - legend.style.display = 'none'; - output.parentNode.style.display = 'block'; - output.innerHTML = String.format( - '<div class="alert-message"><p><%:Download execution result%> <a href="%s">%s</a></p><p><%:Or display result%> <a href="%s">%s</a></p></div>', - link, link, link_nodownload, link_nodownload - ); - - location.hash = '#output'; - } - - ev.preventDefault(); - } - -//]]></script> - -<% - local uci = require "luci.model.uci".cursor() - local commands = { } - - uci:foreach("luci", "command", function(s) commands[#commands+1] = s end) -%> - -<form method="get" action="<%=pcdata(FULL_REQUEST_URI)%>"> - <div class="cbi-map"> - <h2 name="content"><%:Custom Commands%></h2> - <% if #commands == 0 then %> - <div class="cbi-section"> - <div class="table cbi-section-table"> - <div class="tr cbi-section-table-row"> - <p> - <em><%:This section contains no values yet%></em> - </p> - </div> - </div> - </div> - <% else %> - <fieldset class="cbi-section"> - <% local _, command; for _, command in ipairs(commands) do %> - <div class="commandbox"> - <h3><%=pcdata(command.name)%></h3> - <p><%:Command:%> <code><%=pcdata(command.command)%></code></p> - <% if command.param == "1" then %> - <p><%:Arguments:%> <input type="text" id="<%=command['.name']%>" /></p> - <% end %> - <div> - <button class="cbi-button cbi-button-apply" onclick="command_run(event, '<%=command['.name']%>')"><%:Run%></button> - <button class="cbi-button cbi-button-download" onclick="command_download(event, '<%=command['.name']%>')"><%:Download%></button> - <% if command.public == "1" then %> - <button class="cbi-button cbi-button-link" onclick="command_link(event, '<%=command['.name']%>')"><%:Link%></button> - <% end %> - </div> - </div> - <% end %> - - <br style="clear:both" /><br /> - <a name="output"></a> - </fieldset> - <% end %> - - </div> - - <fieldset class="cbi-section" style="display:none"> - <legend id="command-rc-legend"><%:Collecting data...%></legend> - <span id="command-rc-output"></span> - </fieldset> -</form> - -<%+footer%> diff --git a/applications/luci-app-commands/luasrc/view/commands_public.htm b/applications/luci-app-commands/luasrc/view/commands_public.htm deleted file mode 100644 index f20799d40f..0000000000 --- a/applications/luci-app-commands/luasrc/view/commands_public.htm +++ /dev/null @@ -1,50 +0,0 @@ -<%# - Copyright 2016 t123yh <t123yh@outlook.com> - Licensed to the public under the Apache License 2.0. --%> - -<% css = [[ -.alert-success { - color: #3c763d; - background-color: #dff0d8; - border-color: #d6e9c6; -} - -.alert { - padding: 15px; - margin-bottom: 20px; - border: 1px solid transparent; - border-radius: 4px; -} - -.alert-warning { - color: #8a6d3b; - background-color: #fcf8e3; - border-color: #faebcc; -} -]] -%> - -<%+header%> - -<% if exitcode == 0 then %> - <div class="alert alert-success" role="alert"> <%:Command executed successfully.%> </div> -<% else %> - <div class="alert alert-warning" role="alert"> <%:Command exited with status code %> <%= exitcode %> </div> -<% end %> - -<% if stdout ~= "" then %> - <h3><%:Standard Output%></h3> - <pre><%= stdout %></pre> -<% end %> - -<% if stderr ~= "" then %> - <h3><%:Standard Error%></h3> - <pre><%= stderr %></pre> -<% end %> - -<script> - <%# Display top bar on mobile devices -%> - document.getElementsByClassName('brand')[0].style.setProperty("display", "block", "important"); -</script> - -<%+footer%>
\ No newline at end of file |