function getAliases() { if (!isDomainAdmin()) { return FALSE; } $sql = 'SELECT' . ' alias_id,' . ' (username || \'@\' || domain) AS email,' . ' domain,' . ' destination,' . ' active' . ' FROM virtual_aliases' . ' JOIN virtual_domains USING(domain_id)' . ' WHERE domain IN (' . quotedAdminDomainString() . ' )' . ' AND username != \'\'' . ' AND (username || \'@\' || domain) NOT IN (' . quotedAdminUserString() . ' )' . ' AND destination IN (' . quotedAdminUserString() . ' )' . ' ORDER BY domain, username, destination'; return db_getrows($sql); }
function db_getrow($sql, $params = FALSE) { $rows = db_getrows($sql, $params); if (!$rows) { return FALSE; } return $rows[0]; }
function getLocalForwards() { $sql = 'SELECT' . ' alias_id,' . ' (username || \'@\' || domain) AS email,' . ' domain,' . ' destination,' . ' active' . ' FROM virtual_aliases' . ' JOIN virtual_domains USING(domain_id)' . ' WHERE (username || \'@\' || domain) NOT IN (' . quotedAdminUserString() . ' )' . ' ORDER BY domain, username, destination'; $rows = db_getrows($sql); $ret = array(); foreach ($rows as $row) { if (!validEmailAddress($row['destination']) && validUserName($row['destination'])) { $row['aliases'] = getNumLocalAliasDestination($row['destination']); $ret[] = $row; } } return $ret; }
function getForwards() { if (!isDomainAdmin()) { return FALSE; } $sql = 'SELECT' . ' alias_id,' . ' (username || \'@\' || domain) AS email,' . ' domain,' . ' destination,' . ' active' . ' FROM virtual_aliases' . ' JOIN virtual_domains USING(domain_id)' . ' WHERE domain IN (' . quotedAdminDomainString() . ' )' . ' AND (username || \'@\' || domain) IN (' . quotedAdminUserString() . ' )' . ' AND (username || \'@\' || domain) != destination' . ' AND (username || \'@\' || domain || \'@autoreply.\' || domain) != destination' . ' ORDER BY domain, username, destination'; $rows = db_getrows($sql); $i = 0; foreach ($rows as $row) { if ($row['active'] == 't') { $rows[$i]['active'] = TRUE; } else { $rows[$i]['active'] = FALSE; } $i++; } return $rows; }
function getLocalAliases() { if (!isSiteAdmin()) { return FALSE; } $sql = 'SELECT' . ' alias_id,' . ' name,' . ' destination,' . ' active' . ' FROM local_aliases' . ' ORDER BY name'; $rows = db_getrows($sql); $i = 0; foreach ($rows as $row) { if ($row['active'] == 't') { $rows[$i]['active'] = TRUE; } else { $rows[$i]['active'] = FALSE; } $rows[$i]['forwards'] = getNumVirtualForwards($row['name']); $i++; } return $rows; }
function getSyslog($limit = FALSE, $start = FALSE) { global $priorities; $sql = 'SELECT * FROM (' . ' SELECT' . ' id,' . ' DATE_PART(\'epoch\', devicereportedtime) AS time,' . ' priority AS priority_id,' . ' message,' . ' syslogtag AS service' . ' FROM systemevents' . ' WHERE facility = ?'; $params = array(SYSLOG_MAIL); if ($start) { $sql .= ' AND id > ?'; $params[] = $start; } $sql .= ' ORDER BY id DESC'; if ($limit) { $sql .= ' LIMIT ?'; $params[] = $limit; } $sql .= ') AS LOG' . ' ORDER BY id'; db_set_active('logs'); $rows = db_getrows($sql, $params); db_set_active('default'); if (!$rows) { return FALSE; } $i = 0; foreach ($rows as $row) { $pid = null; $service = str_replace(':', '', $row['service']); if (preg_match('/^(.*)\\[(.*)\\]$/', $service, $matches)) { $service = $matches[1]; $pid = $matches[2]; } $rows[$i]['pid'] = $pid; $rows[$i]['service'] = $service; $message = htmlspecialchars($row['message']); $rows[$i]['message'] = $message; $i++; } return $rows; }
function getAdminUsers($like = FALSE, $userId = FALSE) { if (!$userId) { $userId = $_SESSION['user']['user_id']; } if (!isDomainAdmin($userId)) { return FALSE; } $sql = 'SELECT' . ' user_id,' . ' username || \'@\' || domain AS email,' . ' username,' . ' domain,' . ' role_id,' . ' description AS name,' . ' active' . ' FROM virtual_users' . ' JOIN virtual_domains USING(domain_id)' . ' WHERE domain IN (' . quotedAdminDomainString() . ' )'; if ($like) { $sql .= ' AND (username || \'@\' || domain) LIKE ?'; } $sql .= ' ORDER BY domain, username'; if ($like) { $params = array('%' . $like . '%'); } else { $params = array(); } $users = db_getrows($sql, $params); if (!$users) { return FALSE; } $i = 0; foreach ($users as $tmpUser) { $u = $users[$i]; $u['local'] = userLocal($u['email']); $u['active'] = FALSE; if ($tmpUser['active'] == 't') { $u['active'] = TRUE; } $users[$i] = $u; $i++; } return $users; }
function getAllDomains() { $sql = 'SELECT domain_id, domain FROM virtual_domains'; return db_getrows($sql); }
include_once '../lib/session.inc.php'; include_once '../lib/user.inc.php'; include_once '../lib/domains.inc.php'; requireDomainAdmin(); $query = $_POST['query']; $mode = $_POST['mode']; if ($query && !$mode && $query != 'all') { $sql = 'SELECT' . ' domain_id,' . ' domain' . ' FROM virtual_domains' . ' WHERE domain LIKE ?' . ' AND domain IN (' . quotedAdminDomainString() . ' )' . ' ORDER BY domain'; $rows = db_getrows($sql, array('%' . strtolower($query) . '%')); $domains = array('success' => true, 'domains' => $rows); print json_encode($domains); } else { if ($mode == 'load' || $query == 'all') { $sql = 'SELECT' . ' domain_id,' . ' domain' . ' FROM virtual_domains' . ' WHERE domain IN (' . quotedAdminDomainString() . ' )' . ' ORDER BY domain'; $rows = db_getrows($sql); $domains = array('success' => true, 'domains' => $rows); print json_encode($domains); } else { if ($mode == 'add') { requireSiteAdmin(); addDomain($_POST['domain']); } else { if ($mode == 'remove') { requireSiteAdmin(); $remove = $_POST['domains']; $domainIds = split(',', $remove); foreach ($domainIds as $domainId) { removeDomain($domainId); } print json_encode(array('success' => TRUE));