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.

247 lines
7.5 KiB

  1. //DataTables
  2. //Sort file size data.
  3. jQuery.extend(jQuery.fn.dataTableExt.oSort, {
  4. "file-size-units": {
  5. K : 1024,
  6. M : Math.pow(1024, 2),
  7. G : Math.pow(1024, 3),
  8. T : Math.pow(1024, 4),
  9. P : Math.pow(1024, 5),
  10. E : Math.pow(1024, 6)
  11. },
  12. "file-size-pre": function(a) {
  13. var x = a.substring(0, a.length - 1);
  14. var x_unit = a.substring(a.length - 1, a.length);
  15. if(jQuery.fn.dataTableExt.oSort['file-size-units'][x_unit]) {
  16. return parseInt(x * jQuery.fn.dataTableExt.oSort['file-size-units'][x_unit], 10);
  17. }
  18. else {
  19. return parseInt(x + x_unit, 10);
  20. }
  21. },
  22. "file-size-asc": function(a, b) {
  23. return ((a < b) ? -1 : ((a > b) ? 1 : 0));
  24. },
  25. "file-size-desc": function(a, b) {
  26. return ((a < b) ? 1 : ((a > b) ? -1 : 0));
  27. }
  28. });
  29. //DataTables
  30. //Sort numeric data which has a percent sign with it.
  31. jQuery.extend(jQuery.fn.dataTableExt.oSort, {
  32. "percent-pre": function(a) {
  33. var x = (a === "-") ? 0 : a.replace(/%/, "");
  34. return parseFloat(x);
  35. },
  36. "percent-asc": function(a, b) {
  37. return ((a < b) ? -1 : ((a > b) ? 1 : 0));
  38. },
  39. "percent-desc": function(a, b) {
  40. return ((a < b) ? 1 : ((a > b) ? -1 : 0));
  41. }
  42. });
  43. //DataTables
  44. //Sort IP addresses
  45. jQuery.extend(jQuery.fn.dataTableExt.oSort, {
  46. "ip-address-pre": function(a) {
  47. // split the address into octets
  48. //
  49. var x = a.split('.');
  50. // pad each of the octets to three digits in length
  51. //
  52. function zeroPad(num, places) {
  53. var zero = places - num.toString().length + 1;
  54. return Array(+(zero > 0 && zero)).join("0") + num;
  55. }
  56. // build the resulting IP
  57. var r = '';
  58. for(var i=0; i<x.length; i++)
  59. r = r + zeroPad(x[i],3);
  60. // return the formatted IP address
  61. //
  62. return r;
  63. },
  64. "ip-address-asc": function(a, b) {
  65. return ((a < b) ? -1 : ((a > b) ? 1 : 0));
  66. },
  67. "ip-address-desc": function(a, b) {
  68. return ((a < b) ? 1 : ((a > b) ? -1 : 0));
  69. }
  70. });
  71. // If dataTable with provided ID exists, destroy it.
  72. function destroy_dataTable(table_id) {
  73. var table = $("#" + table_id);
  74. var ex = document.getElementById(table_id);
  75. if ($.fn.DataTable.fnIsDataTable(ex)) {
  76. table.hide().dataTable().fnClearTable();
  77. table.dataTable().fnDestroy();
  78. }
  79. }
  80. function get_os_data(url, element) {
  81. $.get(url, function(data) {
  82. $(element).text(data);
  83. }, "json");
  84. }
  85. var dashboard = {};
  86. dashboard.getUptime = function() {
  87. get_os_data('/info/uptime/', "#get-uptime");
  88. }
  89. dashboard.getOSname = function() {
  90. get_os_data('/info/platform/osname/', "#get-osname");
  91. }
  92. dashboard.getHostname = function() {
  93. get_os_data('/info/platform/hostname/', "#get-hostname");
  94. }
  95. dashboard.getKernel = function() {
  96. get_os_data('/info/platform/kernel/', "#get-kernel");
  97. }
  98. dashboard.getCPUcount = function() {
  99. get_os_data('/info/getcpus/count/', "#get-cpucount");
  100. }
  101. dashboard.getCPUtype = function() {
  102. get_os_data('/info/getcpus/type/', "#get-cputype");
  103. }
  104. dashboard.getDisk = function() {
  105. $.getJSON('/info/getdisk/', function(data) {
  106. destroy_dataTable("get_disk");
  107. $("#filter-ps").val("").off("keyup");
  108. var psTable = $("#get_disk").dataTable({
  109. aaData: data,
  110. aoColumns: [
  111. { sTitle: "FILESYSTEM" },
  112. { sTitle: "SIZE" },
  113. { sTitle: "USED" },
  114. { sTitle: "AVAIL" },
  115. { sTitle: "USE %" },
  116. { sTitle: "MOUNTED" }
  117. ],
  118. bPaginate: false,
  119. bFilter: true,
  120. sDom: "lrtip",
  121. bAutoWidth: false,
  122. bInfo: false
  123. }).fadeIn();
  124. $("#filter-ps").on("keyup", function() {
  125. psTable.fnFilter(this.value);
  126. });
  127. });
  128. }
  129. dashboard.getUsers = function() {
  130. $.getJSON('/info/getusers/', function(data) {
  131. destroy_dataTable("get_users");
  132. $("#filter-ps").val("").off("keyup");
  133. var psTable = $("#get_users").dataTable({
  134. aaData: data,
  135. aoColumns: [
  136. { sTitle: "USER" },
  137. { sTitle: "TTY" },
  138. { sTitle: "LOOGED IN FROM" }
  139. ],
  140. bPaginate: false,
  141. bFilter: true,
  142. sDom: "lrtip",
  143. bAutoWidth: false,
  144. bInfo: false
  145. }).fadeIn();
  146. $("#filter-ps").on("keyup", function() {
  147. psTable.fnFilter(this.value);
  148. });
  149. });
  150. }
  151. dashboard.getNetstat = function() {
  152. $.getJSON('/info/getnetstat/', function(data) {
  153. destroy_dataTable("get_netstat");
  154. $("#filter-ps").val("").off("keyup");
  155. var psTable = $("#get_netstat").dataTable({
  156. aaData: data,
  157. aoColumns: [
  158. { sTitle: "COUNT" },
  159. { sTitle: "LOCAL IP" },
  160. { sTitle: "LOCAL PORT" },
  161. { sTitle: "FOREIGN" }
  162. ],
  163. bPaginate: true,
  164. sPaginationType: "two_button",
  165. bFilter: true,
  166. sDom: "lrtip",
  167. bAutoWidth: false,
  168. bInfo: false
  169. }).fadeIn();
  170. $("#filter-ps").on("keyup", function() {
  171. psTable.fnFilter(this.value);
  172. });
  173. });
  174. }
  175. dashboard.getProc = function() {
  176. $.getJSON('/info/proc/', function(data) {
  177. destroy_dataTable("get_proc");
  178. $("#filter-ps").val("").off("keyup");
  179. var psTable = $("#get_proc").dataTable({
  180. aaData: data,
  181. aoColumns: [
  182. { sTitle: "USER" },
  183. { sTitle: "PID" },
  184. { sTitle: "%CPU" },
  185. { sTitle: "%MEM" },
  186. { sTitle: "VSZ" },
  187. { sTitle: "RSS" },
  188. { sTitle: "TTY" },
  189. { sTitle: "STAT" },
  190. { sTitle: "START" },
  191. { sTitle: "TIME" },
  192. { sTitle: "COMMAND" }
  193. ],
  194. bPaginate: true,
  195. sPaginationType: "full_numbers",
  196. bFilter: true,
  197. sDom: "lrtip",
  198. bAutoWidth: false,
  199. bInfo: false
  200. }).fadeIn();
  201. $("#filter-ps").on("keyup", function() {
  202. psTable.fnFilter(this.value);
  203. });
  204. });
  205. }
  206. dashboard.getIps = function() {
  207. $.getJSON('/info/getips/', function(data) {
  208. destroy_dataTable("get_ips");
  209. $("#filter-ps").val("").off("keyup");
  210. var psTable = $("#get_ips").dataTable({
  211. aaData: data,
  212. aoColumns: [
  213. { sTitle: "INTERFACE" },
  214. { sTitle: "MAC ADDRESS" },
  215. { sTitle: "IPv4 ADDRESS" },
  216. { sTitle: "IPv6 ADDRESS" }
  217. ],
  218. bPaginate: false,
  219. bFilter: true,
  220. sDom: "lrtip",
  221. bAutoWidth: false,
  222. bInfo: false
  223. }).fadeIn();
  224. $("#filter-ps").on("keyup", function() {
  225. psTable.fnFilter(this.value);
  226. });
  227. });
  228. }