Beispiel #1
0
/**
 * Recursively create directories
 *
 * @param array $pTarget target directory
 * @param float $pPerms octal permissions
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function mkdir_p($pTarget, $pPerms = 0755)
{
    // clean up input
    $pTarget = str_replace("//", "/", trim($pTarget));
    if (empty($pTarget) || $pTarget == ';' || $pTarget == "/") {
        return FALSE;
    }
    if (ini_get('safe_mode')) {
        $pTarget = preg_replace('/^\\/tmp/', $_SERVER['DOCUMENT_ROOT'] . '/temp', $pTarget);
    }
    if (file_exists($pTarget) || is_dir($pTarget)) {
        return FALSE;
    }
    if (!is_windows()) {
        if (substr($pTarget, 0, 1) != '/') {
            $pTarget = "/{$pTarget}";
        }
        if (preg_match('#\\.\\.#', $pTarget)) {
            bitdebug("mkdir_p() - We don't allow '..' in path for security reasons: {$pTarget}");
            return FALSE;
        }
    }
    $oldu = umask(0);
    // make use of PHP5 recursive mkdir feature
    if (version_compare(phpversion(), "5.0.0", ">=")) {
        @mkdir($pTarget, $pPerms, TRUE);
        umask($oldu);
        return TRUE;
    } else {
        if (@mkdir($pTarget, $pPerms)) {
            bitdebug("mkdir_p() - creating {$pTarget}");
            umask($oldu);
            return TRUE;
        } else {
            umask($oldu);
            $parent = substr($pTarget, 0, strrpos($pTarget, '/'));
            // recursively create parents
            if (mkdir_p($parent, $pPerms)) {
                // make the actual target!
                if (@mkdir($pTarget, $pPerms)) {
                    return TRUE;
                } elseif (!is_dir($pTarget)) {
                    error_log("mkdir() - could not create {$pTarget}");
                }
            }
        }
    }
}
Beispiel #2
0
 /**
  * verifyMX
  *
  * @param array $pEmail
  * @param array $pValidate
  * @access public
  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  */
 function verifyMX($pEmail, &$pErrors)
 {
     global $gBitSystem, $gDebug;
     $HTTP_HOST = $_SERVER['SERVER_NAME'];
     $ret = false;
     if (validate_email_syntax($pEmail)) {
         list($Username, $domain) = preg_split("/@/", $pEmail);
         //checkdnsrr will check to see if there are any MX records for the domain
         if (!is_windows() and checkdnsrr($domain, "MX")) {
             bitdebug("Confirmation : MX record for {$domain} exists.");
             $MXWeights = array();
             getmxrr($domain, $MXHost, $MXWeights);
             $hosts = array();
             //create an array that combines the MXWeights with their associated hosts
             for ($i = 0; $i < count($MXHost); $i++) {
                 $hosts[$MXHost[$i]] = $MXWeights[$i];
             }
             //sorts the hosts by weight
             asort($hosts);
             if (!empty($hosts)) {
                 //hosts shouldn't be empty here, since we passed the checkdnsrr check, but the server COULD have died between the first and second check.
                 $Connect = '';
                 foreach ($hosts as $host => $priority) {
                     $Connect = @fsockopen($host, 25, $errNo, $errStr, 10);
                     // 10 second timeout to open each MX server, seems adequate to me, increase as necessary
                     // Success in fsockopen
                     if ($Connect) {
                         bitdebug("Connection succeeded to {$host} SMTP.");
                         stream_set_timeout($Connect, 30);
                         $out = $this->getSmtpResponse($Connect);
                         // Judgment is that a service preparing to begin a transaction will send a 220 string after a succesful handshake
                         if (preg_match("/^220/", $out)) {
                             // Inform client's reaching to server who connect.
                             if ($gBitSystem->hasValidSenderEmail()) {
                                 $senderEmail = $gBitSystem->getConfig('site_sender_email');
                                 fputs($Connect, "HELO {$HTTP_HOST}\r\n");
                                 bitdebug("Run : HELO {$HTTP_HOST}");
                                 // Receive server's answering cord.
                                 $out = $this->getSmtpResponse($Connect);
                                 // Inform sender's address to server.
                                 fputs($Connect, "MAIL FROM: <{$senderEmail}>\r\n");
                                 bitdebug("Run : MAIL FROM: &lt;{$senderEmail}&gt;");
                                 // Receive server's answering cord.
                                 $from = $this->getSmtpResponse($Connect);
                                 // Inform listener's address to server.
                                 fputs($Connect, "RCPT TO: <{$pEmail}>\r\n");
                                 bitdebug("Run : RCPT TO: &lt;{$pEmail}&gt;");
                                 // Receive server's answering cord.
                                 $to = $this->getSmtpResponse($Connect);
                                 // Finish connection.
                                 fputs($Connect, "QUIT\r\n");
                                 bitdebug("Run : QUIT");
                                 fclose($Connect);
                                 //Checks if we received a 250 OK from the server. If we did not, the server is telling us that this address is not a valid mailbox.
                                 if (!preg_match("/^250/", $from) || !preg_match("/^250/", $to) && !preg_match("/Please use your ISP relay/", $to)) {
                                     $pErrors['email'] = $pEmail . " is not recognized by the mail server. Try double checking the address for typos.";
                                     bit_error_log("INVALID EMAIL : " . $pEmail . " SMTP FROM : " . $from . " SMTP TO: " . $to);
                                     $ret = false;
                                     break;
                                     //break out of foreach and fall through to the end of function
                                 } else {
                                     $ret = true;
                                     //address has been verified by the server, no more checking necessary
                                     break;
                                 }
                             }
                         } elseif (preg_match("/^420/", $out)) {
                             // Yahoo has a bad, bad habit of issuing 420's
                             bit_error_log("UNKNOWN EMAIL : " . $pEmail . " SMTP response: " . $out);
                             $ret = true;
                         } else {
                             $pErrors['email'] = 'Connection rejected by MX server';
                             bit_error_log("INVALID EMAIL : " . $pEmail . " SMTP response: " . $out);
                             $ret = false;
                         }
                     } else {
                         //fsockopen failed
                         if (!$gBitSystem->getConfig('users_validate_email_role')) {
                             //will ONLY stuff mErrors if you have not set a default role for verifiable emails, otherwise this is not a game breaking case
                             $pErrors['email'] = "One or more mail servers not responding";
                         }
                         $ret = -1;
                         //-1 implies ambiguity, MX servers found, but unable to be reached.
                     }
                 }
             } else {
                 $pErrors['email'] = "Mail server not found";
                 $ret = false;
             }
         } else {
             $pErrors['email'] = "Mail server not found";
             $ret = false;
         }
     } else {
         $pErrors['email'] = "Invalid email syntax";
         $ret = false;
     }
     return $ret;
 }