Advertisement
d00m178

Test menu in Openwrt

Mar 31st, 2018
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. <%+header%>
  2.  
  3. <%
  4. local fs = require "nixio.fs"
  5. %>
  6.  
  7. <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
  8. <script type="text/javascript">//<![CDATA[
  9. ////////////////////////////////////////////////////////////////////////////////////////////////
  10.  
  11. //https://github.com/nelsonic/stopwatch
  12.  
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
  14.  
  15. // global object
  16. T = {} ;
  17.  
  18. function displayTimer() {
  19.  
  20. T.timerDiv = document.getElementById("timer");
  21.  
  22. // initilized all local variables:
  23. var hours='00', minutes='00',
  24. miliseconds=0, seconds='00',
  25. time = '',
  26. timeNow = new Date().getTime(); // timestamp (miliseconds)
  27.  
  28. T.difference = timeNow - T.timerStarted;
  29.  
  30. // milliseconds
  31. if(T.difference > 10) {
  32. miliseconds = Math.floor((T.difference % 1000) / 10);
  33. if(miliseconds < 10) {
  34. miliseconds = '0'+String(miliseconds);
  35. }
  36. }
  37. // seconds
  38. if(T.difference > 1000) {
  39. seconds = Math.floor(T.difference / 1000);
  40. if (seconds > 60) {
  41. seconds = seconds % 60;
  42. }
  43. if(seconds < 10) {
  44. seconds = '0'+String(seconds);
  45. }
  46. }
  47.  
  48. // minutes
  49. if(T.difference > 60000) {
  50. minutes = Math.floor(T.difference/60000);
  51. if (minutes > 60) {
  52. minutes = minutes % 60;
  53. }
  54. if(minutes < 10) {
  55. minutes = '0'+String(minutes);
  56. }
  57. }
  58.  
  59. // hours
  60. if(T.difference > 3600000) {
  61. hours = Math.floor(T.difference/3600000);
  62. // if (hours > 24) {
  63. // hours = hours % 24;
  64. // }
  65. if(hours < 10) {
  66. hours = '0'+String(hours);
  67. }
  68. }
  69.  
  70. time = hours + ':'
  71. time += minutes + ':'
  72. time += seconds + ':'
  73. time += miliseconds;
  74.  
  75. T.timerDiv.innerHTML = time;
  76. }
  77.  
  78. function startTimer() {
  79. // save start time
  80. T.timerStarted = new Date().getTime()
  81. console.log('T.timerStarted: '+T.timerStarted)
  82.  
  83. if (T.difference > 0) {
  84. T.timerStarted = T.timerStarted - T.difference
  85. }
  86. // update timer periodically
  87. T.timerInterval = setInterval(function() {
  88. displayTimer()
  89. }, 10);
  90.  
  91. // show / hide the relevant buttons:
  92. //document.getElementById('go').style.display="none";
  93. //document.getElementById('stop').style.display="inline";
  94. //document.getElementById('clear').style.display="none";
  95. }
  96.  
  97. function stopTimer() {
  98. clearInterval(T.timerInterval); // stop updating the timer
  99.  
  100. //document.getElementById('stop').style.display="none";
  101. //document.getElementById('go').style.display="inline";
  102. //document.getElementById('clear').style.display="inline";
  103. }
  104.  
  105. function clearTimer() {
  106.  
  107. T.timerDiv = document.getElementById("timer");
  108.  
  109. clearInterval(T.timerInterval);
  110. T.timerDiv.innerHTML = "00:00:00:00"; // reset timer to all zeros
  111. T.difference = 0;
  112.  
  113. //document.getElementById('stop').style.display="none";
  114. //document.getElementById('go').style.display="inline";
  115. //document.getElementById('clear').style.display="none";
  116. }
  117.  
  118. ////////////////////////////////////////////////////////////////////////////////////////////////
  119.  
  120. var stxhr = new XHR();
  121.  
  122. function update_status(field)
  123. {
  124. var tool = field.name;
  125. var addr = field.value;
  126.  
  127. var legend = document.getElementById('diag-rc-legend');
  128. var output = document.getElementById('diag-rc-output');
  129.  
  130. stopTimer();
  131. clearTimer();
  132. startTimer();
  133.  
  134. if (legend && output)
  135. {
  136. output.innerHTML =
  137. '<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
  138. '<%:Waiting for command to complete...%>'
  139. ;
  140.  
  141. legend.parentNode.style.display = 'block';
  142. legend.style.display = 'inline';
  143.  
  144. stxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/diag_' + tool + '/' + addr, null,
  145.  
  146. function(x)
  147. {
  148. if (x.responseText)
  149. {
  150. legend.style.display = 'none';
  151. output.innerHTML = String.format('<pre>%h</pre>', x.responseText);
  152. stopTimer();
  153.  
  154. }
  155. else
  156. {
  157. legend.style.display = 'none';
  158. output.innerHTML = '<span class="error"><%:Bad address specified!%></span>';
  159. }
  160. }
  161. );
  162.  
  163. }
  164. }
  165.  
  166. //]]></script>
  167.  
  168. <form method="post" action="<%=pcdata(luci.http.getenv("REQUEST_URI"))%>">
  169.  
  170. <div class="cbi-map">
  171. <h2><a id="content" name="content"><%:REMOTE CLIENT%></a></h2>
  172.  
  173. <fieldset class="cbi-section">
  174. <legend><%:Enter server ID and send request%></legend>
  175.  
  176. <br />
  177.  
  178. <div style="width:33%; float:left;">
  179. <input style="margin: 5px 0" type="text" value="enter server ID" name="send" /><br />
  180. <input type="button" value="<%:Send%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.send)" />
  181. <br>
  182. <br>
  183.  
  184. </div>
  185.  
  186. <br style="clear:both" /><br />
  187.  
  188. </fieldset>
  189. </div>
  190.  
  191. <input type="button" name="stop" value="<%:Stop%>" class="cbi-button cbi-button-apply" onclick="update_status(this.form.stop)" />
  192.  
  193. <fieldset class="cbi-section" style="display:none">
  194. <legend id="diag-rc-legend"><%:Loading ...%></legend>
  195. <span id="timer">00:00:00:00</span>
  196. <span id="diag-rc-output"></span>
  197. </fieldset>
  198. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement