SQRL Login with Viewdata
This commit is contained in:
@@ -396,6 +396,54 @@ function ANSIFrame() {
|
||||
return output;
|
||||
};
|
||||
|
||||
this.qrcode = function(qr,subframe) {
|
||||
// SMALL Image
|
||||
var full = ascii(0xdb);
|
||||
var top = ascii(0xdf);
|
||||
var bot = ascii(0xdc);
|
||||
var blank = ' ';
|
||||
|
||||
var qrcode = '';
|
||||
|
||||
/*
|
||||
// Render the top line
|
||||
var line = ascii(27)+'[1;37m'+bot;
|
||||
for (var y = 0; y < qr.size; y++) {
|
||||
line += bot;
|
||||
}
|
||||
qrcode += line+bot+bot+ascii(27)+'[0m'+"\r\n";
|
||||
*/
|
||||
|
||||
// Render the body
|
||||
for (var x = -1; x < qr.size; x=x+2) {
|
||||
line = ascii(27)+'[1;37m'+full;
|
||||
|
||||
for (var y = 0; y < qr.size; y++) {
|
||||
// Top is white
|
||||
if (((x==-1)? 0 : qr.getModule(x, y)) == 0) {
|
||||
line += (qr.getModule(x+1, y)) ? top : full;
|
||||
|
||||
// Top is black
|
||||
} else {
|
||||
line += (qr.getModule(x+1, y)) ? blank : bot;
|
||||
}
|
||||
}
|
||||
|
||||
qrcode += line+full+ascii(27)+'[0m'+"\r\n";
|
||||
}
|
||||
|
||||
// Render the bottom
|
||||
line = ascii(27)+'[1;37m'+top;
|
||||
for (var y = 0; y < qr.size; y++) {
|
||||
line += top;
|
||||
}
|
||||
qrcode += line+top+ascii(27)+'[0m'+"\r\n";
|
||||
|
||||
ans2bin(fo.parse(qrcode),subframe);
|
||||
subframe.open();
|
||||
subframe.cycle();
|
||||
};
|
||||
|
||||
this.save=function() {
|
||||
file = system.mods_dir+'ansitex/text/'+this.page+'.tex';
|
||||
w = new File(file);
|
||||
|
@@ -23,12 +23,7 @@ function sqrllogin() {
|
||||
var complete = false;
|
||||
var cancel = false;
|
||||
|
||||
var page = new Frame(1,2,80,22,BG_BLACK|LIGHTGRAY);
|
||||
|
||||
page.gotoxy(1,1);
|
||||
ans2bin(fo.parse(base64_decode(fo.content)),page);
|
||||
page.open();
|
||||
page.cycle();
|
||||
fo.render();
|
||||
|
||||
log(LOG_DEBUG,'OPTIONS: '+JSON.stringify(loadOptions('sqrl')));
|
||||
sqrl = loadOptions('sqrl');
|
||||
@@ -46,52 +41,8 @@ function sqrllogin() {
|
||||
.map(function(x) {return x.charCodeAt(0)});
|
||||
var qr = qrcodegen.QrCode.encodeBinary(data,qrcodegen.QrCode.Ecc.LOW);
|
||||
|
||||
// SMALL Image
|
||||
var full = ascii(0xdb);
|
||||
var top = ascii(0xdf);
|
||||
var bot = ascii(0xdc);
|
||||
var blank = ' ';
|
||||
|
||||
var qrcode = '';
|
||||
|
||||
/*
|
||||
// Render the top line
|
||||
var line = ascii(27)+'[1;37m'+bot;
|
||||
for (var y = 0; y < qr.size; y++) {
|
||||
line += bot;
|
||||
}
|
||||
qrcode += line+bot+bot+ascii(27)+'[0m'+"\r\n";
|
||||
*/
|
||||
|
||||
// Render the body
|
||||
for (var x = -1; x < qr.size; x=x+2) {
|
||||
line = ascii(27)+'[1;37m'+full;
|
||||
|
||||
for (var y = 0; y < qr.size; y++) {
|
||||
// Top is white
|
||||
if (((x==-1)? 0 : qr.getModule(x, y)) == 0) {
|
||||
line += (qr.getModule(x+1, y)) ? top : full;
|
||||
|
||||
// Top is black
|
||||
} else {
|
||||
line += (qr.getModule(x+1, y)) ? blank : bot;
|
||||
}
|
||||
}
|
||||
|
||||
qrcode += line+full+ascii(27)+'[0m'+"\r\n";
|
||||
}
|
||||
|
||||
// Render the bottom
|
||||
line = ascii(27)+'[1;37m'+top;
|
||||
for (var y = 0; y < qr.size; y++) {
|
||||
line += top;
|
||||
}
|
||||
qrcode += line+top+ascii(27)+'[0m'+"\r\n";
|
||||
|
||||
subframe = new Frame(37,2,43,22,BG_BLACK|LIGHTGRAY,page);
|
||||
ans2bin(fo.parse(qrcode),subframe);
|
||||
subframe.open();
|
||||
subframe.cycle();
|
||||
subframe = new Frame(38,2,43,22,BG_BLACK|LIGHTGRAY);
|
||||
fo.qrcode(qr,subframe);
|
||||
|
||||
fo.sendBaseline('CANCEL_MSG',false);
|
||||
|
||||
@@ -113,22 +64,38 @@ function sqrllogin() {
|
||||
http.SendRequest();
|
||||
http.ReadResponse();
|
||||
|
||||
if (http.response_code == 404) {
|
||||
log(LOG_DEBUG,'- NUT not Authorised yet.');
|
||||
switch (http.response_code) {
|
||||
case 404:
|
||||
log(LOG_DEBUG,'- NUT not Authorised yet.');
|
||||
break;
|
||||
|
||||
} else {
|
||||
log(LOG_INFO,'NUT: ('+JSON.stringify(http.response_code)+'): '+JSON.stringify(http.body));
|
||||
case 200:
|
||||
if (http.body.isReady) {
|
||||
log(LOG_INFO,'NUT: '+http.body.msg);
|
||||
log(LOG_INFO,'NEXT: '+http.body.nextPage);
|
||||
|
||||
//@todo
|
||||
action = ACTION_GOTO;
|
||||
next_page = { frame: 98,index: 'a' };
|
||||
complete = true;
|
||||
if (typeof subframe === 'object')
|
||||
subframe.close();
|
||||
|
||||
complete = true;
|
||||
subframe.close();
|
||||
page.close();
|
||||
// We are done
|
||||
read = '2';
|
||||
|
||||
// We are done
|
||||
read = '2';
|
||||
} else {
|
||||
log(LOG_ERROR,'- Unhandled isReady: '+http.body.isReady);
|
||||
|
||||
// We are done
|
||||
read = '2';
|
||||
cancel = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
log(LOG_ERROR,'- Unhandled response code: '+http.response_code);
|
||||
|
||||
// We are done
|
||||
read = '2';
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +108,6 @@ function sqrllogin() {
|
||||
complete = true;
|
||||
if (typeof subframe === 'object')
|
||||
subframe.close();
|
||||
page.close();
|
||||
action = ACTION_GOTO;
|
||||
next_page = { frame: 98,index: 'a' };
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ var VIEWDATA_CANNOT_SEND_TOKEN = ascii(27)+'ACANNOT SEND VALIDATION CODE, PLEAS
|
||||
var VIEWDATA_USER_EXISTS = ascii(27)+'AERROR USER EXISTS, PLEASE TRY AGAIN *00';
|
||||
var VIEWDATA_USER_CREATE_ERROR = ascii(27)+'AERROR CREATING USER, PLEASE TRY AGAIN *00';
|
||||
var VIEWDATA_LOGIN_ERROR = ascii(27)+'AERROR LOGGING IN, PLEASE TRY AGAIN *00';
|
||||
var VIEWDATA_CANCEL_MSG = ascii(27)+'GPRESS 2 TO CANCEL';
|
||||
var VIEWDATA_CANCEL_MSG = ascii(27)+'BPRESS 2 TO CANCEL';
|
||||
|
||||
// Our frame object
|
||||
function VIEWDATAFrame() {
|
||||
@@ -111,7 +111,7 @@ function VIEWDATAFrame() {
|
||||
|
||||
header = VIEWDATA_DOWN;
|
||||
|
||||
log(LOG_DEBUG,' - FRAME User: ['+JSON.stringify(user)+']');
|
||||
//log(LOG_DEBUG,' - FRAME User: ['+JSON.stringify(user)+']');
|
||||
|
||||
// Dont show the page number on system login page
|
||||
if (user.number || (this.type != FRAME_TYPE_LOGIN && NO_HISTORY_FRAMES.indexOf(this.page) == -1)) {
|
||||
@@ -193,7 +193,7 @@ function VIEWDATAFrame() {
|
||||
|
||||
for(p=0;p<text.length;p++) {
|
||||
// Look for a special character until the end of the frame width
|
||||
cte = (r*FRAME_WIDTH - ((r-1)*FRAME_WIDTH+c));
|
||||
cte = (r*VIEWDATA_FRAME_WIDTH - ((r-1)*VIEWDATA_FRAME_WIDTH+c));
|
||||
match = text.substr(p,cte).match(/[\r\n\x1b]/);
|
||||
//log(LOG_DEBUG,'SPECIAL CHAR ['+r+'x'+c+'] ['+p+'-'+cte+'] for: '+match);
|
||||
|
||||
@@ -388,7 +388,7 @@ function VIEWDATAFrame() {
|
||||
p += advance;
|
||||
}
|
||||
|
||||
if (c>FRAME_WIDTH) {
|
||||
if (c>VIEWDATA_FRAME_WIDTH) {
|
||||
c = 1;
|
||||
r++;
|
||||
}
|
||||
@@ -404,6 +404,69 @@ function VIEWDATAFrame() {
|
||||
return output;
|
||||
};
|
||||
|
||||
this.qrcode = function(qr,subframe) {
|
||||
var offset = 18/2; // @todo For some reason RIGHT movements results in 2 spaces
|
||||
// Render the body
|
||||
var qrcode = VIEWDATA_HOME+VIEWDATA_DOWN.repeat(5)+VIEWDATA_RIGHT.repeat(offset);
|
||||
//var line = '';
|
||||
|
||||
for (var x = -1; x < qr.size; x=x+3) {
|
||||
var line = VIEWDATA_RIGHT.repeat(offset)+ascii(0x97);
|
||||
|
||||
for (var y = -1; y < qr.size; y=y+2) {
|
||||
var char = 0;
|
||||
|
||||
//TL
|
||||
char |= ((x==-1) || (y==-1) || ! qr.getModule(x,y)) ? (1<<0) : (0<<0);
|
||||
//TR
|
||||
char |= ((x==-1) || (y == qr.size-1) || ! qr.getModule(x,y+1)) ? (1<<1) : (0<<1);
|
||||
//ML
|
||||
char |= ((y==-1) || ! qr.getModule(x+1,y)) ? (1<<2) : (0<<2);
|
||||
//MR
|
||||
char |= ((y == qr.size-1) || ! qr.getModule(x+1,y+1)) ? (1<<3) : (0<<3);
|
||||
//BL
|
||||
char |= ((x==qr.size-2) || (y==-1) || ! qr.getModule(x+2,y)) ? (1<<4) : (0<<4);
|
||||
//BR
|
||||
char |= ((x==qr.size-2) || (y == qr.size-1) || ! qr.getModule(x+2,y+1)) ? (1<<5) : (0<<5);
|
||||
|
||||
char += 0x20;
|
||||
if (char > 0x3f)
|
||||
char += 0x20;
|
||||
|
||||
line += ascii(char);
|
||||
}
|
||||
|
||||
// Render the right column
|
||||
if (y%2)
|
||||
line += ascii(0x35);
|
||||
|
||||
qrcode += line+' '.repeat(VIEWDATA_FRAME_WIDTH-Math.ceil(qr.size/2)-2-offset*2-(y%2 ? 0 : 1))+VIEWDATA_RIGHT.repeat(offset);
|
||||
}
|
||||
|
||||
log(LOG_DEBUG,'WIDTH:'+VIEWDATA_FRAME_WIDTH);
|
||||
log(LOG_DEBUG,'QR :'+(Math.ceil(qr.size/2)+1));
|
||||
log(LOG_DEBUG,'OFF :'+offset);
|
||||
log(LOG_DEBUG,'Y :'+(y%2 ? 0 : 1));
|
||||
log(LOG_DEBUG,'X :'+(x%3 ? 0 : 1));
|
||||
|
||||
// Render the bottom
|
||||
if (x%3) {
|
||||
line = VIEWDATA_RIGHT.repeat(offset)+ascii(0x97);
|
||||
for (var y = 0; y < qr.size; y=y+2) {
|
||||
line += ascii(0x23);
|
||||
}
|
||||
|
||||
// Render the right column
|
||||
if (y%2 == 0) {
|
||||
line += ascii(0x21);
|
||||
}
|
||||
|
||||
qrcode += line+' '.repeat(VIEWDATA_FRAME_WIDTH-Math.ceil(qr.size/2)-2-offset-(y%2 ? 0 : 1));
|
||||
}
|
||||
|
||||
write_raw(qrcode+VIEWDATA_DOWN);
|
||||
};
|
||||
|
||||
this.save=function() {
|
||||
file = system.mods_dir+'ansitex/text/'+this.page+'.tex';
|
||||
w = new File(file);
|
||||
|
Reference in New Issue
Block a user