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

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

@ -45,6 +45,30 @@ function cursorOff() {
console.gotoxy(0,24); 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;
}
/** /**
* Return an argument from argv, or an error if it doesnt exit * Return an argument from argv, or an error if it doesnt exit
* *
@ -92,6 +116,20 @@ function getFrame(page) {
return frame; 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 * Return the frame as a string
*/ */