More util refactoring

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2018-11-03 16:35:41 +01:00
parent 0f96713fe7
commit 8eb5dbe69a
4 changed files with 37 additions and 37 deletions

View File

@ -1,11 +1,13 @@
<?php <?php
$config['SITE_NAME'] = 'HOSTNAME'; define('SITE_NAME_CONST', 'SITE_NAME');
$config['SITE_URL'] = 'http://' . $config['SITE_NAME'] . '/';
$config['SMTP_DOMAIN'] = $config['SITE_NAME']; $config[SITE_NAME_CONST] = 'HOSTNAME';
$config['SMTP_FROMADDR'] = 'no-reply@' . $config['SITE_NAME']; $config['SITE_URL'] = 'http://' . $config[SITE_NAME_CONST] . '/';
$config['ADMIN_EMAIL'] = 'admin@' . $config['SITE_NAME'];
$config['SMTP_DOMAIN'] = $config[SITE_NAME_CONST];
$config['SMTP_FROMADDR'] = 'no-reply@' . $config[SITE_NAME_CONST];
$config['ADMIN_EMAIL'] = 'admin@' . $config[SITE_NAME_CONST];
$config['DB_PASSWORD'] = 'MYSQL_PASSWORD'; $config['DB_PASSWORD'] = 'MYSQL_PASSWORD';

View File

@ -1,5 +1,7 @@
<?php <?php
define('SEARCH_STR', 'search');
$webuidir = ""; $webuidir = "";
$search_expression = ""; $search_expression = "";
@ -45,9 +47,9 @@ if(isset($options['auto']) || isset($options['a']) )
if($auto_search == 0) if($auto_search == 0)
{ {
if(isset($options['search'])) if(isset($options[SEARCH_STR]))
{ {
$search_expression = $options['search']; $search_expression = $options[SEARCH_STR];
} else { } else {
print "\nError: must provide a search expression\n\n"; print "\nError: must provide a search expression\n\n";
display_help(); display_help();
@ -55,7 +57,7 @@ if($auto_search == 0)
} }
} }
else { else {
if(isset($options['search'])) if(isset($options[SEARCH_STR]))
{ {
print "\nError: don't specify BOTH --search AND --auto\n\n"; print "\nError: don't specify BOTH --search AND --auto\n\n";
display_help(); display_help();
@ -160,8 +162,8 @@ $data = array(
'id' => 0, 'id' => 0,
'sort' => $sort, 'sort' => $sort,
'order' => $order, 'order' => $order,
'type' => 'search', 'type' => SEARCH_STR,
'search' => $search_expression, SEARCH_STR => $search_expression,
'searchtype' => 'expert' 'searchtype' => 'expert'
); );
@ -178,7 +180,7 @@ if($auto_search == 1)
$queries = $sa->get(); $queries = $sa->get();
foreach ($queries as $query) { foreach ($queries as $query) {
$data['search'] = $query['query']; $data[SEARCH_STR] = $query['query'];
$data['id'] = $query['id']; $data['id'] = $query['id'];
do_search($data, $automated_search_recipients); do_search($data, $automated_search_recipients);
@ -248,7 +250,7 @@ function do_search($data = array(), $automated_search_recipients = array())
$mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $automated_search_recipients, $msg); $mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $automated_search_recipients, $msg);
} }
else { else {
print "search = " . $data['search'] . "\n"; print "search = " . $data[SEARCH_STR] . "\n";
print_r($all_ids); print_r($all_ids);
print $EOL . $EOL; print $EOL . $EOL;
} }
@ -261,17 +263,14 @@ function do_search($data = array(), $automated_search_recipients = array())
function display_help() { function display_help() {
$phpself = basename(__FILE__); $phpself = basename(__FILE__);
echo("\nUsage: $phpself [OPTIONS...] --webui [PATH] --search '[SEARCH EXPRESSION]' | --auto\n\n"); echo "\nUsage: $phpself [OPTIONS...] --webui [PATH] --search '[SEARCH EXPRESSION]' | --auto\n\n";
echo("\nThe results go to the recipients defined in \$automated_search_recipients, see config-site.php\n\n"); echo "\nThe results go to the recipients defined in \$automated_search_recipients, see config-site.php\n\n";
echo("\t--webui=\"[REQUIRED: path to the piler webui directory]\"\n"); echo "\t--webui=\"[REQUIRED: path to the piler webui directory]\"\n";
echo("\t--search=\"[REQUIRED (unless you specify --auto): the search expression]\"\n\n"); echo "\t--search=\"[REQUIRED (unless you specify --auto): the search expression]\"\n\n";
echo("options:\n"); echo "options:\n";
echo("\t-a | --auto: Perform an automated search based on queries defined via the piler gui\n"); echo "\t-a | --auto: Perform an automated search based on queries defined via the piler gui\n";
echo("\t-y | --yesterday: Search \"yesterday\"\n"); echo "\t-y | --yesterday: Search \"yesterday\"\n";
echo("\t-d | --dry-run: Only print the found IDs\n"); echo "\t-d | --dry-run: Only print the found IDs\n";
echo("\t-h | --help: Prints this help screen and exits\n"); echo "\t-h | --help: Prints this help screen and exits\n";
} }
?>

View File

@ -23,7 +23,7 @@ if ( $options = getopt( $opts, $lopts ) )
$webuidir = $options['webui']; $webuidir = $options['webui'];
} else } else
{ {
echo("\nError: must provide path to WebUI directory\n\n"); echo "\nError: must provide path to WebUI directory\n\n";
display_help(); display_help();
exit; exit;
@ -190,12 +190,9 @@ if($fp) {
function display_help() { function display_help() {
$phpself = basename(__FILE__); $phpself = basename(__FILE__);
echo("\nUsage: $phpself --webui [PATH] [OPTIONS...]\n\n"); echo "\nUsage: $phpself --webui [PATH] [OPTIONS...]\n\n";
echo("\t--webui=\"[REQUIRED: path to the Piler WebUI Directory]\"\n\n"); echo "\t--webui=\"[REQUIRED: path to the Piler WebUI Directory]\"\n\n";
echo("options:\n"); echo "options:\n";
echo("\t-v Provide a verbose output\n"); echo "\t-v Provide a verbose output\n";
echo("\t-h Prints this help screen and exits\n"); echo "\t-h Prints this help screen and exits\n";
} }
?>

View File

@ -1,5 +1,7 @@
<?php <?php
define('EMAIL_STR', 'email');
ini_set("session.save_path", "/tmp"); ini_set("session.save_path", "/tmp");
$webuidir = ""; $webuidir = "";
@ -28,8 +30,8 @@ if($options = getopt($opts, $lopts)) {
$daemonize = 1; $daemonize = 1;
} }
if(isset($options['email'])) { if(isset($options[EMAIL_STR])) {
$email = $options['email']; $email = $options[EMAIL_STR];
} }
} }
@ -107,8 +109,8 @@ function poll_imap_accounts($email = '') {
if(isset($query->rows)) { if(isset($query->rows)) {
foreach($query->rows as $q) { foreach($query->rows as $q) {
$access_token = $ug->refresh_access_token($q['email']); $access_token = $ug->refresh_access_token($q[EMAIL_STR]);
$g->download_users_emails($q['email'], $access_token); $g->download_users_emails($q[EMAIL_STR], $access_token);
} }
} }
} }