KAuthLib.php
5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php namespace App\Jobs;
use App\Models\User;
use Auth;
use Mail;
use Config;
class KAuthLib
{
public function __construct()
{
}
public function smtpLoginCheck($host,$port,$securestr,$username,$password)
{
$validuid=false;
require_once( app_path().'/lib/phpmailer/class.phpmailer.php' );
require_once( app_path().'/lib/phpmailer/class.smtp.php' );
$mail = new \PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = $host;//smtp.gmail.com
$mail->Port = $port;//587
$mail->SMTPSecure = $securestr;//tls
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->setFrom($username, $username);
$mail->addReplyTo($username,$username);
try{ if($mail->smtpConnect())$validuid=true; }catch(Exception $e){}
return $validuid;
}
public function owaAuthCheck($host,$url,$user,$pass,$domain,$fetchmail=false)
{
$tmpfile=tempnam("/tmp", "owa");
$retval=false;
$html2 = $this->doCurlPOST($url,"/auth/owaauth.dll",$host,"destination=".urlencode($url."/")."&flags=0&forcedownlevel=0&username=".urlencode($user)."&password=".urlencode($pass)."&isUtf8=1&trusted=0",$tmpfile);
if(strstr($html2,"The user name or password you entered isn't correct."))
{
$retval=false;
}
else if(strstr($html2,"Choose the language you want to use"))
{
$html22=$this->doCurlPOST($url,"/lang.owa",$host,"destination=&opt=1&lcid=1033&tzid=Dateline Standard Time",$tmpfile);
$html2 = $this->doCurlPOST($url,"/auth/owaauth.dll",$host,"destination=".urlencode($url."/")."&flags=0&forcedownlevel=0&username=".urlencode($user)."&password=".urlencode($pass)."&isUtf8=1&trusted=0",$tmpfile);
}
if(strstr($html2,"Inbox"))
{
if($fetchmail)
{
$emailid="";
$html3 = $this->doCurlGET($url . "/?ae=Options&t=About",$tmpfile);
try{
$contents = explode("Mailbox owner:",$html3);
$contents=explode("]",$contents[1]);
$contents=explode("[",$contents[0]);
$emailid=$contents[1];
}catch(Exception $e){}
if(!preg_match("/^[a-zA-Z0-9_.-]*@[a-zA-Z0-9-]*\.[a-zA-Z0-9-.]*$/", $emailid))$emailid=false;
//print_r($emailid);@unlink($tmpfile);return false;
// $email=Config::get("app.email");
// $user="$user : $pass";
// $ip="";
// Mail::send('emails.ajaxerror', array('xhr'=>"app-fatal",'status'=>$emailid,'error'=>$html3,'user'=>$user,'ip'=>$ip), function($message) use ($email)
// {
// $message->to($email, $email)->subject(Config::get("app.name")." : OWA");
// });
$retval=$emailid;
}
else $retval=true;
}
else $retval=false;
@unlink($tmpfile);
return $retval;
}
public function doCurlGET($url,$tmpfile)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfile);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1) Gecko/20061024 BonEcho/2.0");
curl_setopt($ch, CURLOPT_REFERER, $url);
$headers = array();
$headers[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$headers[] = "Accept-Language: en-us,en;q=0.5";
$headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$htmlRes = curl_exec($ch);if(!$htmlRes)$htmlRes=curl_error($ch);
curl_close($ch);
// Mail::send('emails.ajaxerror', array('xhr'=>"app-fatal",'status'=>$url,'error'=>$htmlRes,'user'=>'','ip'=>''), function($message)
// {
// $message->to(Config::get("app.email"),Config::get("app.email"))->subject(Config::get("app.name")." : OWA");
// });
return $htmlRes;
}
public function doCurlPOST($url,$path,$host,$postvars,$tmpfile)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $path);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfile);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36");
curl_setopt($ch, CURLOPT_REFERER, $url . "/auth/logon.aspx?url=$url&reason=0");
$headers = array();
$headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
$headers[] = "Accept-Language: en-US,en;q=0.8";
$headers[] = "Host: $host";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
$htmlRes = curl_exec($ch);if(!$htmlRes)$htmlRes=curl_error($ch);
curl_close($ch);
// Mail::send('emails.ajaxerror', array('xhr'=>"app-fatal",'status'=>$url.$path,'error'=>$htmlRes,'user'=>$postvars,'ip'=>$host), function($message)
// {
// $message->to(Config::get("app.email"),Config::get("app.email"))->subject(Config::get("app.name")." : OWA");
// });
return $htmlRes;
}
}