Frame import into message base

This commit is contained in:
Deon George 2019-10-15 21:48:16 +11:00
parent d31778d7b9
commit 7b13525108
4 changed files with 214 additions and 108 deletions

View File

@ -12,17 +12,17 @@ load('texfuncs.js');
while(bbs.online) {
var mode = false; // Initial mode
var next_page = { frame: 1,index: 'a'}; // Start Frame
var next_page = { frame: 1,index: 'a'}; // Start Frame
var action = ACTION_GOTO; // Initial action
var inkey_timeout = 0; // Timeout waiting for input @todo required? check if idle timetout occurs
var fo = null; // Current Frame
var fo = null; // Current Frame
ansiterm.send('ext_mode','clear','cursor');
while (action != ACTION_TERMINATE) {
bbs.nodesync(false); // @todo Stop the display of telegrams
bbs.nodesync(false); // @todo Stop the display of telegrams
read = console.inkey(K_NONE,inkey_timeout);
system.node_list[bbs.node_num-1].action=0xff; // to ensure our node status is updated correctly
inkey_timeout = 60000; // Set our key timeout to 60s
inkey_timeout = 60000; // Set our key timeout to 60s
log(LOG_DEBUG,'READ: ['+read+']');
log(LOG_DEBUG,'MODE START: ['+read+']');
@ -273,4 +273,4 @@ exit();
}
log(LOG_DEBUG,'ACTION END: ['+read+']');
}
}
}

View File

@ -1,54 +1,115 @@
load('texdefs.js');
load('texfuncs.js');
// File to convert
file = getArg('-f','No file specified with -f',true);
// Page
p = getArg('-p','No page specified with -p',true);
// Index
i = getArg('-i','No index specified with -i',false);
// Key
key = getArg('-k','No index specified with -k',false);
// Cost
cost = getArg('-c','No index specified with -c',false);
// Owner
owner = getArg('-o','No owner specified with -o',true);
// Import
send = getArg('-s','Use -s 1 to send',false);
file = getArg('-S','Use -S filename',false);
frame = '';
f = new File(file);
if (! f.exists || ! f.open('r')) {
log(LOG_ERROR,'Unable to open ['+file+']');
exit(1);
if (! send || ! file) {
// File to convert
file = getArg('-f','No file specified with -f',true);
// Page
p = getArg('-p','No page specified with -p',true);
// Index
i = getArg('-i','No index specified with -i',false);
// Key
key = getArg('-k','No index specified with -k',false);
// Cost
cost = getArg('-c','No index specified with -c',false);
// Owner
owner = getArg('-o','No owner specified with -o',true);
// Import
send = getArg('-s','Use -s 1 to send',false);
f = new File(file);
if (! f.exists || ! f.open('r')) {
log(LOG_ERROR,'! ERROR: Unable to open ['+file+']');
exit(1);
}
frame = new Frame(p,i);
frame.owner = base64_encode(owner.replace(/\\1/g,"\1"));
frame.content = base64_encode(f.read());
if (key) {
frame.key = key.split(',').map(function(t){return parseInt(t)});
if (frame.key.length != 10) {
log(LOG_ERROR,'! ERROR: Must specify 10 keys with -k');
exit(1);
}
}
// Public
frame.isPublic = (argv.indexOf('-P') >= 0);
frame.isAccessible = (argv.indexOf('-A') >= 0);
if (cost)
frame.cost = cost;
// Date
frame.date = new Date().toISOString();
// Store the frame in file
file = system.text_dir+'ansitex/'+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);
}
w.write(JSON.stringify(frame));
w.close();
printf('Saved file: %s.tex',frame.page);
}
frame = new Frame(p,i);
frame.owner = base64_encode(owner.replace(/\\1/g,"\1"));
frame.content = base64_encode(f.read());
// @NOTE: We need to use a binary signature then base64 encode it, as mailers may strip 0x0a while messages are in transit.
if (send == 1) {
if (! file_exists(file)) {
log(LOG_ERROR,'! ERROR: File '+file+' doesnt exist?');
exit(1);
}
if (key) {
frame.key = key.split(',').map(function(t){return parseInt(t)});
if (! frame) {
f = new File(file);
if (! f.open('r')) {
log(LOG_ERROR,'! ERROR: Unable to open '+file);
exit(1);
}
if (frame.key.length != 10) {
log(LOG_ERROR,'Must specify 10 keys with -k');
exit(1);
}
}
try {
frame = JSON.parse(f.read());
x = new Frame(0);
frame.render = x.render;
// Public
frame.isPublic = (argv.indexOf('-P') >= 0);
frame.isAccessible = (argv.indexOf('-A') >= 0);
if (cost)
frame.cost = cost;
// @todo Figure out how to delete this duplicate code
Object.defineProperty(frame,'page', {
get: function() {return this.frame+this.index}
});
} catch (error) {
log(LOG_ERROR,error);
exit(1);
}
f.close();
}
// Date
frame.date = new Date().toISOString();
if (file_exists(file+'.gpg'))
file_remove(file+'.gpg')
w = new File(system.text_dir+'ansitex/'+frame.page+'.tex');
if (! w.open('w')) {
log(LOG_ERROR,'Unable to create TEX file for '+frame.page);
exit(1);
}
result = system.exec('gpg --homedir /opt/sbbs/mods/keys --batch --local-user 516@videotex -s '+file);
w = new File(file+'.gpg');
w.write(JSON.stringify(frame));
w.close();
if (w.open('r')) {
msg = base64_encode(w.read());
printf('Saved file: %s.tex',frame.page);
} else {
log(LOG_ERROR,'! ERROR: Unable to send with GPG for '+frame.page + ' Error: '+w.error);
exit(1);
}
w.close();
msgBaseExport(null,frame.page,msg);
printf('GPG Result: %s',result);
}

