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.

273 lines
7.7 KiB

7 years ago
  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 new 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(pydashUrls['uptime'], "#get-uptime");
  88. };
  89. dashboard.getOSname = function () {
  90. get_os_data( pydashUrls['platform'] + 'osname/', "#get-osname");
  91. };
  92. dashboard.getHostname = function () {
  93. get_os_data( pydashUrls['platform'] + 'hostname/', "#get-hostname");
  94. };
  95. dashboard.getKernel = function () {
  96. get_os_data( pydashUrls['platform'] + 'kernel/', "#get-kernel");
  97. };
  98. dashboard.getCPUcount = function () {
  99. get_os_data( pydashUrls['getcpus'] + 'count/', "#get-cpucount");
  100. };
  101. dashboard.getCPUtype = function () {
  102. get_os_data( pydashUrls['getcpus'] + 'type/', "#get-cputype");
  103. };
  104. dashboard.getDisk = function () {
  105. $.getJSON( pydashUrls['getdisk'], function (data) {
  106. destroy_dataTable("get_disk");
  107. var $filterPs = $("#filter-ps");
  108. $filterPs.val("").off("keyup");
  109. var psTable = $("#get_disk").dataTable({
  110. aaData: data,
  111. aoColumns: [
  112. { sTitle: "FILESYSTEM" },
  113. { sTitle: "SIZE" },
  114. { sTitle: "USED" },
  115. { sTitle: "AVAIL" },
  116. { sTitle: "USE %" },
  117. { sTitle: "MOUNTED" }
  118. ],
  119. bPaginate: false,
  120. bFilter: true,
  121. sDom: "lrtip",
  122. bAutoWidth: false,
  123. bInfo: false
  124. }).fadeIn();
  125. $filterPs.on("keyup", function () {
  126. psTable.fnFilter(this.value);
  127. });
  128. });
  129. };
  130. dashboard.getUsers = function () {
  131. $.getJSON( pydashUrls['getusers'], function (data) {
  132. destroy_dataTable("get_users");
  133. var $filterPs = $("#filter-ps");
  134. $filterPs.val("").off("keyup");
  135. var psTable = $("#get_users").dataTable({
  136. aaData: data,
  137. aoColumns: [
  138. { sTitle: "USER" },
  139. { sTitle: "TTY" },
  140. { sTitle: "LOOGED IN FROM",
  141. sDefaultContent: "unavailable" }
  142. ],
  143. aaSorting: [
  144. [0, "desc"]
  145. ],
  146. bPaginate: true,
  147. sPaginationType: "two_button",
  148. bFilter: false,
  149. bAutoWidth: false,
  150. bInfo: false
  151. }).fadeIn();
  152. $filterPs.on("keyup", function () {
  153. psTable.fnFilter(this.value);
  154. });
  155. });
  156. };
  157. dashboard.getNetstat = function () {
  158. $.getJSON( pydashUrls['getnetstat'], function (data) {
  159. destroy_dataTable("get_netstat");
  160. var $filterPs = $("#filter-ps");
  161. $filterPs.val("").off("keyup");
  162. var psTable = $("#get_netstat").dataTable({
  163. aaData: data,
  164. aoColumns: [
  165. { sTitle: "COUNT" },
  166. { sTitle: "LOCAL IP" },
  167. { sTitle: "LOCAL PORT" },
  168. { sTitle: "FOREIGN" }
  169. ],
  170. bPaginate: true,
  171. sPaginationType: "two_button",
  172. bFilter: true,
  173. sDom: "lrtip",
  174. bAutoWidth: false,
  175. bInfo: false
  176. }).fadeIn();
  177. $filterPs.on("keyup", function () {
  178. psTable.fnFilter(this.value);
  179. });
  180. });
  181. };
  182. dashboard.getProc = function () {
  183. $.getJSON( pydashUrls['getproc'], function (data) {
  184. destroy_dataTable("get_proc");
  185. var $filterPs = $("#filter-ps");
  186. $filterPs.val("").off("keyup");
  187. var psTable = $("#get_proc").dataTable({
  188. aaData: data,
  189. aoColumns: [
  190. { sTitle: "USER" },
  191. { sTitle: "PID" },
  192. { sTitle: "%CPU" },
  193. { sTitle: "%MEM" },
  194. { sTitle: "VSZ" },
  195. { sTitle: "RSS" },
  196. { sTitle: "TTY" },
  197. { sTitle: "STAT" },
  198. { sTitle: "START" },
  199. { sTitle: "TIME" },
  200. { sTitle: "COMMAND" }
  201. ],
  202. bPaginate: true,
  203. sPaginationType: "full_numbers",
  204. bFilter: true,
  205. sDom: "lrtip",
  206. bAutoWidth: false,
  207. bInfo: false
  208. }).fadeIn();
  209. $filterPs.on("keyup", function () {
  210. psTable.fnFilter(this.value);
  211. });
  212. });
  213. };
  214. dashboard.getIps = function () {
  215. $.getJSON( pydashUrls['getips'], function (data) {
  216. destroy_dataTable("get_ips");
  217. var $filterPs = $("#filter-ps");
  218. $filterPs.val("").off("keyup");
  219. var psTable = $("#get_ips").dataTable({
  220. aaData: data,
  221. aoColumns: [
  222. { sTitle: "INTERFACE" },
  223. { sTitle: "MAC ADDRESS" },
  224. { sTitle: "IP ADDRESS" },
  225. { sTitle: "IP ADDRESS",
  226. sDefaultContent: "unavailable" }
  227. ],
  228. bPaginate: false,
  229. bFilter: true,
  230. sDom: "lrtip",
  231. bAutoWidth: false,
  232. bInfo: false
  233. }).fadeIn();
  234. $filterPs.on("keyup", function () {
  235. psTable.fnFilter(this.value);
  236. });
  237. });
  238. };
  239. // Expand-Contract div/table
  240. $(document).ready(function () {
  241. $(".widget-content").show();
  242. $(".widget-header").click(function () {
  243. $(this).next(".widget-content").slideToggle(500);
  244. $("i", this).toggleClass("icon-minus icon-plus");
  245. });
  246. });