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">//<![CDATA[
38 var stxhr = new XHR();
40 function command_run(id)
43 var field = document.getElementById(id);
45 args = encodeURIComponent(field.value);
47 var legend = document.getElementById('command-rc-legend');
48 var output = document.getElementById('command-rc-output');
53 '
<img src=
"<%=resource%>/icons/loading.gif" alt=
"<%:Loading%>" style=
"vertical-align:middle" /> ' +
54 '<%:Waiting for command to complete...%
>'
57 legend.parentNode.style.display = 'block';
58 legend.style.display = 'inline';
60 stxhr.get('<%=url('admin/system/commands/run')%
>/' + id + (args ? '/' + args : ''), null,
66 st.stdout = '[<%:Binary data not displayed, download instead.%
>]';
68 legend.style.display = 'none';
69 output.innerHTML = String.format(
70 '
<pre><strong># %h\n
</strong>%h
<span style=
"color:red">%h
</span></pre>' +
71 '
<div class=
"alert-message warning">%s (<%:Code:%
> %d)
</div>',
72 st.command, st.stdout, st.stderr,
73 (st.exitcode ==
0) ? '<%:Command successful%
>' : '<%:Command failed%
>',
78 legend.style.display = 'none';
79 output.innerHTML = '
<span class=
"error"><%:Failed to execute command!%
></span>';
82 location.hash = '#output';
88 function command_download(id)
91 var field = document.getElementById(id);
93 args = encodeURIComponent(field.value);
95 location.href = '<%=url('admin/system/commands/download')%
>/' + id + (args ? '/' + args : '');
98 function command_link(id)
100 var legend = document.getElementById('command-rc-legend');
101 var output = document.getElementById('command-rc-output');
104 var field = document.getElementById(id);
106 args = encodeURIComponent(field.value);
108 if (legend && output)
110 var prefix = location.protocol + '//' + location.host + '<%=url('command')%
>/';
111 var suffix = (args ? '/' + args : '');
113 var link = prefix + id + suffix;
114 var link_nodownload = prefix + id +
"s" + suffix;
116 legend.style.display = 'none';
117 output.parentNode.style.display = 'block';
118 output.innerHTML = String.format(
119 '
<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>',
120 link, link, link_nodownload, link_nodownload
123 location.hash = '#output';
130 local uci = require
"luci.model.uci".cursor()
133 uci:foreach(
"luci",
"command", function(s) commands[#commands+
1] = s end)
136 <form method=
"get" action=
"<%=pcdata(FULL_REQUEST_URI)%>">
137 <div class=
"cbi-map">
138 <h2 name=
"content"><%:Custom Commands%
></h2>
140 <fieldset class=
"cbi-section">
141 <% local _, command; for _, command in ipairs(commands) do %
>
142 <div class=
"commandbox">
143 <h3><%=pcdata(command.name)%
></h3>
144 <p><%:Command:%
> <code><%=pcdata(command.command)%
></code></p>
145 <% if command.param ==
"1" then %
>
146 <p><%:Arguments:%
> <input type=
"text" id=
"<%=command['.name']%>" /></p>
149 <input type=
"button" value=
"<%:Run%>" class=
"cbi-button cbi-button-apply" onclick=
"command_run('<%=command['.name']%>')" />
150 <input type=
"button" value=
"<%:Download%>" class=
"cbi-button cbi-button-download" onclick=
"command_download('<%=command['.name']%>')" />
151 <% if command.public ==
"1" then %
>
152 <input type=
"button" value=
"<%:Link%>" class=
"cbi-button cbi-button-link" onclick=
"command_link('<%=command['.name']%>')" />
158 <br style=
"clear:both" /><br />
159 <a name=
"output"></a>
163 <fieldset class=
"cbi-section" style=
"display:none">
164 <legend id=
"command-rc-legend"><%:Collecting data...%
></legend>
165 <span id=
"command-rc-output"></span>