trID = 1; if ($this->fp = @fsockopen($this->server, $this->port, $errno, $errstr, 2)) { $this->_put("VER $this->trID MSNP11 CVR0\r\n"); while (! feof($this->fp)) { $data = $this->_get(); switch ($code = substr($data, 0, 3)) { default: echo $this->_get_error($code); return false; break; case 'VER': $this->_put("CVR $this->trID 0x0409 winnt 5.1 i386 MSNMSGR 7.0.0777 msmsgs $passport\r\n"); break; case 'CVR': $this->_put("USR $this->trID TWN I $passport\r\n"); break; case 'XFR': list(, , , $ip) = explode (' ', $data); list($ip, $port) = explode (':', $ip); if ($this->fp = @fsockopen($ip, $port, $errno, $errstr, 2)) { $this->trID = 1; $this->_put("VER $this->trID MSNP11 CVR0\r\n"); } else { if (! empty($this->debug)) echo 'Unable to connect to msn server (transfer)'; return false; } break; case 'USR': if (isset($this->authed)) { return true; } else { $this->passport = $passport; $this->password = urlencode($password); list(,,,, $code) = explode(' ', trim($data)); if ($auth = $this->_ssl_auth($code)) { $this->_put("USR $this->trID TWN S $auth\r\n"); $this->authed = 1; } else { if (! empty($this->debug)) echo 'auth failed'; return false; } } break; } } } else { if (! empty($this->debug)) echo 'Unable to connect to msn server'; return false; } } function rx_data() { $count_lst = 0; $contacts = -1; $this->_put("SYN $this->trID 0 0\r\n"); while (! feof($this->fp)) { $data = $this->_get(); if ($data) { $linedata = explode(" ",$data); //echo $data.'
'; switch($code = substr($data, 0, 3)) { default: // uncommenting this line here would probably give a load of "error code not found" messages. //echo $this->_get_error($code); break; case 'CHL': $bits = explode (' ', trim($data)); $clsHashCreator = new clsCHLFactory; $return = $clsHashCreator->generateCHLHash($bits[2]); $this->_put("QRY $this->trID PROD0090YUAUV{2B 32\r\n$return"); break; case 'RNG': // someone's trying to talk to us list(, $sid, $server, , $as, $email, $name) = explode(' ', $data); list($sb_ip, $sb_port) = explode(':', $server); $sbsess = new switchboard; if ($sbsess->auth($sb_ip, $sb_port, $this->passport, $sid, $as)) { // sb session opened // recieve users message if ($msg = $sbsess->rx_im()) { // send the message straight back! $sbsess->tx_im($this->fp, $msg, $this->passport, $email); // close IM sessions $sbsess->im_close(); } else { echo 'No message was received from user.'; } } else { echo 'Unable to authenticate with switchboard.'; } break; case 'LST': preg_match_all('/N=([^ ]*)|F=([^ ]*)|C=([^ ]*)/',$data,$matches); // data: Passport,Nickname,Status // data: $matches[1][0],$matches[2][1],"" $count_lst++; if ($count_lst == $contacts) { $this->_put("CHG $this->trID BSY 0\r\n"); $count_lst = 0; } break; case 'ILN': // data: $linedata[3],$linedata[4],$linedata[2] break; case 'NLN': // data: $linedata[2],$linedata[3],$linedata[1] break; case 'FLN': // data: substr($linedata[1],0,strlen($linedata[1])-2),"","FLN" break; case 'UBX': $read_data = $this->_getlen(intval($linedata[2])+1); preg_match_all('/(.*)<\/PSM>|(.*)<\/CurrentMedia>/',$read_data,$matches); // data: Passport,PersonalMessage,CurrentMedia // data: $linedata[1],$matches[1][0],$matches[2][1] break; case 'SYN': $contacts = intval($linedata[4]); break; } } } } /*====================================*\ Various private functions \*====================================*/ function _ssl_auth($auth_string) { if (empty($this->ssh_login)) { if ($this->curl_bin) { exec("$this->curl -m 60 -LkI $this->nexus", $header); $header = implode($header, null); } else { $ch = curl_init($this->nexus); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_TIMEOUT, 2); $header = curl_exec($ch); curl_close($ch); } preg_match ('/DALogin=(.*?),/', $header, $out); if (isset($out[1])) { $slogin = $out[1]; } else { return false; } } else { $slogin = $this->ssh_login; } if ($this->curl_bin) { $header1 = '"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in='.$this->passport.',pwd='.$this->password.','.$auth_string.'"'; exec("$this->curl -m 60 -LkI -H $header1 https://$slogin", $auth_string); $header = null; foreach ($auth_string as $key => $value) { if (strstr($value, 'Unauthorized')) { echo 'Unauthorised'; return false; } elseif (strstr($value, 'Authentication-Info')) { $header = $value; } } } else { $ch = curl_init($slogin); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in='.$this->passport.',pwd='.$this->password.','.$auth_string, 'Host: login.passport.com' )); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_TIMEOUT, 2); $header = curl_exec($ch); curl_close($ch); } preg_match ("/from-PP='(.*?)'/", $header, $out); return (isset($out[1])) ? $out[1] : false; } function _get() { if ($data = @fgets($this->fp, 4096)) { if ($this->debug) echo "
<<< $data
\n"; return $data; } else { return false; } } function _getlen($len) { if ($data = @fgets($this->fp, $len)) { if ($this->debug) echo "
<<< $data
\n"; return $data; } else { return false; } } function _put($data) { fwrite($this->fp, $data); $this->trID++; if ($this->debug) echo "
>>> $data
"; } function _get_error($code) { switch ($code) { case 201: return 'Error: 201 Invalid parameter'; break; case 217: return 'Error: 217 Principal not on-line'; break; case 500: return 'Error: 500 Internal server error'; break; case 540: return 'Error: 540 Challenge response failed'; break; case 601: return 'Error: 601 Server is unavailable'; break; case 710: return 'Error: 710 Bad CVR parameters sent'; break; case 713: return 'Error: 713 Calling too rapidly'; break; case 731: return 'Error: 731 Not expected'; break; case 800: return 'Error: 800 Changing too rapidly'; break; case 910: case 921: return 'Error: 910/921 Server too busy'; break; case 911: return 'Error: 911 Authentication failed'; break; case 923: return 'Error: 923 Kids Passport without parental consent'; break; case 928: return 'Error: 928 Bad ticket'; break; default: return 'Error code '.$code.' not found'; break; } } } ?>