Frame import into message base
This commit is contained in:
parent
d31778d7b9
commit
7b13525108
@ -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+']');
|
||||
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());
|
||||
frame = new Frame(p,i);
|
||||
frame.owner = base64_encode(owner.replace(/\\1/g,"\1"));
|
||||
frame.content = base64_encode(f.read());
|
||||
|
||||
if (key) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Public
|
||||
frame.isPublic = (argv.indexOf('-P') >= 0);
|
||||
frame.isAccessible = (argv.indexOf('-A') >= 0);
|
||||
if (cost)
|
||||
// Public
|
||||
frame.isPublic = (argv.indexOf('-P') >= 0);
|
||||
frame.isAccessible = (argv.indexOf('-A') >= 0);
|
||||
if (cost)
|
||||
frame.cost = cost;
|
||||
|
||||
// Date
|
||||
frame.date = new Date().toISOString();
|
||||
// Date
|
||||
frame.date = new Date().toISOString();
|
||||
|
||||
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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
w.write(JSON.stringify(frame));
|
||||
w.close();
|
||||
// @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);
|
||||
}
|
||||
|
||||
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
7
mods/keys/genkey.txt
Normal 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
|
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user