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
15 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
16 <script type="text/javascript">//<![CDATA[
17 var stxhr = new XHR();
19 function command_run(id)
22 var field = document.getElementById(id);
24 args = encodeURIComponent(field.value);
26 var legend = document.getElementById('command-rc-legend');
27 var output = document.getElementById('command-rc-output');
32 '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
33 '<%:Waiting for command to complete...%>'
36 legend.parentNode.style.display = 'block';
37 legend.style.display = 'inline';
39 stxhr.get('<%=luci.dispatcher.build_url("admin", "system", "commands", "run")%>/' + id + (args ? '/' + args : ''), null,
45 st.stdout = '[<%:Binary data not displayed, download instead.%>]';
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%>',
57 legend.style.display = 'none';
58 output.innerHTML = '<span class="error"><%:Failed to execute command!%></span>';
61 location.hash = '#output';
67 function command_download(id)
70 var field = document.getElementById(id);
72 args = encodeURIComponent(field.value);
74 location.href = '<%=luci.dispatcher.build_url("admin", "system", "commands", "download")%>/' + id + (args ? '/' + args : '');
77 function command_link(id)
79 var legend = document.getElementById('command-rc-legend');
80 var output = document.getElementById('command-rc-output');
83 var field = document.getElementById(id);
85 args = encodeURIComponent(field.value);
89 var link = location.protocol + '//' + location.hostname +
90 (location.port ? ':' + location.port : '') +
91 location.pathname.split(';')[0] + 'command/' +
92 id + (args ? '/' + args : '');
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>',
101 location.hash = '#output';
108 local uci = require "luci.model.uci".cursor()
111 uci:foreach("luci", "command", function(s) commands[#commands+1] = s end)
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>
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" value="openwrt.org" id="<%=command['.name']%>" /></p>
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']%>')" />
136 <br style="clear:both" /><br />
137 <a name="output"></a>
141 <fieldset class="cbi-section" style="display:none">
142 <legend id="command-rc-legend"><%:Collecting data...%></legend>
143 <span id="command-rc-output"></span>