Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

macielcr7

Msn + PHP

Recommended Posts

Galera tenho esse codigo mais não tenho como testar e quero que alguem teste pra mim em um servidor.!' Online PHP

 

e depois poste aqui uma MSG dizendo SE funfou legal ou Não

 

VLW.!'

 

MSN.PHP

<form id="form1" name="form1" method="post" action="sample.php">
  <table width="500" border="0" align="center" cellpadding="1" cellspacing="2">
    <tr>
      <td width="148"><div align="right"><strong>Email:</strong></div></td>
      <td width="352"><input name="email_" type="text" size="35" /></td>
    </tr>
    <tr>
      <td><div align="right"><strong>Senha:</strong></div></td>
      <td><input name="senha_" type="password" size="35" /></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="button" id="button" value="Logar no MSN" /></td>
    </tr>
  </table>
</form>

msn_sb.class.php

<?php

class switchboard
{
	// font colours/styles
	var $font_fn = 'Arial';
	var $font_co = '333333';
	var $font_ef = '';


	// other
	var $debug = 1;
	var $trID = 1;
	var $email = '';


	function switchboard()
	{
		$this->session_start_time = time();
	}


	/**
	 *
	 * desc	:	send IM message
	 *
	 * in	:	$ns		=	notification server connection
	 *		$msg		=	message to send
	 *		$passport	=	current logged in user
	 *		$email		=	user to send message to
	 *
	 * out	:	true on success else return false
	 *
	 */

	function tx_im($ns, $msg, $passport, $email)
	{
		$message = "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nX-MMS-IM-Format: FN=$this->font_fn; EF=$this->font_ef; CO=$this->font_co; CS=0; PF=22\r\n\r\n$msg";
		$message = "MSG 20 N ".strlen($message)."\r\n$message";

		if (@is_resource($this->sb))
		{
			// switchboard session already open
			$this->_put($message);

			return true;
		}
		else
		{
			// open switchboard session through NS
			fputs($ns, "XFR $this->trID SB\r\n");


			$ns_data = fgets($ns, 4096);

			@list($xfr,,, $server,, $as) = explode(' ', $ns_data);

			if ($xfr != 'XFR')
			{
				echo 'unable to read NS info. last message: ';
				echo $ns_data;

				return false;
			}



			list($server, $port) = explode(':', $server);

			if ($this->sb = @fsockopen($server, $port, $errno, $errstr, 5))
			{
				$this->_put("USR $this->trID $passport $as\r\n");
				$this->_get();

				if (is_array($email))
				{
					foreach($email as $key => $value)
					{
						$this->_put("CAL $this->trID $value\r\n");

						if (strstr($this->_get(), 'CAL'))
						{
							$this->_get(); // should be JOI...
						}
					}
				}
				else
				{
					$this->_put("CAL $this->trID $email\r\n");

					if (strstr($this->_get(), 'CAL'))
					{
						$this->_get(); // should be JOI...
					}
				}



				$this->_put($message);

				return true;
			}
		}

		return false;
	}


	/**
	 *
	 * desc	:	recieve an IM from the switchboard
	 *
	 * in	:	none
	 * out	:	a. null on fail/no message
	 *		b. message string
	 *
	 */

	function rx_im()
	{
		$message = null;
		$msglen = null;

		stream_set_timeout($this->sb, 1);

		while (!feof($this->sb))
		{
			$data = ($msglen) ? $this->_get($msglen) : $this->_get();


			switch (substr($data, 0, 3))
			{
				default:
					//if (empty($msglen)) continue;

					$message.= $data;

					if (strlen($message) >= $msglen && !empty($msglen))
					{
						$mesg = explode("\n", trim($message));

						$last = end($mesg);


						//if (@substr($last, 0, 10) != 'TypingUser')
						if (!strstr($message, 'TypingUser'))
						{
							// this isn't a notification that the user is typing a message
							return $last;
						}


						$msglen = null;
						$message = null;
					}

					if ($this->session_start_time + 10 < time())
					{
						// looks like we've been idle for a while
						echo 'IM timed out';
						$this->im_close();
						return null;
					}
				break;
				case 'MSG':
					list(,,, $msglen) = explode (' ', $data);
				break;
				case 'BYE':
					return null;
				break;
			}
		}

		return null;
	}


	/**
	 *
	 * desc	:	authorise with switchboard from an IM invitation
	 *
	 * in	:	$server		=	switchboard server ip
	 *		$port		=	switchboard server port
	 *		$passport	=	logged in users passport email
	 *		$sID		=	session id
	 *		$as		=	auth string
	 *
	 * out	:	true on success else return false
	 *
	 */

	function auth($server, $port, $passport, $sID, $as)
	{
		if ($this->sb = @fsockopen($server, $port, $errno, $errstr, 5))
		{
			$this->_put("ANS $this->trID $passport $as $sID\r\n");

			if (!$this->rx_iro()) return false;

			return true;
		}

		return false;
	}


	/**
	 *
	 * desc	:	recieve IRO commands from IM session
	 *
	 * in	:	none
	 * out	:	true on success else return false
	 *
	 */

	function rx_iro()
	{
		if ($data = $this->_get())
		{
			@list($iro, , $cur_num, $tot, $email, $name) = explode(' ', $data);

			$sbsess->email = $email;

			if ($iro != 'IRO')
			{
				echo "** BAD data in rx_iro(): see line above **\n";
				return false;
			}

			// recieve names/list of others connected
			for ($i=1; $i<$tot; $i++)
			{
				if (!$data = $this->_get())
				{
					echo "** BAD data in rx_iro(): see line above **\n";
					return false;
				}

			}

			@list($ans) = explode(' ', $this->_get());

			if ($ans != 'ANS') return false;

			return true;
		}

		return false;
	}


