Move frame owner/log to videotex.ini
This commit is contained in:
60
load/defs.js
60
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;
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user