diff --git a/util/daily-report.php b/util/daily-report.php index 155fb5a5..95f8e8f1 100644 --- a/util/daily-report.php +++ b/util/daily-report.php @@ -3,6 +3,10 @@ $webuidir = ""; $verbose = 0; +$archivesizeraw = $sqlsizeraw = $sphinxsizeraw = 0; +$averagemessagesweekraw = $averagemessagesmonthraw = $averagemessagesizeraw = $averagesizedayraw = $averagesqlsizeraw = $averagesphinxsizeraw = 0; + + if(isset($_SERVER['argv'][1])) { $webuidir = $_SERVER['argv'][1]; } for($i=2; $i<$_SERVER['argc']; $i++){ @@ -66,13 +70,42 @@ $mail = new ModelMailMail(); list($totalmem, $meminfo, $totalswap, $swapinfo) = $health->meminfo(); $shortdiskinfo = $health->diskinfo(); - list($archive_size, $counters) = $counter->get_counters(); + list($archivesizeraw, $counters) = $counter->get_counters(); + $archive_size = nice_size($archivesizeraw, ' '); + $sysinfo = $health->sysinfo(); $options = $health->get_options(); - + /* these next counters are for projecting space */ + $averagemessagesweekraw = ($processed_emails[1]) / 7; + $averagemessagesmonthraw = ($processed_emails[2]) / 30; + $averagemessagesizeraw = $archivesizeraw / $counters['rcvd']; + $averagesqlsizeraw = $sqlsizeraw / $counters['rcvd']; + $averagesphinxsizeraw = $sphinxsizeraw / $counters['rcvd']; + $averagesizedayraw = ($averagemessagesizeraw+$averagesqlsizeraw+$averagesphinxsizeraw) * $averagemessagesweekraw; + foreach($shortdiskinfo as $part) { + if( $part['partition'] == DATA_PARTITION ) { $datapart = $part['freespace']*1024; } + } + + $averagemessages = round($averagemessagesweekraw); // average of messages over the past week + $averagemessagesize = nice_size($averagemessagesizeraw,' '); // average message size on disk + $averagesqlsize = nice_size($averagesqlsizeraw,' '); // average metadata size in sql + $averagesphinxsize = nice_size($averagesphinxsizeraw,' '); // average sphinx index + $averagesizeday = nice_size($averagesizedayraw,' '); // average size per day + $daysleftatcurrentrate = convert_days_ymd($datapart / $averagesizedayraw); // number of days of free space left + if ( $averagemessagesweekraw > $averagemessagesmonthraw ) { + $useagetrend = 1; + } elseif( $averagemessagesweekraw < $averagemessagesmonthraw ) { + $useagetrend = -1; + } else { + $useagetrend = 0; + } + + + /* start email message */ + $msg = "From: " . SMTP_FROMADDR . EOL; $msg .= "To: " . ADMIN_EMAIL . EOL; $msg .= "Subject: =?UTF-8?Q?" . preg_replace("/\n/", "", my_qp_encode($text_daily_piler_report)) . "?=" . EOL; @@ -81,7 +114,7 @@ $mail = new ModelMailMail(); $msg .= EOL . EOL; ob_start(); - + include($webuidir . "/view/theme/default/templates/health/daily-report.tpl"); $msg .= ob_get_contents(); diff --git a/util/db-mysql.sql b/util/db-mysql.sql index d243a4ce..ea3f40d0 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -349,3 +349,20 @@ create table if not exists `google_imap` ( key(`email`) ) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS `counter_stats` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `date` int(11) NOT NULL, + `email` varchar(255) NOT NULL, + `domain` varchar(255) NOT NULL, + `sent` int(11) NOT NULL, + `recd` int(11) NOT NULL, + `sentsize` int(11) NOT NULL, + `recdsize` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `date` (`date`), + KEY `email` (`email`), + KEY `domain` (`domain`) +) ENGINE=InnoDB; + + diff --git a/util/db-upgrade-0.18-vs-0.19.sql b/util/db-upgrade-0.1.18-vs-0.1.19.sql similarity index 100% rename from util/db-upgrade-0.18-vs-0.19.sql rename to util/db-upgrade-0.1.18-vs-0.1.19.sql diff --git a/util/db-upgrade-0.19-vs-0.20.sql b/util/db-upgrade-0.1.19-vs-0.1.20.sql similarity index 100% rename from util/db-upgrade-0.19-vs-0.20.sql rename to util/db-upgrade-0.1.19-vs-0.1.20.sql diff --git a/util/db-upgrade-0.20-vs-0.21.sql b/util/db-upgrade-0.1.20-vs-0.1.21.sql similarity index 100% rename from util/db-upgrade-0.20-vs-0.21.sql rename to util/db-upgrade-0.1.20-vs-0.1.21.sql diff --git a/util/db-upgrade-0.1.22-vs-0.1.23.sql b/util/db-upgrade-0.1.22-vs-0.1.23.sql index f892e60b..fe412bef 100644 --- a/util/db-upgrade-0.1.22-vs-0.1.23.sql +++ b/util/db-upgrade-0.1.22-vs-0.1.23.sql @@ -7,5 +7,20 @@ create table if not exists `domain_user` ( ) ENGINE=InnoDB; +CREATE TABLE IF NOT EXISTS `counter_stats` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `date` int(11) NOT NULL, + `email` varchar(255) NOT NULL, + `domain` varchar(255) NOT NULL, + `sent` int(11) NOT NULL, + `recd` int(11) NOT NULL, + `sentsize` int(11) NOT NULL, + `recdsize` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `date` (`date`), + KEY `email` (`email`), + KEY `domain` (`domain`) +) ENGINE=InnoDB; + alter table metadata drop index message_id; diff --git a/util/generate_stats.php b/util/generate_stats.php new file mode 100644 index 00000000..e4ebcef1 --- /dev/null +++ b/util/generate_stats.php @@ -0,0 +1,100 @@ +addServer($m[0], $m[1]); + } + + Registry::set('memcache', $memcache); +} + +$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PREFIX); +Registry::set('db', $db); + +$loader->model('accounting/accounting'); +$messagestats = new ModelAccountingAccounting(); + +$_SESSION['username'] = 'cli-admin'; +$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; + +extract($language->data); + +//$day_to_process = strtotime($day_to_process); +$records = $messagestats->run_counters($start,$end); + +$timeend = microtime(true); +$timegone = $timeend - $timestart; + +echo("\nFinished Executing Statistics Generation\n"); +echo("*************************************************\n"); +echo("Start Date: ".date("d M Y",$records['starttimestamp'])."\n"); +echo("Stop Date: ".date("d M Y",$records['endtimestamp'])."\n"); +echo("Removed ".$records['deletedstats']." records\n"); +echo("Added ".$records['addedstats']." records\n"); +echo("Completed Run in ".$timegone." seconds\n\n"); + +# Functions +function display_help() { + $phpself = basename(__FILE__); + echo("\nUsage: $phpself --webui [PATH] [OPTIONS...]\n\n"); + echo("\t--webui=\"[REQUIRED: path to the Piler WebUI Directory]\"\n\n"); + echo("options:\n"); + echo("\t-a Reruns statistics for all records in the message view\n"); + echo("\t-h Prints this help screen and exits\n"); + echo("\t--start=\"Beginning of date range to process, ok values are today, yesterday or DDMMMYYYY...anything php's strtotime can process. Optional, will default to beginning of current day.\"\n"); + echo("\t--stop=\"End of date range, same parameters as above. Optional (will default to end of current day)\"\n\n"); +} +?> \ No newline at end of file diff --git a/webui/config.php b/webui/config.php index e2e9f27d..bcd83b5f 100644 --- a/webui/config.php +++ b/webui/config.php @@ -61,6 +61,7 @@ $config['DEFAULT_POLICY'] = 'default_policy'; $config['DIR_BASE'] = '/var/www/piler.yourdomain.com/'; +$config['DIR_SPHINX'] = '/var/piler/sphinx/'; $config['DIR_STAT'] = '/var/piler/stat'; $config['DIR_IMAP'] = '/var/piler/imap'; $config['DIR_TMP'] = '/var/piler/tmp'; @@ -122,7 +123,7 @@ $memcached_servers = array( ); $partitions_to_monitor = array('/', '/home', '/var', '/tmp'); - +$config['DATA_PARTITION'] = '/var'; $langs = array( 'hu', @@ -174,6 +175,8 @@ define('TABLE_REMOTE', 'remote'); define('TABLE_DOMAIN', 'domain'); define('TABLE_DOMAIN_USER', 'domain_user'); define('TABLE_COUNTER', 'counter'); +define('TABLE_COUNTER_MSG', 'counter_messages'); +define('TABLE_STAT_COUNTER', 'counter_stats'); define('TABLE_AUDIT', 'audit'); define('TABLE_ARCHIVING_RULE', 'archiving_rule'); define('TABLE_RETENTION_RULE', 'retention_rule'); diff --git a/webui/controller/accounting/accounting.php b/webui/controller/accounting/accounting.php new file mode 100644 index 00000000..dc633719 --- /dev/null +++ b/webui/controller/accounting/accounting.php @@ -0,0 +1,99 @@ +id = "content"; + $this->template = "accounting/accounting.tpl"; + $this->layout = "common/layout"; + + $request = Registry::get('request'); + $db = Registry::get('db'); + + $this->load->model('user/user'); + $this->load->model('group/group'); + $this->load->model('accounting/accounting'); + $counters = new ModelAccountingAccounting(); + + $this->data['page'] = 0; + $this->data['page_len'] = get_page_length(); + $this->data['sort'] = 'item'; + $this->data['sorttype'] = 0; + $this->data['order'] = 0; + + // 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']; + } + + // get sort field + if ( isset($this->request->get['sort']) ) { + if(@$this->request->get['sort'] == "item") { $this->data['sort'] = 'item'; } + if(@$this->request->get['sort'] == "oldest") { $this->data['sort'] = 'oldest'; $this->data['sorttype'] = 1; } + if(@$this->request->get['sort'] == "newest") { $this->data['sort'] = 'newest'; $this->data['sorttype'] = 1; } + if(@$this->request->get['sort'] == "sent") { $this->data['sort'] = 'sent'; } + if(@$this->request->get['sort'] == "sentsize") { $this->data['sort'] = 'sentsize'; $this->data['sorttype'] = 2; } + if(@$this->request->get['sort'] == "sentavg") { $this->data['sort'] = 'sentavg'; $this->data['sorttype'] = 2; } + if(@$this->request->get['sort'] == "recd") { $this->data['sort'] = 'recd'; } + if(@$this->request->get['sort'] == "recdsize") { $this->data['sort'] = 'recdsize'; $this->data['sorttype'] = 2; } + if(@$this->request->get['sort'] == "recdavg") { $this->data['sort'] = 'recdavg'; $this->data['sorttype'] = 2; } + } + + // get sort order + if(isset($this->request->get['order']) && is_numeric($this->request->get['order'])) { + $this->data['order'] = $this->request->get['order']; + } + + // get type of accounting view + if(@$this->request->get['view'] == "email") { + $this->data['view'] = 'email'; + $this->data['viewname'] = "Emails"; + $this->data['accounting'] = $counters->get_accounting('email',$this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']); + $this->data['total_records'] = $counters->count_accounting('email'); + } + + if(@$this->request->get['view'] == "domain") { + $this->data['view'] = 'domain'; + $this->data['viewname'] = "Domains"; + $this->data['accounting'] = $counters->get_accounting('domain',$this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']); + $this->data['total_records'] = $counters->count_accounting('domain'); + } + + if($this->data['accounting']) { + foreach($this->data['accounting'] as $id=>$row) { + if($this->data['sorttype'] == 0){ + $this->data['accounting'][$id]['display'] = $row[$this->data['sort']]; + } + if($this->data['sorttype'] == 1){ + $this->data['accounting'][$id]['display'] = date("d M Y",$row[$this->data['sort']]); + } + if($this->data['sorttype'] == 2){ + $this->data['accounting'][$id]['display'] = nice_size($row[$this->data['sort']]); + } + } + } + + $this->document->title = $this->data['text_accounting']; + + $this->data['today'] = time()-(time()%86400); + $this->data['days'] = 15; + + $this->data['timespan'] = @$this->request->get['timespan']; + $this->data['uid'] = @$this->request->get['uid']; + + $this->data['admin_user'] = Registry::get('admin_user'); + $this->data['readonly_admin'] = Registry::get('readonly_admin'); + + $this->data['prev_page'] = $this->data['page'] - 1; + $this->data['next_page'] = $this->data['page'] + 1; + + $this->data['total_pages'] = floor($this->data['total_records'] / $this->data['page_len']); + + $this->render(); + } + +} + +?> diff --git a/webui/controller/health/worker.php b/webui/controller/health/worker.php index 82df0b9c..92045cd2 100644 --- a/webui/controller/health/worker.php +++ b/webui/controller/health/worker.php @@ -6,6 +6,9 @@ class ControllerHealthWorker extends Controller { public function index(){ + $archivesizeraw = $sqlsizeraw = $sphinxsizeraw = 0; + $averagemessagesweekraw = $averagemessagesmonthraw = $averagemessagesizeraw = $averagesizedayraw = $averagesqlsizeraw = $averagesphinxsizeraw = 0; + $this->id = "content"; $this->template = "health/worker.tpl"; $this->layout = "common/layout-empty"; @@ -60,7 +63,9 @@ class ControllerHealthWorker extends Controller { $db->select_db($db->database); - list($this->data['archive_size'], $this->data['counters']) = $this->model_stat_counter->get_counters(); + list($archivesizeraw, $this->data['counters']) = $this->model_stat_counter->get_counters(); + + $this->data['archive_size'] = nice_size($archivesizeraw, ' '); $this->data['prefix'] = ''; if(isset($this->data['counters'][MEMCACHED_PREFIX . 'rcvd'])) { $this->data['prefix'] = MEMCACHED_PREFIX; } @@ -68,7 +73,38 @@ class ControllerHealthWorker extends Controller { $this->data['sysinfo'] = $this->model_health_health->sysinfo(); $this->data['options'] = $this->model_health_health->get_options(); + + $sqlsizeraw = $this->model_health_health->get_database_size(); + + $sphinxsizeraw = $this->model_health_health->get_sphinx_size(); + + /* these next counters are for projecting space */ + $averagemessagesweekraw = ($this->data['processed_emails'][1]) / 7; + $averagemessagesmonthraw = ($this->data['processed_emails'][2]) / 30; + $averagemessagesizeraw = $archivesizeraw / $this->data['counters']['rcvd']; + $averagesqlsizeraw = $sqlsizeraw / $this->data['counters']['rcvd']; + $averagesphinxsizeraw = $sphinxsizeraw / $this->data['counters']['rcvd']; + $averagesizedayraw = ($averagemessagesizeraw+$averagesqlsizeraw+$averagesphinxsizeraw) * $averagemessagesweekraw; + $datapart = 0; + foreach($this->data['shortdiskinfo'] as $part) { + if( $part['partition'] == DATA_PARTITION ) { $datapart = $part['freespace']*1024; } + } + + $this->data['averagemessages'] = round($averagemessagesweekraw); // average of messages over the past week + $this->data['averagemessagesize'] = nice_size($averagemessagesizeraw,' '); // average message size on disk + $this->data['averagesqlsize'] = nice_size($averagesqlsizeraw,' '); // average metadata size in sql + $this->data['averagesphinxsize'] = nice_size($averagesphinxsizeraw,' '); // average sphinx index + $this->data['averagesizeday'] = nice_size($averagesizedayraw,' '); // average size per day + $this->data['daysleftatcurrentrate'] = convert_days_ymd($datapart / $averagesizedayraw); // number of days of free space left + if ( $averagemessagesweekraw > $averagemessagesmonthraw ) { + $this->data['usagetrend'] = 1; + } elseif( $averagemessagesweekraw < $averagemessagesmonthraw ) { + $this->data['usagetrend'] = -1; + } else { + $this->data['usagetrend'] = 0; + } + $this->render(); } diff --git a/webui/language/en/messages.php b/webui/language/en/messages.php index 4f83a31f..6aec4806 100644 --- a/webui/language/en/messages.php +++ b/webui/language/en/messages.php @@ -364,5 +364,18 @@ $_['text_primary_domain'] = "Primary Domain"; $_['text_search_domains'] = "Search domains"; $_['text_search_domain_to_add'] = "Search domain to add"; +$_['text_space_projection'] = 'Space Projection'; +$_['text_average_messages_day'] = 'Average Messages per Day'; +$_['text_average_message_size'] = 'Average Message + Metadata + Index Size'; +$_['text_average_size_day'] = 'Average Size per Day'; +$_['text_partition_full'] = 'Partition Projected to be Full in'; +$_['text_usage_trend'] = 'Usage Trend'; +$_['text_usage_increasing'] = 'Increasing'; +$_['text_usage_decreasing'] = 'Decreasing'; +$_['text_usage_neutral'] = 'Neutral'; +$_['text_accounting'] = 'Archive Accounting'; +$_['text_accounting_email'] = 'By-Email Accounting'; +$_['text_accounting_domain'] = 'By-Domain Accounting'; + ?> diff --git a/webui/language/hu/messages.iso-8859-2.php b/webui/language/hu/messages.iso-8859-2.php index b0fb0a01..86002d72 100644 --- a/webui/language/hu/messages.iso-8859-2.php +++ b/webui/language/hu/messages.iso-8859-2.php @@ -365,4 +365,17 @@ $_['text_primary_domain'] = "Els $_['text_search_domains'] = "Domainek keresése"; $_['text_search_domain_to_add'] = "Írja be a domain nevének elejét"; +$_['text_space_projection'] = 'Tárterület elõrejelzés'; +$_['text_average_messages_day'] = 'Levelek számának napi átlaga'; +$_['text_average_message_size'] = 'Átlagos levélméret + Meta adatok + Index méret'; +$_['text_average_size_day'] = 'Napi átlag méret'; +$_['text_partition_full'] = 'partíció beteléséig hátralevõ idõ'; +$_['text_usage_trend'] = 'Kihasználtság trend'; +$_['text_usage_increasing'] = 'nõ'; +$_['text_usage_decreasing'] = 'csökken'; +$_['text_usage_neutral'] = 'nem változik'; +$_['text_accounting'] = 'Archívum statisztika'; +$_['text_accounting_email'] = 'Email szerint'; +$_['text_accounting_domain'] = 'Domain szerint'; + ?> diff --git a/webui/language/hu/messages.php b/webui/language/hu/messages.php index 4bb8703c..0012b20f 100644 --- a/webui/language/hu/messages.php +++ b/webui/language/hu/messages.php @@ -365,4 +365,17 @@ $_['text_primary_domain'] = "ElsÅ‘dleges Domain"; $_['text_search_domains'] = "Domainek keresése"; $_['text_search_domain_to_add'] = "Ãrja be a domain nevének elejét"; +$_['text_space_projection'] = 'Tárterület elÅ‘rejelzés'; +$_['text_average_messages_day'] = 'Levelek számának napi átlaga'; +$_['text_average_message_size'] = 'Ãtlagos levélméret + Meta adatok + Index méret'; +$_['text_average_size_day'] = 'Napi átlag méret'; +$_['text_partition_full'] = 'partíció beteléséig hátralevÅ‘ idÅ‘'; +$_['text_usage_trend'] = 'Kihasználtság trend'; +$_['text_usage_increasing'] = 'nÅ‘'; +$_['text_usage_decreasing'] = 'csökken'; +$_['text_usage_neutral'] = 'nem változik'; +$_['text_accounting'] = 'Archívum statisztika'; +$_['text_accounting_email'] = 'Email szerint'; +$_['text_accounting_domain'] = 'Domain szerint'; + ?> diff --git a/webui/language/pt/messages.php b/webui/language/pt/messages.php index 6af15d4e..88fb10a7 100644 --- a/webui/language/pt/messages.php +++ b/webui/language/pt/messages.php @@ -364,4 +364,17 @@ $_['text_primary_domain'] = "Primary Domain"; $_['text_search_domains'] = "Search domains"; $_['text_search_domain_to_add'] = "Search domain to add"; +$_['text_space_projection'] = 'Space Projection'; +$_['text_average_messages_day'] = 'Average Messages per Day'; +$_['text_average_message_size'] = 'Average Message + Metadata + Index Size'; +$_['text_average_size_day'] = 'Average Size per Day'; +$_['text_partition_full'] = 'Partition Projected to be Full in'; +$_['text_usage_trend'] = 'Useage Trend'; +$_['text_usage_increasing'] = 'Increasing'; +$_['text_usage_decreasing'] = 'Decreasing'; +$_['text_usage_neutral'] = 'Neutral'; +$_['text_accounting'] = 'Archive Accounting'; +$_['text_accounting_email'] = 'By-Email Accounting'; +$_['text_accounting_domain'] = 'By-Domain Accounting'; + ?> diff --git a/webui/model/accounting/accounting.php b/webui/model/accounting/accounting.php new file mode 100644 index 00000000..99af9ea6 --- /dev/null +++ b/webui/model/accounting/accounting.php @@ -0,0 +1,242 @@ +__getAcceptedDomains() ); + $return = array( + 'starttimestamp' => 0, + 'endtimestamp' => 0, + 'addedstats' => 0, + 'deletedstats' => 0, + ); + + if ( !is_null($start) ) + { + $start = $this->__decodeDate( $start ); + } elseif ( is_null($start) ) + { + //if we are passed nothing, operate on today + $start = $this->__decodeDate( "00:00:00" ); + } + + if ( !is_null($end) ) + { + $end = $this->__decodeDate( $end ); + $end = $end + 86400; + } elseif ( is_null($end) ) + { + //if we are passed nothing, operate on today + $end = $this->__decodeDate( "00:00:00" ); + $end = $end + 86400; + } + + $return['starttimestamp'] = $start; + $return['endtimestamp'] = $end; + + // run query to return all messages + $tousers = $this->db->query('SELECT `sent`-(`sent`%86400) as `day`,`to`,count(*) as `count`,sum(`size`) as `size` FROM ' . VIEW_MESSAGES . ' WHERE `sent` >= '.$start.' AND `sent` < '.$end.' GROUP BY FROM_UNIXTIME(`day`, "%Y.%m.%d."), `to`;'); + $fromusers = $this->db->query('SELECT `sent`-(`sent`%86400) as `day`,`from`,count(*) as `count`,sum(`size`) as `size` FROM ' . VIEW_MESSAGES . ' WHERE `sent` >= '.$start.' AND `sent` < '.$end.' GROUP BY FROM_UNIXTIME(`day`, "%Y.%m.%d."), `from`;'); + + // process results from above four queries + if($tousers->num_rows > 0) + { + foreach($tousers->rows as $row) + { + $counter[$row['day']][$row['to']]['recd'] = $row['count']; + $counter[$row['day']][$row['to']]['sizerecd'] = $row['size']; + } + } + if($fromusers->num_rows > 0) + { + foreach($fromusers->rows as $row) + { + $counter[$row['day']][$row['from']]['sent'] = $row['count']; + $counter[$row['day']][$row['from']]['sizesent'] = $row['size']; + } + } + + foreach( $counter as $date=>$users ) + { + + // execute queries to update the users and domains counter table + $deletestats = $this->db->query("DELETE FROM " . TABLE_STAT_COUNTER . " WHERE `date` = $date;"); + $return['deletedstats'] = $return['deletedstats'] + $this->db->countAffected(); + + foreach( $users as $username => $userdata) + { + //todo: consolidate + $sent = isset($userdata['sent']) ? $userdata['sent'] : 0; + $recd = isset($userdata['recd']) ? $userdata['recd'] : 0; + $sizesent = isset($userdata['sizesent']) ? $userdata['sizesent'] : 0; + $sizerecd = isset($userdata['sizerecd']) ? $userdata['sizerecd'] : 0; + + $parts = explode('@',$username); + + if ( isset($accepteddomains[ $parts[1] ]) ) { + $addusers = $this->db->query("INSERT INTO " . TABLE_STAT_COUNTER . " (`date`,`email`,`domain`,`sent`,`recd`,`sentsize`,`recdsize`) VALUES($date,'$username','".$parts[1]."',$sent,$recd,$sizesent,$sizerecd);"); + $return['addedstats'] = $return['addedstats'] + $this->db->countAffected(); + } + } + + } + + if(ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("processed %s to %s: %d records deleted, %d records added",date("d M Y",$return['starttimestamp']),date("d M Y",$return['endtimestamp']),$return['deletedstats'],$return['addedstats'])); } + + return $return; + } + + public function get_accounting($item = 'email',$page=0,$pagelen=0,$sort='item',$order=0 ) { + + // item can be either email or domain, maybe folder in the future?? + + $_order = 0; + $_order = ""; + $limit = ""; + $return = array(); + + /* + if(MEMCACHED_ENABLED) { + $memcache = Registry::get('memcache'); + + $statscounter = $memcache->get(Registry::get('statscounters')); + + if(isset($counter[MEMCACHED_PREFIX . 'counters_last_update'])) { + if(isset($counter[MEMCACHED_PREFIX . 'size'])) { $asize = nice_size($counter[MEMCACHED_PREFIX . 'size'], ' '); } + unset($counter[MEMCACHED_PREFIX . 'size']); + + return array ($asize, $counter); + } + } */ + + $account_for_emails = $this->__getEmails(); + $account_for_domains = $this->__getDomains(); + + + + if ($item == 'email') { + $account_for_emails = $this->__getEmails(); + $account_for_domains = $this->__getDomains(); + $query = "SELECT `email` AS `item`,MIN(`date`) as `oldest`,MAX(`date`) as `newest`,sum(`sent`) as `sent`,sum(`recd`) as `recd`,SUM(`sentsize`) as `sentsize`,AVG(`sentsize`) as `sentavg`,SUM(`recdsize`) as `recdsize`,AVG(`recdsize`) as `recdavg` FROM " . TABLE_STAT_COUNTER; + $where = "WHERE `email` IN ('".implode("','",$account_for_emails)."') OR `domain` IN ('".implode("','",$account_for_domains)."')"; + $group = "GROUP BY `email`"; + } elseif ($item == 'domain') { + $account_for_domains = $this->__getDomains(); + $query = "SELECT `domain` AS `item`,MIN(`date`) as `oldest`,MAX(`date`) as `newest`,sum(`sent`) as `sent`,sum(`recd`) as `recd`,SUM(`sentsize`) as `sentsize`,AVG(`sentsize`) as `sentavg`,SUM(`recdsize`) as `recdsize`,AVG(`recdsize`) as `recdavg` FROM " . TABLE_STAT_COUNTER; + $where = "WHERE `domain` IN ('".implode("','",$account_for_domains)."')"; + $group = "GROUP BY `domain`"; + } else { + return false; + } + + if($order == 0) { $order = "ASC"; } + else { $order = "DESC"; } + + $_order = "ORDER BY `$sort` $order"; + + $from = (int)$page * (int)$pagelen; + + if($pagelen > 0) { $limit = " LIMIT " . (int)$from . ", " . (int)$pagelen; } + + $query = $this->db->query($query.' '.$where.' '.$group.' '.$_order.' '.$limit.';'); + + if($query->num_rows >= 1) + { + return $query->rows; + } else { + // no results found + return false; + } + } + + + public function count_accounting($item = 'email') { + + $account_for_emails = $this->__getEmails(); + $account_for_domains = $this->__getDomains(); + + $query = "SELECT `email` AS `item`,MIN(`date`) as `oldest`,MAX(`date`) as `newest`,sum(`sent`) as `sent`,sum(`recd`) as `recd`,sum(`sentsize`) as `sentsize`,sum(`recdsize`) as `recdsize` FROM " . TABLE_STAT_COUNTER; + + if ($item == 'email') { + $where = "WHERE `email` IN ('".implode("','",$account_for_emails)."') OR `domain` IN ('".implode("','",$account_for_domains)."')"; + $group = "GROUP BY `email`"; + } elseif ($item == 'domain') { + $where = "WHERE `domain` IN ('".implode("','",$account_for_domains)."')"; + $group = "GROUP BY `domain`"; + } else { + return false; + } + + $query = $this->db->query($query.' '.$where.' '.$group.';'); + + return $query->num_rows; + } + + private function __getEmails() { + $return = array(); + array_push($return,$_SESSION['email']); + foreach ($_SESSION['emails'] as $e) { + array_push($return,$e); + } + + return $return; + } + + private function __getDomains() { + $return = array(); + + if(Registry::get('admin_user') >= 1) { + $return = $this->__getAcceptedDomains(); + }elseif(Registry::get('auditor_user') == 1) { + array_push($return,$_SESSION['domain']); + foreach ($return as $d) { + array_push($return,$d); + } + } + + return $return; + } + + + private function __getAcceptedDomains() { + // todo: move to domains model? + $return = array(); + + $query = $this->db->query("SELECT domain, mapped FROM " . TABLE_DOMAIN . " ORDER BY domain ASC"); + + foreach($query->rows as $domain) + { + if ($domain['domain'] == $domain['mapped']) { + array_push($return,$domain['domain']); + } else { + array_push($return,$domain['mapped']); + } + } + + return $return; + } + + private function __decodeDate( $input ) { + + if ( !is_numeric($input) ) + { + // if we are passed words (yesterday, today), convert to unix timestamps representing the start of the day + $input = strtotime($input); + $return = $input - ($input%86400); + + } elseif ( is_numeric($input) ) + { + // if we are passed unix timestamps, ensure they represent the start of the day + $return = $input - ($input%86400); + } + + return $return; + + } + +} +?> diff --git a/webui/model/health/health.php b/webui/model/health/health.php index d6316cb6..30cb9667 100644 --- a/webui/model/health/health.php +++ b/webui/model/health/health.php @@ -80,7 +80,7 @@ class ModelHealthHealth extends Model { public function diskinfo() { $shortinfo = array(); - $s = exec("df -h", $output); + $s = exec("df", $output); $partitions = Registry::get('partitions_to_monitor'); @@ -90,6 +90,7 @@ class ModelHealthHealth extends Model { if(isset($p[5]) && in_array($p[5], $partitions)) { $shortinfo[] = array( 'partition' => $p[5], + 'freespace' => $p[3], 'utilization' => preg_replace("/\%/", "", $p[4]) ); } @@ -137,6 +138,46 @@ class ModelHealthHealth extends Model { } + public function get_database_size() { + $data = array(); + + $query = $this->db->query("SELECT table_schema AS `name`, + SUM( data_length + index_length ) AS `size` + FROM information_schema.TABLES + WHERE table_schema = '".DB_DATABASE."' + GROUP BY table_schema;"); + if(isset($query->rows)) { + $data = array_pop($query->rows); + } + + return $data['size']; + } + + + public function get_sphinx_size() { + $dirSize=0; + $directory = DIR_SPHINX; + + if(!$dh=opendir($directory)) { + return false; + } + + while($file = readdir($dh)) { + if($file == "." || $file == "..") { + continue; + } + + if(is_file($directory."/".$file)) { + $dirSize += filesize($directory."/".$file); + } + if(is_dir($directory."/".$file)) { + $dirSize += getDirectorySize($directory."/".$file); + } + } + + closedir($dh); + return $dirSize; + } } diff --git a/webui/model/user/user.php b/webui/model/user/user.php index ddf7d9dc..01c35778 100644 --- a/webui/model/user/user.php +++ b/webui/model/user/user.php @@ -85,12 +85,14 @@ class ModelUserUser extends Model { public function get_users_all_domains($uid = 0) { $data = array(); + array_push($data, $_SESSION['domain']); + if($uid > 0) { $query = $this->db->query("SELECT domain FROM " . TABLE_DOMAIN_USER . " WHERE uid=?", array((int)$uid)); if(isset($query->rows)) { foreach ($query->rows as $q) { - array_push($data, $q['domain']); + if(!in_array($q['domain'], $data)) { array_push($data, $q['domain']); } } } } diff --git a/webui/system/misc.php b/webui/system/misc.php index ac1d3846..69de7995 100644 --- a/webui/system/misc.php +++ b/webui/system/misc.php @@ -460,4 +460,18 @@ function make_short_string($what, $length) { } +function convert_days_ymd($convert) { + $years = ($convert / 365) ; // days / 365 days + $years = floor($years); // Remove all decimals + + $month = ($convert % 365) / 30.5; // I choose 30.5 for Month (30,31) ;) + $month = floor($month); // Remove all decimals + + $days = ($convert % 365) % 30.5; // the rest of days + + // Return array of years, months, days + return array( $years,$month,$days ); +} + + ?> diff --git a/webui/view/javascript/piler.js b/webui/view/javascript/piler.js index 696b5fa7..43dd5396 100644 --- a/webui/view/javascript/piler.js +++ b/webui/view/javascript/piler.js @@ -590,8 +590,6 @@ var Piler = document.body.style.cursor = 'default'; }) .fail(function(a, b) { alert("Problem retrieving XML data:" + b) }); - - setInterval('Piler.load_health()', Piler.health_refresh * 1000); }, diff --git a/webui/view/theme/default/templates/accounting/accounting.tpl b/webui/view/theme/default/templates/accounting/accounting.tpl new file mode 100644 index 00000000..f68a258f --- /dev/null +++ b/webui/view/theme/default/templates/accounting/accounting.tpl @@ -0,0 +1,79 @@ +

 

+ +

+'.$text_accounting_email.''; } else { echo ''.$text_accounting_email.''; } ?> | +'.$text_accounting_domain.''; } else { echo ''.$text_accounting_domain.''; } ?> +

