BLUSHIF

Untitled

Aug 7th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>SWPR</title>
  5. </head>
  6. <body onload="ldx();">
  7. <style type="text/css">
  8. .responded {
  9. color:green;
  10. }
  11. .checking,.unchecked {
  12. color:#FF8C00;
  13. }
  14. .timeout {
  15. color:red;
  16. }
  17. </style>
  18. <ul data-bind="foreach:servers">
  19. <li> <a href="#" data-bind="text:name,attr:{href: 'http://'+name}">tester</a> <span data-bind="text:status,css:status"></span>
  20. </li>
  21. </ul>
  22. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  23. <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
  24. <script>
  25. function ping(ip, callback) {
  26. if (!this.inUse) {
  27. this.status = 'unchecked';
  28. this.inUse = true;
  29. this.callback = callback;
  30. this.ip = ip;
  31. var _that = this;
  32. this.img = new Image();
  33. this.img.onload = function () {
  34. _that.inUse = false;
  35. _that.callback('responded');
  36. wrt(ip);
  37. };
  38. this.img.onerror = function (e) {
  39. if (_that.inUse) {
  40. _that.inUse = false;
  41. _that.callback('responded', e);
  42. wrt(ip);
  43. }
  44. };
  45. this.start = new Date().getTime();
  46. this.img.src = "http://" + ip;
  47. this.timer = setTimeout(function () {
  48. if (_that.inUse) {
  49. _that.inUse = false;
  50. _that.callback('timeout');
  51. }
  52. }, 1500);
  53. }
  54. }
  55. var PingModel = function (servers) {
  56. var self = this;
  57. var myServers = [];
  58. ko.utils.arrayForEach(servers, function (location) {
  59. myServers.push({
  60. name: location,
  61. status: ko.observable('unchecked')
  62. });
  63. });
  64. self.servers = ko.observableArray(myServers);
  65. ko.utils.arrayForEach(self.servers(), function (s) {
  66. s.status('checking');
  67. new ping(s.name, function (status, e) {
  68. s.status(status);
  69. });
  70. });
  71. };
  72. var arr = ["localhost:8080"];
  73. function wrt(string){
  74. arr.push("http://"+string);
  75. console.log(arr);
  76. ldx();
  77. }
  78. function ldx() {
  79. const ip1 = Myraspberrypiserver1;
  80. const ip2 = Myraspberrypiserver2;
  81. const ip3 = Myraspberrypiserver3;
  82. const ip4 = Myraspberrypiserver4;<--these are all placeholders for the actual ip addrs
  83. const ip5 = Myraspberrypiserver5;
  84. var komodel = new PingModel([ip1,ip2,ip3,ip4,ip5]);
  85. ko.applyBindings(komodel);
  86. }
  87. </script>
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment