overview_status.htm 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!-- ++ BEGIN ++ Dynamic DNS ++ overview_status.htm ++ -->
  2. <script type="text/javascript">//<![CDATA[
  3. // helper to extract section from objects id
  4. // cbi.ddns.SECTION._xyz
  5. function _id2section(id) {
  6. var x = id.split(".");
  7. return x[2];
  8. }
  9. // helper to move status data to the relevant
  10. // screen objects
  11. // called by XHR.poll and onclick_startstop
  12. function _data2elements(data) {
  13. // Service sections
  14. for( i = 1; i < data.length; i++ )
  15. {
  16. var section = data[i].section // Section to handle
  17. var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
  18. var btn = document.getElementById("cbid.ddns." + section + "._startstop"); // Start/Stop button
  19. var rip = document.getElementById("cbid.ddns." + section + "._domainIP.two"); // Registered IP
  20. var lup = document.getElementById("cbid.ddns." + section + "._update.one"); // Last Update
  21. var nup = document.getElementById("cbid.ddns." + section + "._update.two"); // Next Update
  22. if ( !(cbx && btn && rip && lup && nup) ) { return; } // security check
  23. // process id
  24. if (data[i].pid > 0) {
  25. // stop always possible if process running
  26. btn.value = "PID: " + data[i].pid;
  27. btn.className = "cbi-button cbi-input-reset";
  28. } else {
  29. // default Start / enabled
  30. btn.value = "<%:Start%>";
  31. btn.className = "cbi-button cbi-input-apply";
  32. }
  33. btn.disabled = false; // button enabled
  34. // last update
  35. switch (data[i].datelast) {
  36. case "_empty_":
  37. lup.innerHTML = '<em><%:Unknown error%></em>' ;
  38. break;
  39. case "_never_":
  40. lup.innerHTML = '<em><%:Never%></em>' ;
  41. break;
  42. default:
  43. lup.innerHTML = data[i].datelast;
  44. break;
  45. }
  46. // next update
  47. switch (data[i].datenext) {
  48. case "_empty_":
  49. nup.innerHTML = '<em><%:Unknown error%></em>' ;
  50. break;
  51. case "_verify_":
  52. nup.innerHTML = '<em><%:Verify%></em>';
  53. break;
  54. case "_runonce_":
  55. case "_stopped_":
  56. case "_disabled_":
  57. if (cbx.checked && data[i].datenext == "_runonce_") {
  58. nup.innerHTML = '<em><%:Run once%></em>';
  59. } else if (cbx.checked) {
  60. nup.innerHTML = '<em><%:Stopped%></em>';
  61. } else {
  62. nup.innerHTML = '<em><%:Disabled%></em>';
  63. btn.value = '----------';
  64. btn.className = "cbi-button cbi-input-button"; // no image
  65. btn.disabled = true; // disabled
  66. }
  67. break;
  68. default:
  69. nup.innerHTML = data[i].datenext;
  70. break;
  71. }
  72. // domain
  73. // (data[i].domain ignored here
  74. // registered IP
  75. // rip.innerHTML = "Registered IP";
  76. if (data[i].domain == "_nodomain_")
  77. rip.innerHTML = '';
  78. else if (data[i].reg_ip == "_nodata_")
  79. rip.innerHTML = '<em><%:No data%></em>';
  80. else
  81. rip.innerHTML = data[i].reg_ip;
  82. // monitored interfacce
  83. // data[i].iface ignored here
  84. }
  85. }
  86. // event handler for enabled checkbox
  87. function onchange_enabled(id) {
  88. // run original function in cbi.js
  89. // whatever is done there
  90. cbi_d_update(id);
  91. var section = _id2section(id);
  92. var cbx = document.getElementById("cbid.ddns." + section + ".enabled");
  93. var btn = document.getElementById("cbid.ddns." + section + "._startstop");
  94. if ( !(cbx && btn) ) { return; } // security check
  95. var pid_txt = btn.value;
  96. var pid_found = ( pid_txt.search("PID") >= 0 ) ? true : false;
  97. if (pid_found) {
  98. // btn.value = "PID: 0000";
  99. btn.className = "cbi-button cbi-button-reset";
  100. btn.disabled = false;
  101. } else if (cbx.checked) {
  102. btn.value = "<%:Start%>";
  103. btn.className = "cbi-button cbi-button-apply";
  104. btn.disabled = false;
  105. } else {
  106. btn.value = '----------';
  107. btn.className = "cbi-button cbi-input-button"; // no image
  108. btn.disabled = true; // disabled
  109. }
  110. }
  111. // event handler for start/stop button
  112. function onclick_startstop(id) {
  113. // extract section
  114. var section = _id2section(id);
  115. // get elements
  116. var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
  117. var obj = document.getElementById("cbi-ddns-overview-status-legend"); // object defined below to make in-/visible
  118. if ( !(obj && cbx) ) { return; } // security check
  119. // make me visible
  120. obj.parentNode.style.display = "block";
  121. // do start/stop
  122. var btnXHR = new XHR();
  123. btnXHR.get('<%=luci.dispatcher.build_url("admin", "services", "ddns", "startstop")%>/' + section + '/' + cbx.checked, null,
  124. function(x, data) {
  125. if (x.responseText == "_uncommitted_") {
  126. // we need a trick to display Ampersand "&" in stead of "&#38;" or "&amp;"
  127. // after translation
  128. txt="<%:Please [Save & Apply] your changes first%>";
  129. alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
  130. } else {
  131. // should have data because status changed
  132. // so update screen
  133. if (data) { _data2elements(data); }
  134. }
  135. // make me invisible
  136. obj.parentNode.style.display = "none";
  137. }
  138. );
  139. }
  140. // force to immediate show status on page load (not waiting for XHR.poll)
  141. XHR.get('<%=luci.dispatcher.build_url("admin", "services", "ddns", "status")%>', null,
  142. function(x, data) {
  143. if (data) { _data2elements(data); }
  144. }
  145. );
  146. // define only ONE XHR.poll in a page because if one is running it blocks the other one
  147. // optimum is to define on Map or Section Level from here you can reach all elements
  148. // we need update every 15 seconds only
  149. XHR.poll(15, '<%=luci.dispatcher.build_url("admin", "services", "ddns", "status")%>', null,
  150. function(x, data) {
  151. if (data) { _data2elements(data); }
  152. }
  153. );
  154. //]]></script>
  155. <fieldset class="cbi-section" style="display:none">
  156. <legend id="cbi-ddns-overview-status-legend"><%:Applying changes%></legend>
  157. <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
  158. <span id="cbi-ddns-overview-status-text"><%:Waiting for changes to be applied...%></span>
  159. </fieldset>
  160. <!-- ++ END ++ Dynamic DNS ++ overview_status.htm ++ -->