+ + + + + + + +
+
+
 
+
 
+
 
+
Sent
+
 
+
 
+
Received
+
 
+
 
+
+
+
+
Oldest Record
+
Newest Record
+
Items
+
Size
+
Avg Size
+
Items
+
Size
+
Avg Size
+
+ + +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + +

No Found

+ \ No newline at end of file diff --git a/webui/view/theme/default/templates/common/layout.tpl b/webui/view/theme/default/templates/common/layout.tpl index bdc0c81f..cb644dfb 100644 --- a/webui/view/theme/default/templates/common/layout.tpl +++ b/webui/view/theme/default/templates/common/layout.tpl @@ -20,7 +20,7 @@ -request->get['route']) && $this->request->get['route'] == 'health/health') { ?> onload="Piler.load_health();"> +request->get['route']) && $this->request->get['route'] == 'health/health') { ?> onload="Piler.load_health(); setInterval('Piler.load_health()', Piler.health_refresh * 1000);">
diff --git a/webui/view/theme/default/templates/common/menu-admin.tpl b/webui/view/theme/default/templates/common/menu-admin.tpl index 9d4f9485..b7ddabb8 100644 --- a/webui/view/theme/default/templates/common/menu-admin.tpl +++ b/webui/view/theme/default/templates/common/menu-admin.tpl @@ -14,6 +14,7 @@
+
+
+
+ ()
+ + + ()
+ ()
+ years, months, days ("" )
+ 0 ) { print $text_usage_increasing; } elseif( $usagetrend < 0 ) { print $text_useage_decreasing; } else { print $text_usage_neutral; } ?> ()
+
+
+ diff --git a/webui/view/theme/default/templates/health/worker.tpl b/webui/view/theme/default/templates/health/worker.tpl index 3b681949..c6ce3fe8 100644 --- a/webui/view/theme/default/templates/health/worker.tpl +++ b/webui/view/theme/default/templates/health/worker.tpl @@ -86,6 +86,32 @@ + +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
""
+
years, months, days
+
+
+
+
0 ) { print $text_usage_increasing; } elseif( $usagetrend < 0 ) { print $text_usage_decreasing; } else { print $text_usage_neutral; } ?>
+
+
+