2019-10-03 04:08:48 +00:00
|
|
|
load('texdefs.js');
|
|
|
|
load('texfuncs.js');
|
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
// Import
|
|
|
|
send = getArg('-s','Use -s 1 to send',false);
|
|
|
|
file = getArg('-S','Use -S filename',false);
|
|
|
|
frame = '';
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
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);
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
f = new File(file);
|
|
|
|
if (! f.exists || ! f.open('r')) {
|
|
|
|
log(LOG_ERROR,'! ERROR: Unable to open ['+file+']');
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
// Public
|
|
|
|
frame.isPublic = (argv.indexOf('-P') >= 0);
|
|
|
|
frame.isAccessible = (argv.indexOf('-A') >= 0);
|
|
|
|
if (cost)
|
|
|
|
frame.cost = cost;
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
// Date
|
|
|
|
frame.date = new Date().toISOString();
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
// 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);
|
2019-10-03 04:08:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
// @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();
|
2019-10-03 04:08:48 +00:00
|
|
|
|
2019-10-15 10:48:16 +00:00
|
|
|
msgBaseExport(null,frame.page,msg);
|
|
|
|
printf('GPG Result: %s',result);
|
|
|
|
}
|