You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
8.6 KiB

  1. /*******************************
  2. Abstracted Functions
  3. *******************************/
  4. // Gets data from provided url
  5. // and updates DOM element (element variable)
  6. function generate_os_data(url, element){
  7. $.get( url, function( data ) {
  8. $(element).text(data);
  9. } );
  10. }
  11. // If dataTable with proved ID (table_id)
  12. // exists, destroy it. Obliterate it.
  13. // Leave no evidence.
  14. function destroy_dataTable(table_id){
  15. var table = $('#'+table_id);
  16. var ex = document.getElementById(table_id);
  17. if ( $.fn.DataTable.fnIsDataTable( ex ) ) {
  18. table.hide().dataTable().fnClearTable();
  19. table.dataTable( ).fnDestroy();
  20. }
  21. }
  22. // Function and variables to refresh page data &
  23. // counter on top right of page
  24. var page_refresh_counter = $('#page_data_refresh');
  25. function page_data_refresh_tick(){
  26. if (Number( page_refresh_counter.text() )==0){
  27. refresh_all();
  28. page_refresh_counter.fadeOut().text(20).fadeIn();
  29. setTimeout(function(){ page_data_refresh_tick(); },1000);
  30. return false;
  31. }
  32. else{
  33. setTimeout(function(){
  34. page_refresh_counter.text( Number(page_refresh_counter.text())-1);
  35. page_data_refresh_tick();
  36. },1000);
  37. }
  38. }
  39. /*******************************
  40. Data Call Functions
  41. *******************************/
  42. function get_ps(){
  43. $.get( "sh/ps.php", function( data ) {
  44. destroy_dataTable('ps_dashboard');
  45. $('#filter-ps').val('').off('keyup');
  46. var psTable = $('#ps_dashboard').dataTable({
  47. "aaData": data,
  48. "aoColumns": [
  49. { "sTitle":"USER","mDataProp":null },
  50. { "sTitle":"PID","mDataProp":null },
  51. { "sTitle":"%CPU","mDataProp":null },
  52. { "sTitle":"%MEM","mDataProp":null },
  53. { "sTitle":"VSZ","mDataProp":null },
  54. { "sTitle":"RSS","mDataProp":null },
  55. { "sTitle":"TTY","mDataProp":null },
  56. { "sTitle":"STAT","mDataProp":null },
  57. { "sTitle":"START","mDataProp":null },
  58. { "sTitle":"TIME","mDataProp":null },
  59. { "sTitle":"COMMAND","mDataProp":null }
  60. ],
  61. "bPaginate": true,
  62. "sPaginationType": "full_numbers",
  63. "bFilter": true,
  64. "sDom": "lrtip",
  65. "bAutoWidth": false,
  66. "bInfo": false
  67. }).fadeIn();
  68. $('#filter-ps').on('keyup',function(){
  69. psTable.fnFilter(this.value);
  70. });
  71. }, "json" );
  72. }
  73. function get_users(){
  74. $.get( "sh/users.php", function( data ) {
  75. destroy_dataTable('users_dashboard');
  76. $('#users_dashboard').dataTable({
  77. "aaData": data,
  78. "aoColumns": [
  79. { "sTitle":"Type","mDataProp":null },
  80. { "sTitle":"User","mDataProp":null },
  81. { "sTitle":"Home","mDataProp":null }
  82. ],
  83. "aaSorting": [[ 0, "desc" ]],
  84. "iDisplayLength": 5,
  85. "bPaginate": true,
  86. "sPaginationType": "full_numbers",
  87. "bFilter": false,
  88. "bAutoWidth": false,
  89. "bInfo": false
  90. }).fadeIn();
  91. }, "json" );
  92. $('select[name="users_dashboard_length"]').val('5');
  93. }
  94. function get_online(){
  95. $.get( "sh/online.php", function( data ) {
  96. destroy_dataTable('online_dashboard');
  97. $('#online_dashboard').dataTable({
  98. "aaData": data,
  99. "aoColumns": [
  100. { "sTitle":"Who","mDataProp":null },
  101. { "sTitle":"From","mDataProp":null },
  102. { "sTitle":"Login At","mDataProp":null },
  103. { "sTitle":"Idle","mDataProp":null }
  104. ],
  105. "aaSorting": [[ 0, "desc" ]],
  106. "iDisplayLength": 5,
  107. "bPaginate": true,
  108. "sPaginationType": "full_numbers",
  109. "bFilter": false,
  110. "bAutoWidth": false,
  111. "bInfo": false
  112. }).fadeIn();
  113. }, "json" );
  114. $('select[name="online_dashboard_length"]').val('5');
  115. }
  116. function get_ram(){
  117. $.get( "sh/mem.php", function( data ) {
  118. var ram_total = data[1];
  119. var ram_used = parseInt( (data[2]/ram_total)*100);
  120. var ram_free = parseInt( (data[3]/ram_total)*100);
  121. $('#ram-total').text(ram_total);
  122. $('#ram-used').text(data[2]);
  123. $('#ram-free').text(data[3]);
  124. $('#ram-free-per').text( ram_free );
  125. $('#ram-used-per').text( ram_used );
  126. }, "json" );
  127. }
  128. function get_df(){
  129. $.get( '{{ getdisk }}' , function( data ) {
  130. var table = $('#df_dashboard');
  131. var ex = document.getElementById('df_dashboard');
  132. if ( $.fn.DataTable.fnIsDataTable( ex ) ) {
  133. table.hide().dataTable().fnClearTable();
  134. table.dataTable( ).fnDestroy();
  135. }
  136. table.dataTable({
  137. "aaData": data,
  138. "aoColumns": [
  139. { "sTitle":"Filesystem","mDataProp":null },
  140. { "sTitle":"Size","mDataProp":null },
  141. { "sTitle":"Used","mDataProp":null },
  142. { "sTitle":"%Avail","mDataProp":null },
  143. { "sTitle":"Use%","mDataProp":null },
  144. { "sTitle":"Mounted","mDataProp":null }
  145. ],
  146. "bPaginate": false,
  147. "bFilter": false,
  148. "bAutoWidth": true,
  149. "bInfo": false
  150. }).fadeIn();
  151. }, "json" );
  152. }
  153. function get_whereis(){
  154. $.get( "sh/whereis.php", function( data ) {
  155. var table = $('#whereis_dashboard');
  156. var ex = document.getElementById('whereis_dashboard');
  157. if ( $.fn.DataTable.fnIsDataTable( ex ) ) {
  158. table.hide().dataTable().fnClearTable();
  159. table.dataTable( ).fnDestroy();
  160. }
  161. table.dataTable({
  162. "aaData": data,
  163. "aoColumns": [
  164. { "sTitle":"Software","mDataProp":null },
  165. { "sTitle":"Installation","mDataProp":null }
  166. ],
  167. "bPaginate": false,
  168. "bFilter": false,
  169. "aaSorting": [[ 1, "desc" ]],
  170. "bAutoWidth": false,
  171. "bInfo": false
  172. }).fadeIn();
  173. }, "json" );
  174. }
  175. function get_os_info(){
  176. generate_os_data('sh/issue.php','#os-info');
  177. generate_os_data('sh/hostname.php','#os-hostname');
  178. generate_os_data('sh/uptime.php','#os-uptime');
  179. }
  180. function get_ip(){
  181. $.get( 'sh/ip.php', function( data ) {
  182. destroy_dataTable('ip_dashboard');
  183. $('#ip_dashboard').dataTable({
  184. "aaData": data,
  185. "aoColumns": [
  186. { "sTitle":"Interface","mDataProp":null },
  187. { "sTitle":"IP","mDataProp":null }
  188. ],
  189. "bPaginate": false,
  190. "bFilter": false,
  191. "bAutoWidth": true,
  192. "bInfo": false
  193. }).fadeIn();
  194. }, 'json' );
  195. }
  196. function get_ispeed(){
  197. var rate = $('#ispeed-rate');
  198. // 0 = MB
  199. // 1 = KB
  200. var AS = 1;
  201. $.get("sh/speed.php?as=" + AS, function (data) {
  202. rate.text(data);
  203. });
  204. var lead = rate.next(".lead");
  205. if (AS == 0) lead.text("MB/s");
  206. if (AS == 1) lead.text("KB/s");
  207. }
  208. /*
  209. Function that calls all the other functions which refresh
  210. each individual widget
  211. */
  212. function refresh_all(){
  213. get_ram();
  214. get_ps();
  215. get_df();
  216. get_os_info();
  217. get_users();
  218. get_online();
  219. get_whereis();
  220. get_ip();
  221. get_ispeed();
  222. }
  223. // Initialize Page function calls
  224. refresh_all();
  225. //page_data_refresh_tick();