Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. <script>
  2. jQuery.extend({
  3. postJSON: function(url, data, callback) {
  4. return jQuery.ajax({
  5. type: "POST",
  6. url: url,
  7. data: JSON.stringify(data),
  8. success: callback,
  9. dataType: "json",
  10. contentType: "application/json",
  11. processData: false
  12. });
  13. }
  14. });
  15.  
  16. function fileSelected(o) {
  17. $(o).parent().parent().find('.form-control').html($(o).val().split(/[\\|/]/).pop());
  18. hideError();
  19.  
  20. var reader = new FileReader();
  21. reader.onload = function() {
  22. var arrayBuffer = this.result;
  23. bytes = new Uint8Array(arrayBuffer);
  24. csr_data = '';
  25. for(i=0; i<bytes.length; i++) {
  26. csr_data += ("0" + bytes[i].toString(16)).substr(-2);
  27. }
  28.  
  29. if (csr_data.substr(0x40, 0x40) == "0".repeat(0x40)) {
  30. $("#license-code-form").show();
  31. } else {
  32. $("#license-code-form").hide();
  33. sign_csr(csr_data, null);
  34. }
  35. }
  36. reader.readAsArrayBuffer(o.files[0]);
  37. }
  38.  
  39. function manualRetrieve() {
  40. hideError();
  41.  
  42. license_code = $("#redeem-code")[0].value;
  43.  
  44. if (license_code.length != 8) {
  45. showError("Invalid license code");
  46. return;
  47. }
  48.  
  49. license_code = license_code.toUpperCase();
  50.  
  51. if (/^[0-9A-Z]{8}$/.test(license_code) != true) {
  52. showError("Invalid license code");
  53. return;
  54. }
  55.  
  56. sign_csr(csr_data, license_code);
  57. }
  58.  
  59. function hideError() {
  60. $("#license_error").hide();
  61. }
  62.  
  63. function showError(txt) {
  64. $("#license_error_text").html(txt);
  65. $("#license_error").show();
  66. }
  67.  
  68. function sign_csr(csr_data, code) {
  69. if (code != null) {
  70. o = { csr_data: csr_data, redeem_code: code };
  71. } else {
  72. o = { csr_data: csr_data };
  73. }
  74.  
  75. $.postJSON("server.php?u=sign", o, function(r) {
  76. if ('error' in r) {
  77. showError(r.error);
  78. } else {
  79. get_license(csr_data, code);
  80. }
  81. });
  82. }
  83.  
  84. function get_license(csr_data, code) {
  85. if (code != null) {
  86. o = { csr_data: csr_data, redeem_code: code };
  87. } else {
  88. o = { csr_data: csr_data };
  89. }
  90.  
  91. $.postJSON("server.php?u=retrieve", o, function(r) {
  92. if ('error' in r) {
  93. showError(r.error);
  94. } else {
  95. license_file = new Uint8Array(r.license.length/2);
  96. for(i=0; i<r.license.length/2; i++) {
  97. license_file[i] = parseInt(r.license.substr(i*2,2),16);
  98. }
  99. download(license_file, "license.dat");
  100. license_success();
  101. }
  102. });
  103. }
  104.  
  105. function license_success() {
  106. $("#upload_form").hide();
  107. $("#license-code-form").hide();
  108. $("#license_success").show();
  109. }
  110.  
  111. function download(content, filename, contentType) {
  112. if(!contentType) { contentType = 'application/octet-stream'; }
  113. var a = document.createElement('a');
  114. var blob = new Blob([content], {'type':contentType});
  115. a.href = window.URL.createObjectURL(blob);
  116. a.download = filename;
  117. a.click();
  118. }
  119. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement