ClientIP, $this->ClientPort); // Inform about new connection print "New Authenticator connection from " . $this->ClientIP . ":" . $this->ClientPort . "\n\n"; // Remember / Create sockets $this->Local = $Socket; $this->Remote = socket_create (AF_INET, SOCK_STREAM, SOL_TCP); socket_connect ($this->Remote, "login.oscar.aol.com", 5190); // Set contexts setContextSocket ($this->Local, $this); setContextSocket ($this->Remote, $this); } // }}} // {{{ handle /** * Handle incoming data * * @param resource $Socket * * @access public * @return void */ public function handle ($Socket) { if ($Socket == $this->Local) $this->handleLocal (); elseif ($Socket == $this->Remote) $this->handleRemote (); } // }}} // {{{ handleLocal /** * Read FLAP from local and forward to remote * * @access private * @return void */ private function handleLocal () { // Read FLAP from local connection if (!($Data = flapRead ($this->Local, true, "AUTH>>"))) return; // Create an empty TLV-Set $TLV = null; // Try to peek username if ($Data ["Channel"] == 0x01) { // Copy the FLAP-Packet $xData = $Data; // Skip version-string (we just expect this) $xData ["Payload"] = substr ($xData, 4); // Read TLVs from FLAP $TLV = flapTreatTLV ($xData); } elseif ($Data ["Channel"] == 0x02) { $SNAC = flapReadSNAC ($Data); if (($SNAC ["Family"] == 0x0017) && ($SNAC ["Subtype"] == 0x0002)) $TLV = flapTreatTLV ($SNAC); } // Look for a username if (is_array ($TLV)) foreach ($TLV as $Item) if ($Item ["Type"] == 0x0001) $this->ClientUser = $Item ["Payload"]; // Forward FLAP to remote side writeFlap ($this->Remote, $Data, false, "AUTH<<"); } // }}} // {{{ handleRemote /** * Read FLAP from remote, filter and forward to local * * @access private * @return void */ private function handleRemote () { // Read FLAP from remote connection if (!($Data = flapRead ($this->Remote, true, "AUTH<<"))) return; // Try to filter packets $Failed = false; $Proxy = null; if ($Data ["Channel"] == 2) { $SNAC = flapReadSNAC ($Data); if (($SNAC ["Family"] == 0x0017) && ($SNAC ["Subtype"] == 0x0003)) $TLV = flapTreatTLV ($SNAC); else $TLV = null; } else $TLV = flapTreatTLV ($Data); if (is_array ($TLV)) foreach ($TLV as $ID=>$Item) { // Handle Authentication-Failure if ($Item ["Type"] == 0x0008) $Failed = true; elseif (($Item ["Type"] == 0x0005) || ($Item ["Type"] == 0x0006)) { // Check if we have a proxy-handle if (!is_object ($Proxy)) $Proxy = new proxyOscar ($this->Local, $this->ClientUser); // Remember and rewrite Address of BOS-Server if ($Item ["Type"] == 0x0005) { $Proxy->setAddress ($TLV [$ID]["Payload"]); $TLV [$ID]["Payload"] = $Proxy->getAddress (); $TLV [$ID]["Length"] = strlen ($TLV [$ID]["Payload"]); // Remember the cookie } else $Proxy->setCookie ($Item ["Payload"]); } } // Rebuild the packet if ($TLV !== null) { if (isset ($SNAC) && is_array ($SNAC)) { $SNAC = flapRewriteTLV ($SNAC, $TLV); $Data = flapRewriteSNAC ($Data, $SNAC); } else $Data = flapRewriteTLV ($Data, $TLV); } if (is_object ($Proxy)) print "A[Authentication done\n"; // Forward FLAP to local side writeFlap ($this->Local, $Data, false, "AUTH>>"); } // }}} } ?>