diff --git a/util/automated-search.php b/util/automated-search.php index 234727f..1ec62b2 100644 --- a/util/automated-search.php +++ b/util/automated-search.php @@ -8,11 +8,13 @@ $sort = "date"; $order = 0; $dry_run = 0; +$auto_search = 0; -$opts = 'w:s:dyh'; +$opts = 'w:s:dayh'; $lopts = array( 'webui:', 'search:', + 'auto', 'dry-run', 'yesterday', 'help' @@ -36,16 +38,33 @@ display_help(); exit; } - -if(isset($options['search'])) + +if(isset($options['auto']) || isset($options['a']) ) { - $search_expression = $options['search']; -} else { - print "\nError: must provide a search expression\n\n"; - display_help(); - exit; + $auto_search = 1; } +if($auto_search == 0) +{ + if(isset($options['search'])) + { + $search_expression = $options['search']; + } else { + print "\nError: must provide a search expression\n\n"; + display_help(); + exit; + } +} +else { + if(isset($options['search'])) + { + print "\nError: don't specify BOTH --search AND --auto\n\n"; + display_help(); + exit; + } +} + + if(isset($options['dry-run']) || isset($options['d']) ) { $dry_run = 1; @@ -148,55 +167,83 @@ $loader->model('search/search'); $loader->model('search/message'); +$loader->model('search/auto'); $loader->model('mail/mail'); -$search = new ModelSearchSearch(); -$mail = new ModelMailMail(); -$a = $search->preprocess_post_expert_request($data); - -if(isset($options['yesterday']) || isset($options['y']) ) +if($auto_search == 1) { - $a['date1'] = $a['date2'] = date("Y.m.d", time() - 86400); -} + $sa = new ModelSearchAuto(); -list ($n, $total_found, $all_ids, $messages) = $search->search_messages($a, $page); + $queries = $sa->get(); -if($dry_run == 0) -{ - $msg = "From: " . SMTP_FROMADDR . EOL; - $msg .= "To: " . ADMIN_EMAIL . EOL; - $msg .= "Subject: =?UTF-8?Q?" . preg_replace("/\n/", "", my_qp_encode($title)) . "?=" . EOL; - $msg .= "Message-ID: <" . generate_random_string(25) . '@' . SITE_NAME . ">" . EOL; - $msg .= "MIME-Version: 1.0" . EOL; - $msg .= "Content-Type: text/html; charset=\"utf-8\"" . EOL; - $msg .= EOL . EOL; + foreach ($queries as $query) { + $data['search'] = $query['query']; - ob_start(); - include($webuidir . "/view/theme/default/templates/search/auto.tpl"); - $msg .= ob_get_contents(); - - ob_end_clean(); - - $x = $mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $automated_search_recipients, $msg); + do_search($data, $automated_search_recipients); + } } else { - print "search = $search_expression\n"; - print_r($all_ids); - print EOL; + do_search($data, $automated_search_recipients); } +function do_search($data = array(), $automated_search_recipients = array()) +{ + global $options; + global $dry_run; + global $webuidir; + + $search = new ModelSearchSearch(); + $mail = new ModelMailMail(); + + $a = $search->preprocess_post_expert_request($data); + + if(isset($options['yesterday']) || isset($options['y']) ) + { + $a['date1'] = $a['date2'] = date("Y.m.d", time() - 86400); + } + + list ($n, $total_found, $all_ids, $messages) = $search->search_messages($a, 0); + + if($dry_run == 0) + { + $msg = "From: " . SMTP_FROMADDR . EOL; + $msg .= "To: " . ADMIN_EMAIL . EOL; + $msg .= "Subject: =?UTF-8?Q?" . preg_replace("/\n/", "", my_qp_encode($title)) . "?=" . EOL; + $msg .= "Message-ID: <" . generate_random_string(25) . '@' . SITE_NAME . ">" . EOL; + $msg .= "MIME-Version: 1.0" . EOL; + $msg .= "Content-Type: text/html; charset=\"utf-8\"" . EOL; + $msg .= EOL . EOL; + + ob_start(); + include($webuidir . "/view/theme/default/templates/search/auto.tpl"); + $msg .= ob_get_contents(); + + ob_end_clean(); + + $x = $mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $automated_search_recipients, $msg); + } + else { + print "search = " . $data['search'] . "\n"; + print_r($all_ids); + print EOL . EOL; + } + +} + + function display_help() { $phpself = basename(__FILE__); - echo("\nUsage: $phpself --webui [PATH] --search '[SEARCH EXPRESSION]' [OPTIONS...]\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("\t--webui=\"[REQUIRED: path to the piler webui directory]\"\n"); - echo("\t--search=\"[REQUIRED: the search expression]\"\n\n"); + echo("\t--search=\"[REQUIRED (unless you specify --auto): the search expression]\"\n\n"); echo("options:\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-d | --dry-run: Only print the found IDs\n"); echo("\t-h | --help: Prints this help screen and exits\n"); diff --git a/util/db-mysql.sql b/util/db-mysql.sql index efffbfc..de6a4ba 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -411,3 +411,8 @@ ) Engine=InnoDB; +create table if not exists `autosearch` ( + `id` int not null auto_increment primary key, + `query` varchar(512) not null +) Engine=InnoDB; + diff --git a/util/db-upgrade-0.1.24-vs-0.1.25.sql b/util/db-upgrade-0.1.24-vs-0.1.25.sql index 21c1ab4..7672ddb 100644 --- a/util/db-upgrade-0.1.24-vs-0.1.25.sql +++ b/util/db-upgrade-0.1.24-vs-0.1.25.sql @@ -29,3 +29,10 @@ alter table google change column id id char(32) not null primary key; alter table google_imap change column id id char(32) not null primary key; + +create table if not exists `autosearch` ( + `id` int not null auto_increment primary key, + `query` varchar(512) not null +) Engine=InnoDB; + + diff --git a/webui/config.php b/webui/config.php index 9bdf47b..ed386ed 100644 --- a/webui/config.php +++ b/webui/config.php @@ -331,6 +331,7 @@ define('TABLE_IMPORT', 'import'); define('TABLE_GOOGLE', 'google'); define('TABLE_GOOGLE_IMAP', 'google_imap'); +define('TABLE_AUTOSEARCH', 'autosearch'); define('VIEW_MESSAGES', 'v_messages'); define('EOL', "\n"); diff --git a/webui/controller/search/autosearch.php b/webui/controller/search/autosearch.php new file mode 100644 index 0000000..6e83a4b --- /dev/null +++ b/webui/controller/search/autosearch.php @@ -0,0 +1,117 @@ +id = "content"; + $this->template = "search/autosearch.tpl"; + $this->layout = "common/layout"; + + + $request = Registry::get('request'); + $db = Registry::get('db'); + + $ldap_id = 0; + + + $this->load->model('search/auto'); + + $this->document->title = $this->data['text_automated_search']; + + + $this->data['username'] = Registry::get('username'); + + $this->data['page'] = 0; + $this->data['page_len'] = get_page_length(); + + $this->data['total'] = 0; + + $this->data['domains'] = array(); + + /* get search term if there's any */ + + $this->data['search'] = ''; + + $this->data['remove'] = 0; + $this->data['removed_query'] = ''; + + if(isset($this->request->post['search'])) { $this->data['search'] = $this->request->post['search']; } + else if(isset($this->request->get['search'])) { $this->data['search'] = $this->request->get['search']; } + + + + /* get page */ + + if(isset($this->request->get['page']) && is_numeric($this->request->get['page']) && $this->request->get['page'] > 0) { + $this->data['page'] = $this->request->get['page']; + } + + + + /* check if we are admin */ + + if(Registry::get('admin_user') == 1) { + + if($this->request->server['REQUEST_METHOD'] == 'POST') { + if($this->validate() == true) { + if($this->model_search_auto->add($this->request->post) == 1) { + $this->data['x'] = $this->data['text_successfully_added']; + } else { + $this->data['errorstring'] = $this->data['text_failed_to_add']; + } + } + else { + $this->data['errorstring'] = $this->data['text_error_message']; + $this->data['errors'] = $this->error; + $this->data['post'] = $this->request->post; + } + } + + if(isset($this->request->get['remove']) && $this->request->get['remove'] == 1 && $this->request->get['id'] > 0) { + $this->model_search_auto->remove($this->request->get['id']); + + $this->data['remove'] = 1; + $this->data['removed_query'] = $this->request->get['name']; + } + + + $this->data['data'] = $this->model_search_auto->get($this->data['search']); + } + else { + $this->template = "common/error.tpl"; + $this->data['errorstring'] = $this->data['text_you_are_not_admin']; + } + + + $this->data['prev_page'] = $this->data['page'] - 1; + $this->data['next_page'] = $this->data['page'] + 1; + + $this->data['total'] = floor(count($this->data['data']) / $this->data['page_len']); + + + $this->render(); + } + + + private function validate() { + + if(!isset($this->request->post['query']) || strlen($this->request->post['query']) < 3) { + $this->data['text_field_length'] = str_replace("?",3,$this->data['text_field_length']); + } + + if (!$this->error) { + return true; + } else { + return false; + } + + } + + + +} + +?> diff --git a/webui/language/de/messages.php b/webui/language/de/messages.php index d99b2b5..de499f0 100644 --- a/webui/language/de/messages.php +++ b/webui/language/de/messages.php @@ -472,5 +472,9 @@ $_['text_print_message'] = "Print"; $_['text_forward_selected_emails_to'] = "Forward selected emails to"; $_['text_search_expression'] = "Search expression"; +$_['text_automated_search'] = "Automated search"; +$_['text_delete_confirm_message'] = "Do you wish to delete"; +$_['text_existing'] = "Existing"; +$_['text_new'] = "new"; ?> diff --git a/webui/language/en/messages.php b/webui/language/en/messages.php index 9b45df3..4d92d21 100644 --- a/webui/language/en/messages.php +++ b/webui/language/en/messages.php @@ -31,6 +31,7 @@ $_['text_attachment_size'] = "Attachment size"; $_['text_attachment_type'] = "Attachment type"; $_['text_audit'] = "Audit"; +$_['text_automated_search'] = "Automated search"; $_['text_back'] = "Back"; $_['text_background_colour'] = "Background colour"; @@ -75,6 +76,7 @@ $_['text_deferred_queue'] = "deferred queue"; $_['text_deferred_queue_sender'] = "deferred queue vs. sender"; $_['text_delay'] = "Delay"; +$_['text_delete_confirm_message'] = "Do you wish to delete"; $_['text_deleted_users'] = "deleted"; $_['text_deliver'] = "Deliver"; $_['text_delivered'] = "Delivered"; @@ -116,6 +118,7 @@ $_['text_error'] = "Error"; $_['text_exact_domain_name_or_email_address'] = "exact domain name or email address"; $_['text_exclude'] = "Exclude"; +$_['text_existing'] = "Existing"; $_['text_existing_domains'] = "Existing domains"; $_['text_existing_email'] = "Existing email"; $_['text_existing_folders'] = "Existing folders"; @@ -219,6 +222,7 @@ $_['text_months'] = "months"; $_['text_monthly_report'] = "Monthly report"; +$_['text_new'] = "new"; $_['text_new_users'] = "new"; $_['text_next'] = "Next"; $_['text_no_domain_found'] = 'No domain found'; diff --git a/webui/language/es/messages.php b/webui/language/es/messages.php index 2e3185c..fc170ca 100644 --- a/webui/language/es/messages.php +++ b/webui/language/es/messages.php @@ -471,5 +471,9 @@ $_['text_print_message'] = "Print"; $_['text_forward_selected_emails_to'] = "Forward selected emails to"; $_['text_search_expression'] = "Search expression"; +$_['text_automated_search'] = "Automated search"; +$_['text_delete_confirm_message'] = "Do you wish to delete"; +$_['text_existing'] = "Existing"; +$_['text_new'] = "new"; ?> diff --git a/webui/language/hu/messages.iso-8859-2.php b/webui/language/hu/messages.iso-8859-2.php index 7a683e0..c56dcad 100644 --- a/webui/language/hu/messages.iso-8859-2.php +++ b/webui/language/hu/messages.iso-8859-2.php @@ -31,6 +31,7 @@ $_['text_attachment_size'] = "Mell�klet m�ret"; $_['text_attachment_type'] = "Mell�klet t�pus"; $_['text_audit'] = "Audit"; +$_['text_automated_search'] = "Automatikus keres�s"; $_['text_back'] = "Vissza"; $_['text_background_colour'] = "H�tt�rsz�n"; @@ -75,6 +76,7 @@ $_['text_deferred_queue'] = "k�s�bbi kik�ld�sre v�r� �zenetsor"; $_['text_deferred_queue_sender'] = "k�s�bbi kik�ld�sre v�r� �zenetsor (felad� szerint)"; $_['text_delay'] = "K�sleltet�s"; +$_['text_delete_confirm_message'] = "T�r�lni akarja"; $_['text_deleted_users'] = "t�r�lt"; $_['text_deliver'] = "K�zbes�t�s"; $_['text_delivered'] = "K�zbes�tett"; @@ -117,6 +119,7 @@ $_['text_error'] = "Hiba"; $_['text_exact_domain_name_or_email_address'] = "pontos domainn�v vagy email c�m"; $_['text_exclude'] = "Kihagy"; +$_['text_existing'] = "L�tez�"; $_['text_existing_domains'] = "L�tez� domainek"; $_['text_existing_email'] = "L�tez� email"; $_['text_existing_entries'] = "Jelenlegi bejegyz�sek"; @@ -220,6 +223,7 @@ $_['text_months'] = "h�nap"; $_['text_monthly_report'] = "Havi jelent�s"; +$_['text_new'] = "�j"; $_['text_new_users'] = "�j"; $_['text_next'] = "K�vetkez�"; $_['text_no_domain_found'] = 'Nem tal�ltam domaineket'; diff --git a/webui/language/hu/messages.php b/webui/language/hu/messages.php index cf2d3c6..8d33689 100644 --- a/webui/language/hu/messages.php +++ b/webui/language/hu/messages.php @@ -31,6 +31,7 @@ $_['text_attachment_size'] = "Melléklet méret"; $_['text_attachment_type'] = "Melléklet típus"; $_['text_audit'] = "Audit"; +$_['text_automated_search'] = "Automatikus keresés"; $_['text_back'] = "Vissza"; $_['text_background_colour'] = "Háttérszín"; @@ -75,6 +76,7 @@ $_['text_deferred_queue'] = "későbbi kiküldésre váró üzenetsor"; $_['text_deferred_queue_sender'] = "későbbi kiküldésre váró üzenetsor (feladó szerint)"; $_['text_delay'] = "Késleltetés"; +$_['text_delete_confirm_message'] = "Törölni akarja"; $_['text_deleted_users'] = "törölt"; $_['text_deliver'] = "Kézbesítés"; $_['text_delivered'] = "Kézbesített"; @@ -117,6 +119,7 @@ $_['text_error'] = "Hiba"; $_['text_exact_domain_name_or_email_address'] = "pontos domainnév vagy email cím"; $_['text_exclude'] = "Kihagy"; +$_['text_existing'] = "Létező"; $_['text_existing_domains'] = "Létező domainek"; $_['text_existing_email'] = "Létező email"; $_['text_existing_entries'] = "Jelenlegi bejegyzések"; @@ -220,6 +223,7 @@ $_['text_months'] = "hónap"; $_['text_monthly_report'] = "Havi jelentés"; +$_['text_new'] = "új"; $_['text_new_users'] = "új"; $_['text_next'] = "Következő"; $_['text_no_domain_found'] = 'Nem találtam domaineket'; diff --git a/webui/language/pt/messages.php b/webui/language/pt/messages.php index 05f32bb..f36b724 100644 --- a/webui/language/pt/messages.php +++ b/webui/language/pt/messages.php @@ -461,5 +461,9 @@ $_['text_refresh_qr_code'] = "Renovar código QR"; $_['text_forward_selected_emails_to'] = "Forward selected emails to"; $_['text_search_expression'] = "Search expression"; +$_['text_automated_search'] = "Automated search"; +$_['text_delete_confirm_message'] = "Do you wish to delete"; +$_['text_existing'] = "Existing"; +$_['text_new'] = "new"; ?> diff --git a/webui/model/search/auto.php b/webui/model/search/auto.php new file mode 100644 index 0000000..fa33077 --- /dev/null +++ b/webui/model/search/auto.php @@ -0,0 +1,51 @@ +db->query("SELECT * FROM " . TABLE_AUTOSEARCH . " ORDER BY id ASC"); + + if(isset($query->rows)) { + foreach($query->rows as $q) { + + $data[] = array('id' => $q['id'], 'query' => $q['query']); + } + } + + return $data; + } + + + public function add($data = array()) { + if(!isset($data['query'])) { return 0; } + + $query = $this->db->query("INSERT INTO " . TABLE_AUTOSEARCH . " (query) VALUES (?)", array($data['query'])); + $rc = $this->db->countAffected(); + + LOGGER("add new automated search query: " . $data['query'] . " (rc=$rc)"); + + return $rc; + } + + + public function remove($id = 0) { + if($id == 0) { return 0; } + + $query = $this->db->query("DELETE FROM " . TABLE_AUTOSEARCH . " WHERE id=?", array($id)); + + $rc = $this->db->countAffected(); + + LOGGER("remove autosearch: $id (rc=$rc)"); + + return $rc; + } + + +} + + +?> diff --git a/webui/view/theme/default/templates/common/layout.tpl b/webui/view/theme/default/templates/common/layout.tpl index a5838bc..96344f1 100644 --- a/webui/view/theme/default/templates/common/layout.tpl +++ b/webui/view/theme/default/templates/common/layout.tpl @@ -48,6 +48,8 @@ +
+
diff --git a/webui/view/theme/default/templates/common/menu.tpl b/webui/view/theme/default/templates/common/menu.tpl index 40d4d39..3b36f3d 100644 --- a/webui/view/theme/default/templates/common/menu.tpl +++ b/webui/view/theme/default/templates/common/menu.tpl @@ -41,6 +41,7 @@
  •  
  •  
  • +
  •  
  • diff --git a/webui/view/theme/default/templates/search/autosearch.tpl b/webui/view/theme/default/templates/search/autosearch.tpl new file mode 100644 index 0000000..5473a2e --- /dev/null +++ b/webui/view/theme/default/templates/search/autosearch.tpl @@ -0,0 +1,79 @@ + + + + +

    + +
    :
    + +
    + + +
    + +
    "> + +
    + /> + +
    +
    + + +
    + + +
    + +
    + +

    + +
    + + 0){ ?> + + + + + + + + + + + + + + + + + +
    + +
    + + + + + + + + diff --git a/webui/view/theme/mobile/templates/common/layout.tpl b/webui/view/theme/mobile/templates/common/layout.tpl index 4eac1eb..6c2c47d 100644 --- a/webui/view/theme/mobile/templates/common/layout.tpl +++ b/webui/view/theme/mobile/templates/common/layout.tpl @@ -41,6 +41,8 @@ } ?>> +
    +