From 16e54ffbfd7bc9c3e736b36d774b616082cb59cb Mon Sep 17 00:00:00 2001 From: SJ Date: Fri, 2 Aug 2013 12:30:09 +0200 Subject: [PATCH] added an option to change the stored retention values --- util/db-mysql.sql | 6 ++- util/db-upgrade-0.1.23-vs-0.1.24.sql | 3 ++ webui/config.php | 2 + webui/controller/policy/updateretention.php | 42 +++++++++++++++++++ webui/language/de/messages.php | 3 ++ webui/language/en/messages.php | 3 ++ webui/language/hu/messages.iso-8859-2.php | 3 ++ webui/language/hu/messages.php | 3 ++ webui/language/pt/messages.php | 4 +- webui/model/policy/retention.php | 19 +++++++++ .../theme/default/templates/health/worker.tpl | 2 +- .../default/templates/policy/retention.tpl | 6 +++ .../templates/policy/updateretention.tpl | 9 ++++ .../theme/mobile/templates/health/worker.tpl | 2 +- .../mobile/templates/policy/retention.tpl | 6 +++ .../templates/policy/updateretention.tpl | 9 ++++ 16 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 webui/controller/policy/updateretention.php create mode 100644 webui/view/theme/default/templates/policy/updateretention.tpl create mode 100644 webui/view/theme/mobile/templates/policy/updateretention.tpl diff --git a/util/db-mysql.sql b/util/db-mysql.sql index 6e6ea265..4eb806f2 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -55,21 +55,23 @@ create index metadata_idx4 on metadata(`bodydigest`); create index metadata_idx5 on metadata(`deleted`); create index metadata_idx6 on metadata(`arrived`); create index metadata_idx7 on metadata(`retained`); +create index metadata_idx8 on metadata(`fromdomain`); create table if not exists `rcpt` ( `id` bigint unsigned not null, `to` varchar(128) not null, - `todomain` varchar(64) not null, + `todomain` varchar(128) not null, unique(`id`,`to`) ) Engine=InnoDB; create index `rcpt_idx` on `rcpt`(`id`); create index `rcpt_idx2` on `rcpt`(`to`); +create index `rcpt_idx3` on `rcpt`(`todomain`); drop view if exists `v_messages`; -create view `v_messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`metadata`.`fromdomain` AS `fromdomain`,`rcpt`.`to` AS `to`,`rcpt`.`todomain` AS `todomain`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size`, `metadata`.`direction` AS `direction`, `metadata`.`sent` AS `sent`, `metadata`.`arrived` AS `arrived`, `metadata`.`digest` AS `digest`, `metadata`.`bodydigest` AS `bodydigest` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`); +create view `v_messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`metadata`.`fromdomain` AS `fromdomain`,`rcpt`.`to` AS `to`,`rcpt`.`todomain` AS `todomain`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size`, `metadata`.`direction` AS `direction`, `metadata`.`sent` AS `sent`, `metadata`.`retained` AS `retained`, `metadata`.`arrived` AS `arrived`, `metadata`.`digest` AS `digest`, `metadata`.`bodydigest` AS `bodydigest` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`); create table if not exists `attachment` ( diff --git a/util/db-upgrade-0.1.23-vs-0.1.24.sql b/util/db-upgrade-0.1.23-vs-0.1.24.sql index 13902309..dcd0d058 100644 --- a/util/db-upgrade-0.1.23-vs-0.1.24.sql +++ b/util/db-upgrade-0.1.23-vs-0.1.24.sql @@ -10,6 +10,9 @@ alter table retention_rule add column domain varchar(255) default null; alter table retention_rule drop index `from`; create unique index `entry` on retention_rule (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`); +drop view if exists `v_messages`; +create view `v_messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`metadata`.`fromdomain` AS `fromdomain`,`rcpt`.`to` AS `to`,`rcpt`.`todomain` AS `todomain`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size`, `metadata`.`direction` AS `direction`, `metadata`.`sent` AS `sent`, `metadata`.`retained` AS `retained`, `metadata`.`arrived` AS `arrived`, `metadata`.`digest` AS `digest`, `metadata`.`bodydigest` AS `bodydigest` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`); + create table if not exists `ldap` ( `id` int not null auto_increment primary key, `description` varchar(255) not null, diff --git a/webui/config.php b/webui/config.php index 150ab179..bd2352df 100644 --- a/webui/config.php +++ b/webui/config.php @@ -123,6 +123,8 @@ $config['PAGE_LEN'] = 20; $config['MAX_NUMBER_OF_FROM_ITEMS'] = 5; $config['MAX_SEARCH_HITS'] = 1000; +$config['DEFAULT_RETENTION'] = 0; + $config['LOCALHOST'] = '127.0.0.1'; $config['PILER_HOST'] = '1.2.3.4'; $config['PILER_PORT'] = 25; diff --git a/webui/controller/policy/updateretention.php b/webui/controller/policy/updateretention.php new file mode 100644 index 00000000..4bb678f2 --- /dev/null +++ b/webui/controller/policy/updateretention.php @@ -0,0 +1,42 @@ +id = "content"; + $this->template = "policy/updateretention.tpl"; + $this->layout = "common/layout"; + + + $request = Registry::get('request'); + + $db = Registry::get('db'); + + $this->load->model('policy/retention'); + + $this->document->title = $this->data['text_retention_rules']; + + if(Registry::get('admin_user') == 0) { + die("go away"); + } + + $this->data['n'] = 0; + $this->data['domain'] = ''; + $this->data['days'] = 0; + + if(isset($this->request->get['domain']) && isset($this->request->get['days'])) { + $this->data['domain'] = $this->request->get['domain']; + $this->data['days'] = $this->request->get['days']; + + $this->data['n'] = $this->model_policy_retention->update_retention_time($this->data); + } + + $this->render(); + } + +} + +?> diff --git a/webui/language/de/messages.php b/webui/language/de/messages.php index 3b0fc9fc..8f171a57 100644 --- a/webui/language/de/messages.php +++ b/webui/language/de/messages.php @@ -271,6 +271,7 @@ $_['text_restore_message'] = "Nachricht wiederherstellen"; $_['text_restore_to_mailbox'] = "Nachricht im Postfach wiederherstellen"; $_['text_restored'] = "Wiederhergestellt"; $_['text_result'] = "Ergebnis"; +$_['text_retention_days'] = "Aufbewahrungstagen"; $_['text_retention_rules'] = "Aufbewahrungsregeln"; $_['text_role'] = "Berechtigung"; $_['text_running'] = "läuft"; @@ -340,7 +341,9 @@ $_['text_unauthorized_download_attachment'] = "Anhang unerlaubt heruntergeladen" $_['text_unauthorized_remove_message'] = "unerlaubte Nachrichtenlöschung"; $_['text_unauthorized_view_message'] = "unerlaubte Nachrichtenansicht"; $_['text_unknown'] = "unbekannt"; +$_['text_update_retention_within_this_domain'] = "Update retention values within this domain"; $_['text_update_selected_uids'] = "Ausgewählte Benutzerkennungen aktualisieren"; +$_['text_updated_records'] = "Updated records"; $_['text_uptime'] = "Betriebszeit"; $_['text_user'] = "Benutzer"; $_['text_users'] = "Benutzer"; diff --git a/webui/language/en/messages.php b/webui/language/en/messages.php index ad6421e8..31e04b2d 100644 --- a/webui/language/en/messages.php +++ b/webui/language/en/messages.php @@ -271,6 +271,7 @@ $_['text_restore_message'] = "restore message"; $_['text_restore_to_mailbox'] = "Restore message to mailbox"; $_['text_restored'] = "Restored"; $_['text_result'] = "Result"; +$_['text_retention_days'] = "Retention days"; $_['text_retention_rules'] = "Retention rules"; $_['text_role'] = "Role"; $_['text_running'] = "running"; @@ -340,7 +341,9 @@ $_['text_unauthorized_download_attachment'] = "unauthorized attachment download" $_['text_unauthorized_remove_message'] = "unauthorized message removal"; $_['text_unauthorized_view_message'] = "unathorized message view"; $_['text_unknown'] = "unknown"; +$_['text_update_retention_within_this_domain'] = "Update retention values within this domain"; $_['text_update_selected_uids'] = "Update selected uids"; +$_['text_updated_records'] = "Updated records"; $_['text_uptime'] = "Uptime"; $_['text_user'] = "User"; $_['text_users'] = "Users"; diff --git a/webui/language/hu/messages.iso-8859-2.php b/webui/language/hu/messages.iso-8859-2.php index ffeea454..cf999a24 100644 --- a/webui/language/hu/messages.iso-8859-2.php +++ b/webui/language/hu/messages.iso-8859-2.php @@ -271,6 +271,7 @@ $_['text_restore_message'] = "lev $_['text_restore_to_mailbox'] = "Levél visszaállítása postafiókba"; $_['text_restored'] = "Visszaállítva"; $_['text_result'] = "Eredmény"; +$_['text_retention_days'] = "Megtartási idõ [nap]"; $_['text_retention_rules'] = "Megtartási szabályok"; $_['text_role'] = "Felhasználótípus"; $_['text_running'] = "fut"; @@ -340,7 +341,9 @@ $_['text_unauthorized_domain'] = "Nem megengedett domain"; $_['text_unauthorized_download_attachment'] = "jogosulatlan melléklet letöltés"; $_['text_unauthorized_remove_message'] = "jogosulatlan üzenet törlés"; $_['text_unauthorized_view_message'] = "jogosulatlan üzenet megtekintés"; +$_['text_update_retention_within_this_domain'] = "Megtartási idõ frissítése ebben a domainben"; $_['text_update_selected_uids'] = "Kijelölt azonosítók módosítása"; +$_['text_updated_records'] = "Frissített rekordok"; $_['text_uptime'] = "Uptime"; $_['text_user'] = "Felhasználó"; $_['text_users'] = "Felhasználók"; diff --git a/webui/language/hu/messages.php b/webui/language/hu/messages.php index 9ac3ae1b..1c244e13 100644 --- a/webui/language/hu/messages.php +++ b/webui/language/hu/messages.php @@ -271,6 +271,7 @@ $_['text_restore_message'] = "levél visszaállítása"; $_['text_restore_to_mailbox'] = "Levél visszaállítása postafiókba"; $_['text_restored'] = "Visszaállítva"; $_['text_result'] = "Eredmény"; +$_['text_retention_days'] = "Megtartási idÅ‘ [nap]"; $_['text_retention_rules'] = "Megtartási szabályok"; $_['text_role'] = "Felhasználótípus"; $_['text_running'] = "fut"; @@ -340,7 +341,9 @@ $_['text_unauthorized_domain'] = "Nem megengedett domain"; $_['text_unauthorized_download_attachment'] = "jogosulatlan melléklet letöltés"; $_['text_unauthorized_remove_message'] = "jogosulatlan üzenet törlés"; $_['text_unauthorized_view_message'] = "jogosulatlan üzenet megtekintés"; +$_['text_update_retention_within_this_domain'] = "Megtartási idÅ‘ frissítése ebben a domainben"; $_['text_update_selected_uids'] = "Kijelölt azonosítók módosítása"; +$_['text_updated_records'] = "Frissített rekordok"; $_['text_uptime'] = "Uptime"; $_['text_user'] = "Felhasználó"; $_['text_users'] = "Felhasználók"; diff --git a/webui/language/pt/messages.php b/webui/language/pt/messages.php index 7cbf673d..6c355120 100644 --- a/webui/language/pt/messages.php +++ b/webui/language/pt/messages.php @@ -260,12 +260,12 @@ $_['text_remove_this_policy'] = "Remover esta política"; $_['text_remove_this_group'] = "Remover este grupo"; $_['text_remove_this_user'] = "Remover este usuário"; $_['text_reset_counters'] = "Zerar contadores"; - $_['text_restore'] = "reenviar"; $_['text_restore_message'] = "reenviar mensagem"; $_['text_restore_to_mailbox'] = "Reenviar mensagem"; $_['text_restored'] = "Reenviado."; $_['text_result'] = "Resultado"; +$_['text_retention_days'] = "Retention days"; $_['text_retention_rules'] = "Regras de retenção"; $_['text_role'] = "Função"; $_['text_running'] = "processando"; @@ -334,7 +334,9 @@ $_['text_unauthorized_download_attachment'] = "unauthorized attachment download" $_['text_unauthorized_remove_message'] = "remoção de mensagem não autorizada"; $_['text_unauthorized_view_message'] = "visualização de mensagem não autorizada"; $_['text_unknown'] = "desconhecido"; +$_['text_update_retention_within_this_domain'] = "Update retention values within this domain"; $_['text_update_selected_uids'] = "Atualizar UIDs selecionados"; +$_['text_updated_records'] = "Updated records"; $_['text_uptime'] = "Uptime"; $_['text_user'] = "Usuário"; $_['text_users'] = "Usuários"; diff --git a/webui/model/policy/retention.php b/webui/model/policy/retention.php index 3aee860b..330e062c 100644 --- a/webui/model/policy/retention.php +++ b/webui/model/policy/retention.php @@ -34,6 +34,25 @@ class ModelPolicyRetention extends Model { public function remove_rule($id = 0) { $query = $this->db->query("DELETE FROM " . TABLE_RETENTION_RULE . " WHERE id=?", array($id)); + + return $this->db->countAffected(); + } + + + public function update_retention_time($data = array()) { + if(DEFAULT_RETENTION <= 0) { return 0; } + + if(!isset($data['domain']) || !isset($data['days']) || $data['domain'] == '' || $data['days'] < 1) { return 0; } + + $default_retention = DEFAULT_RETENTION * 86400; + + $delta = NOW + 86400 * $data['days'] - $default_retention; + $start_ts = NOW - $default_retention; + + $query = $this->db->query("UPDATE " . VIEW_MESSAGES . " SET retained=? WHERE arrived > ? AND (todomain=? OR fromdomain=?)", array($delta, $start_ts, $data['domain'], $data['domain'])); + + if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("update retention date: domain='%s', days=%d, hits=%d, exec time=%.2f sec", $data['domain'], $data['days'], $this->db->countAffected(), $query->exec_time)); } + return $this->db->countAffected(); } diff --git a/webui/view/theme/default/templates/health/worker.tpl b/webui/view/theme/default/templates/health/worker.tpl index f6362e2a..13ab96a2 100644 --- a/webui/view/theme/default/templates/health/worker.tpl +++ b/webui/view/theme/default/templates/health/worker.tpl @@ -45,7 +45,7 @@ - => / (%)
+ => / (%)
diff --git a/webui/view/theme/default/templates/policy/retention.tpl b/webui/view/theme/default/templates/policy/retention.tpl index 4503d843..3e609d33 100644 --- a/webui/view/theme/default/templates/policy/retention.tpl +++ b/webui/view/theme/default/templates/policy/retention.tpl @@ -98,6 +98,9 @@   + +   + @@ -114,6 +117,9 @@ 0) { print $rule['_attachment_size']; ?> + +   + diff --git a/webui/view/theme/default/templates/policy/updateretention.tpl b/webui/view/theme/default/templates/policy/updateretention.tpl new file mode 100644 index 00000000..00972f55 --- /dev/null +++ b/webui/view/theme/default/templates/policy/updateretention.tpl @@ -0,0 +1,9 @@ + +
+ +:
+:
+: + +
+ diff --git a/webui/view/theme/mobile/templates/health/worker.tpl b/webui/view/theme/mobile/templates/health/worker.tpl index d6e87b73..833a76c1 100644 --- a/webui/view/theme/mobile/templates/health/worker.tpl +++ b/webui/view/theme/mobile/templates/health/worker.tpl @@ -72,7 +72,7 @@
-
=> / (%)
+
=> / (%)
diff --git a/webui/view/theme/mobile/templates/policy/retention.tpl b/webui/view/theme/mobile/templates/policy/retention.tpl index 7eae26f5..6ee92182 100644 --- a/webui/view/theme/mobile/templates/policy/retention.tpl +++ b/webui/view/theme/mobile/templates/policy/retention.tpl @@ -96,6 +96,9 @@
 
+ +
 
+
@@ -112,6 +115,9 @@
0) { print $rule['_attachment_size']; ?>
+ +
 
+ diff --git a/webui/view/theme/mobile/templates/policy/updateretention.tpl b/webui/view/theme/mobile/templates/policy/updateretention.tpl new file mode 100644 index 00000000..00972f55 --- /dev/null +++ b/webui/view/theme/mobile/templates/policy/updateretention.tpl @@ -0,0 +1,9 @@ + +
+ +:
+:
+: + +
+