Put SQRL configuration into ini, better trap failed init
This commit is contained in:
parent
38a88eb7c0
commit
cdb0519c49
@ -4,6 +4,10 @@
|
||||
;gpg_key=0@videotex
|
||||
|
||||
; The prefix configurations need to be kept in sync with other nodes
|
||||
[sqrl]
|
||||
auth_url=http://ansitex.bbs.leenooks.net
|
||||
auth_path=sqrl/login
|
||||
auth_post=api/sqrl
|
||||
|
||||
; Frames with no specific owner are owned by this key
|
||||
[prefix]
|
||||
|
@ -117,7 +117,7 @@ function getPageOwners() {
|
||||
if (! pageowners.length) {
|
||||
var f = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
||||
|
||||
if (f.open("r")) {
|
||||
if (f.open('r')) {
|
||||
var logoans = f.iniGetValue('prefix','logoans');
|
||||
var logovtx = f.iniGetValue('prefix','logovtx');
|
||||
var users = f.iniGetValue('prefix','user');
|
||||
@ -145,16 +145,16 @@ function getPageOwners() {
|
||||
return pageowners;
|
||||
}
|
||||
|
||||
function loadOptions() {
|
||||
ini = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
||||
function loadOptions(option) {
|
||||
var f = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
||||
|
||||
if (!ini.open("r")) {
|
||||
if (! f.open('r')) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
val = ini.iniGetObject(null);
|
||||
val = f.iniGetObject(option);
|
||||
|
||||
ini.close();
|
||||
f.close();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -30,8 +30,10 @@ function sqrllogin() {
|
||||
page.open();
|
||||
page.cycle();
|
||||
|
||||
log(LOG_DEBUG,'OPTIONS: '+JSON.stringify(loadOptions('sqrl')));
|
||||
sqrl = loadOptions('sqrl');
|
||||
http = new HTTPRequest();
|
||||
http.SetupGet('/sqrl/login',undefined,'http://ansitex.leenooks.net');
|
||||
http.SetupGet(sqrl.auth_path,undefined,sqrl.auth_url);
|
||||
http.request_headers.push('Accept: application/json');
|
||||
|
||||
try {
|
||||
@ -39,103 +41,105 @@ function sqrllogin() {
|
||||
http.ReadResponse();
|
||||
log(LOG_INFO,'SQRL: '+JSON.stringify(http.body));
|
||||
|
||||
} catch(err) {
|
||||
log(LOG_INFO, "http error: " + err);
|
||||
return false;
|
||||
}
|
||||
var data = http.body
|
||||
.split('')
|
||||
.map(function(x) {return x.charCodeAt(0)});
|
||||
var qr = qrcodegen.QrCode.encodeBinary(data,qrcodegen.QrCode.Ecc.LOW);
|
||||
|
||||
var data = http.body
|
||||
.split('')
|
||||
.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 = ' ';
|
||||
|
||||
// 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+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+full;
|
||||
var qrcode = '';
|
||||
|
||||
// Render the top line
|
||||
var line = ascii(27)+'[1;37m'+bot+bot;
|
||||
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;
|
||||
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+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+full+ascii(27)+'[0m'+"\r\n";
|
||||
}
|
||||
|
||||
// Render the bottom
|
||||
line = ascii(27)+'[1;37m'+full+full;
|
||||
for (var y = 0; y < qr.size; y++) {
|
||||
line += full;
|
||||
}
|
||||
qrcode += line+full+full+ascii(27)+'[0m'+"\r\n";
|
||||
|
||||
subframe = new Frame(39,2,42,22,BG_BLACK|LIGHTGRAY,page);
|
||||
ans2bin(fo.parse(qrcode),subframe);
|
||||
subframe.open();
|
||||
subframe.cycle();
|
||||
|
||||
fo.sendBaseline('CANCEL_MSG',false);
|
||||
|
||||
// Loop and see if the user has logged in
|
||||
nut = http.body.substr(http.body.indexOf('nut='),68);
|
||||
|
||||
var read = '';
|
||||
while (read !== '2') {
|
||||
read = console.inkey(K_NONE,1000);
|
||||
|
||||
if (read == 2)
|
||||
cancel = true;
|
||||
|
||||
http = new HTTPRequest();
|
||||
http.SetupGet(sqrl.auth_post+'?'+nut,undefined,sqrl.auth_url);
|
||||
http.request_headers.push('Accept: application/json');
|
||||
|
||||
log(LOG_DEBUG,'Checking NUT in ['+nut+']');
|
||||
http.SendRequest();
|
||||
http.ReadResponse();
|
||||
|
||||
if (http.response_code == 404) {
|
||||
log(LOG_DEBUG,'- NUT not Authorised yet.');
|
||||
|
||||
// Top is black
|
||||
} else {
|
||||
line += (qr.getModule(x+1, y)) ? blank : bot;
|
||||
log(LOG_INFO,'NUT: ('+JSON.stringify(http.response_code)+'): '+JSON.stringify(http.body));
|
||||
|
||||
//@todo
|
||||
action = ACTION_GOTO;
|
||||
next_page = { frame: 98,index: 'a' };
|
||||
|
||||
complete = true;
|
||||
subframe.close();
|
||||
page.close();
|
||||
|
||||
// We are done
|
||||
read = '2';
|
||||
}
|
||||
}
|
||||
|
||||
qrcode += line+full+full+ascii(27)+'[0m'+"\r\n";
|
||||
}
|
||||
|
||||
// Render the bottom
|
||||
line = ascii(27)+'[1;37m'+full+full;
|
||||
for (var y = 0; y < qr.size; y++) {
|
||||
line += full;
|
||||
}
|
||||
qrcode += line+full+full+ascii(27)+'[0m'+"\r\n";
|
||||
|
||||
subframe = new Frame(39,2,42,22,BG_BLACK|LIGHTGRAY,page);
|
||||
ans2bin(fo.parse(qrcode),subframe);
|
||||
subframe.open();
|
||||
subframe.cycle();
|
||||
|
||||
fo.sendBaseline('CANCEL_MSG',false);
|
||||
|
||||
// Loop and see if the user has logged in
|
||||
nut = http.body.substr(http.body.indexOf('nut='),68);
|
||||
|
||||
var read = '';
|
||||
while (read !== '2') {
|
||||
read = console.inkey(K_NONE,1000);
|
||||
|
||||
if (read == 2)
|
||||
cancel = true;
|
||||
|
||||
http = new HTTPRequest();
|
||||
http.SetupGet('/api/sqrl?'+nut,undefined,'http://ansitex.leenooks.net');
|
||||
http.request_headers.push('Accept: application/json');
|
||||
|
||||
log(LOG_DEBUG,'Checking NUT in ['+nut+']');
|
||||
http.SendRequest();
|
||||
http.ReadResponse();
|
||||
|
||||
if (http.response_code == 404) {
|
||||
log(LOG_DEBUG,'- NUT not Authorised yet.');
|
||||
|
||||
} else {
|
||||
log(LOG_INFO,'NUT: ('+JSON.stringify(http.response_code)+'): '+JSON.stringify(http.body));
|
||||
|
||||
//@todo
|
||||
action = ACTION_GOTO;
|
||||
next_page = { frame: 98,index: 'a' };
|
||||
|
||||
complete = true;
|
||||
subframe.close();
|
||||
page.close();
|
||||
|
||||
// We are done
|
||||
read = '2';
|
||||
}
|
||||
} catch(err) {
|
||||
log(LOG_INFO,'SQRL Error: '+err);
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
if (cancel) {
|
||||
complete = true;
|
||||
subframe.close();
|
||||
log(LOG_INFO,'DEBUG: ' + typeof subframe);
|
||||
if (typeof subframe !== 'undefined')
|
||||
subframe.close();
|
||||
page.close();
|
||||
action = ACTION_GOTO;
|
||||
next_page = { frame: 98,index: 'a' };
|
||||
|
Loading…
Reference in New Issue
Block a user