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 search_audit($data = array()) { $where = ''; $arr = $results = array(); $from = 0; $sort = "ts"; $order = "DESC"; $sortorder = "ORDER BY ts DESC"; $date1 = $date2 = 0; $q = ''; $session = Registry::get('session'); if ($data['sort'] == "user") { $sort = "email"; } if ($data['sort'] == "ipaddr") { $sort = "ipaddr"; } if ($data['sort'] == "ref") { $sort = "meta_id"; } if ($data['sort'] == "action") { $sort = "action"; } if ($data['sort'] == "description") { $sort = "description"; } if ($data['order'] == 1) { $order = "ASC"; } $sortorder = "ORDER BY `{$sort}` {$order}"; if (isset($data['action']) && $data['action'] != ACTION_ALL) { $where .= " AND ( " . $this->append_search_criteria("action", $data['action'], $arr) . " )"; } if (isset($data['ipaddr']) && $data['ipaddr']) { $where .= " AND ( " . $this->append_search_criteria("ipaddr", $data['ipaddr'], $arr) . " )"; } if (isset($data['user']) && $data['user']) { $where .= " AND ( " . $this->append_search_criteria("email", $data['user'], $arr) . " )"; } if (isset($data['ref']) && $data['ref']) { $where .= " AND ( " . $this->append_search_criteria("meta_id", $data['ref'], $arr) . " )"; } if (Registry::get('admin_user') == 0 && RESTRICTED_AUDITOR == 1) { $auditdomains = $session->get("auditdomains"); while (list($k, $v) = each($auditdomains)) { if ($q) { $q .= ","; } $q .= "?"; array_push($arr, $v); } $where .= " AND domain IN ({$q}) "; reset($session->get("auditdomains")); } if (isset($data['date1'])) { $date1 = $data['date1']; } if (isset($data['date2'])) { $date2 = $data['date2']; } $date = fixup_date_condition('ts', $date1, $date2); if ($date) { $where .= " AND {$date} "; } if ($where) { $where = " WHERE " . substr($where, 5, strlen($where)); } $from = $data['page_len'] * $data['page']; if ($where) { $query = $this->db->query("SELECT COUNT(*) AS count FROM " . TABLE_AUDIT . " {$where}", $arr); $n = $query->row['count']; if (ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("audit query: '%s' in %.2f s, %d hits", $query->query, $query->exec_time, $query->row['count'])); } } else { $n = MAX_AUDIT_HITS; } if ($n > 0) { if ($n > MAX_AUDIT_HITS) { $n = MAX_AUDIT_HITS; } $query = $this->db->query("SELECT * FROM " . TABLE_AUDIT . " {$where} {$sortorder} LIMIT {$from}," . $data['page_len'], $arr); $this->session->set("audit_query", array('where' => $where, 'sortorder' => $sortorder, 'arr' => $arr)); if (ENABLE_SYSLOG == 1) { syslog(LOG_INFO, sprintf("audit query: '%s', param: '%s' in %.2f s, %d hits", $query->query, implode(' ', $arr), $query->exec_time, $query->num_rows)); } if (isset($query->rows)) { foreach ($query->rows as $a) { $a['description'] = preg_replace("/\"/", "'", $a['description']); $results[] = array('id' => $a['meta_id'], 'piler_id' => isset($m[$a['meta_id']]) ? $m[$a['meta_id']] : '', 'action' => $a['action'], 'email' => $a['email'], 'date' => date(DATE_TEMPLATE . " H:i", $a['ts']), 'ipaddr' => DEMO_MODE == 1 ? anonimize_ip_addr($a['ipaddr']) : $a['ipaddr'], 'description' => $a['description'], 'shortdescription' => make_short_string($a['description'], MAX_CGI_FROM_SUBJ_LEN)); } } } return array($n, $results); }