2 LuCI - Lua Configuration Interface
3 Copyright
2012 Jo-Philipp Wich
<jow@openwrt.org
>
5 Licensed under the Apache License, Version
2.0 (the
"License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-
2.0
25 font-size:
1.5em !important;
26 line-height:
2em !important;
30 .commandbox input[
type=
"text"] {
31 width:
50% !important;
44 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
45 <script type=
"text/javascript">//<![CDATA[
46 var stxhr = new XHR();
48 function command_run(id)
51 var field = document.getElementById(id);
53 args = encodeURIComponent(field.value);
55 var legend = document.getElementById('command-rc-legend');
56 var output = document.getElementById('command-rc-output');
61 '
<img src=
"<%=resource%>/icons/loading.gif" alt=
"<%:Loading%>" style=
"vertical-align:middle" /> ' +
62 '<%:Waiting for command to complete...%
>'
65 legend.parentNode.style.display = 'block';
66 legend.style.display = 'inline';
68 stxhr.get('<%=luci.dispatcher.build_url(
"admin",
"system",
"commands",
"run")%
>/' + id + (args ? '/' + args : ''), null,
74 st.stdout = '[<%:Binary data not displayed, download instead.%
>]';
76 legend.style.display = 'none';
77 output.innerHTML = String.format(
78 '
<pre><strong># %h\n
</strong>%h
<span style=
"color:red">%h
</span></pre>' +
79 '
<div class=
"alert-message warning">%s (<%:Code:%
> %d)
</div>',
80 st.command, st.stdout, st.stderr,
81 (st.exitcode ==
0) ? '<%:Command successful%
>' : '<%:Command failed%
>',
86 legend.style.display = 'none';
87 output.innerHTML = '
<span class=
"error"><%:Failed to execute command!%
></span>';
90 location.hash = '#output';
96 function command_download(id)
99 var field = document.getElementById(id);
101 args = encodeURIComponent(field.value);
103 location.href = '<%=luci.dispatcher.build_url(
"admin",
"system",
"commands",
"download")%
>/' + id + (args ? '/' + args : '');
106 function command_link(id)
108 var legend = document.getElementById('command-rc-legend');
109 var output = document.getElementById('command-rc-output');
112 var field = document.getElementById(id);
114 args = encodeURIComponent(field.value);
116 if (legend && output)
118 var link = location.protocol + '//' + location.hostname +
119 (location.port ? ':' + location.port : '') +
120 location.pathname.split(';')[
0] + 'command/' +
121 id + (args ? '/' + args : '');
123 legend.style.display = 'none';
124 output.parentNode.style.display = 'block';
125 output.innerHTML = String.format(
126 '
<div class=
"alert-message"><%:Access command with%
> <a href=
"%s">%s
</a></div>',
130 location.hash = '#output';
137 local uci = require
"luci.model.uci".cursor()
140 uci:foreach(
"luci",
"command", function(s) commands[#commands+
1] = s end)
143 <form method=
"get" action=
"<%=pcdata(luci.http.getenv("REQUEST_URI
"))%>">
144 <div class=
"cbi-map">
145 <h2><a id=
"content" name=
"content"><%:Custom Commands%
></a></h2>
147 <fieldset class=
"cbi-section">
148 <% local _, command; for _, command in ipairs(commands) do %
>
149 <div class=
"commandbox">
150 <h3><%=pcdata(command.name)%
></h3>
151 <p><%:Command:%
> <code><%=pcdata(command.command)%
></code></p>
152 <% if command.param ==
"1" then %
>
153 <p><%:Arguments:%
> <input type=
"text" id=
"<%=command['.name']%>" /></p>
156 <input type=
"button" value=
"<%:Run%>" class=
"cbi-button cbi-button-apply" onclick=
"command_run('<%=command['.name']%>')" />
157 <input type=
"button" value=
"<%:Download%>" class=
"cbi-button cbi-button-download" onclick=
"command_download('<%=command['.name']%>')" />
158 <% if command.public ==
"1" then %
>
159 <input type=
"button" value=
"<%:Link%>" class=
"cbi-button cbi-button-link" onclick=
"command_link('<%=command['.name']%>')" />
165 <br style=
"clear:both" /><br />
166 <a name=
"output"></a>
170 <fieldset class=
"cbi-section" style=
"display:none">
171 <legend id=
"command-rc-legend"><%:Collecting data...%
></legend>
172 <span id=
"command-rc-output"></span>