Added command line options to export-attachments.php

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2021-04-06 18:59:16 +02:00
parent ca6fddedf6
commit edceee12c9

View File

@ -2,8 +2,31 @@
define('LOCK_FILE', '/var/piler/tmp/export-attachments.lock');
$webuidir = "";
require_once("config.php");
$outdir = '';
$opts = 'hw:d:';
$lopts = [
'webui:',
'dir:',
'help'
];
if($options = getopt($opts, $lopts)) {
if(isset($options['webui'])) { $webuidir = $options['webui']; }
if(isset($options['dir'])) { $outdir = $options['dir']; }
if(isset($options['help'])) { usage(); }
}
if($webuidir == '' || $outdir == '') { usage(); }
require_once("$webuidir/config.php");
require(DIR_SYSTEM . "/startup.php");
@ -27,8 +50,6 @@ Registry::set('db', $db);
Registry::set('auditor_user', 1);
$outdir = "/path/to/attachments";
openlog("export-attachments", LOG_PID, LOG_MAIL);
$fp = fopen(LOCK_FILE, "w");
@ -68,3 +89,14 @@ $attachment->update_checkpoint($i);
// Release lock
flock($fp, LOCK_UN);
fclose($fp);
function usage() {
print "\nUsage: " . __FILE__ . "\n\n";
print "\t--webui <path to webui directory>\n";
print "\t--dir <basedir to write attachments>\n";
print "\t--help\n\n";
exit;
}