applications/luci-commands: remove bogus default value from arguments field
[project/luci.git] / applications / luci-commands / luasrc / view / commands.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2012 Jo-Philipp Wich <jow@openwrt.org>
4
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
8
9         http://www.apache.org/licenses/LICENSE-2.0
10
11 -%>
12
13 <%+header%>
14
15 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
16 <script type="text/javascript">//<![CDATA[
17         var stxhr = new XHR();
18
19         function command_run(id)
20         {
21                 var args;
22                 var field = document.getElementById(id);
23                 if (field)
24                         args = encodeURIComponent(field.value);
25
26                 var legend = document.getElementById('command-rc-legend');
27                 var output = document.getElementById('command-rc-output');
28
29                 if (legend && output)
30                 {
31                         output.innerHTML =
32                                 '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
33                                 '<%:Waiting for command to complete...%>'
34                         ;
35
36                         legend.parentNode.style.display = 'block';
37                         legend.style.display = 'inline';
38
39                         stxhr.get('<%=luci.dispatcher.build_url("admin", "system", "commands", "run")%>/' + id + (args ? '/' + args : ''), null,
40                                 function(x, st)
41                                 {
42                                         if (st)
43                                         {
44                                                 if (st.binary)
45                                                         st.stdout = '[<%:Binary data not displayed, download instead.%>]';
46
47                                                 legend.style.display = 'none';
48                                                 output.innerHTML = String.format(
49                                                         '<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' +
50                                                         '<div class="alert-message warning">%s (<%:Code:%> %d)</div>',
51                                                         st.command, st.stdout, st.stderr,
52                                                         (st.exitcode == 0) ? '<%:Command successful%>' : '<%:Command failed%>',
53                                                         st.exitcode);
54                                         }
55                                         else
56                                         {
57                                                 legend.style.display = 'none';
58                                                 output.innerHTML = '<span class="error"><%:Failed to execute command!%></span>';
59                                         }
60
61                                         location.hash = '#output';
62                                 }
63                         );
64                 }
65         }
66
67         function command_download(id)
68         {
69                 var args;
70                 var field = document.getElementById(id);
71                 if (field)
72                         args = encodeURIComponent(field.value);
73
74                 location.href = '<%=luci.dispatcher.build_url("admin", "system", "commands", "download")%>/' + id + (args ? '/' + args : '');
75         }
76
77         function command_link(id)
78         {
79                 var legend = document.getElementById('command-rc-legend');
80                 var output = document.getElementById('command-rc-output');
81
82                 var args;
83                 var field = document.getElementById(id);
84                 if (field)
85                         args = encodeURIComponent(field.value);
86
87                 if (legend && output)
88                 {
89                         var link = location.protocol + '//' + location.hostname +
90                                    (location.port ? ':' + location.port : '') +
91                                            location.pathname.split(';')[0] + 'command/' +
92                                            id + (args ? '/' + args : '');
93
94                         legend.style.display = 'none';
95                         output.parentNode.style.display = 'block';
96                         output.innerHTML = String.format(
97                                 '<div class="alert-message warning"><%:Access command with%> <a href="%s">%s</a></div>',
98                                 link, link
99                         );
100
101                         location.hash = '#output';
102                 }
103         }
104
105 //]]></script>
106
107 <%
108         local uci = require "luci.model.uci".cursor()
109         local commands = { }
110
111         uci:foreach("luci", "command", function(s) commands[#commands+1] = s end)
112 %>
113
114 <form method="get" action="<%=pcdata(luci.http.getenv("REQUEST_URI"))%>">
115         <div class="cbi-map">
116                 <h2><a id="content" name="content"><%:Custom Commands%></a></h2>
117
118                 <fieldset class="cbi-section">
119                         <% local _, command; for _, command in ipairs(commands) do %>
120                         <div style="width:30%; float:left; height:150px; position:relative">
121                                 <h3><%=pcdata(command.name)%></h3>
122                                 <p><%:Command:%> <code><%=pcdata(command.command)%></code></p>
123                                 <% if command.param == "1" then %>
124                                         <p><%:Arguments:%> <input style="width: 50%" type="text" id="<%=command['.name']%>" /></p>
125                                 <% end %>
126                                 <div style="position:absolute; left:0; bottom:20px">
127                                         <input type="button" value="<%:Run%>" class="cbi-button cbi-button-apply" onclick="command_run('<%=command['.name']%>')" />
128                                         <input type="button" value="<%:Download%>" class="cbi-button cbi-button-download" onclick="command_download('<%=command['.name']%>')" />
129                                         <% if command.public == "1" then %>
130                                                 <input type="button" value="<%:Link%>" class="cbi-button cbi-button-link" onclick="command_link('<%=command['.name']%>')" />
131                                         <% end %>
132                                 </div>
133                         </div>
134                         <% end %>
135
136                         <br style="clear:both" /><br />
137                         <a name="output"></a>
138                 </fieldset>
139         </div>
140
141         <fieldset class="cbi-section" style="display:none">
142                 <legend id="command-rc-legend"><%:Collecting data...%></legend>
143                 <span id="command-rc-output"></span>
144         </fieldset>
145 </form>
146
147 <%+footer%>