Ejemplo n.º 1
0
function checkmail($mail, $force = 0)
{
    // Retourne 0 si tout va bien, sinon retourne un code erreur...
    // 6 si le mail contient aucun ou plus d'un @
    // 1 2 3 ou 4 si le domaine est incorrect.
    // 5 s'il y a caractères interdits dans la partie gauche du @
    if ($force == 0 && trim($mail) == "") {
        return 0;
    }
    $t = explode("@", $mail);
    if (count($t) != 2) {
        return 6;
    }
    $c = checkfqdn($t[1]);
    if ($c) {
        return $c;
    }
    // Verification de la partie gauche :
    if (!checkloginmail($t[0])) {
        return 5;
    }
    return 0;
}
Ejemplo n.º 2
0
 /**
  * Add a user to a protected folder
  * 
  * @global    m_err   $err
  * @global    m_bro   $bro
  * @global    m_admin $admin
  * @param     string  $user
  * @param     string  $password
  * @param     string  $dir
  * @param     string  $password   The password to add (cleartext)
  * @param     string  $dir        The folder we add it to (relative to user root).
  * @return    boolean             TRUE if the user has been added, or FALSE if an error occurred
  */
 function add_user($user, $password, $dir)
 {
     global $err, $bro, $admin;
     $err->log("hta", "add_user", $user . "/" . $dir);
     if (empty($user)) {
         $err->raise('hta', _("Please enter a user"));
         return false;
     }
     if (empty($password)) {
         $err->raise('hta', _("Please enter a password"));
         return false;
     }
     $absolute = $bro->convertabsolute($dir, 0);
     if (!file_exists($absolute)) {
         $err->raise("hta", printf("The folder '%s' does not exist", $dir));
         return false;
     }
     // @todo delete cf!. functions.php checkloginemail definition
     if (checkloginmail($user)) {
         // Check this password against the password policy using common API :
         if (is_callable(array($admin, "checkPolicy"))) {
             if (!$admin->checkPolicy("hta", $user, $password)) {
                 return false;
                 // The error has been raised by checkPolicy()
             }
         }
         $file = @fopen("{$absolute}/.htpasswd", "a+");
         if (!$file) {
             $err->raise("hta", _("File already exist"));
             return false;
         }
         fseek($file, 0);
         while (!feof($file)) {
             $s = fgets($file, 1024);
             $t = explode(":", $s);
             if ($t[0] == $user) {
                 $err->raise("hta", _("The user '%s' already exist for this folder"), $user);
                 return false;
             }
         }
         fseek($file, SEEK_END);
         if (empty($t[1]) || substr($t[1], -1) != "\n") {
             fwrite($file, "\n");
         }
         fwrite($file, "{$user}:" . _md5cr($password) . "\n");
         fclose($file);
         return true;
     } else {
         $err->raise("hta", _("Please enter a valid username"));
         return false;
     }
 }