erver '.$this->socks_host_name); $this->OutputDebug('Negotiating the authentication method ...'); } $send_error = 'it was not possible to send data to the SOCKS server'; $receive_error = 'it was not possible to receive data from the SOCKS server'; $version = 5; $methods = 1; $method = 0; if(!fputs($this->connection, chr($version).chr($methods).chr($method))) $error = $this->SetDataAccessError($send_error); else { $response = fgets($this->connection, 3); if(strlen($response) != 2) $error = $this->SetDataAccessError($receive_error); elseif(Ord($response[1]) != $method) $error = 'the SOCKS server requires an authentication method that is not yet supported'; else { if($this->debug) $this->OutputDebug('Connecting to '.$host_server_type.' server IP '.$host_ip.' port '.$host_port.'...'); $command = 1; $address_type = 1; if(!fputs($this->connection, chr($version).chr($command)."\x00".chr($address_type).pack('Nn', ip2long($host_ip), $host_port))) $error = $this->SetDataAccessError($send_error); else { $response = fgets($this->connection, 11); if(strlen($response) != 10) $error = $this->SetDataAccessError($receive_error); else { $socks_errors = array( "\x00"=>'', "\x01"=>'general SOCKS server failure', "\x02"=>'connection not allowed by ruleset', "\x03"=>'Network unreachable', "\x04"=>'Host unreachable', "\x05"=>'Connection refused', "\x06"=>'TTL expired', "\x07"=>'Command not supported', "\x08"=>'Address type not supported' ); $error_code = $response[1]; $error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown'); if(strlen($error)) $error = 'SOCKS error: '.$error; } } } } if(strlen($error)) { fclose($this->connection); return($error); } } if($this->debug) $this->OutputDebug("Connected to $host_name"); if(strlen($this->proxy_host_name) && strcmp(strtolower($this->protocol), 'HTTPS')) { if(function_exists('stream_socket_enable_crypto') && in_array('ssl', stream_get_transports())) $this->state = "ConnectedToProxy"; else { $this->OutputDebug("It is not possible to start SSL after connecting to the proxy server. If the proxy refuses to forward the SSL request, you may need to upgrade to PHP 5.1 or later with OpenSSL support enabled."); $this->state="Connected"; } } else $this->state="Connected"; return(""); } } Function Disconnect() { if($this->debug) $this->OutputDebug("Disconnected from ".$this->host_name); if($this->use_curl) { curl_close($this->connection); $this->response=""; } else fclose($this->connection); $this->state="Disconnected"; return(""); } /* Public methods */ Function GetRequestArguments($url,&$arguments) { if(strlen($this->error)) return($this->error); $arguments=array(); $parameters=@parse_url($url); if(!$parameters) return($this->SetError("it was not specified a valid URL")); if(!IsSet($parameters["scheme"])) return($this->SetError("it was not specified the protocol type argument")); switch(strtolower($parameters["scheme"])) { case "http": case "https": $arguments["Protocol"]=$parameters["scheme"]; break; default: return($parameters["scheme"]." connection scheme is not yet supported"); } if(!IsSet($parameters["host"])) return($this->SetError("it was not specified the connection host argument")); $arguments["HostName"]=$parameters["host"]; $arguments["Headers"]=array("Host"=>$parameters["host"].(IsSet($parameters["port"]) ? ":".$parameters["port"] : "")); if(IsSet($parameters["user"])) { $arguments["AuthUser"]=UrlDecode($parameters["user"]); if(!IsSet($parameters["pass"])) $arguments["AuthPassword"]=""; } if(IsSet($parameters["pass"])) { if(!IsSet($parameters["user"])) $arguments["AuthUser"]=""; $arguments["AuthPassword"]=UrlDecode($parameters["pass"]); } if(IsSet($parameters["port"])) { if(strcmp($parameters["port"],strval(intval($parameters["port"])))) return($this->SetError("it was not specified a valid connection host argument")); $arguments["HostPort"]=intval($parameters["port"]); } else $arguments["HostPort"]=0; $arguments["RequestURI"]=(IsSet($parameters["path"]) ? $parameters["path"] : "/").(IsSet($parameters["query"]) ? "?".$parameters["query"] : ""); if(strlen($this->user_age