2 Copyright 2012 Jo-Philipp Wich <jow@openwrt.org>
3 Licensed to the public under the Apache License 2.0.
18 font-size: 1.5em !important;
19 line-height: 2em !important;
23 .commandbox input[type="text"] {
24 width: 50% !important;
37 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
38 <script type="text/javascript">//<![CDATA[
39 var stxhr = new XHR();
41 function command_run(id)
44 var field = document.getElementById(id);
46 args = encodeURIComponent(field.value);
48 var legend = document.getElementById('command-rc-legend');
49 var output = document.getElementById('command-rc-output');
54 '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
55 '<%:Waiting for command to complete...%>'
58 legend.parentNode.style.display = 'block';
59 legend.style.display = 'inline';
61 stxhr.get('<%=url('admin/system/commands/run')%>/' + id + (args ? '/' + args : ''), null,
67 st.stdout = '[<%:Binary data not displayed, download instead.%>]';
69 legend.style.display = 'none';
70 output.innerHTML = String.format(
71 '<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' +
72 '<div class="alert-message warning">%s (<%:Code:%> %d)</div>',
73 st.command, st.stdout, st.stderr,
74 (st.exitcode == 0) ? '<%:Command successful%>' : '<%:Command failed%>',
79 legend.style.display = 'none';
80 output.innerHTML = '<span class="error"><%:Failed to execute command!%></span>';
83 location.hash = '#output';
89 function command_download(id)
92 var field = document.getElementById(id);
94 args = encodeURIComponent(field.value);
96 location.href = '<%=url('admin/system/commands/download')%>/' + id + (args ? '/' + args : '');
99 function command_link(id)
101 var legend = document.getElementById('command-rc-legend');
102 var output = document.getElementById('command-rc-output');
105 var field = document.getElementById(id);
107 args = encodeURIComponent(field.value);
109 if (legend && output)
111 var prefix = location.protocol + '//' + location.host + '<%=url('command')%>/';
112 var suffix = (args ? '/' + args : '');
114 var link = prefix + id + suffix;
115 var link_nodownload = prefix + id + "s" + suffix;
117 legend.style.display = 'none';
118 output.parentNode.style.display = 'block';
119 output.innerHTML = String.format(
120 '<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>',
121 link, link, link_nodownload, link_nodownload
124 location.hash = '#output';
131 local uci = require "luci.model.uci".cursor()
134 uci:foreach("luci", "command", function(s) commands[#commands+1] = s end)
137 <form method="get" action="<%=pcdata(FULL_REQUEST_URI)%>">
138 <div class="cbi-map">
139 <h2 name="content"><%:Custom Commands%></h2>
141 <fieldset class="cbi-section">
142 <% local _, command; for _, command in ipairs(commands) do %>
143 <div class="commandbox">
144 <h3><%=pcdata(command.name)%></h3>
145 <p><%:Command:%> <code><%=pcdata(command.command)%></code></p>
146 <% if command.param == "1" then %>
147 <p><%:Arguments:%> <input type="text" id="<%=command['.name']%>" /></p>
150 <input type="button" value="<%:Run%>" class="cbi-button cbi-button-apply" onclick="command_run('<%=command['.name']%>')" />
151 <input type="button" value="<%:Download%>" class="cbi-button cbi-button-download" onclick="command_download('<%=command['.name']%>')" />
152 <% if command.public == "1" then %>
153 <input type="button" value="<%:Link%>" class="cbi-button cbi-button-link" onclick="command_link('<%=command['.name']%>')" />
159 <br style="clear:both" /><br />
160 <a name="output"></a>
164 <fieldset class="cbi-section" style="display:none">
165 <legend id="command-rc-legend"><%:Collecting data...%></legend>
166 <span id="command-rc-output"></span>