Put SQRL configuration into ini, better trap failed init

This commit is contained in:
Deon George 2020-08-14 12:33:33 +10:00
parent 38a88eb7c0
commit cdb0519c49
3 changed files with 99 additions and 91 deletions

View File

@ -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]

View File

@ -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;
}

View File

@ -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,11 +41,6 @@ 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)});
@ -107,7 +104,7 @@ function sqrllogin() {
cancel = true;
http = new HTTPRequest();
http.SetupGet('/api/sqrl?'+nut,undefined,'http://ansitex.leenooks.net');
http.SetupGet(sqrl.auth_post+'?'+nut,undefined,sqrl.auth_url);
http.request_headers.push('Accept: application/json');
log(LOG_DEBUG,'Checking NUT in ['+nut+']');
@ -133,8 +130,15 @@ function sqrllogin() {
}
}
} catch(err) {
log(LOG_INFO,'SQRL Error: '+err);
cancel = true;
}
if (cancel) {
complete = true;
log(LOG_INFO,'DEBUG: ' + typeof subframe);
if (typeof subframe !== 'undefined')
subframe.close();
page.close();
action = ACTION_GOTO;