Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- jQuery.extend({
- postJSON: function(url, data, callback) {
- return jQuery.ajax({
- type: "POST",
- url: url,
- data: JSON.stringify(data),
- success: callback,
- dataType: "json",
- contentType: "application/json",
- processData: false
- });
- }
- });
- function fileSelected(o) {
- $(o).parent().parent().find('.form-control').html($(o).val().split(/[\\|/]/).pop());
- hideError();
- var reader = new FileReader();
- reader.onload = function() {
- var arrayBuffer = this.result;
- bytes = new Uint8Array(arrayBuffer);
- csr_data = '';
- for(i=0; i<bytes.length; i++) {
- csr_data += ("0" + bytes[i].toString(16)).substr(-2);
- }
- if (csr_data.substr(0x40, 0x40) == "0".repeat(0x40)) {
- $("#license-code-form").show();
- } else {
- $("#license-code-form").hide();
- sign_csr(csr_data, null);
- }
- }
- reader.readAsArrayBuffer(o.files[0]);
- }
- function manualRetrieve() {
- hideError();
- license_code = $("#redeem-code")[0].value;
- if (license_code.length != 8) {
- showError("Invalid license code");
- return;
- }
- license_code = license_code.toUpperCase();
- if (/^[0-9A-Z]{8}$/.test(license_code) != true) {
- showError("Invalid license code");
- return;
- }
- sign_csr(csr_data, license_code);
- }
- function hideError() {
- $("#license_error").hide();
- }
- function showError(txt) {
- $("#license_error_text").html(txt);
- $("#license_error").show();
- }
- function sign_csr(csr_data, code) {
- if (code != null) {
- o = { csr_data: csr_data, redeem_code: code };
- } else {
- o = { csr_data: csr_data };
- }
- $.postJSON("server.php?u=sign", o, function(r) {
- if ('error' in r) {
- showError(r.error);
- } else {
- get_license(csr_data, code);
- }
- });
- }
- function get_license(csr_data, code) {
- if (code != null) {
- o = { csr_data: csr_data, redeem_code: code };
- } else {
- o = { csr_data: csr_data };
- }
- $.postJSON("server.php?u=retrieve", o, function(r) {
- if ('error' in r) {
- showError(r.error);
- } else {
- license_file = new Uint8Array(r.license.length/2);
- for(i=0; i<r.license.length/2; i++) {
- license_file[i] = parseInt(r.license.substr(i*2,2),16);
- }
- download(license_file, "license.dat");
- license_success();
- }
- });
- }
- function license_success() {
- $("#upload_form").hide();
- $("#license-code-form").hide();
- $("#license_success").show();
- }
- function download(content, filename, contentType) {
- if(!contentType) { contentType = 'application/octet-stream'; }
- var a = document.createElement('a');
- var blob = new Blob([content], {'type':contentType});
- a.href = window.URL.createObjectURL(blob);
- a.download = filename;
- a.click();
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement