function handler_duplicated($page, $action = 'list', $email = null) { $page->changeTpl('emails/duplicated.tpl'); $states = array('pending' => 'En attente...', 'safe' => 'Pas d\'inquiétude', 'unsafe' => 'Recherches en cours', 'dangerous' => 'Usurpations par cette adresse'); $page->assign('states', $states); if (Post::has('action')) { S::assert_xsrf_token(); } switch (Post::v('action')) { case 'create': if (trim(Post::v('emailN')) != '') { Xdb::execute('INSERT IGNORE INTO email_watch (email, state, detection, last, uid, description) VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})', trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); } break; case 'edit': Xdb::execute('UPDATE email_watch SET state = {?}, last = NOW(), uid = {?}, description = {?} WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN')); break; default: if ($action == 'delete' && !is_null($email)) { Xdb::execute('DELETE FROM email_watch WHERE email = {?}', $email); } } if ($action != 'create' && $action != 'edit') { $action = 'list'; } $page->assign('action', $action); if ($action == 'list') { $it = XDB::iterRow('SELECT w.email, w.detection, w.state, s.email AS forlife FROM email_watch AS w INNER JOIN email_redirect_account AS r ON (w.email = r.redirect) INNER JOIN email_source_account AS s ON (s.uid = r.uid AND s.type = \'forlife\') ORDER BY w.state, w.email, s.email'); $table = array(); $props = array(); while (list($email, $date, $state, $forlife) = $it->next()) { if (count($props) == 0 || $props['mail'] != $email) { if (count($props) > 0) { $table[] = $props; } $props = array('mail' => $email, 'detection' => $date, 'state' => $state, 'users' => array($forlife)); } else { $props['users'][] = $forlife; } } if (count($props) > 0) { $table[] = $props; } $page->assign('table', $table); } elseif ($action == 'edit') { $it = XDB::iterRow('SELECT w.detection, w.state, w.last, w.description, a.hruid AS edit, s.email AS forlife FROM email_watch AS w INNER JOIN email_redirect_account AS r ON (w.email = r.redirect) INNER JOIN email_source_account AS s ON (s.uid = r.uid AND s.type = \'forlife\') LEFT JOIN accounts AS a ON (w.uid = a.uid) WHERE w.email = {?} ORDER BY s.email', $email); $props = array(); while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) { if (count($props) == 0) { $props = array('mail' => $email, 'detection' => $detection, 'state' => $state, 'last' => $last, 'description' => $description, 'edit' => $edit, 'users' => array($forlife)); } else { $props['users'][] = $forlife; } } $page->assign('doublon', $props); } }
function handler_ipwatch($page, $action = 'list', $ip = null) { $page->changeTpl('admin/ipwatcher.tpl'); $states = array('safe' => 'Ne pas surveiller', 'unsafe' => 'Surveiller les inscriptions', 'dangerous' => 'Surveiller tous les accès', 'ban' => 'Bannir cette adresse'); $page->assign('states', $states); switch (Post::v('action')) { case 'create': if (trim(Post::v('ipN')) != '') { S::assert_xsrf_token(); Xdb::execute('INSERT IGNORE INTO ip_watch (ip, mask, state, detection, last, uid, description) VALUES ({?}, {?}, {?}, CURDATE(), NOW(), {?}, {?})', ip_to_uint(trim(Post::v('ipN'))), ip_to_uint(trim(Post::v('maskN'))), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); } break; case 'edit': S::assert_xsrf_token(); Xdb::execute('UPDATE ip_watch SET state = {?}, last = NOW(), uid = {?}, description = {?}, mask = {?} WHERE ip = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), ip_to_uint(Post::v('maskN')), ip_to_uint(Post::v('ipN'))); break; default: if ($action == 'delete' && !is_null($ip)) { S::assert_xsrf_token(); Xdb::execute('DELETE FROM ip_watch WHERE ip = {?}', ip_to_uint($ip)); } } if ($action != 'create' && $action != 'edit') { $action = 'list'; } $page->assign('action', $action); if ($action == 'list') { $sql = "SELECT w.ip, IF(s.ip IS NULL,\n IF(w.ip = s2.ip, s2.host, s2.forward_host),\n IF(w.ip = s.ip, s.host, s.forward_host)),\n w.mask, w.detection, w.state, a.hruid\n FROM ip_watch AS w\n LEFT JOIN log_sessions AS s ON (s.ip = w.ip)\n LEFT JOIN log_sessions AS s2 ON (s2.forward_ip = w.ip)\n LEFT JOIN accounts AS a ON (a.uid = s.uid)\n GROUP BY w.ip, a.hruid\n ORDER BY w.state, w.ip, a.hruid"; $it = Xdb::iterRow($sql); $table = array(); $props = array(); while (list($ip, $host, $mask, $date, $state, $hruid) = $it->next()) { $ip = uint_to_ip($ip); $mask = uint_to_ip($mask); if (count($props) == 0 || $props['ip'] != $ip) { if (count($props) > 0) { $table[] = $props; } $props = array('ip' => $ip, 'mask' => $mask, 'host' => $host, 'detection' => $date, 'state' => $state, 'users' => array($hruid)); } else { $props['users'][] = $hruid; } } if (count($props) > 0) { $table[] = $props; } $page->assign('table', $table); } elseif ($action == 'edit') { $sql = "SELECT w.detection, w.state, w.last, w.description, w.mask,\n a1.hruid AS edit, a2.hruid AS hruid, s.host\n FROM ip_watch AS w\n LEFT JOIN accounts AS a1 ON (a1.uid = w.uid)\n LEFT JOIN log_sessions AS s ON (w.ip = s.ip)\n LEFT JOIN accounts AS a2 ON (a2.uid = s.uid)\n WHERE w.ip = {?}\n GROUP BY a2.hruid\n ORDER BY a2.hruid"; $it = Xdb::iterRow($sql, ip_to_uint($ip)); $props = array(); while (list($detection, $state, $last, $description, $mask, $edit, $hruid, $host) = $it->next()) { if (count($props) == 0) { $props = array('ip' => $ip, 'mask' => uint_to_ip($mask), 'host' => $host, 'detection' => $detection, 'state' => $state, 'last' => $last, 'description' => $description, 'edit' => $edit, 'users' => array($hruid)); } else { $props['users'][] = $hruid; } } $page->assign('ip', $props); } }
} /* * Check dead emails */ if ($panne_level > 0) { $res = XDB::fetchAllAssoc("SELECT r.redirect, a.hruid\n FROM email_redirect_account AS r\n INNER JOIN accounts AS a ON (a.uid = r.uid)\n WHERE r.broken_level = {?} AND r.flags != 'broken'\n ORDER BY a.hruid", $panne_level); if ($res) { echo "Nouvelles adresses en panne detectees :\n"; foreach ($res as $assoc) { echo '* ' . $assoc['redirect'] . ' pour ' . $assoc['hruid'] . "\n"; } echo "\n\n"; Xdb::execute("UPDATE email_redirect_account\n SET flags = 'broken'\n WHERE broken_level = 3"); } Xdb::execute('UPDATE email_redirect_account SET broken_level = {?} WHERE broken_level > {?}', $panne_level, $panne_level); } /* * Retrieve the users with no active redirection, but still one working * inactive redirection. */ if ($opt_verbose) { $res = XDB::fetchAllAssoc("SELECT a.hruid, r2.redirect\n FROM accounts AS a\n LEFT JOIN email_redirect_account AS r1 ON (a.uid = r1.uid AND r1.flags = 'active')\n INNER JOIN email_redirect_account AS r2 ON (a.uid = r2.uid AND r2.flags = 'inactive'\n AND r2.type != 'imap' AND r2.type != 'homonym')\n WHERE r1.uid IS NULL\n GROUP BY a.uid"); if ($res) { echo "Camarades n'ayant plus d'adresses actives, mais ayant une adresse inactive :\n"; foreach ($res as $user) { echo '* ' . $user['redirect'] . ' pour ' . $user['hruid'] . "\n"; } } echo "\n";