7
mods/keys/genkey.txt Normal file
View File

@ -0,0 +1,7 @@
Key-Type: default
Key-Usage: encrypt,sign
Name-Real: Your Name
Name-Comment: Ansitex Page *???#
Name-Email: ???@videotex
Expire-Date: 0
%commit

View File

@ -1,48 +1,72 @@
if (!String.prototype.repeat) {
String.prototype.repeat = function(count) {
'use strict';
if (this == null) {
throw new TypeError('can\'t convert ' + this + ' to object');
}
var str = '' + this;
count = +count;
if (count != count) {
count = 0;
}
if (count < 0) {
throw new RangeError('repeat count must be non-negative');
}
if (count == Infinity) {
throw new RangeError('repeat count must be less than infinity');
}
count = Math.floor(count);
if (str.length == 0 || count == 0) {
return '';
}
// Ensuring count is a 31-bit integer allows us to heavily optimize the
// main part. But anyway, most current (August 2014) browsers can't handle
// strings 1 << 28 chars or longer, so:
if (str.length * count >= 1 << 28) {
throw new RangeError('repeat count must not overflow maximum string size');
}
var rpt = '';
for (;;) {
if ((count & 1) == 1) {
rpt += str;
}
count >>>= 1;
if (count == 0) {
break;
}
str += str;
}
return rpt;
};
String.prototype.repeat = function(count) {
'use strict';
if (this == null) {
throw new TypeError('can\'t convert ' + this + ' to object');
}
var str = '' + this;
count = +count;
if (count != count) {
count = 0;
}
if (count < 0) {
throw new RangeError('repeat count must be non-negative');
}
if (count == Infinity) {
throw new RangeError('repeat count must be less than infinity');
}
count = Math.floor(count);
if (str.length == 0 || count == 0) {
return '';
}
// Ensuring count is a 31-bit integer allows us to heavily optimize the
// main part. But anyway, most current (August 2014) browsers can't handle
// strings 1 << 28 chars or longer, so:
if (str.length * count >= 1 << 28) {
throw new RangeError('repeat count must not overflow maximum string size');
}
var rpt = '';
for (;;) {
if ((count & 1) == 1) {
rpt += str;
}
count >>>= 1;
if (count == 0) {
break;
}
str += str;
}
return rpt;
};
}
function cursorOff() {
ansiterm.send('ext_mode','clear','cursor');
console.gotoxy(0,24);
ansiterm.send('ext_mode','clear','cursor');
console.gotoxy(0,24);
}
/**
* Find a message base by code
*
* @param code
* @returns {number | string|boolean}
*/
function findMsgBase(code)
{
if (! code)
code = "tex_data";
// Find the actual sub-code
var sub_code;
for (var s in msg_area.sub) {
var sub = msg_area.sub[s];
if (sub.code.substr(-code.length).toLowerCase() == code)
return sub.code;
}
return false;
}
/**
@ -52,16 +76,16 @@ function cursorOff() {
* @param error
*/
function getArg(key,error,abort) {
index = argv.indexOf(key);
index = argv.indexOf(key);
if ((index !== -1) && (! (argv[index+1] === undefined || argv[index+1].match(/^-/)))) {
return argv[index+1];
}
if ((index !== -1) && (! (argv[index+1] === undefined || argv[index+1].match(/^-/)))) {
return argv[index+1];
}
if (abort) {
log(LOG_ERROR,error);
exit(1);
}
if (abort) {
log(LOG_ERROR,error);
exit(1);
}
}
function getFrame(page) {
@ -75,29 +99,43 @@ function getFrame(page) {
}
try {
frame = JSON.parse(f.read());
x = new Frame(0);
frame.render = x.render;
frame = JSON.parse(f.read());
x = new Frame(0);
frame.render = x.render;
// @todo Figure out how to delete this duplicate code
Object.defineProperty(frame,'page', {
get: function() {return this.frame+this.index}
});
// @todo Figure out how to delete this duplicate code
Object.defineProperty(frame,'page', {
get: function() {return this.frame+this.index}
});
} catch (error) {
log(LOG_ERROR,error);
return null;
}
log(LOG_ERROR,error);
return null;
}
log(LOG_DEBUG,'Loaded frame: ['+frame.frame+']['+frame.index+'] ('+frame.page+')');
log(LOG_DEBUG,'Loaded frame: ['+frame.frame+']['+frame.index+'] ('+frame.page+')');
return frame;
}
function msgBaseExport(msgbase,page,text) {
var msgbase = new MsgBase(findMsgBase(msgbase));
log(LOG_DEBUG,'Sending ['+page+'] to message base ['+msgbase.cfg.code+']');
var hdr = { to:'All', from:'Videotex', subject:'Frame: '+page };
var body = '';
body += text+"\r\n";
body += "--- " + js.exec_file + " " + '1.0' + "\r\n";
return msgbase.save_msg(hdr, body);
}
/**
* Return the frame as a string
*/
function pageStr(page) {
if (! page.index)
page.index = 'a';
if (! page.index)
page.index = 'a';
return page.frame+page.index;
}