Skip to content
Snippets Groups Projects
Commit dd23b036 authored by Otto Zaiser's avatar Otto Zaiser
Browse files

Commit inicial

parents
No related branches found
No related tags found
No related merge requests found
.tsa .btn-pill {
border-radius: 50px;
}
.tsa form .btn-primary {
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
font-weight: normal;
}
.tsa .dropArea {
border: 1px dashed #0094D4;
background-color: #ffffff;
padding: 50px;
text-align: center;
-webkit-border-radius: 5px;
border-radius: 5px;
transition: 0.3s;
}
.tsa .hash {
word-wrap: break-word;
}
.tsa .replacedTxt {
margin-bottom: 20px;
}
.tsa .dropArea p {
margin-bottom: 5px;
}
.tsa .dropAreaVerify {
border: 1px dashed #4cae4c;
}
.tsa .dropArea:hover {
background-color: #f0f7ff;
border-style: solid;
}
.tsa .dropAreaVerify:hover {
background-color: #e5fce5;
border-style: solid;
}
.tsa .dropArea .droptxt {
font-size: 1.2em;
margin-bottom: -5px;
}
.tsa .dropArea .glyphicon-cloud-upload {
font-size: 8em;
margin-bottom: 40px;
color: #ccc;
}
@media screen and (max-width: 768px) {
.tsa .dropArea .glyphicon-cloud-upload {
font-size: 4em;
margin-bottom: 20px;
}
.tsa .dropArea {
padding: 20px;
}
}
.tsa .loading {
background-color: #0094D4;
margin-top: 5px;
display: none;
padding: 10px;
text-align: center;
-webkit-border-radius: 5px;
border-radius: 5px;
}
.tsa [hidden]{
display: none !important;
}
.tsa .btn-lg {
min-width: 200px;
}
.tsa form{
max-width: 100%;
}
.tsa .tab-pane {
background-color: #f8f8f8;
border: 1px solid #ddd;
border-top: 0px;
padding: 40px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
.tsa .nav-tabs>li.active>a, .tsa .nav-tabs>li.active>a:focus,.tsa .nav-tabs>li.active>a:hover{
background-color: #f8f8f8;
}
@media screen and (min-width: 768px) {
.tsa .nav-tabs.nav-justified>.active>a, .tsa .nav-tabs.nav-justified>.active>a:focus, .tsa .nav-tabs.nav-justified>.active>a:hover{
border-bottom-color: #f8f8f8;
}
}
.tsa .tab-pane h2 {
margin-top: 0px;
}
.tsa .nav-tabs {
font-size: 1.5em;
}
.tsa .alert {
margin-top: 15px;
}
@media screen and (max-width: 768px) {
.tsa .tab-pane {
border-top: 1px solid #ddd;
}
}
main.main-content-inside .tsa h3 {
color: #333333;
font-size: 1.2em;
margin-top: 10px;
padding: 0;
background-image: none;
}
@media screen and (max-width: 992px) {
.tsa h3 {
margin-top: 30px;
}
.tsa .nav-tabs {
font-size: 1.3em;
}
}
@media screen and (max-width: 1200px) {
.tsa .dropArea .droptxt {
font-size: 1em;
margin-bottom: 15px;
}
}
js/tsa.js 0 → 100644
var $ = jQuery;
var tsa_api = 'https://tsaapi.bfa.ar/api/tsa/';
var loader_gif = 'lib/images/loader.svg';
var ots_api = '';
var deadline_date = new Date('2018-09-03 00:00:00');
var current_date = new Date();
var whash = window.location.hash;
var currentTab = whash.substring(5, 6);
(function ($, Drupal, drupalSettings) {
var ntsa_api = drupalSettings.tsa.tsa_api;
if(ntsa_api) tsa_api = ntsa_api;
whash && $('ul.nav a[href="' + whash + '"]').tab('show');
$('.nav-tabs a').click(function (e) {
$(this).tab('show');
var scrollmem = $('body').scrollTop() || $('html').scrollTop();
whash = this.hash;
currentTab = whash.substring(5, 6);
window.location.hash = whash;
$('html,body').scrollTop(scrollmem);
});
for (let i = 1; i < 4; i++) {
$('#selectOriginal_' + i+', #selectOriginalArea_' + i).on('click', function () {
$('#fileUploadOriginal_' + i).click();
return false;
});
if (i == 1) {
$('#fileUploadOriginal_' + i).change(
function () {
var file = $(this).prop('files')[0];
stamp(file);
}
);
} else {
$('#fileUploadOriginal_' + i).change(
function () {
var file = $(this).prop('files')[0];
original_file_check(file);
}
);
$('#selectRecibo_' + i+', #selectReciboArea_' + i).on('click', function () {
$('#fileUploadRecibo_' + i).click();
return false;
});
$('#fileUploadRecibo_' + i).change(
function () {
var file = $(this).prop('files')[0];
ots_check(file);
}
);
}
}
})(jQuery, Drupal, drupalSettings);
function stamp(file) {
var reader = new FileReader();
reader.readAsArrayBuffer(file, "UTF-8")
reader.onload = function (evt) {
var file_contents = evt.target.result;
var hash = sha256.create();
hash.update(file_contents);
var file_hash = hash.hex();
$('#originalInfo_1').html('<p>Nombre del archivo: <b>' + file.name + '</b></p><p>Hash del archivo: <b><span class="hash">' + file_hash + '</span></b></p>');
$('#selectOriginal_1').html('Seleccioná otro archivo <span class="sr-only">para marcar</span>');
$.ajax({
url: tsa_api + "stamp/",
type: "POST",
data: {
"file_hash": file_hash
},
dataType: "json",
success: function (response) {
var ots = ' {"file_hash": "' + file_hash + '", "rd": "' + response.temporary_ots + '"}';
var saveData = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
var json = JSON.stringify(data),
blob = new Blob([json], {
type: "octet/stream"
}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
}());
var data = response.temporary_rd
fileName = file.name + ".rd.temp";
saveData(data, fileName);
}
});
}
}
function verify_bfa(ots) {
var pending = false;
var message = '';
$('#response_' + currentTab).removeClass();
$.ajax({
url: tsa_api + "verify/",
type: "POST",
data: {
"file_hash": ots.file_hash,
"rd": ots.rd
},
dataType: "json",
success: function (response) {
if (response.status == 'success') {
icon = 'glyphicon-ok';
st = 'alert alert-success';
response_messages = response.messages.replace(ots.file_hash, $('#hidden_original_file_name_' + currentTab).val());
} else if (response.status == 'pending') {
pending = true;
icon = 'glyphicon-time';
st = 'alert alert-warning';
response_messages = response.messages;
} else {
icon = 'glyphicon-remove';
st = 'alert alert-danger';
response_messages = response.messages;
}
message = '<span class="glyphicon ' + icon + '" aria-hidden="true"></span> ' + response_messages;
$('#response_' + currentTab).addClass(st);
$('#response_' + currentTab).html(message);
if (!pending) {
var saveData = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
var json = JSON.stringify(data),
blob = new Blob([json], {
type: "octet/stream"
}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
}());
var data = response.permanent_rd;
fileName = $('#hidden_original_file_name_' + currentTab).val() + ".rd";
if (currentTab == '2') {
ms = 'Seleccioná otro archivo <span class="sr-only">.rd.temp</span>';
} else if (currentTab == '3') {
ms = 'Seleccioná otro archivo <span class="sr-only">.rd</span>';
}
$('#selectRecibo_' + currentTab).html(ms);
$('#reciboInstructions_' + currentTab).hide();
if ($('#reciboInfo_' + currentTab).html().includes('.temp')) {
saveData(data, fileName);
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
responseText = 'No se encontró el archivo';
if (errorThrown == 'timeout') {
responseText = 'No se pudo conectar a Blockchain Federal Argentina';
}
if (whash == '#certificado-tab') {
rp_id = "#response_cert";
} else {
rp_id = "#response";
}
$('#response_' + currentTab).html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> ' + responseText);
$('#response_' + currentTab).addClass('alert alert-danger');
},
timeout: 5000
});
}
function original_file_check(file) {
$('#response_' + currentTab).html('');
$('#response_' + currentTab).removeClass();
$('#reciboInfo_' + currentTab).html('');
$('#reciboInstructions_' + currentTab).show();
var reader = new FileReader();
reader.readAsArrayBuffer(file, "UTF-8")
reader.onload = function (evt) {
var file_contents = evt.target.result;
var hash = sha256.create();
hash.update(file_contents);
var file_hash = hash.hex();
$('#hidden_original_file_hash_' + currentTab).val(file_hash);
$('#hidden_original_file_name_' + currentTab).val(file.name);
$('#originalInfo_' + currentTab).html('<p>Nombre del archivo: <b>' + file.name + '</b></p><p>Hash del archivo: <b><span class="hash">' + file_hash + '</span></b></p>');
$('#selectOriginal_' + currentTab).html('Seleccioná otro archivo <span class="sr-only">original</span>');
};
}
function ots_check(file) {
$('#response_' + currentTab).html('');
$('#response_' + currentTab).removeClass();
var file_contents = '';
var file_hash = $('#hidden_original_file_hash_' + currentTab).val();
if (file_hash == '') {
$('#response_' + currentTab).html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Debe ingresar el archivo original');
$('#response_' + currentTab).addClass('alert alert-danger');
return;
}
var reader = new FileReader();
reader.readAsText(file, "UTF-8")
reader.onload = function (evt) {
file_contents = evt.target.result;
$('#reciboInstructions_' + currentTab).hide();
$('#reciboInfo_' + currentTab).html(file.name);
var ots = {
"file_hash": file_hash,
"rd": file_contents
}
verify_bfa(ots);
};
}
function allowDrop(e) {
e.preventDefault();
}
function dropStamp(e) {
e.preventDefault();
var file = e.dataTransfer.items[0].getAsFile();
stamp(file);
}
function dropOriginalFile(e) {
e.preventDefault();
var file = e.dataTransfer.items[0].getAsFile();
original_file_check(file);
}
\ No newline at end of file
/**
* [js-sha256]{@link https://github.com/emn178/js-sha256}
*
* @version 0.9.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
*/
/*jslint bitwise: true */
(function () {
'use strict';
var ERROR = 'input is invalid type';
var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {};
if (root.JS_SHA256_NO_WINDOW) {
WINDOW = false;
}
var WEB_WORKER = !WINDOW && typeof self === 'object';
var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
} else if (WEB_WORKER) {
root = self;
}
var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === 'object' && module.exports;
var AMD = typeof define === 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [-2147483648, 8388608, 32768, 128];
var SHIFT = [24, 16, 8, 0];
var K = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
var blocks = [];
if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
Array.isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
ArrayBuffer.isView = function (obj) {
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
};
}
var createOutputMethod = function (outputType, is224) {
return function (message) {
return new Sha256(is224, true).update(message)[outputType]();
};
};
var createMethod = function (is224) {
var method = createOutputMethod('hex', is224);
if (NODE_JS) {
method = nodeWrap(method, is224);
}
method.create = function () {
return new Sha256(is224);
};
method.update = function (message) {
return method.create().update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createOutputMethod(type, is224);
}
return method;
};
var nodeWrap = function (method, is224) {
var crypto = eval("require('crypto')");
var Buffer = eval("require('buffer').Buffer");
var algorithm = is224 ? 'sha224' : 'sha256';
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash(algorithm).update(message, 'utf8').digest('hex');
} else {
if (message === null || message === undefined) {
throw new Error(ERROR);
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
}
}
if (Array.isArray(message) || ArrayBuffer.isView(message) ||
message.constructor === Buffer) {
return crypto.createHash(algorithm).update(new Buffer(message)).digest('hex');
} else {
return method(message);
}
};
return nodeMethod;
};
var createHmacOutputMethod = function (outputType, is224) {
return function (key, message) {
return new HmacSha256(key, is224, true).update(message)[outputType]();
};
};
var createHmacMethod = function (is224) {
var method = createHmacOutputMethod('hex', is224);
method.create = function (key) {
return new HmacSha256(key, is224);
};
method.update = function (key, message) {
return method.create(key).update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createHmacOutputMethod(type, is224);
}
return method;
};
function Sha256(is224, sharedMemory) {
if (sharedMemory) {
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
this.blocks = blocks;
} else {
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
if (is224) {
this.h0 = 0xc1059ed8;
this.h1 = 0x367cd507;
this.h2 = 0x3070dd17;
this.h3 = 0xf70e5939;
this.h4 = 0xffc00b31;
this.h5 = 0x68581511;
this.h6 = 0x64f98fa7;
this.h7 = 0xbefa4fa4;
} else { // 256
this.h0 = 0x6a09e667;
this.h1 = 0xbb67ae85;
this.h2 = 0x3c6ef372;
this.h3 = 0xa54ff53a;
this.h4 = 0x510e527f;
this.h5 = 0x9b05688c;
this.h6 = 0x1f83d9ab;
this.h7 = 0x5be0cd19;
}
this.block = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false;
this.first = true;
this.is224 = is224;
}
Sha256.prototype.update = function (message) {
if (this.finalized) {
return;
}
var notString, type = typeof message;
if (type !== 'string') {
if (type === 'object') {
if (message === null) {
throw new Error(ERROR);
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw new Error(ERROR);
}
}
} else {
throw new Error(ERROR);
}
notString = true;
}
var code, index = 0, i, length = message.length, blocks = this.blocks;
while (index < length) {
if (this.hashed) {
this.hashed = false;
blocks[0] = this.block;
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
if (notString) {
for (i = this.start; index < length && i < 64; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
} else {
for (i = this.start; index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
blocks[i >> 2] |= code << SHIFT[i++ & 3];
} else if (code < 0x800) {
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else if (code < 0xd800 || code >= 0xe000) {
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
}
}
this.lastByteIndex = i;
this.bytes += i - this.start;
if (i >= 64) {
this.block = blocks[16];
this.start = i - 64;
this.hash();
this.hashed = true;
} else {
this.start = i;
}
}
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 << 0;
this.bytes = this.bytes % 4294967296;
}
return this;
};
Sha256.prototype.finalize = function () {
if (this.finalized) {
return;
}
this.finalized = true;
var blocks = this.blocks, i = this.lastByteIndex;
blocks[16] = this.block;
blocks[i >> 2] |= EXTRA[i & 3];
this.block = blocks[16];
if (i >= 56) {
if (!this.hashed) {
this.hash();
}
blocks[0] = this.block;
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
blocks[15] = this.bytes << 3;
this.hash();
};
Sha256.prototype.hash = function () {
var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6,
h = this.h7, blocks = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
for (j = 16; j < 64; ++j) {
// rightrotate
t1 = blocks[j - 15];
s0 = ((t1 >>> 7) | (t1 << 25)) ^ ((t1 >>> 18) | (t1 << 14)) ^ (t1 >>> 3);
t1 = blocks[j - 2];
s1 = ((t1 >>> 17) | (t1 << 15)) ^ ((t1 >>> 19) | (t1 << 13)) ^ (t1 >>> 10);
blocks[j] = blocks[j - 16] + s0 + blocks[j - 7] + s1 << 0;
}
bc = b & c;
for (j = 0; j < 64; j += 4) {
if (this.first) {
if (this.is224) {
ab = 300032;
t1 = blocks[0] - 1413257819;
h = t1 - 150054599 << 0;
d = t1 + 24177077 << 0;
} else {
ab = 704751109;
t1 = blocks[0] - 210244248;
h = t1 - 1521486534 << 0;
d = t1 + 143694565 << 0;
}
this.first = false;
} else {
s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
ab = a & b;
maj = ab ^ (a & c) ^ bc;
ch = (e & f) ^ (~e & g);
t1 = h + s1 + ch + K[j] + blocks[j];
t2 = s0 + maj;
h = d + t1 << 0;
d = t1 + t2 << 0;
}
s0 = ((d >>> 2) | (d << 30)) ^ ((d >>> 13) | (d << 19)) ^ ((d >>> 22) | (d << 10));
s1 = ((h >>> 6) | (h << 26)) ^ ((h >>> 11) | (h << 21)) ^ ((h >>> 25) | (h << 7));
da = d & a;
maj = da ^ (d & b) ^ ab;
ch = (h & e) ^ (~h & f);
t1 = g + s1 + ch + K[j + 1] + blocks[j + 1];
t2 = s0 + maj;
g = c + t1 << 0;
c = t1 + t2 << 0;
s0 = ((c >>> 2) | (c << 30)) ^ ((c >>> 13) | (c << 19)) ^ ((c >>> 22) | (c << 10));
s1 = ((g >>> 6) | (g << 26)) ^ ((g >>> 11) | (g << 21)) ^ ((g >>> 25) | (g << 7));
cd = c & d;
maj = cd ^ (c & a) ^ da;
ch = (g & h) ^ (~g & e);
t1 = f + s1 + ch + K[j + 2] + blocks[j + 2];
t2 = s0 + maj;
f = b + t1 << 0;
b = t1 + t2 << 0;
s0 = ((b >>> 2) | (b << 30)) ^ ((b >>> 13) | (b << 19)) ^ ((b >>> 22) | (b << 10));
s1 = ((f >>> 6) | (f << 26)) ^ ((f >>> 11) | (f << 21)) ^ ((f >>> 25) | (f << 7));
bc = b & c;
maj = bc ^ (b & d) ^ cd;
ch = (f & g) ^ (~f & h);
t1 = e + s1 + ch + K[j + 3] + blocks[j + 3];
t2 = s0 + maj;
e = a + t1 << 0;
a = t1 + t2 << 0;
}
this.h0 = this.h0 + a << 0;
this.h1 = this.h1 + b << 0;
this.h2 = this.h2 + c << 0;
this.h3 = this.h3 + d << 0;
this.h4 = this.h4 + e << 0;
this.h5 = this.h5 + f << 0;
this.h6 = this.h6 + g << 0;
this.h7 = this.h7 + h << 0;
};
Sha256.prototype.hex = function () {
this.finalize();
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
h6 = this.h6, h7 = this.h7;
var hex = HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] +
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] +
HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] +
HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] +
HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F] +
HEX_CHARS[(h5 >> 28) & 0x0F] + HEX_CHARS[(h5 >> 24) & 0x0F] +
HEX_CHARS[(h5 >> 20) & 0x0F] + HEX_CHARS[(h5 >> 16) & 0x0F] +
HEX_CHARS[(h5 >> 12) & 0x0F] + HEX_CHARS[(h5 >> 8) & 0x0F] +
HEX_CHARS[(h5 >> 4) & 0x0F] + HEX_CHARS[h5 & 0x0F] +
HEX_CHARS[(h6 >> 28) & 0x0F] + HEX_CHARS[(h6 >> 24) & 0x0F] +
HEX_CHARS[(h6 >> 20) & 0x0F] + HEX_CHARS[(h6 >> 16) & 0x0F] +
HEX_CHARS[(h6 >> 12) & 0x0F] + HEX_CHARS[(h6 >> 8) & 0x0F] +
HEX_CHARS[(h6 >> 4) & 0x0F] + HEX_CHARS[h6 & 0x0F];
if (!this.is224) {
hex += HEX_CHARS[(h7 >> 28) & 0x0F] + HEX_CHARS[(h7 >> 24) & 0x0F] +
HEX_CHARS[(h7 >> 20) & 0x0F] + HEX_CHARS[(h7 >> 16) & 0x0F] +
HEX_CHARS[(h7 >> 12) & 0x0F] + HEX_CHARS[(h7 >> 8) & 0x0F] +
HEX_CHARS[(h7 >> 4) & 0x0F] + HEX_CHARS[h7 & 0x0F];
}
return hex;
};
Sha256.prototype.toString = Sha256.prototype.hex;
Sha256.prototype.digest = function () {
this.finalize();
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5,
h6 = this.h6, h7 = this.h7;
var arr = [
(h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF,
(h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF,
(h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF,
(h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF,
(h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF,
(h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, h5 & 0xFF,
(h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, h6 & 0xFF
];
if (!this.is224) {
arr.push((h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, h7 & 0xFF);
}
return arr;
};
Sha256.prototype.array = Sha256.prototype.digest;
Sha256.prototype.arrayBuffer = function () {
this.finalize();
var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
var dataView = new DataView(buffer);
dataView.setUint32(0, this.h0);
dataView.setUint32(4, this.h1);
dataView.setUint32(8, this.h2);
dataView.setUint32(12, this.h3);
dataView.setUint32(16, this.h4);
dataView.setUint32(20, this.h5);
dataView.setUint32(24, this.h6);
if (!this.is224) {
dataView.setUint32(28, this.h7);
}
return buffer;
};
function HmacSha256(key, is224, sharedMemory) {
var i, type = typeof key;
if (type === 'string') {
var bytes = [], length = key.length, index = 0, code;
for (i = 0; i < length; ++i) {
code = key.charCodeAt(i);
if (code < 0x80) {
bytes[index++] = code;
} else if (code < 0x800) {
bytes[index++] = (0xc0 | (code >> 6));
bytes[index++] = (0x80 | (code & 0x3f));
} else if (code < 0xd800 || code >= 0xe000) {
bytes[index++] = (0xe0 | (code >> 12));
bytes[index++] = (0x80 | ((code >> 6) & 0x3f));
bytes[index++] = (0x80 | (code & 0x3f));
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
bytes[index++] = (0xf0 | (code >> 18));
bytes[index++] = (0x80 | ((code >> 12) & 0x3f));
bytes[index++] = (0x80 | ((code >> 6) & 0x3f));
bytes[index++] = (0x80 | (code & 0x3f));
}
}
key = bytes;
} else {
if (type === 'object') {
if (key === null) {
throw new Error(ERROR);
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
key = new Uint8Array(key);
} else if (!Array.isArray(key)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
throw new Error(ERROR);
}
}
} else {
throw new Error(ERROR);
}
}
if (key.length > 64) {
key = (new Sha256(is224, true)).update(key).array();
}
var oKeyPad = [], iKeyPad = [];
for (i = 0; i < 64; ++i) {
var b = key[i] || 0;
oKeyPad[i] = 0x5c ^ b;
iKeyPad[i] = 0x36 ^ b;
}
Sha256.call(this, is224, sharedMemory);
this.update(iKeyPad);
this.oKeyPad = oKeyPad;
this.inner = true;
this.sharedMemory = sharedMemory;
}
HmacSha256.prototype = new Sha256();
HmacSha256.prototype.finalize = function () {
Sha256.prototype.finalize.call(this);
if (this.inner) {
this.inner = false;
var innerHash = this.array();
Sha256.call(this, this.is224, this.sharedMemory);
this.update(this.oKeyPad);
this.update(innerHash);
Sha256.prototype.finalize.call(this);
}
};
var exports = createMethod();
exports.sha256 = exports;
exports.sha224 = createMethod(true);
exports.sha256.hmac = createHmacMethod();
exports.sha224.hmac = createHmacMethod(true);
if (COMMON_JS) {
module.exports = exports;
} else {
root.sha256 = exports.sha256;
root.sha224 = exports.sha224;
if (AMD) {
define(function () {
return exports;
});
}
}
})();
<?php
namespace Drupal\tsa\Controller;
use Drupal\Core\Url;
use Drupal\Component\Utility\Html;
use Drupal\Core\Controller\ControllerBase;
/**
* Defines HelloController class.
*/
class tsaController extends ControllerBase {
/**
* Display the markup.
*
* @return array
* Return markup array.
*/
public function content() {
// Default settings.
$config = \Drupal::config('tsa.settings');
$tsa_api = $config->get('tsa_api');
$element['#tsa_api'] = Html::escape($tsa_api);
$element['#ext_rdt'] = $config->get('ext_rdt');
$element['#ext_rdd'] = $config->get('ext_rdd');
$element['#mainBody'] = $config->get('mainBody');
$element['#tab01'] = $config->get('tab01');
$element['#tab01Title'] = $config->get('tab01Title');
$element['#tab01Body'] = $config->get('tab01Body');
$element['#tab02'] = $config->get('tab02');
$element['#tab02Title'] = $config->get('tab02Title');
$element['#tab02Body'] = $config->get('tab02Body');
$element['#tab02Box01'] = $config->get('tab02Box01');
$element['#tab02Box02'] = $config->get('tab02Box02');
$element['#tab03'] = $config->get('tab03');
$element['#tab03Title'] = $config->get('tab03Title');
$element['#tab03Body'] = $config->get('tab03Body');
$element['#tab03Box01'] = $config->get('tab03Box01');
$element['#tab03Box02'] = $config->get('tab03Box02');
$element['#theme'] = 'tsa_theme';
return $element;
}
}
\ No newline at end of file
<?php
namespace Drupal\tsa\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class tsaForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'tsa_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Form constructor.
$form = parent::buildForm($form, $form_state);
// Default settings.
$config = $this->config('tsa.settings');
// API
$form['tsa_api'] = array(
'#type' => 'textfield',
'#title' => $this->t('URL de API'),
'#default_value' => $config->get('tsa_api'),
);
$form['ext_rdt'] = array(
'#type' => 'textfield',
'#title' => $this->t('Extensión Recibo Temporario'),
'#default_value' => $config->get('ext_rdt'),
);
$form['ext_rdd'] = array(
'#type' => 'textfield',
'#title' => $this->t('Extensión Recibo Definitivo'),
'#default_value' => $config->get('ext_rdd'),
);
$form['mainBody'] = array(
'#type' => 'textarea',
'#title' => $this->t('Texto Principal'),
'#default_value' => $config->get('mainBody'),
);
$form['tab01'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 1: Label'),
'#default_value' => $config->get('tab01'),
);
$form['tab01Title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 1: Título'),
'#default_value' => $config->get('tab01Title'),
);
$form['tab01Body'] = array(
'#type' => 'textarea',
'#title' => $this->t('Tab 1: Texto'),
'#default_value' => $config->get('tab01Body'),
);
$form['tab02'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 2: Label'),
'#default_value' => $config->get('tab02'),
);
$form['tab02Title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 2: Título'),
'#default_value' => $config->get('tab02Title'),
);
$form['tab02Body'] = array(
'#type' => 'textarea',
'#title' => $this->t('Tab 2: Texto'),
'#default_value' => $config->get('tab02Body'),
);
$form['tab02Box01'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 2: Subtítulo Drop 1'),
'#default_value' => $config->get('tab02Box01'),
);
$form['tab02Box02'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 2: Subtítulo Drop 2'),
'#default_value' => $config->get('tab02Box02'),
);
$form['tab03'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 3: Label'),
'#default_value' => $config->get('tab03'),
);
$form['tab03Title'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 3: Título'),
'#default_value' => $config->get('tab03Title'),
);
$form['tab03Body'] = array(
'#type' => 'textarea',
'#title' => $this->t('Tab 3: Texto'),
'#default_value' => $config->get('tab03Body'),
);
$form['tab03Box01'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 3: Subtítulo Drop 1'),
'#default_value' => $config->get('tab03Box01'),
);
$form['tab03Box02'] = array(
'#type' => 'textfield',
'#title' => $this->t('Tab 3: Subtítulo Drop 2'),
'#default_value' => $config->get('tab03Box02'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('tsa.settings');
$config->set('tsa_api', $form_state->getValue('tsa_api'));
$config->set('ext_rdt', $form_state->getValue('ext_rdt'));
$config->set('ext_rdd', $form_state->getValue('ext_rdd'));
$config->set('mainBody', $form_state->getValue('mainBody'));
$config->set('tab01', $form_state->getValue('tab01'));
$config->set('tab01Title', $form_state->getValue('tab01Title'));
$config->set('tab01Body', $form_state->getValue('tab01Body'));
$config->set('tab02', $form_state->getValue('tab02'));
$config->set('tab02Title', $form_state->getValue('tab02Title'));
$config->set('tab02Body', $form_state->getValue('tab02Body'));
$config->set('tab02Box01', $form_state->getValue('tab02Box01'));
$config->set('tab02Box02', $form_state->getValue('tab02Box02'));
$config->set('tab03', $form_state->getValue('tab03'));
$config->set('tab03Title', $form_state->getValue('tab03Title'));
$config->set('tab03Body', $form_state->getValue('tab03Body'));
$config->set('tab03Box01', $form_state->getValue('tab03Box01'));
$config->set('tab03Box02', $form_state->getValue('tab03Box02'));
$config->save();
return parent::submitForm($form, $form_state);
}
protected function getEditableConfigNames() {
return [
'tsa.settings',
];
}
}
{% autoescape false %}
<div class="tsa">
<p>{{ mainBody }}</p>
<ul class="nav nav-tabs nav-justified" role="tablist">
<li role="presentation" class="active"><a href="#tab_1" aria-controls="tab_1" role="tab"
data-toggle="tab">{{ tab01 }}</a></li>
<li role="presentation"><a href="#tab_2" aria-controls="tab_2" role="tab" data-toggle="tab">{{ tab02 }}</a></li>
<li role="presentation"><a href="#tab_3" aria-controls="tab_3" role="tab" data-toggle="tab">{{ tab03 }}</a></li>
</ul>
<form class="box tab-content" method="post" action="" enctype="multipart/form-data">
<div role="tabpanel" class="tab-pane active" id="tab_1">
<h2>{{ tab01Title }}</h2>
<p>{{ tab01Body }}</p>
<div id="selectOriginalArea_1" class="dropArea" ondrop="dropStamp(event)" ondragover="allowDrop(event)">
<div id="originalInfo_1" class="replacedTxt">
<div><span class="glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá un archivo aquí<br>ó</div>
</div>
<div><button type="button" id="selectOriginal_1" class="btn btn-primary btn-pill">Seleccioná un archivo <span class="sr-only">para Sellar</span></button></div>
</div>
<input type="file" id="fileUploadOriginal_1" hidden/>
<!-- <div id="ots_div" class="loading"></div> -->
<div id="response_1" role="alert"></div>
</div>
<div role="tabpanel" class="tab-pane certificadoTab" id="tab_2">
<h2>{{ tab02Title }}</h2>
<p>{{ tab02Body }}</p>
<input type="hidden" name="hidden_original_file_hash_2" id="hidden_original_file_hash_2" />
<input type="hidden" name="hidden_original_file_name_2" id="hidden_original_file_name_2" />
<div class="row">
<div class="col-md-6">
<h3>{{ tab02Box01 }}</h3>
<div id="selectOriginalArea_2" class="dropArea" ondrop="dropOriginalFile(event)"
ondragover="allowDrop(event)">
<div id="originalInfo_2" class="replacedTxt">
<div><span class=" glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá el archivo <b>original</b> aquí<br>ó</div>
</div>
<div><button type="button" id="selectOriginal_2" class="btn btn-primary btn-pill">Seleccioná un archivo <span class="sr-only">original</span></button></div>
</div>
<input type="file" id="fileUploadOriginal_2" hidden/>
</div>
<div class="col-md-6">
<h3>{{ tab02Box02 }}</h3>
<div id="selectReciboArea_2" class="dropArea" ondrop="dropOTSFile(event)" ondragover="allowDrop(event)">
<div class="replacedTxt">
<div id="reciboInfo_2"></div>
<div id="reciboInstructions_2">
<div><span class="glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá el archivo <b>{{ ext_rdt }}</b> aquí<br>ó</div>
</div>
</div>
<div><button type="button" id="selectRecibo_2" class="btn btn-primary btn-pill">Seleccioná un archivo <span class="sr-only">{{ ext_rdt }}</span></button></div>
</div>
<input type="file" id="fileUploadRecibo_2" hidden/>
</div>
</div>
<div id="response_2" role="alert"></div>
</div>
<div role="tabpanel" class="tab-pane verificarTab" id="tab_3">
<h2>{{ tab03Title }}</h2>
<p>{{ tab03Body }}</p>
<input type="hidden" name="hidden_original_file_hash_3" id="hidden_original_file_hash_3" />
<input type="hidden" name="hidden_original_file_name_3" id="hidden_original_file_name_3" />
<div class="row">
<div class="col-md-6">
<h3>{{ tab03Box01 }}</h3>
<div id="selectOriginalArea_3" class="dropArea dropAreaVerify" ondrop="dropOriginalFile(event)"
ondragover="allowDrop(event)">
<div id="originalInfo_3" class="replacedTxt">
<div><span class=" glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá el archivo <b>original</b> aquí<br>ó</div>
</div>
<div><button type="button" id="selectOriginal_3" class="btn btn-success btn-pill">Seleccioná un archivo <span class="sr-only">original</span></button></div>
</div>
<input type="file" id="fileUploadOriginal_3" hidden/>
</div>
<div class="col-md-6">
<h3>{{ tab03Box02 }}</h3>
<div id="selectReciboArea_3" class="dropArea dropAreaVerify" ondrop="dropOTSFile(event)" ondragover="allowDrop(event)">
<div class="replacedTxt">
<div id="reciboInfo_3"></div>
<div id="reciboInstructions_3">
<div><span class="glyphicon glyphicon-cloud-upload" aria-hidden="true"></span></div>
<div class="droptxt">Arrastrá el archivo <b>{{ ext_rdd }}</b> aquí<br>ó</div>
</div>
</div>
<div><button type="button" id="selectRecibo_3" class="btn btn-success btn-pill">Seleccioná un archivo <span class="sr-only">{{ ext_rdd }}</span></button></div>
</div>
<input type="file" id="fileUploadRecibo_3" hidden/>
</div>
</div>
<div id="response_3" role="alert"></div>
</div>
</form>
</div>
{% endautoescape %}
\ No newline at end of file
name: tsa
description: Modulo Custom de TSA
package: BFA
type: module
core: 8.x
\ No newline at end of file
tsa:
version: 1.x
css:
theme:
css/tsa.css: {}
js:
js/vendor/sha256.js: {}
js/tsa.js: {}
dependencies:
- core/jquery
- core/drupalSettings
tsa.admin:
title: 'Configuración TSA'
description: 'Un módulo customizado para la TSA'
parent: system.admin_config_development
route_name: tsa.form
weight: 100
\ No newline at end of file
<?php
use Drupal\Core\Routing\RouteMatchInterface;
function tsa_theme($existing, $type, $theme, $path) {
// return [
// 'tsa_template' => [
// 'variables' => ['source_text' => NULL],
// ],
// ];
$variables = array(
'tsa_theme' => array(
'variables' => array(
'tsa_api' => NULL,
'ext_rdt' => NULL,
'ext_rdd' => NULL,
'mainBody' => NULL,
'tab01' => NULL,
'tab01Title' => NULL,
'tab01Body' => NULL,
'tab02' => NULL,
'tab02Title' => NULL,
'tab02Body' => NULL,
'tab02Box01' => NULL,
'tab02Box02' => NULL,
'tab03' => NULL,
'tab03Title' => NULL,
'tab03Body' => NULL,
'tab03Box01' => NULL,
'tab03Box02' => NULL,
),
'template' => 'tsa-template',
),
);
return $variables;
}
function tsa_preprocess_html(&$variables) {
$variables['#attached']['library'][] = 'tsa/tsa';
$config = \Drupal::config('tsa.settings');
$tsa_api = $config->get('tsa_api');
$variables['#attached']['drupalSettings']['tsa']['tsa_api'] = $tsa_api;
}
\ No newline at end of file
tsa.content:
path: '/tsa'
defaults:
_controller: '\Drupal\tsa\Controller\tsaController::content'
_title: 'Sello de Tiempo'
requirements:
_permission: 'access content'
tsa.form:
path: '/admin/config/development/tsa'
defaults:
_form: 'Drupal\tsa\Form\tsaForm'
_title: 'Configuración TSA'
requirements:
_permission: 'administer site configuration'
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment