Enabled login and shell
This commit is contained in:
166
load/defs.js
166
load/defs.js
@@ -2,6 +2,7 @@
|
||||
* ANSItex definitions
|
||||
*/
|
||||
|
||||
var ACTION_EXIT =99; /* Exit the script */
|
||||
var ACTION_RELOAD =1; /* Reload the current frame */
|
||||
var ACTION_GOTO =2; /* Goto a specific frame */
|
||||
var ACTION_BACKUP =3; /* Goto previous frame */
|
||||
@@ -11,6 +12,11 @@ var ACTION_SUBMITRF =6; /* Submit form contents */
|
||||
var ACTION_STAR =7; /* Star command entry */
|
||||
|
||||
var MODE_BL =1; /* Typing * command on baseline */
|
||||
var MODE_FIELD =2; /* Field Input */
|
||||
var MODE_SUBMITRF =3; /* Asking if form should be submitted */
|
||||
var MODE_RFNOTSENT =4; /* Response frame not sent */
|
||||
var MODE_RFSENT =5; /* Response frame sent */
|
||||
var MODE_RFERROR =6; /* Response frame error */
|
||||
|
||||
var FRAME_LENGTH =22; /* Length of a frame */
|
||||
var FRAME_WIDTH =80; /* Width of a frame */
|
||||
@@ -19,52 +25,71 @@ var FRAME_PAGENUM =12; /* Size of page number (length with a-z) */
|
||||
var FRAME_COST = 9; /* Size of cost (length without unit) */
|
||||
var FRAME_COSTUNIT ='c'; /* Unit of cost */
|
||||
|
||||
var FRAME_TYPE_INFO ='i';
|
||||
var FRAME_TYPE_TERMINATE ='t';
|
||||
var FRAME_TYPE_EXTERNAL ='x';
|
||||
var FRAME_TYPE_RESPONSE ='r';
|
||||
var FRAME_TYPE_LOGIN ='l';
|
||||
var FRAME_TYPE_INFO ='i'; // Information Frame, requires no response after viewed
|
||||
var FRAME_TYPE_TERMINATE ='t'; // Terminate Frame, contents displayed and then carrier dropped
|
||||
var FRAME_TYPE_EXTERNAL ='x'; // Frame the calls an External Method
|
||||
// Contents indicate the method to be called with arguments
|
||||
var FRAME_TYPE_RESPONSE ='r'; // Response frame, input fields are embedded in the frame and after input the
|
||||
// response will be submitted to the Service Provider, or to a method
|
||||
var FRAME_TYPE_LOGIN ='l'; // Login frame, enables the user to authenticate to the system, or to a CUG
|
||||
|
||||
var ERR_NOT_IMPLEMENTED ='\1RNOT IMPLEMENTED YET?';
|
||||
var MSG_SENDORNOT ='\1n\1h\1GKEY 1 TO SEND, 2 NOT TO SEND';
|
||||
var MSG_LOGON ='\1n\1h\1GKEY 1 TO LOGON, 2 TO RETURN';
|
||||
var MSG_SENT ='\1n\1h\1GMESSAGE SENT - KEY # TO CONTINUE';
|
||||
var MSG_NOTSENT ='\1n\1h\1GMESSAGE NOT SENT - KEY # TO CONTINUE';
|
||||
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 NO_HISTORY_FRAMES =['98b'];
|
||||
|
||||
var SYSTEM_FRAMES =['AWgBUkEBR04BQlMBWUkBbgE3AWt0ZXgBbg=='];
|
||||
|
||||
// Our frame object
|
||||
function Frame() {
|
||||
this.version=1;
|
||||
this.frame=null;
|
||||
this.index=null;
|
||||
this.owner=''; // @todo
|
||||
this.cost=0; // @todo
|
||||
this.content='';
|
||||
this.isPublic=false; // @todo
|
||||
this.isAccessible=false; // @todo
|
||||
this.type = FRAME_TYPE_INFO;
|
||||
this.key=[ null,null,null,null,null,null,null,null,null,null ];
|
||||
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.cost=0; // The cost to view the frame @TODO
|
||||
this.content=''; // The frame content
|
||||
|
||||
// Initialise frame array
|
||||
/*
|
||||
this.frame_data = {};
|
||||
this.frame_content = {};
|
||||
for(x=0;x<FRAME_LENGTH;x++)
|
||||
{
|
||||
this.frame_data[x] = {};
|
||||
this.frame_content[x] = {};
|
||||
}
|
||||
*/
|
||||
this.frame_fields = [];
|
||||
// Frame's owned by the system where:
|
||||
// isPublic is FALSE - the user must be logged in to view it
|
||||
// isPublic is TRUE - can be viewed by non-logged in users
|
||||
|
||||
// Frame's owned by Service Providers where:
|
||||
// isPublic is FALSE - can only be viewed if a user is
|
||||
// a member of the Service Providers CUG
|
||||
// isPublic is TRUE - can be viewed by users (if logged in)
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
// The RAW frame content
|
||||
this.raw=function() {
|
||||
return base64_decode(this.content).replace(/(\r\n|\n|\r)/gm,'');
|
||||
};
|
||||
|
||||
// Render the frame to the user
|
||||
this.render=function(withHeader) {
|
||||
owner = base64_decode(this.owner);
|
||||
|
||||
header = '\n\r';
|
||||
|
||||
if (this.type != FRAME_TYPE_LOGIN) {
|
||||
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) {
|
||||
header = '\1n'+owner+' '.repeat(FRAME_HEADER-console.strlen(owner))+'\1n '+
|
||||
'\1W\1H'+this.page+' '.repeat(FRAME_PAGENUM-this.page.length)+' '+
|
||||
'\1G\1H'+' '.repeat(FRAME_COST-this.cost.toString().length)+this.cost+FRAME_COSTUNIT+
|
||||
@@ -90,6 +115,28 @@ function Frame() {
|
||||
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);
|
||||
|
||||
// user.number 0 is unidentified user.
|
||||
if (user.number) {
|
||||
return (
|
||||
(this.isAccessible && this.isPublic) ||
|
||||
(this.isAccessible && ! this.isPublic && user.isMember) ||
|
||||
(user.isOwner)
|
||||
);
|
||||
|
||||
} else {
|
||||
return (system_frame && this.isPublic && this.isAccessible);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Load a frame from disk (.tex file)
|
||||
@@ -102,7 +149,7 @@ Frame.prototype.load = function(filename) {
|
||||
}
|
||||
|
||||
try {
|
||||
load = JSON.parse(f.read());
|
||||
var load = JSON.parse(f.read());
|
||||
|
||||
for (property in load) {
|
||||
this[property] = load[property];
|
||||
@@ -134,8 +181,9 @@ Frame.prototype.load = function(filename) {
|
||||
*/
|
||||
Frame.prototype.parse = function(text) {
|
||||
var c = 1; // column
|
||||
var r = 1; // row
|
||||
var r = 2; // row (row 1 is the header)
|
||||
var output = '';
|
||||
this.frame_fields = [];
|
||||
|
||||
// Default Attributes
|
||||
f = 39;
|
||||
@@ -146,11 +194,11 @@ Frame.prototype.parse = function(text) {
|
||||
// Look for a special character until the end of the frame width
|
||||
cte = (r*FRAME_WIDTH - ((r-1)*FRAME_WIDTH+c));
|
||||
match = text.substr(p,cte).match(/[\r\n\x1b]/);
|
||||
log(LOG_DEBUG,'SPECIAL CHAR ['+r+'x'+c+'] ['+p+'-'+cte+'] for: '+match);
|
||||
//log(LOG_DEBUG,'SPECIAL CHAR ['+r+'x'+c+'] ['+p+'-'+cte+'] for: '+match);
|
||||
|
||||
if (match == null || match.index) {
|
||||
advance = match ? match.index : cte;
|
||||
log(LOG_DEBUG,'INCLUDE: '+text.substr(p,advance));
|
||||
//log(LOG_DEBUG,'INCLUDE: '+text.substr(p,advance));
|
||||
|
||||
output += text.substr(p,advance);
|
||||
p += advance;
|
||||
@@ -165,13 +213,13 @@ Frame.prototype.parse = function(text) {
|
||||
switch (byte) {
|
||||
// Carriage Return
|
||||
case '\r':
|
||||
log(LOG_DEBUG,'CR');
|
||||
// log(LOG_DEBUG,'CR');
|
||||
c=1;
|
||||
break;
|
||||
|
||||
// New line
|
||||
case '\n':
|
||||
log(LOG_DEBUG,'LF');
|
||||
// log(LOG_DEBUG,'LF');
|
||||
r++;
|
||||
break;
|
||||
|
||||
@@ -180,7 +228,7 @@ Frame.prototype.parse = function(text) {
|
||||
advance = 1;
|
||||
// Is the next byte something we know about
|
||||
nextbyte = text.charAt(p+advance);
|
||||
log(LOG_DEBUG,'ESC ['+r+'x'+c+'] NEXT: '+nextbyte);
|
||||
//log(LOG_DEBUG,'ESC ['+r+'x'+c+'] NEXT: '+nextbyte);
|
||||
|
||||
switch (nextbyte) {
|
||||
// CSI
|
||||
@@ -190,7 +238,7 @@ Frame.prototype.parse = function(text) {
|
||||
|
||||
// Find our end CSI param in the next 50 chars
|
||||
matches = text.substr(p+advance,50).match(/([0-9]+[;]?)+([a-zA-Z])/);
|
||||
log(LOG_DEBUG,'CSI ['+r+'x'+c+'] ADVANCE: '+advance+', MATCHES: '+matches+', STRING: '+text.substr(p+advance,50));
|
||||
//log(LOG_DEBUG,'CSI ['+r+'x'+c+'] ADVANCE: '+advance+', MATCHES: '+matches+', STRING: '+text.substr(p+advance,50));
|
||||
|
||||
if (! matches) {
|
||||
chars += nextbyte;
|
||||
@@ -200,17 +248,17 @@ Frame.prototype.parse = function(text) {
|
||||
|
||||
advance += matches[0].length-1;
|
||||
chars += nextbyte+matches[0];
|
||||
log(LOG_DEBUG,'CSI ['+r+'x'+c+'] ADVANCE: '+advance+', CHARS: '+chars+', CHARSLEN: '+chars.length);
|
||||
//log(LOG_DEBUG,'CSI ['+r+'x'+c+'] ADVANCE: '+advance+', CHARS: '+chars+', CHARSLEN: '+chars.length);
|
||||
|
||||
switch (matches[2]) {
|
||||
// Color CSIs
|
||||
case 'm':
|
||||
log(LOG_DEBUG,'CSI m ['+r+'x'+c+'] MATCHES: '+matches[0]+', LENGTH : '+matches[0].length);
|
||||
//log(LOG_DEBUG,'CSI m ['+r+'x'+c+'] MATCHES: '+matches[0]+', LENGTH : '+matches[0].length);
|
||||
|
||||
csi = matches[0].substr(0,matches[0].length-1).split(';');
|
||||
var num = null;
|
||||
for (num in csi) {
|
||||
log(LOG_DEBUG,'CSI m ['+r+'x'+c+'] NUM: '+num+', CSI: '+csi[num]);
|
||||
//log(LOG_DEBUG,'CSI m ['+r+'x'+c+'] NUM: '+num+', CSI: '+csi[num]);
|
||||
// Intensity
|
||||
if (csi[num] >= 0 && csi[num] <= 8) {
|
||||
i = csi[num];
|
||||
@@ -230,12 +278,12 @@ Frame.prototype.parse = function(text) {
|
||||
|
||||
// Advance characters
|
||||
case 'C':
|
||||
log(LOG_DEBUG,'CSI C ['+r+'x'+c+'] CHARS: '+matches[1]);
|
||||
//log(LOG_DEBUG,'CSI C ['+r+'x'+c+'] CHARS: '+matches[1]);
|
||||
c += parseInt(matches[1]); // Advance our position
|
||||
break;
|
||||
|
||||
default:
|
||||
dump('? CSI: '.matches[2]);
|
||||
log(LOG_DEBUG,'? CSI: '.matches[2]);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -247,12 +295,12 @@ Frame.prototype.parse = function(text) {
|
||||
|
||||
// SOS
|
||||
case '_':
|
||||
log(LOG_DEBUG,'SOS ['+r+'x'+c+'] '+advance);
|
||||
//log(LOG_DEBUG,'SOS ['+r+'x'+c+'] '+advance);
|
||||
advance++;
|
||||
|
||||
// Find our end ST param in the next 50 chars
|
||||
matches = text.substr(p+advance,50).match(/(([A-Z]+;[0-9a-z]+)([;]?.+)?)\x1b\\/);
|
||||
log(LOG_DEBUG,'SOS ['+r+'x'+c+'] ADVANCE: '+advance+', MATCHES: '+matches+', LENGTH: '+matches[0].length+', STRING: '+text.substr(p+advance,50));
|
||||
//log(LOG_DEBUG,'SOS ['+r+'x'+c+'] ADVANCE: '+advance+', MATCHES: '+matches+', LENGTH: '+matches[0].length+', STRING: '+text.substr(p+advance,50));
|
||||
|
||||
if (! matches) {
|
||||
chars += nextbyte;
|
||||
@@ -264,12 +312,12 @@ Frame.prototype.parse = function(text) {
|
||||
|
||||
// The last 2 chars of matches[0] are the ESC \
|
||||
sos = matches[0].substr(0,matches[0].length-2).split(';');
|
||||
log(LOG_DEBUG,'SOS ['+r+'x'+c+'] ADVANCE: '+advance+', SOS: '+sos);
|
||||
//log(LOG_DEBUG,'SOS ['+r+'x'+c+'] ADVANCE: '+advance+', SOS: '+sos);
|
||||
|
||||
var num = null;
|
||||
var fieldlen = null;
|
||||
for (num in sos) {
|
||||
log(LOG_DEBUG,'SOS ['+r+'x'+c+'] NUM: '+num+', SOS: '+sos[num]);
|
||||
//log(LOG_DEBUG,'SOS ['+r+'x'+c+'] NUM: '+num+', SOS: '+sos[num]);
|
||||
|
||||
switch (num) {
|
||||
// First value is the field name
|
||||
@@ -285,7 +333,7 @@ Frame.prototype.parse = function(text) {
|
||||
break;
|
||||
}
|
||||
|
||||
log(LOG_DEBUG,'SOS ['+r+'x'+c+'] NUM CHARS: '+x[1]+', TYPE: '+x[2]);
|
||||
//log(LOG_DEBUG,'SOS ['+r+'x'+c+'] NUM CHARS: '+x[1]+', TYPE: '+x[2]);
|
||||
fieldlen = x[1];
|
||||
fieldtype = x[2];
|
||||
break;
|
||||
@@ -296,7 +344,7 @@ Frame.prototype.parse = function(text) {
|
||||
break;
|
||||
|
||||
default:
|
||||
log(LOG_ERROR,'IGNORING ADITIONAL SOS FIELDS. ['+r+'x'+c+'] '+sos[num]);
|
||||
log(LOG_ERROR,'IGNORING ADDITIONAL SOS FIELDS. ['+r+'x'+c+'] '+sos[num]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,11 +355,12 @@ Frame.prototype.parse = function(text) {
|
||||
byte = '';
|
||||
|
||||
this.frame_fields.push({
|
||||
type: fieldtype,
|
||||
length: fieldlen,
|
||||
ftype: fieldtype,
|
||||
flength: fieldlen,
|
||||
r: r,
|
||||
c: c,
|
||||
attribute: {i:i,f:f,b:b},
|
||||
fvalue: '',
|
||||
});
|
||||
|
||||
log(LOG_DEBUG,'SOS Field found at ['+r+'x'+(c-1)+'], Type: '+fieldtype+', Length: '+fieldlen+', Attrs: '+JSON.stringify({i:i,f:f,b:b}));
|
||||
@@ -325,16 +374,13 @@ Frame.prototype.parse = function(text) {
|
||||
break;
|
||||
|
||||
default:
|
||||
//this.frame_data[r][c] = {i:i,f:f,b:b};
|
||||
//this.frame_content[r][c] = byte;
|
||||
log(LOG_DEBUG,'ADD OUTPUT ['+r+'x'+c+'] for: '+byte);
|
||||
c++;
|
||||
}
|
||||
|
||||
output += byte;
|
||||
|
||||
if (advance) {
|
||||
log(LOG_DEBUG,'ADVANCE P ['+r+'x'+c+'] '+advance+', NEXT CHAR: '+text.charAt(p+advance)+' ('+text.charCodeAt(p+advance)+')');
|
||||
//log(LOG_DEBUG,'ADVANCE P ['+r+'x'+c+'] '+advance+', NEXT CHAR: '+text.charAt(p+advance)+' ('+text.charCodeAt(p+advance)+')');
|
||||
output += chars;
|
||||
p += advance;
|
||||
}
|
||||
@@ -344,19 +390,15 @@ Frame.prototype.parse = function(text) {
|
||||
r++;
|
||||
}
|
||||
|
||||
/*
|
||||
// @todo - If we are longer than FRAME_LENGTH, move the output into the next frame.
|
||||
if (r>FRAME_LENGTH) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Debugging
|
||||
if (false && r > 3) {
|
||||
console.write(output);
|
||||
bbs.hangup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
};
|
||||
|
||||
this;
|
@@ -41,6 +41,9 @@ if (!String.prototype.repeat) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off the cursor
|
||||
*/
|
||||
function cursorOff() {
|
||||
ansi.send('ext_mode','clear','cursor');
|
||||
console.gotoxy(0,24);
|
||||
@@ -148,6 +151,12 @@ function saveFrame(frame) {
|
||||
log(LOG_DEBUG,'Saved file: '+frame.page+'.tex');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the baseline.
|
||||
*
|
||||
* @param text
|
||||
* @param reposition
|
||||
*/
|
||||
function sendBaseline(text,reposition) {
|
||||
console.pushxy();
|
||||
console.gotoxy(0,24);
|
||||
@@ -157,4 +166,6 @@ function sendBaseline(text,reposition) {
|
||||
if (! reposition) {
|
||||
console.popxy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this;
|
Reference in New Issue
Block a user