Beispiel #1
0
 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);
     }
 }
Beispiel #2
0
$opts = Console_GetOpt::getopt($argv, 'v');
$opt_verbose = false;
if (PEAR::isError($opts)) {
    echo $opts->getMessage();
} else {
    $opts = $opts[0];
    foreach ($opts as $opt) {
        if ($opt[0] == 'v') {
            $opt_verbose = true;
        }
    }
}
/*
 * Check duplicated addresses
 */
$it = Xdb::iterRow("SELECT  s1.email, s2.email, r1.redirect\n                      FROM  email_redirect_account AS r1\n                INNER JOIN  email_redirect_account AS r2 ON (r1.redirect = r2.redirect AND r1.uid != r2.uid)\n                INNER JOIN  email_source_account   AS s1 ON (s1.uid = r1.uid AND s1.type = 'forlife')\n                INNER JOIN  email_source_account   AS s2 ON (s2.uid = r2.uid AND s2.type = 'forlife')\n                 LEFT JOIN  email_watch            AS w  ON (r1.redirect = w.email)\n                     WHERE  w.email IS NULL\n                  GROUP BY  r1.redirect\n                  ORDER BY  r1.redirect, s1.email");
$insert = array();
$conflits = array();
while (list($alias1, $alias2, $mail) = $it->next()) {
    $insert[] = "('{$mail}', 'pending', CURDATE(), NOW())";
    $conflits[] = "* {$mail} sur {$alias1} et {$alias2}";
}
if (count($conflits) > 0) {
    echo "Nouvelles adresses en doublon détectées :\n" . join("\n", $conflits) . "\n\nVous pouvez entrer les informations collectées à ce sujet sur la page :\n" . "https://www.polytechnique.org/admin/emails/duplicated";
    echo "\n\n";
    $sql = "INSERT IGNORE INTO  email_watch (email, state, detection, last)\n                        VALUES  " . join(", ", $insert);
    XDB::execute($sql);
    if (XDB::errno() != 0) {
        echo 'Error : ' . XDB::error() . "\n{$sql}";
    }
}