PageRenderTime 29ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/js/helpdesk.js

https://gitlab.com/billyprice1/source
JavaScript | 258 lines | 166 code | 51 blank | 41 comment | 59 complexity | 912e487b4761fb2e079567aef6d57e59 MD5 | raw file
  1. /*global GIGO, Browser, unescape */
  2. /*jslint browser: true */
  3. // Call this early, to enable the isp helpdesk tab
  4. //GIGO.list_of_ipv4 = ["a", "ds4", "test_ipv4"];
  5. //GIGO.list_of_ipv6 = ["aaaa", "ds6", "test_ipv6","test_v6mtu"];
  6. GIGO.start_helpdesk = function () {
  7. var want_helpdesk = 0;
  8. if (GIGO.CGI.isp) {
  9. want_helpdesk = 1;
  10. }
  11. if (GIGO.CGI.helpdesk) {
  12. want_helpdesk = 1;
  13. }
  14. if (String(location.pathname).match(/\b(isp|helpdesk)\b/i)) {
  15. want_helpdesk = 1;
  16. }
  17. if (String(location.hostname).match(/\b(isp|helpdesk)\b/i)) {
  18. want_helpdesk = 1;
  19. }
  20. if (String(location.hash).match(/^(isp|helpdesk)\$/i)) {
  21. want_helpdesk = 1;
  22. }
  23. if (want_helpdesk) {
  24. GIGO.tabnav("helpdesk");
  25. } else {
  26. $("#tabbutton_helpdesk_link").addClass("navright");
  27. }
  28. };
  29. GIGO.helpdesk_ob_status = function (n) {
  30. var s = GIGO.results.tests[n].status;
  31. if (s === "ok") return "g";
  32. if (s === "slow") return "g";
  33. if (s === "bad") return "b";
  34. if (s === "timeout") return "t";
  35. };
  36. GIGO.helpdesk_ob_type = function () {
  37. //# global,bad,teredo,6to4,asn(different)
  38. var t = "b";
  39. if ((GIGO.results.ipv6) && (GIGO.results.ipv6.ip)) {
  40. t = "g"; // By default it must have a global address, right?
  41. if (GIGO.helpdesk.teredo) {
  42. t = "t"; // teredo
  43. }
  44. if (GIGO.helpdesk.sixfour) {
  45. t = "6"; // 6to4
  46. }
  47. if (GIGO.helpdesk.tunnel) {
  48. t = "a"; // Check the ASN
  49. }
  50. }
  51. return t;
  52. };
  53. GIGO.helpdesk_score = function () {
  54. var mini_helpdesk, score;
  55. // GIGO.results.tests[x].status
  56. var status_a = GIGO.helpdesk_ob_status("test_a");
  57. var status_ipv4 = GIGO.helpdesk_ob_status("test_ipv4");
  58. var status_aaaa = GIGO.helpdesk_ob_status("test_aaaa");
  59. var status_ipv6_type = GIGO.helpdesk_ob_type();
  60. var status = status_a + status_ipv4 + ":" + status_aaaa + status_ipv6_type;
  61. var ob = new Object;
  62. ob.found = GIGO.sym_helpdesk[status];
  63. ob.qcode = GIGO.sym_helpdesk_qcode[ob.found];
  64. if (ob.found) {
  65. if (GIGO.helpdesk.failed_pmtud) {
  66. ob.found = ob.found + ", Potential MTU issues";
  67. ob.qcode = ob.qcode + ",mtu";
  68. }
  69. if (GIGO.helpdesk.mini_primary.match(/s/)) {
  70. ob.found = ob.found + ", Slow";
  71. ob.qcode = ob.qcode + ",slow"
  72. }
  73. return ob;
  74. }
  75. return;
  76. };
  77. GIGO.helpdesk_good_bad_slow = function (a) {
  78. var slow = 0;
  79. var good = 0;
  80. var tout = 0;
  81. var i = 0;
  82. for (i = 0; i < a.length; i = i + 1) {
  83. if (GIGO.results.tests[a[i]].status === "ok") {
  84. good = 1;
  85. }
  86. if (GIGO.results.tests[a[i]].status === "slow") {
  87. slow = 1;
  88. }
  89. if (GIGO.results.tests[a[i]].status === "timeout") {
  90. tout = 1;
  91. }
  92. }
  93. if (tout) return "Timeout";
  94. if (slow) return "Slow";
  95. if (good) return "Good";
  96. return "Bad";
  97. };
  98. GIGO.helpdesk_ipv4_info = function () {
  99. var test_a, test_asn4, s;
  100. test_a = GIGO.results.tests.test_a;
  101. test_asn4 = GIGO.results.tests.test_asn4;
  102. // status
  103. // ipinfo.ip
  104. // ipinfo.asn
  105. // ipinfo.asn_name
  106. // time_ms
  107. if ((test_a.ipinfo) && (test_a.ipinfo.ip)) {
  108. s = "IPv4: ";
  109. s = s + GIGO.helpdesk_good_bad_slow(["test_a", "test_ds4", "test_ipv4"]);
  110. if (test_asn4 && test_asn4.ipinfo && test_asn4.ipinfo.asn) {
  111. s = s + ", AS" + test_asn4.ipinfo.asn + " - ";
  112. s = s + test_asn4.ipinfo.asn_name;
  113. }
  114. return s;
  115. } else {
  116. return "IPv4: no";
  117. }
  118. };
  119. GIGO.helpdesk_ipv6_info = function () {
  120. var test_aaaa, test_asn6, s;
  121. test_aaaa = GIGO.results.tests.test_aaaa;
  122. test_asn6 = GIGO.results.tests.test_asn6;
  123. // status
  124. // ipinfo.ip
  125. // ipinfo.asn
  126. // ipinfo.asn_name
  127. // time_ms
  128. // We need to warn if any of the IPv6 tries timed out
  129. if ((test_aaaa.ipinfo) && (test_aaaa.ipinfo.ip)) {
  130. s = "IPv6: ";
  131. s = s + GIGO.helpdesk_good_bad_slow(["test_aaaa", "test_ds6", "test_ipv6", "test_v6mtu"]);
  132. if (test_asn6 && test_asn6.ipinfo && test_asn6.ipinfo.asn) {
  133. s = s + ", AS" + test_asn6.ipinfo.asn + " - ";
  134. s = s + test_asn6.ipinfo.asn_name;
  135. }
  136. return s;
  137. } else {
  138. if ((GIGO.results.tests.test_aaaa) && (GIGO.results.tests.test_aaaa.status) && (GIGO.results.tests.test_aaaa.status === "timeout")) {
  139. return "IPv6: broken";
  140. }
  141. if ((GIGO.results.tests.test_ds) && (GIGO.results.tests.test_ds.status) && (GIGO.results.tests.test_ds.status === "timeout")) {
  142. return "IPv6: broken";
  143. }
  144. if ((GIGO.results.tests.test_ipv6) && (GIGO.results.tests.test_ipv6.status) && (GIGO.results.tests.test_ipv6.status === "timeout")) {
  145. return "IPv6: broken";
  146. }
  147. return "IPv6: no";
  148. }
  149. };
  150. // call this late to populate the helpdesk tab
  151. GIGO.finish_helpdesk = function () {
  152. var code, div;
  153. if (!GIGO.results.debug_code) {
  154. return; // Too soon.
  155. }
  156. // Show the replay url
  157. jQuery("#replayurldiv").show();
  158. code = GIGO.helpdesk_score();
  159. div = jQuery("<div>", {
  160. id: "helpdesk_content"
  161. });
  162. // div.append("<div class=beta>BETA -This tab is a work in progress.</div>");
  163. div.append(jQuery("<p>").append("[% 'Your Internet help desk may ask you for the information below.' | i18n | escape_quotes %]"));
  164. if ((code) && (code.qcode)) {
  165. div.append(jQuery("<p>").append(jQuery("<span class=helpdeskcode>").text("Help desk code: " + code.qcode)));
  166. }
  167. if ((code) && (code.found)) {
  168. div.append(jQuery("<p>").append(jQuery("<b>").text(code.found)));
  169. }
  170. // GIGO.results.ipv4 and ipv6, have our ASN info.
  171. // div.append(jQuery("<div>").text(s));
  172. div.append(jQuery("<div>").text(GIGO.helpdesk_ipv4_info()));
  173. div.append(jQuery("<div>").text(GIGO.helpdesk_ipv6_info()));
  174. if (GIGO.helpdesk.other_sites && GIGO.helpdesk.other_sites.count) {
  175. div.append(jQuery("<div>").text(GIGO.other_sites_info()));
  176. }
  177. div.append("<div><p></p></div>"); // Space.
  178. if ((GIGO.results.ipv4) && (GIGO.results.ipv4.ip)) {
  179. div.append(jQuery("<div>").text("IPv4 address: " + GIGO.results.ipv4.ip));
  180. }
  181. if ((GIGO.results.ipv6) && (GIGO.results.ipv6.ip)) {
  182. div.append(jQuery("<div>").text("IPv6 address: " + GIGO.results.ipv6.ip));
  183. }
  184. div.append("<div><p></p></div>"); // Space.
  185. if (GIGO.helpdesk.other_sites) {
  186. div.append(GIGO.other_sites_failures());
  187. }
  188. // IPv4: Good, AS1234, CableCo
  189. // IPv6: Good, Teredo, Not Preferred
  190. // OtherSites: 40/40 Good
  191. // IPv4 address: 192.0.2.1
  192. // IPv6 address: 2001:0c000:201::1
  193. $("#helpdesk_content").replaceWith(div);
  194. // $("#helpdesk_content")
  195. // GIGO.results.tokens
  196. // GIGO.results.score_transition
  197. // GIGO.results.score_strict
  198. // GIGO.results.debug_code
  199. // GIGO.results.tokens_expanded
  200. // GIGO.results.mini_primary
  201. // GIGO.results.mini_secondary
  202. // This is meant to be ran several times; each time will replace
  203. // #helpdesk_content
  204. // First time replaced, will be before the "other sites" tab starts.
  205. // If we have IPV6, then it should say "checking other sites.."
  206. // And perhaps update only when done?
  207. };