Beispiel #1
0
 function auth($conn = null, $user = null, $pass = null, $type = null, $debug = null)
 {
     if (!FUNC4::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     global $_RESULT;
     $_RESULT = $err = array();
     if (!is_resource($conn)) {
         $err[] = 'invalid resource connection';
     }
     if (!is_string($user)) {
         $err[] = 'invalid username type';
     } else {
         if (($user = FUNC4::str_clear($user)) == '') {
             $err[] = 'invalid username value';
         }
     }
     if (!is_string($pass)) {
         $err[] = 'invalid password type';
     } else {
         if (($pass = FUNC4::str_clear($pass)) == '') {
             $err[] = 'invalid password value';
         }
     }
     if ($type == null) {
         $type = 'login';
     }
     if (!is_string($type)) {
         $err[] = 'invalid authentication type';
     } else {
         $type = strtolower(trim($type));
         if (!($type == 'login' || $type == 'plain' || $type == 'cram-md5')) {
             $err[] = 'invalid authentication type value';
         }
     }
     if (count($err) > 0) {
         FUNC4::trace($debug, implode(', ', $err));
     } else {
         $ret = false;
         $_smtp = new SMTP4();
         if ($type == 'login') {
             if (!fwrite($conn, 'AUTH LOGIN' . $_smtp->CRLF)) {
                 $_RESULT[310] = 'can not write';
             } else {
                 if (!SMTP4::_cres($conn, $resp, 334, null, $debug)) {
                     $_RESULT[311] = $resp;
                 } else {
                     if (!fwrite($conn, base64_encode($user) . $_smtp->CRLF)) {
                         $_RESULT[312] = 'can not write';
                     } else {
                         if (!SMTP4::_cres($conn, $resp, 334, null, $debug)) {
                             $_RESULT[313] = $resp;
                         } else {
                             if (!fwrite($conn, base64_encode($pass) . $_smtp->CRLF)) {
                                 $_RESULT[314] = 'can not write';
                             } else {
                                 if (!SMTP4::_cres($conn, $resp, 235, null, $debug)) {
                                     $_RESULT[315] = $resp;
                                 } else {
                                     $_RESULT[316] = $resp;
                                     $ret = true;
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($type == 'plain') {
                 if (!fwrite($conn, 'AUTH PLAIN ' . base64_encode($user . chr(0) . $user . chr(0) . $pass) . $_smtp->CRLF)) {
                     $_RESULT[317] = 'can not write';
                 } else {
                     if (!SMTP4::_cres($conn, $resp, 235, null, $debug)) {
                         $_RESULT[318] = $resp;
                     } else {
                         $_RESULT[319] = $resp;
                         $ret = true;
                     }
                 }
             } else {
                 if ($type == 'cram-md5') {
                     if (!fwrite($conn, 'AUTH CRAM-MD5' . $_smtp->CRLF)) {
                         $_RESULT[200] = 'can not write';
                     } else {
                         if (!SMTP4::_cres($conn, $resp, 334, null, $debug)) {
                             $_RESULT[201] = $resp;
                         } else {
                             if (strlen($pass) > 64) {
                                 $pass = pack('H32', md5($pass));
                             }
                             if (strlen($pass) < 64) {
                                 $pass = str_pad($pass, 64, chr(0));
                             }
                             $pad1 = substr($pass, 0, 64) ^ str_repeat(chr(0x36), 64);
                             $pad2 = substr($pass, 0, 64) ^ str_repeat(chr(0x5c), 64);
                             $chal = substr($resp[count($resp) - 1], 4);
                             $innr = pack('H32', md5($pad1 . base64_decode($chal)));
                             if (!fwrite($conn, base64_encode($user . ' ' . md5($pad2 . $innr)) . $_smtp->CRLF)) {
                                 $_RESULT[202] = 'can not write';
                             } else {
                                 if (!SMTP4::_cres($conn, $resp, 235, null, $debug)) {
                                     $_RESULT[203] = $resp;
                                 } else {
                                     $_RESULT[204] = $resp;
                                     $ret = true;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         return $ret;
     }
 }
Beispiel #2
0
 function mime_type($name = null, $debug = null)
 {
     if (!FUNC4::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     if (!is_string($name)) {
         FUNC4::trace($debug, 'invalid filename type');
     } else {
         $name = FUNC4::str_clear($name);
         $name = trim($name);
         if ($name == '') {
             return FUNC4::trace($debug, 'invalid filename value', 1);
         } else {
             $ret = 'application/octet-stream';
             $arr = array('z' => 'application/x-compress', 'xls' => 'application/x-excel', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', 'cgi' => 'application/x-httpd-cgi', 'php' => 'application/x-httpd-php', 'js' => 'application/x-javascript', 'swf' => 'application/x-shockwave-flash', 'tar' => 'application/x-tar', 'tgz' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'src' => 'application/x-wais-source', 'zip' => 'application/zip', 'kar' => 'audio/midi', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'mpga' => 'audio/mpeg', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'wav' => 'audio/x-wav', 'bmp' => 'image/bmp', 'fif' => 'image/fif', 'gif' => 'image/gif', 'ief' => 'image/ief', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'css' => 'text/css', 'htm' => 'text/html', 'html' => 'text/html', 'txt' => 'text/plain', 'rtx' => 'text/richtext', 'vcf' => 'text/x-vcard', 'xml' => 'text/xml', 'xsl' => 'text/xsl', 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mov' => 'video/quicktime', 'qt' => 'video/quicktime', 'asf' => 'video/x-ms-asf', 'asx' => 'video/x-ms-asf', 'avi' => 'video/x-msvideo', 'vrml' => 'x-world/x-vrml', 'wrl' => 'x-world/x-vrml');
             if (count($exp = explode('.', $name)) >= 2) {
                 $ext = strtolower($exp[count($exp) - 1]);
                 if (trim($exp[count($exp) - 2]) != '' && isset($arr[$ext])) {
                     $ret = $arr[$ext];
                 }
             }
             return $ret;
         }
     }
 }
Beispiel #3
0
 function auth($conn = null, $user = null, $pass = null, $debug = null)
 {
     if (!FUNC4::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     global $_RESULT;
     $_RESULT = array();
     $err = array();
     if (!is_resource($conn)) {
         $err[] = 'invalid resource connection';
     }
     if (!is_string($user)) {
         $err[] = 'invalid username type';
     } else {
         if (($user = FUNC4::str_clear($user)) == '') {
             $err[] = 'invalid username value';
         }
     }
     if (!is_string($pass)) {
         $err[] = 'invalid password type';
     } else {
         if (($pass = FUNC4::str_clear($pass)) == '') {
             $err[] = 'invalid password value';
         }
     }
     if (count($err) > 0) {
         FUNC4::trace($debug, implode(', ', $err));
     } else {
         $_pop3 = new POP34();
         $ret = false;
         if (!fwrite($conn, 'USER ' . $user . $_pop3->CRLF)) {
             $_RESULT[404] = 'can not write';
         } else {
             if (!POP34::_ok($conn, $resp, $debug)) {
                 $_RESULT[405] = $resp;
             } else {
                 if (!fwrite($conn, 'PASS ' . $pass . $_pop3->CRLF)) {
                     $_RESULT[405] = 'can not write';
                 } else {
                     if (!POP34::_ok($conn, $resp, $debug)) {
                         $_RESULT[406] = $resp;
                     } else {
                         $_RESULT[407] = $resp;
                         $ret = true;
                     }
                 }
             }
         }
         return $ret;
     }
 }
Beispiel #4
0
 function split_header($str = null, $debug = null)
 {
     if (!FUNC4::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     if (!(is_string($str) && $str != '')) {
         FUNC4::trace($debug, 'invalid header value');
     } else {
         $str = str_replace(array(";\r\n\t", "; \r\n\t", ";\r\n ", "; \r\n "), '; ', $str);
         $str = str_replace(array(";\n\t", "; \n\t", ";\n ", "; \n "), '; ', $str);
         $str = str_replace(array("\r\n\t", "\r\n "), '', $str);
         $str = str_replace(array("\n\t", "\n "), '', $str);
         $arr = array();
         foreach (explode("\n", $str) as $line) {
             $line = trim(FUNC4::str_clear($line));
             if (trim($line) != '') {
                 if (count($exp1 = explode(':', $line, 2)) == 2) {
                     $name = trim($exp1[0]);
                     $val1 = trim($exp1[1]);
                     if (strlen($name) > 1 && $val1 != '') {
                         $name = ucfirst($name);
                         $hadd = array();
                         if (substr(strtolower($name), 0, 8) == 'content-') {
                             $exp2 = explode('; ', $val1);
                             $cnt2 = count($exp2);
                             if ($cnt2 > 1) {
                                 for ($i = 1; $i < $cnt2; $i++) {
                                     if (count($exp3 = explode('=', $exp2[$i], 2)) == 2) {
                                         $hset = trim($exp3[0]);
                                         $hval = trim($exp3[1], ' "');
                                         if ($hset != '' && $hval != '') {
                                             $hadd[strtolower($hset)] = $hval;
                                         }
                                     }
                                 }
                             }
                         }
                         $arr[] = count($hadd) > 0 ? array($name => trim($exp2[0]), '+' => $hadd) : array($name => $val1);
                     }
                 }
             }
         }
         if (count($arr) > 0) {
             return $arr;
         } else {
             FUNC4::trace($debug, 'invalid header value');
         }
     }
 }
Beispiel #5
0
 function attach($content = null, $type = null, $name = null, $charset = null, $encoding = null, $disposition = null, $id = null, $debug = null)
 {
     if (!FUNC4::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     $err = array();
     if (!(is_string($content) && $content != '')) {
         $err[] = 'invalid content type';
     }
     if ($type != null) {
         if (!is_string($type)) {
             $err[] = 'invalid type value';
         } else {
             $type = trim(FUNC4::str_clear($type));
             if (strlen($type) < 4) {
                 $err[] = 'invalid type value';
             }
         }
     }
     if ($name != null) {
         if (!is_string($name)) {
             $err[] = 'invalid name type';
         } else {
             $name = trim(FUNC4::str_clear($name));
             if ($name == '') {
                 $err[] = 'invalid name value';
             }
         }
     }
     if ($charset != null) {
         if (!is_string($charset)) {
             $err[] = 'invalid charset type';
         } else {
             if (!(strlen($charset) >= 2 && FUNC4::is_alpha($charset, true, '-'))) {
                 $err[] = 'invalid charset value';
             }
         }
     }
     if ($encoding == null) {
         $encoding = 'base64';
     } else {
         if (is_string($encoding)) {
             $encoding = strtolower($encoding);
             if (!isset($this->_mime->mencarr[$encoding])) {
                 $err[] = 'invalid encoding value';
             }
         } else {
             $err[] = 'invalid encoding type';
         }
     }
     if ($disposition == null) {
         $disposition = 'attachment';
     } else {
         if (is_string($disposition)) {
             $disposition = strtolower(FUNC4::str_clear($disposition));
             if (!($disposition == 'inline' || $disposition == 'attachment')) {
                 $err[] = 'invalid disposition value';
             }
         } else {
             $err[] = 'invalid disposition type';
         }
     }
     if ($id != null) {
         if (!is_string($id)) {
             $err[] = 'invalid id type';
         } else {
             $id = FUNC4::str_clear($id, array(' '));
             if ($id == '') {
                 $err[] = 'invalid id value';
             }
         }
     }
     if (count($err) > 0) {
         FUNC4::trace($debug, implode(', ', $err));
     } else {
         $this->Attach[] = array('content' => $content, 'type' => $type, 'name' => $name, 'charset' => $charset, 'encoding' => $encoding, 'disposition' => $disposition, 'id' => $id);
         return $this->_result(array(0 => 'add attachment'), true);
     }
 }