diff --git a/ctrl/videotex.ini b/ctrl/videotex.ini index 9cb3e75..7d9bb45 100644 --- a/ctrl/videotex.ini +++ b/ctrl/videotex.ini @@ -3,14 +3,7 @@ ; Our key used to sign frames we send to other systems gpg_key=516@videotex +; The prefix configurations need to be kept in sync with other nodes [prefix] key=0@videotex - -[prefix:5161] -key=5161@videotex - -[prefix:51] -key=51@videotex - -[prefix:516] -key=516@videotex +logo=AWgBUkEBR04BQlMBWUkBbgE3AWt0ZXgBbg== diff --git a/load/defs.js b/load/defs.js index 8d30aee..a1d9115 100644 --- a/load/defs.js +++ b/load/defs.js @@ -41,20 +41,18 @@ var ERR_NOT_IMPLEMENTED ='\1n\1h\1RNOT IMPLEMENTED YET?'; var ERR_ROUTE ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08'; var ERR_METHOD_NOT_EXIST ='\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08'; var ACCESS_DENIED ='\1n\1h\1RACCESS DENIED. \1RMISTAKE? TRY AGAIN OR TELL US *08'; -var INACTIVITY ='\1n\1h\1RINACTIVITY ALERT'; +var INACTIVITY ='\1n\1h\1RINACTIVITY ALERT, DISCONNECT PENDING...'; var INACTIVE ='\1n\1h\1RINACTIVITY DISCONNECT'; var NO_HISTORY_FRAMES =['980a','98b','981a']; -var SYSTEM_FRAMES =['AWgBUkEBR04BQlMBWUkBbgE3AWt0ZXgBbg==']; - // Our frame object function TexFrame() { this.version=1; // The version of this frame - in case we update functionality and we need to be // backwards compatible this.frame=null; // Frame Number [0-9]+ this.index=null; // Frame Index [a-z] - this.owner=''; // The Service Provider owning the frame. + this.owner=0; // The Service Provider owning the frame. this.cost=0; // The cost to view the frame @TODO this.content=''; // The frame content @@ -69,14 +67,13 @@ function TexFrame() { this.isPublic=false; // Is this frame accessible to non CUG users // If FALSE user must be a member of the CUG to view the frame + // All users, including unauthenticated, are members of 'system' (owner = 0) this.isAccessible=false; // Is this frame available to be accessed // If FALSE, only the SP can view/edit the frame this.type = FRAME_TYPE_INFO; // The frame type - see FRAME_TYPES above this.key=[ null,null,null,null,null,null,null,null,null,null ]; // Key actions [0-9] - this.frame_fields = []; // If a response frame, the embedded fields in the frame - // Render the frame to the user this.render=function(withHeader) { owner = base64_decode(this.owner); @@ -87,9 +84,9 @@ function TexFrame() { // Dont show the page number on system login page if (user.number || (this.type != FRAME_TYPE_LOGIN && NO_HISTORY_FRAMES.indexOf(this.page) == -1)) { - log(LOG_DEBUG,'- Owner: ['+JSON.stringify(owner)+']'); + log(LOG_DEBUG,'- Owner: ['+this.pageowner+']'); - header = '\1n'+owner+' '.repeat(FRAME_HEADER-console.strlen(owner))+'\1n '+ + header = '\1n'+this.pageownerlogo+' '.repeat(FRAME_HEADER-console.strlen(this.pageownerlogo))+'\1n '+ '\1W\1H'+this.page+' '.repeat(FRAME_PAGENUM-this.page.length)+' '+ '\1G\1H'+' '.repeat(FRAME_COST-this.cost.toString().length)+this.cost+FRAME_COSTUNIT+ (console.screen_columns > 80 ? '\n\r' : ''); @@ -105,6 +102,7 @@ function TexFrame() { this.fieldValue=function(key) { for each (var k in this.frame_fields) { log(LOG_DEBUG,' - k:'+JSON.stringify(k)); + if (k.fname == key) { return k.fvalue; } @@ -129,8 +127,6 @@ function TexFrame() { this[property] = load[property]; } - //this.content = base64_decode(this.content); - } catch (error) { log(LOG_ERROR,'Frame error: '+error); return null; @@ -391,26 +387,11 @@ function TexFrame() { log(LOG_DEBUG,'Saved file: '+this.page+'.tex'); } - Object.defineProperty(this,'page', { - get: function() { - if (this.frame == null || this.index == null) return null; - return this.frame+this.index; - } - }); - - Object.defineProperty(this,'fields', { - get: function() { - return this.frame_fields; - } - }); - Object.defineProperty(this,'accessible',{ get: function() { log(LOG_DEBUG,'- Checking if user can access frame: '+this.page); log(LOG_DEBUG,' - User: '+JSON.stringify(user.number)); - log(LOG_DEBUG,' - Frame Owner: '+JSON.stringify(this.owner)+', System Frame: '+(SYSTEM_FRAMES.indexOf(this.owner)>-1)); - - system_frame = (SYSTEM_FRAMES.indexOf(this.owner)>-1); + log(LOG_DEBUG,' - Frame Owner: '+JSON.stringify(this.owner)+', System Frame: '+(this.pageowner == 0)); // user.number 0 is unidentified user. if (user.number) { @@ -421,10 +402,35 @@ function TexFrame() { ); } else { - return (system_frame && this.isPublic && this.isAccessible); + return (this.pageowner == 0 && this.isPublic && this.isAccessible); } } }); + + Object.defineProperty(this,'fields', { + get: function() { + return this.frame_fields; + } + }); + + Object.defineProperty(this,'page', { + get: function() { + if (this.frame == null || this.index == null) return null; + return this.frame.toString()+this.index; + } + }); + + Object.defineProperty(this,'pageowner', { + get: function() { + return pageOwner(this.frame).prefix; + } + }) + + Object.defineProperty(this,'pageownerlogo', { + get: function() { + return base64_decode(pageOwner(this.frame).logo); + } + }) } this; \ No newline at end of file diff --git a/load/funcs.js b/load/funcs.js index 8cd594c..d021979 100644 --- a/load/funcs.js +++ b/load/funcs.js @@ -1,3 +1,6 @@ +// Array of page owners +pageowners = []; + // String repeat. if (!String.prototype.repeat) { String.prototype.repeat = function(count) { @@ -129,26 +132,64 @@ function pageStr(page) { if (! page.index) page.index = 'a'; - return page.frame+page.index; + return page.frame.toString()+page.index; } /** - * Save the frame + * Read our videotex.ini configuration and determine who owns a page. + * If there is no prefix for the page, it is owned by the system '0' * - * @param frame + * @param page + * @returns {undefined} */ -function saveFrame(frame) { - file = system.mods_dir+'ansitex/text/'+frame.page+'.tex'; - w = new File(file); - if (! w.open('w')) { - log(LOG_ERROR,'! ERROR: Unable to create TEX file for '+frame.page); - exit(1); +function pageOwner(page) { + // Load the owner configuration into memory + if (! pageowners.length) { + var f = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini')); + + if (f.open("r")) { + var logo = f.iniGetValue('prefix','logo'); + pageowners.push({prefix: 0,logo: logo}); + + f.iniGetSections('prefix:').forEach(function (prefix) { + var p = parseInt(prefix.substr(7)); + var logo = f.iniGetValue(prefix,'logo',''); + pageowners.push({prefix: p,logo: logo}); + }); + } + + f.close(); + + // Sort the pageowners ascending + pageowners.sort(compare); + + log(LOG_DEBUG,'+ pageOwner: pageowners='+JSON.stringify(pageowners)); } - w.write(JSON.stringify(frame)); - w.close(); + var pageowner = o = null; - log(LOG_DEBUG,'Saved file: '+frame.page+'.tex'); + pageowners.forEach(function(owner) { + var p = owner.prefix.toString(); + o = owner; + + log(LOG_DEBUG,'- pageOwner: p='+p+'('+p.length+') ,o: '+o); + match = ''; + + var re = new RegExp('^' + p, 'g'); + if (page.toString().match(re) && (p.length > match.length)) { + match = p; + pageowner = o; + log(LOG_DEBUG,'= pageOwner: p='+p+',o: '+o); + } + }); + + log(LOG_DEBUG,'+ pageOwner: page='+page+', owner: '+JSON.stringify(pageowner ? pageowner : o)); + + return pageowner ? pageowner : o; +} + +function compare(a,b) { + return (a.prefix < b.prefix) ? 1 : ((b.prefix < a.prefix) ? -1 : 0); } /** diff --git a/main.js b/main.js index fe2c673..8948bbb 100644 --- a/main.js +++ b/main.js @@ -34,7 +34,8 @@ while(bbs.online) { var cf = null; // Current Input Field var cc = null; // Current Control Method - var timeout = 0; // Track our inactivity timeout + var timeout = false; // Track our inactivity timeout + var timer = time(); var control = []; // Methods that need to process input ansi.send('ext_mode','clear','cursor'); @@ -46,30 +47,33 @@ while(bbs.online) { // If we have no action, read from the terminal if (action == false) { read = console.inkey(K_NONE,inkey_timeout); - } - log(LOG_DEBUG,'READ: ['+read+'] ('+read.charCodeAt(0)+')'); - if (read == '' && ! (user.security.exemptions&UFLAG_H) ) { - if (timeout++ > 1) { - sendBaseline(INACTIVE,false); - bbs.hangup(); + if (read == '' && ! (user.security.exemptions&UFLAG_H) ) { + if (time() > timer+inkey_timeout/1000) { + sendBaseline(INACTIVE,false); + bbs.hangup(); + + } else { + timeout = true; + sendBaseline(INACTIVITY,false); + + if (cf) + console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m'); + } } else { - sendBaseline(INACTIVITY,false); - if (cf) - console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m'); + if (timeout) { + sendBaseline('',false); + + if (cf) + console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m'); + } + + timer = time(); + timeout = false; } - - } else { - if (timeout) { - sendBaseline('',false); - - if (cf) - console.write(KEY_ESC+'['+cf.attribute.i+';'+cf.attribute.f+';'+cf.attribute.b+'m'); - } - - timeout = 0; } + log(LOG_DEBUG,'READ: ['+read+'] ('+read.charCodeAt(0)+')'); system.node_list[bbs.node_num-1].action=0xff; // to ensure our node status is updated correctly diff --git a/save.js b/save.js index 3bc0f86..1b8321b 100644 --- a/save.js +++ b/save.js @@ -84,7 +84,7 @@ if (! send || ! frame || file) { } // Store the frame in file - saveFrame(frame); + frame.save(); } // @NOTE: We need to use a binary signature then base64 encode it, as mailers may strip 0x0a while messages are in transit.