X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fxorg.misc.inc.php;h=c5e4e1d2bf378fd77256492cd8623f8457a3f451;hb=92630203925015ac6f70faaf4aacd05d26e5924b;hp=ed8bff1250762ae42c56bd41f5d76692b9506de4;hpb=5480a216efce111c1afa6ec3508bda292732d09e;p=platal.git diff --git a/include/xorg.misc.inc.php b/include/xorg.misc.inc.php index ed8bff1..c5e4e1d 100644 --- a/include/xorg.misc.inc.php +++ b/include/xorg.misc.inc.php @@ -19,7 +19,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -function quoted_printable_encode($input, $line_max = 76) { +function quoted_printable_encode($input, $line_max = 76) +{ $lines = preg_split("/(?:\r\n|\r|\n)/", $input); $eol = "\n"; $linebreak = "=0D=0A=\n "; @@ -27,81 +28,197 @@ function quoted_printable_encode($input, $line_max = 76) { $output = ""; foreach ($lines as $j => $line) { - $linlen = strlen($line); - $newline = ""; - for($i = 0; $i < $linlen; $i++) { - $c = $line{$i}; - $dec = ord($c); - if ( ($dec == 32) && ($i == ($linlen - 1)) ) { - // convert space at eol only - $c = "=20"; - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { - // always encode "\t", which is *not* required - $c = $escape.strtoupper(sprintf("%02x",$dec)); - } - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted - $output .= $newline.$escape.$eol; - $newline = " "; - } - $newline .= $c; - } // end of for - $output .= $newline; - if ($j 126) ) { + // always encode "\t", which is *not* required + $c = $escape.strtoupper(sprintf("%02x",$dec)); + } + if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted + $output .= $newline.$escape.$eol; + $newline = " "; + } + $newline .= $c; + } // end of for + $output .= $newline; + if ($j 'e', 'è' => 'e', 'ë' => 'e', 'ê' => 'e', + 'á' => 'a', 'à' => 'a', 'ä' => 'a', 'â' => 'a', 'Ã¥' => 'a', 'ã' => 'a', + 'ï' => 'i', 'î' => 'i', 'ì' => 'i', 'í' => 'i', + 'ô' => 'o', 'ö' => 'o', 'ò' => 'o', 'ó' => 'o', 'õ' => 'o', 'ø' => 'o', + 'ú' => 'u', 'ù' => 'u', 'û' => 'u', 'ü' => 'u', + 'ç' => 'c', 'ñ' => 'n'); +$uc_convert = array('É' => 'E', 'È' => 'E', 'Ë' => 'E', 'Ê' => 'E', + 'Á' => 'A', 'À' => 'A', 'Ä' => 'A', 'Â' => 'A', 'Å' => 'A', 'Ã' => 'A', + 'Ï' => 'I', 'Î' => 'I', 'Ì' => 'I', 'Í' => 'I', + 'Ô' => 'O', 'Ö' => 'O', 'Ò' => 'O', 'Ó' => 'O', 'Õ' => 'O', 'Ø' => 'O', + 'Ú' => 'U', 'Ù' => 'U', 'Û' => 'U', 'Ü' => 'U', + 'Ç' => 'C', 'Ñ' => 'N'); + +function replace_accent($string) +{ + global $lc_convert, $uc_convert; + $string = strtr($string, $lc_convert); + return strtr($string, $uc_convert); +} + +/** creates a username from a first and last name + * + * @param $prenom the firstname + * @param $nom the last name + * + * return STRING the corresponding username + */ +function make_username($prenom,$nom) +{ + /* on traite le prenom */ + $prenomUS=replace_accent(trim($prenom)); + $prenomUS=stripslashes($prenomUS); + + /* on traite le nom */ + $nomUS=replace_accent(trim($nom)); + $nomUS=stripslashes($nomUS); + + // calcul du login + $username = strtolower($prenomUS.".".$nomUS); + $username = str_replace(" ","-",$username); + $username = str_replace("'","",$username); + return $username; } -/* Un soundex en français posté par Frédéric Bouchery - Voici une adaptation en PHP de la fonction soundex2 francisée de Frédéric BROUARD (http://sqlpro.developpez.com/Soundex/). - C'est une bonne démonstration de la force des expressions régulières compatible Perl. - trouvé sur http://expreg.com/voirsource.php?id=40&type=Chaines%20de%20caract%E8res */ +/* Un soundex en français posté par Frédéric Bouchery + Voici une adaptation en PHP de la fonction soundex2 francisée de Frédéric BROUARD (http://sqlpro.developpez.com/Soundex/). + C'est une bonne démonstration de la force des expressions régulières compatible Perl. +trouvé sur http://expreg.com/voirsource.php?id=40&type=Chaines%20de%20caract%E8res */ function soundex_fr($sIn) -{ - // Si il n'y a pas de mot, on sort immédiatement +{ + static $convVIn, $convVOut, $convGuIn, $convGuOut, $accents; + if (!isset($convGuIn)) { + global $uc_convert, $lc_convert; + $convGuIn = array( 'GUI', 'GUE', 'GA', 'GO', 'GU', 'SC', 'CA', 'CO', 'CU', 'QU', 'Q', 'CC', 'CK', 'G', 'ST', 'PH'); + $convGuOut = array( 'KI', 'KE', 'KA', 'KO', 'KU', 'SK', 'KA', 'KO', 'KU', 'K', 'K', 'K', 'K', 'J', 'T', 'F'); + $convVIn = array( '/E?(AU)/', '/([EA])?[UI]([NM])([^EAIOUY]|$)/', '/[AE]O?[NM]([^AEIOUY]|$)/', + '/[EA][IY]([NM]?[^NM]|$)/', '/(^|[^OEUIA])(OEU|OE|EU)([^OEUIA]|$)/', '/OI/', + '/(ILLE?|I)/', '/O(U|W)/', '/O[NM]($|[^EAOUIY])/', '/(SC|S|C)H/', + '/([^AEIOUY1])[^AEIOUYLKTP]([UAO])([^AEIOUY])/', '/([^AEIOUY]|^)([AUO])[^AEIOUYLKTP]([^AEIOUY1])/', '/^KN/', + '/^PF/', '/C([^AEIOUY]|$)/', + '/C/', '/Z$/', '/(?numRows()) { + $_SESSION['check_ip'] = $res->fetchOneCell(); + } else { + $_SESSION['check_ip'] = 'safe'; + } + } $test = array(); switch ($level) { - case 'unsafe': $test[] = "state = 'unsafe'"; - case 'dangerous': $test[] = "state = 'dangerous'"; - case 'ban': $test[] = "state = 'ban'"; break; + case 'unsafe': $test[] = 'unsafe'; + case 'dangerous': $test[] = 'dangerous'; + case 'ban': $test[] = 'ban'; break; default: return false; } - $res = XDB::query("SELECT state - FROM ip_watch - WHERE ip = {?} AND (" . implode(' OR ', $test) . ')', - $_SERVER['REMOTE_ADDR']); - return $res->numRows(); + return in_array($_SESSION['check_ip'], $test); +} + +function check_email($email, $message) +{ + $res = XDB::query("SELECT state, description + FROM emails_watch + WHERE state != 'safe' AND email = {?}", $email); + if ($res->numRows()) { + send_warning_mail($message); + return true; + } + return false; +} + +function check_account() +{ + return S::v('watch'); +} + +function check_redirect($red = null) +{ + require_once 'emails.inc.php'; + if (is_null($red)) { + $red = new Redirect(S::v('uid')); + } + $_SESSION['no_redirect'] = !$red->other_active(''); + $_SESSION['mx_failures'] = $red->get_broken_mx(); } function send_warning_mail($title) { $mailer = new PlMailer(); $mailer->setFrom("webmaster@polytechnique.org"); - $mailer->addTo("florent.bruneau@polytechnique.org"); - $mailer->setSubject($title); + $mailer->addTo("hotliners@staff.polytechnique.org"); + $mailer->setSubject("[Plat/al Security Alert] $title"); $mailer->setTxtBody("Identifiants de session :\n" . var_export($_SESSION, true) . "\n\n" - ."Identifiants de connexion :\n" . var_export($_SERVER, true)); + ."Identifiants de connexion :\n" . var_export($_SERVER, true)); $mailer->send(); } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>