static function list_content($directory, $filter = "", $exclude = "") { if (substr($directory, -1) != '/') { $directory .= "/"; } $excludeAlways = array(".", "..", "index.php", "Thumbs.db"); $arrFilter = array(); $arrExclude = array(); $results = array(); if (strlen($filter)) { $arrFilter = explode(' ', $filter); } if (strlen($exclude)) { $arrExclude = explode(' ', $exclude); } $handler = opendir($directory); while ($filename = readdir($handler)) { if ($arrFilter) { if (!in_array(file_extension($filename), $arrFilter)) { continue; } } if ($arrExclude) { if (in_array(file_extension($filename), $arrExclude)) { continue; } } $filenamepath = $directory . $filename; if (!in_array($filename, $excludeAlways)) { if (is_dir($directory . $filename . '/')) { $results[0][] = $filename; } else { $filename_stats = stat($filenamepath); $results[1][] = array($filename, nice_size($filename_stats[7]), date('l, F dS 20y - H:i:s', $filename_stats[8]), date('l, F dS 20y - H:i:s', $filename_stats[9]), $filename_stats); } } } closedir($handler); return $results; }
public function index() { $archivesizeraw = $sqlsizeraw = $sphinxsizeraw = 0; $averagemessagesweekraw = $averagemessagesmonthraw = $averagemessagesizeraw = $averagesizedayraw = $averagesqlsizeraw = $averagesphinxsizeraw = 0; $averagemessagestotalraw = 0; $this->id = "content"; $this->template = "health/worker.tpl"; $this->layout = "common/layout-empty"; $db_history = Registry::get('db_history'); $this->load->model('health/health'); $this->load->model('stat/counter'); if (ENABLE_SAAS == 1) { $this->load->model('saas/customer'); } $request = Registry::get('request'); $lang = Registry::get('language'); $this->data['health'] = array(); if (Registry::get('admin_user') != 1 && Registry::get('readonly_admin') != 1) { die("go away"); } ini_set("default_socket_timeout", 5); foreach (Registry::get('health_smtp_servers') as $smtp) { if ($smtp[0]) { $this->data['health'][] = $this->model_health_health->checksmtp($smtp, $lang->data['text_error']); } } if (ENABLE_SAAS == 1) { $this->data['num_of_online_users'] = $this->model_saas_customer->count_online(); } $this->data['processed_emails'] = $this->model_health_health->count_processed_emails(); list($this->data['uptime'], $this->data['cpuload']) = $this->model_health_health->uptime(); $x = exec(CPU_USAGE_COMMAND); $this->data['cpuinfo'] = 100 - (int) $x; $this->data['quarantinereportinfo'] = @file_get_contents(DAILY_QUARANTINE_REPORT_STAT); list($this->data['totalmem'], $this->data['meminfo'], $this->data['totalswap'], $this->data['swapinfo']) = $this->model_health_health->meminfo(); $this->data['shortdiskinfo'] = $this->model_health_health->diskinfo(); /* counter related stuff */ $db = Registry::get('db'); $db->select_db($db->database); list($archivesizeraw, $archivestoredsizeraw, $this->data['counters']) = $this->model_stat_counter->get_counters(); $oldest_record_timestamp = $this->model_health_health->get_oldest_record_ts(); $total_number_days = round((time() - $this->model_health_health->get_first_email_arrival_ts()) / 86400); $this->data['archive_size'] = nice_size($archivesizeraw, ' '); $this->data['archive_stored_size'] = nice_size($archivestoredsizeraw, ' '); $this->data['prefix'] = ''; if (isset($this->data['counters'][MEMCACHED_PREFIX . 'rcvd'])) { $this->data['prefix'] = MEMCACHED_PREFIX; } $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(); /* * message count variables */ //average messages per day, computed over the past week $averagemessagesweekraw = $this->data['processed_emails'][2] / 7; //average messages per day, computed over the past month $averagemessagesmonthraw = $this->data['processed_emails'][3] / 30; //average messages per day, computed over the time period since the first email was archived if ($total_number_days > 0) { $averagemessagestotalraw = $this->data['counters']['rcvd'] / $total_number_days; } /* * message size variables */ if ($this->data['counters']['rcvd'] > 0) { //average message size, computed for total messages in database $averagemessagesizeraw = $archivesizeraw / $this->data['counters']['rcvd']; //average message metadata size, computed for total messages in database $averagesqlsizeraw = $sqlsizeraw / $this->data['counters']['rcvd']; //average message sphinx index size, computed for total messages in database $averagesphinxsizeraw = $sphinxsizeraw / $this->data['counters']['rcvd']; } //average total message size per day, computed over the time period since the first email was archived $averagesizedayraw = ($averagemessagesizeraw + $averagesqlsizeraw + $averagesphinxsizeraw) * $averagemessagestotalraw; $datapart = 0; foreach ($this->data['shortdiskinfo'] as $part) { if ($part['partition'] == DATA_PARTITION) { $datapart = $part['freespace'] * 1024; } // if the partition is the selected storage partition, record freespace on that partition } $this->data['oldestmessagets'] = $oldest_record_timestamp; // date of the oldest record in the db $this->data['averagemessages'] = round($averagemessagesweekraw); // rounded average of messages over the past week $this->data['averagemessagesize'] = nice_size($averagemessagesizeraw, ' '); // formatted average message size on disk $this->data['averagesqlsize'] = nice_size($averagesqlsizeraw, ' '); // formatted average metadata size in sql $this->data['averagesphinxsize'] = nice_size($averagesphinxsizeraw, ' '); // formatted average sphinx index $this->data['averagesizeday'] = nice_size($averagesizedayraw, ' '); // formatted average size per day // estimated number of days of free space left $averagesizedayraw > 0 ? $this->data['daysleftatcurrentrate'] = convert_days_ymd($datapart / $averagesizedayraw) : ($this->data['daysleftatcurrentrate'] = 0); /* * determine if the trend of the last week compared to the last month is * increasing, decreasing, or neutral * (only applies to message count, not size) */ if ($averagemessagesweekraw > $averagemessagesmonthraw) { $this->data['usagetrend'] = 1; } elseif ($averagemessagesweekraw < $averagemessagesmonthraw) { $this->data['usagetrend'] = -1; } else { $this->data['usagetrend'] = 0; } $this->data['indexer_stat'] = $this->model_health_health->indexer_stat(); $this->data['purge_stat'] = $this->model_health_health->purge_stat(); $this->render(); }
private function get_meta_data($ids = array(), $q = '', $sortorder = '') { $messages = array(); $rcpt = $srcpt = array(); $tag = array(); $note = array(); if (count($ids) == 0) { return $messages; } if (MEMCACHED_ENABLED) { $cache_key = $this->make_cache_file_name($ids, 'meta'); $memcache = Registry::get('memcache'); $m = $memcache->get($cache_key); if (isset($m['meta'])) { return unserialize($m['meta']); } } $session = Registry::get('session'); $query = $this->db->query("SELECT `id`, `to` FROM `" . TABLE_RCPT . "` WHERE `id` IN ({$q})", $ids); if (isset($query->rows)) { foreach ($query->rows as $r) { if (!isset($rcpt[$r['id']])) { $srcpt[$r['id']] = $r['to']; $rcpt[$r['id']] = $r['to']; } else { $rcpt[$r['id']] .= ",\n" . $r['to']; } } } $query = $this->db->query("SELECT `id`, `from`, `subject`, `piler_id`, `reference`, `size`, `spam`, `sent`, `arrived`, `attachments` FROM `" . TABLE_META . "` WHERE `id` IN ({$q}) {$sortorder}", $ids); if (isset($query->rows)) { array_unshift($ids, (int) $session->get("uid")); $tags = $this->db->query("SELECT `id`, `tag` FROM `" . TABLE_TAG . "` WHERE `uid`=? AND `id` IN ({$q})", $ids); foreach ($tags->rows as $t) { $tag[$t['id']] = $t['tag']; } $notes = $this->db->query("SELECT `id`, `note` FROM " . TABLE_NOTE . " WHERE `uid`=? AND `id` IN ({$q})", $ids); foreach ($notes->rows as $n) { $note[$n['id']] = $n['note']; } $lang = Registry::get('language'); $this->model_search_message->connect_to_pilergetd(); foreach ($query->rows as $m) { $m['shortfrom'] = make_short_string($m['from'], MAX_CGI_FROM_SUBJ_LEN); $m['from'] = escape_gt_lt_quote_symbols($m['from']); isset($srcpt[$m['id']]) ? $m['shortto'] = $srcpt[$m['id']] : ($m['shortto'] = ''); isset($rcpt[$m['id']]) ? $m['to'] = $rcpt[$m['id']] : ($m['to'] = ''); $m['to'] = escape_gt_lt_quote_symbols($m['to']); if ($m['subject'] == "") { $m['subject'] = "<" . $lang->data['text_no_subject'] . ">"; } $m['subject'] = escape_gt_lt_quote_symbols($m['subject']); $m['shortsubject'] = make_short_string($m['subject'], MAX_CGI_FROM_SUBJ_LEN); $m['date'] = date(DATE_TEMPLATE, $m['sent']); $m['size'] = nice_size($m['size']); in_array($m['from'], $session->get("emails")) ? $m['yousent'] = 1 : ($m['yousent'] = 0); /* * verifying 20 messages takes some time, still it's useful */ if (ENABLE_ON_THE_FLY_VERIFICATION == 1) { $data = $this->model_search_message->get_raw_message($m['piler_id']); $m['verification'] = $this->model_search_message->verify_message($m['piler_id'], $data); $data = ''; } if (isset($tag[$m['id']])) { $m['tag'] = $tag[$m['id']]; } else { $m['tag'] = ''; } if (isset($note[$m['id']])) { $m['note'] = $note[$m['id']]; } else { $m['note'] = ''; } $m['note'] = preg_replace("/\"/", "*", strip_tags($m['note'])); $m['tag'] = preg_replace("/\"/", "*", strip_tags($m['tag'])); array_push($messages, $m); } $this->model_search_message->disconnect_from_pilergetd(); } if (MEMCACHED_ENABLED) { $memcache->add($cache_key, array('meta' => serialize($messages)), 0, MEMCACHED_TTL); } return $messages; }
public function index() { $this->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('domain/domain'); $this->load->model('accounting/accounting'); if (ENABLE_SAAS == 1) { $this->load->model('saas/ldap'); } $this->data['page'] = 0; $this->data['page_len'] = get_page_length(); $this->data['sort'] = 'item'; $this->data['sorttype'] = 0; $this->data['order'] = 0; $this->data['search'] = ''; /* get search term if there's any */ 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']; } // 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'] = $this->data['text_email']; $this->data['accounting'] = $this->model_accounting_accounting->get_accounting('email', $this->data['search'], $this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']); $this->data['total_records'] = $this->model_accounting_accounting->count_accounting('email', $this->data['search']); } if (@$this->request->get['view'] == "domain") { $this->data['view'] = 'domain'; $this->data['viewname'] = $this->data['text_domain']; $this->data['accounting'] = $this->model_accounting_accounting->get_accounting('domain', $this->data['search'], $this->data['page'], $this->data['page_len'], $this->data['sort'], $this->data['order']); $this->data['total_records'] = $this->model_accounting_accounting->count_accounting('domain', $this->data['search']); $this->data['mydomain_count'] = $this->model_domain_domain->count_mydomains(); $this->data['user_count'] = 0; if (ENABLE_SAAS == 1) { $this->data['accounts'] = array(); foreach ($this->data['accounting'] as $a) { $this->data['accounts'][$a['item']] = $this->model_saas_ldap->get_accounts_in_domain($a['item']); $this->data['user_count'] += count($this->data['accounts'][$a['item']]); } } } if (@$this->request->get['view'] == "accounts" && isset($this->request->get['domain'])) { $this->template = "accounting/accounts.tpl"; $this->data['domain'] = $this->request->get['domain']; $this->data['accounts'] = $this->model_saas_ldap->get_accounts_in_domain($this->request->get['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(DATE_TEMPLATE, $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(); }
| downloaded: Fri, 17 Sep 2010 13:14:59 GMT as PHP file | | code URL: | http://phparadise.de/php-code/file-handling/file-informations/ | | description: | this snippet will give you informations about a file like size, last modified | date and more | ------------------------------------------------------------------------------*/ function nice_size($fs) { if ($fs >= 1073741824) { $fs = round($fs / 1073741824 * 100 / 100) . ' Gb'; } elseif ($fs >= 1048576) { $fs = round($fs / 1048576 * 100 / 100) . ' Mb'; } elseif ($fs >= 1024) { $fs = round($fs / 1024 * 100 / 100) . ' Kb'; } else { $fs = $fs . ' b'; } return $fs; } $file_stats = stat('/home/papajohn/public_html/phpparser/dummy.txt'); //$file_stats = stat(__file__); // demo echo ' <p> filesize: ' . nice_size($file_stats[7]) . '<br /> last access: ' . date('l, F dS 20y - H:i:s', $file_stats[8]) . '<br /> last modified: ' . date('l, F dS 20y - H:i:s', $file_stats[9]) . ' </p>';