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,6 +1,12 @@
load('texdefs.js');
load('texfuncs.js');
// Import
send = getArg('-s','Use -s 1 to send',false);
file = getArg('-S','Use -S filename',false);
frame = '';
if (! send || ! file) {
// File to convert
file = getArg('-f','No file specified with -f',true);
// Page
@ -13,10 +19,12 @@ key = getArg('-k','No index specified with -k',false);
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,'Unable to open ['+file+']');
log(LOG_ERROR,'! ERROR: Unable to open ['+file+']');
exit(1);
}
@ -28,7 +36,7 @@ if (key) {
frame.key = key.split(',').map(function(t){return parseInt(t)});
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);
}
}
@ -42,9 +50,11 @@ if (cost)
// Date
frame.date = new Date().toISOString();
w = new File(system.text_dir+'ansitex/'+frame.page+'.tex');
// Store the frame in file
file = system.text_dir+'ansitex/'+frame.page+'.tex';
w = new File(file);
if (! w.open('w')) {
log(LOG_ERROR,'Unable to create TEX file for '+frame.page);
log(LOG_ERROR,'! ERROR: Unable to create TEX file for '+frame.page);
exit(1);
}
@ -52,3 +62,54 @@ w.write(JSON.stringify(frame));
w.close();
printf('Saved file: %s.tex',frame.page);
}
// @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 (! 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);
}
/**
* 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
*
@ -92,6 +116,20 @@ function getFrame(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
*/