	/**
	 *
	 * desc	:	close switchboard connection
	 *
	 * in	:	none
	 * out	:	none
	 *
	 */

	function im_close()
	{
		$this->_put("OUT\r\n");
		@fclose($this->sb);
	}


	/*====================================*\
		Various private functions
	\*====================================*/

	function _get($use_fread=0)
	{
		$data = ($use_fread) ? @fread($this->sb, $use_fread) : @fgets($this->sb, 4096);

		if ($data)
		{
			if ($this->debug) echo "<div class=\"r\"><<< SB: $data</div>\n";
			return $data;
		}
		else
		{
			return false;
		}
	}

	function _put($data)
	{
		@fputs($this->sb, $data);
		$this->trID++;

		if ($this->debug) echo "<div class=\"g\">>>> SB: $data</div>";
	}
}

?>

msnp9.class.php

<?php

class msn
{
	// messenger.hotmail.com is an exchange server
	// using it will redirect to a server with an open slot
	// using a known server ip will help connect faster

	// commenting out $ssh_login will mean the url to the
	// secure login server will be taken from a secure
	// session.  this will slow down connecting a bit.
	// Note: comment out $ssh_login if you experience auth failures

	var $server	=	'messenger.hotmail.com';
	var $port	=	1863;

	var $nexus	=	'https://nexus.passport.com/rdr/pprdr.asp';
	var $ssh_login	=	'login.live.com/login2.srf';

	var $debug	=	1;


	// curl is used for the secure login, if you don't have
	// the php_curl library installed, you can use a curl binary
	// instead. $use_curl needs to be set to 1 to enable this.
	// set $curl to the path where curl is installed.
	// curl can be downloaded here: http://curl.haxx.se/download.html

	var $curl_bin	=	0;
	var $curl	=	'/usr/local/bin/curl';	// linux
	//var $curl	=	'c:\curl.exe';		// windows




	/**
	 *
	 * desc	:	Connect to MSN Messenger Network
	 *
	 * in	:	$passport	=	passport i.e: user@hotmail.com
	 *		$password	=	password for passport
	 *
	 * out	:	true on success else return false
	 *
	 */

	function connect($passport, $password)
	{
		$this->trID = 1;

		if ($this->fp = @fsockopen($this->server, $this->port, $errno, $errstr, 2))
		{
			$this->_put("VER $this->trID MSNP9 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 win 4.10 i386 MSNMSGR 7.0.0816 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 MSNP9 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()
	{
		$this->_put("SYN $this->trID 0\r\n");
		$this->_put("CHG $this->trID NLN\r\n");

		while (! feof($this->fp))
		{
			$data = $this->_get();

			if ($data)
			{
				//echo $data.'<br />';

				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));

						$return = md5($bits[2].'Q1P7W2E4J9R8U3S5');
						$this->_put("QRY $this->trID msmsgs@msnmsgr.com 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;
				}
			}
		}
	}


	/*====================================*\
		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('https://'.$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 "<div class=\"r\"><<< $data</div>\n";

			return $data;
		}
		else
		{
			return false;
		}
	}


	function _put($data)
	{
		fwrite($this->fp, $data);

		$this->trID++;

		if ($this->debug) echo "<div class=\"g\">>>> $data</div>";
	}


	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;
		}
	}

}


?>

sample.php

 

<?php
	ob_implicit_flush();
	$email1 = $_POST["email_"];
	$senha1 = $_POST["senha_"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <title>MSN Protocol 9 Class Example Usage</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript"></script>
    <style type="text/css" media="screen" title="default">
	body {
		font: 76%/1.4 tahoma, verdana, arial, helvetica, sans-serif;
	}
	.r {
		color: red;
	}
	.g {
		color: green;
	}
    </style>
  </head>
  <body>



<?php


	include('msnp9.class.php');
	include('msn_sb.class.php');

	$msn = new msn;

	if ($msn->connect($email1, $senha1))
	{
		// we're connected
		// run rx_data function to 'idle' on the network
		// rx_state will loop until the connection is dropped

		$msn->rx_data();

		echo '<p>Connection dropped</p>';
	}
	else
	{
		// wrong username and password?
		echo '<p>Error Connecting to the MSN Network</p>';
	}


?>



  </body>
</html>

FALEM SE FUNFOU OU NÃO.!' http://forum.imasters.com.br/public/style_emoticons/default/joia.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara de onde você puxou isso....?

 

De uma laboratorio em PHP.... ele libera codigos muito bons.!'

 

LEMBRANDO QUE O CODIGO VEIO DE TERCEIROS....NÃO FOI DE MINHA AUTORIA.!'

Compartilhar este post


Link para o post
Compartilhar em outros sites

Se o código não é seu não poste como tal.

 

 

06ª - Plágios e infrações de copyright

Favor não postar quaisquer tipos de plágios ou conteúdo protegido por leis de copyright. Caso necessite postar conteúdo legal de terceiros, informe a fonte. (livro, revista, website, etc..)

 

Informe a fonte sempre que postar código de terceiros e tenha sempre certeza de que você tem permissão do autor para publicações desse tipo.

 

Esse tópico está sendo fechado e, caso haja uma justificativa para tal publicação "como sendo de autoria própria", envie uma MP (mensagem privada) para mim ou outro moderador solicitando que o tópico seja reaberto.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.