fiberhome.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. function encryptFunc(a, b, c) {
  2. var b = CryptoJS.enc.Utf8.parse(b);
  3. var c = CryptoJS.enc.Utf8.parse(c);
  4. var d = '';
  5. if (typeof a == 'string') {
  6. var e = CryptoJS.enc.Utf8.parse(a);
  7. d = CryptoJS.AES.encrypt(e, b, {
  8. iv: c,
  9. mode: CryptoJS.mode.CBC,
  10. padding: CryptoJS.pad.Pkcs7
  11. })
  12. } else if (typeof a == 'object') {
  13. data = JSON.stringify(a);
  14. var e = CryptoJS.enc.Utf8.parse(data);
  15. d = CryptoJS.AES.encrypt(e, b, {
  16. iv: c,
  17. mode: CryptoJS.mode.CBC,
  18. padding: CryptoJS.pad.Pkcs7
  19. })
  20. }
  21. return d.ciphertext.toString()
  22. }
  23. function decryptFunc(a, b, c) {
  24. var b = CryptoJS.enc.Utf8.parse(b);
  25. var c = CryptoJS.enc.Utf8.parse(c);
  26. var d = CryptoJS.enc.Hex.parse(a);
  27. var e = CryptoJS.enc.Base64.stringify(d);
  28. var f = CryptoJS.AES.decrypt(e, b, {
  29. iv: c,
  30. mode: CryptoJS.mode.CBC,
  31. padding: CryptoJS.pad.Pkcs7
  32. });
  33. var g = f.toString(CryptoJS.enc.Utf8);
  34. return g.toString()
  35. }
  36. function int_aes_iv() {
  37. var a = '';
  38. for (var i = 0; i < 16; i++) {
  39. a += String.fromCharCode(i + 112)
  40. }
  41. return a
  42. }
  43. function Session() {
  44. xhr = new XMLHttpRequest();
  45. tokenUrl = 'http://' + document.domain + '/api/tmp/FHNCAPIS?ajaxmethod=get_refresh_sessionid&' + '_=' + Math.random();
  46. xhr.open("GET", tokenUrl, false);
  47. xhr.send();
  48. if (xhr.status != 200) {
  49. return null;
  50. }
  51. return JSON.parse(xhr.responseText).sessionid;
  52. }
  53. function Login(u, p) {
  54. if (u == undefined || p == undefined) {
  55. u = "superadmin";
  56. p = "F1ber$dm";
  57. }
  58. d = {"dataObj":{"username":u,"password":p},"ajaxmethod":"DO_WEB_LOGIN"};
  59. uri = "/api/sign/DO_WEB_LOGIN" + '?_=' + Math.random();
  60. return Post(d, uri);
  61. }
  62. function Post(d, uri) {
  63. if (uri === undefined) {
  64. uri = "/api/tmp/FHAPIS" + '?_=' + Math.random();
  65. }
  66. if (document === undefined || document.domain === undefined) {
  67. domain = "192.168.8.1";
  68. } else {
  69. domain = document.domain;
  70. }
  71. sessionId = Session();
  72. if (sessionId === null) {
  73. return "HTTP_NoSession";
  74. }
  75. iv = int_aes_iv();
  76. xhr = new XMLHttpRequest();
  77. apiUrl = 'http://' + domain + uri;
  78. xhr.open("POST", apiUrl, false);
  79. xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  80. xhr.setRequestHeader('Accept', 'application/json, text/javascript, */*; q=0.01');
  81. xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
  82. k = sessionId.substring(0, 16);
  83. d.sessionid = sessionId;
  84. data = encryptFunc(d, k, iv);
  85. xhr.send(data);
  86. if (xhr.status != 200) {
  87. return 'HTTP_' + xhr.status;
  88. }
  89. return decryptFunc(xhr.responseText, k, iv);
  90. }
  91. Login();
  92. Post({"dataObj":{"MemoryTotal":"DeviceInfo.MemoryStatus.Total", "MemoryFree": "DeviceInfo.MemoryStatus.Free"},"ajaxmethod":"get_value_by_xmlnode"});
  93. Post({"dataObj":{"KEY":"UPTIME"},"ajaxmethod":"get_cmd_result_web"});
  94. Post({"dataObj":{"KEY":"REBOOT_WEB"},"ajaxmethod":"do_cmd_web"});
  95. Post({"dataObj":null,"ajaxmethod":"version_detection"});