Ejemplo n.º 1
0
 public function accept()
 {
     $client = new $this->client_class(parent::accept());
     if (!is_subclass_of($client, 'socketServerClient')) {
         throw new socketException("Invalid serverClient class specified! Has to be a subclass of socketServerClient");
     }
     $this->on_accept($client);
     return $client;
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  */
 function __construct($host, $port = 25, $user = null, $pass = null)
 {
     parent::__construct();
     $this->smtp_host = $host;
     $this->smtp_port = $port;
     $this->smtp_user = $user;
     $this->smtp_pass = $pass;
     $this->set_header('mime-version', '1.0');
     $this->set_header('date', date('r'));
     $this->set_header('x-mailer', 'Gekko');
 }
Ejemplo n.º 3
0
 public function send(socket $socket, request $request)
 {
     if ($this->has_cookie()) {
         $request->add_header('Cookie', $this->get_cookie_header());
     }
     $request_message = $request->fetch();
     // echo $request_message;
     $socket->write($request_message);
     $response = new response($socket->read());
     $cookies = $response->get_header('Set-Cookie');
     if ($cookies !== null) {
         if (is_array($cookies)) {
             foreach ($cookies as $cookie) {
                 $this->parse_cookie($cookie);
             }
         } else {
             $this->parse_cookie($cookies);
         }
     }
     return $response;
 }
Ejemplo n.º 4
0
 /**
  * Constructor.
  */
 function __construct($host, $port = 80, $user = null, $pass = null)
 {
     parent::__construct();
     $this->http_host = $host;
     $this->http_port = $port;
     $this->http_user = $user;
     $this->http_pass = $pass;
     $this->set_header('host', "{$this->http_host}:{$this->http_port}");
     if ($this->http_user) {
         $this->set_header('authorization', "basic " . base64_encode("{$this->http_user}:{$this->http_pass}"));
     }
 }
Ejemplo n.º 5
0
 public function read($length = 4096)
 {
     try {
         $this->read_buffer .= parent::read($length);
         $this->on_read();
     } catch (socketException $e) {
         $old_socket = (int) $this->socket;
         $this->close();
         $this->socket = $old_socket;
         $this->disconnected = true;
         $this->on_disconnect();
     }
 }
Ejemplo n.º 6
0
 public function priv_bash($line, $args)
 {
     $channel = $line['to'];
     $random = false;
     if (strpos($channel, "#") === false) {
         return;
     }
     if ($this->ircClass->getStatusRaw() != STATUS_CONNECTED_REGISTERED) {
         return;
     }
     if (time() < $this->delay) {
         $this->ircClass->notice($line['fromNick'], "Please wait " . ($this->delay - time()) . " seconds before using this function again.", 0);
         return;
     }
     //?search=test&sort=0&show=25
     if ($args['nargs'] > 0) {
         if ($args['arg1'] == "+") {
             $random = true;
             $query = "random1&show=1";
         } else {
             if ($args['arg1'] == "-") {
                 $this->ircClass->notice($line['fromNick'], "This is an unsupported function.");
                 return;
             } else {
                 $num = $args['arg1'];
                 if (substr($num, 0, 1) == "#") {
                     $num = substr($num, 1);
                 }
                 $num = intval($num);
                 if ($num <= 0) {
                     $search = urlencode($args['query']);
                     $random = true;
                     $query = "search=" . $search . "&show=1&sort=0";
                 } else {
                     $query = "{$num}";
                 }
             }
         }
     } else {
         $random = true;
         $query = "random&show=1";
     }
     $line['channel'] = $channel;
     $line['random'] = $random;
     $host = "www.bash.org";
     $port = 80;
     $path = "/";
     $getQuery = socket::generateGetQuery($query, $host, $path, "1.0");
     $this->ircClass->addQuery($host, $port, $getQuery, $line, $this, "priv_bash_stageTwo");
 }
 function __construct($ip = "127.0.0.1", $port = 4000, $auth = false)
 {
     parent::__construct($ip, $port, $auth);
 }
Ejemplo n.º 8
0
 public function search_response($line, $args, $result, $site)
 {
     if ($result == QUERY_ERROR) {
         $this->ircClass->notice($line['fromNick'], "Error: " . $site);
         return;
     }
     $site = str_replace("&#160;", ";", $site);
     $site = str_replace("\r", "", $site);
     $site = html_entity_decode($site);
     preg_match_all("/<li>\\s*<a href=\"\\/title\\/(.+?)\\/.+?>(.+?)<\\/a>\\s*(\\(.+?\\)){1}?(\\s)?(.+?)*?<\\/li>/i", $site, $matches, PREG_PATTERN_ORDER);
     $topTen = array();
     for ($i = 0; $i < count($matches[1]); $i++) {
         if ($matches[4][$i] == " ") {
             continue;
         }
         $link = trim($matches[1][$i]);
         $title = trim($matches[2][$i]);
         $date = trim($matches[3][$i]);
         $lTitle = strtolower($title);
         if (!isset($this->cache[$lTitle])) {
             $this->cache[$lTitle] = array();
             $this->cache[$lTitle][$date] = $link;
         } else {
             if (!isset($this->cache[$lTitle][$date])) {
                 $this->cache[$lTitle][$date] = $link;
                 krsort($this->cache[$lTitle]);
             }
         }
         $topTen[] = $title . " " . $date;
     }
     $tkey = strtolower($args["query"]);
     $lArgs = explode(chr(32), $tkey);
     $tCount = count($lArgs);
     if ($tCount > 0) {
         $date = $lArgs[count($lArgs) - 1];
         $title = trim(str_replace($date, "", $tkey));
     }
     if (isset($this->cache[$tkey])) {
         foreach ($this->cache[$tkey] as $date => $link) {
             break;
         }
         $line["link"] = $link;
         $line["title"] = $tkey;
         $line["date"] = $date;
         $search = socket::generateGetQuery("", "www.imdb.com", "/title/" . $link . "/", "1.0");
         $this->ircClass->addQuery("www.imdb.com", 80, $search, $line, $this, "title_response");
     } else {
         if ($tCount > 0 && isset($this->cache[$title]) && isset($this->cache[$title][$date])) {
             $link = $this->cache[$title][$date];
             $line["link"] = $link;
             $line["title"] = $title;
             $line["date"] = $date;
             $search = socket::generateGetQuery("", "www.imdb.com", "/title/" . $link . "/", "1.0");
             $this->ircClass->addQuery("www.imdb.com", 80, $search, $line, $this, "title_response");
         } else {
             $total = count($topTen);
             $total = $total > 10 ? 10 : $total;
             if ($total <= 0) {
                 $this->ircClass->notice($line['fromNick'], "No responses from server.  Try broadening your search.  If you included a date, remove it and try again.");
                 return;
             }
             $this->ircClass->notice($line['fromNick'], "Top " . $total . " responses from www.imdb.com");
             $resp = "";
             for ($i = 0; $i < $total; $i++) {
                 $resp .= DARK . "[" . BRIGHT . $topTen[$i] . DARK . "] - ";
             }
             $multi = irc::multiLine($resp);
             foreach ($multi as $mult) {
                 $this->ircClass->notice($line['fromNick'], $mult);
             }
         }
     }
 }
Ejemplo n.º 9
0
 public function priv_leo($line, $args)
 {
     if ($args['nargs'] < 1) {
         $this->sendMsg($line, $args, 'You need to supply a search string');
         return;
     }
     $cmdLower = irc::myStrToLower($args['cmd']);
     switch ($cmdLower) {
         case '!fra':
             $query = 'lp=frde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search=' . urlencode($args['query']) . '&relink=off';
             $getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/frde');
             break;
         case '!esp':
             $query = 'lp=esde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search=' . urlencode($args['query']) . '&relink=off';
             $getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/esde');
             break;
         case '!ita':
             $query = 'lp=itde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search=' . urlencode($args['query']) . '&relink=off';
             $getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/itde');
             break;
             // skip chinese, output is garbage only anyway
             //case '!chn':
             //	$query = 'lp=chde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search='.urlencode($args['query']).'&relink=off';
             //	$getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/chde');
             //	break;
         // skip chinese, output is garbage only anyway
         //case '!chn':
         //	$query = 'lp=chde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search='.urlencode($args['query']).'&relink=off';
         //	$getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/chde');
         //	break;
         default:
             $query = 'lp=ende&lang=de&searchLoc=0&cmpType=relaxes&sectHdr=off&spellToler=on&search=' . urlencode($args['query']) . '&relink=off';
             $getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/ende');
     }
     // switch
     $this->ircClass->addQuery('dict.leo.org', 80, $getQuery, $line, $this, 'sendLeoResults');
 }
Ejemplo n.º 10
0
 public function priv_video($line, $args)
 {
     if ($args['nargs'] < 1) {
         $this->sendMsg($line, $args, 'You need to supply a search string');
         return;
     }
     $getQuery = socket::generateGetQuery('q=' . urlencode($args['query']) . '&hl=en', 'video.google.' . $this->extension, '/videosearch');
     $this->ircClass->addQuery('video.google.' . $this->extension, 80, $getQuery, $line, $this, 'sendVideoResults');
 }
 function __construct($ip = "0.0.0.0", $port = 4000, $auth = false)
 {
     parent::__construct($ip, $port, $auth);
     $this->start();
 }
Ejemplo n.º 12
0
 /**
  * Extends the parent console method.
  * For now we just set another type.
  *
  * @param string $msg
  * @param string $type
  */
 protected function console($msg, $type = 'WebSocket')
 {
     parent::console($msg, $type);
 }
Ejemplo n.º 13
0
 /**
  * Enters passive mode and opens a data connection
  * @param resource $sock Reference to the data connection stream
  * @returns boolean True on success
  */
 function pasv(&$sock)
 {
     $this->write("PASV\r\n");
     $success = $this->chat("227");
     if ($success) {
         // where to connect?
         preg_match("/\\(([\\d,]*)\\)/", $this->last(), $match);
         $match = explode(",", $match[1]);
         if (isset($match[5])) {
             $host = "{$match[0]}.{$match[1]}.{$match[2]}.{$match[3]}";
             $port = $match[4] * 256 + $match[5];
             $sock = new socket();
             $sock->connect($host, $port);
             if ($sock->status()) {
                 return true;
             } else {
                 $this->error(__("Couldn't open data connection to %s:%s.", $host, $port), E_USER_ERROR);
                 return false;
             }
         } else {
             $this->debug($match, __FILE__, __LINE__);
         }
     }
 }
Ejemplo n.º 14
0
 public function function_response($line, $args, $result, $site)
 {
     if ($result == QUERY_ERROR) {
         $this->ircClass->notice($line['fromNick'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - Error: " . $site);
         return;
     }
     $location = $this->checkLocation($site);
     if (count($location) >= 3) {
         $domain = $location['scheme'] . '://' . $location['host'] . $location['path'];
         if (isset($location['query'])) {
             $domain .= '?' . $location['query'];
             $query = $location['query'];
         } else {
             $query = "";
         }
         $search = socket::generateGetQuery($query, $location['host'], $location['path'], "1.0");
         $this->ircClass->addQuery($location['host'], 80, $search, $line, $this, "function_response");
     } else {
         //$site = html_entity_decode($site);
         $site = str_replace("\n", "", $site);
         $site = str_replace("\r", "", $site);
         preg_match_all('/<base href="(.*?)" \\/>/is', $site, $matches);
         // TODO: Fix the page url, seems to contain HTML ONLY SEEMS TO HAPPEN WHEN YOU CALL A FUNCTION THAT RETURNS A SEARCH
         $page_url = isset($matches[1][0]) ? $this->parse_php_url($matches[1][0]) : null;
         $response = array('query' => $this->query, 'fromWho' => $line['fromNick'], 'toWho' => '', 'mask' => $line['fromHost'], 'channel' => $line['to'], 'function' => '', 'versions' => '', 'defenition' => '', 'description' => '', 'url' => $page_url, 'matches' => '', 'library' => '', 'hits' => 1, 'timestamp' => time());
         if (isset($line['toWho'])) {
             $response['toWho'] = $line['toWho'];
         }
         if (preg_match('/<li class="header up"><a href="funcref.php">Function Reference<\\/a><\\/li>/is', $site)) {
             // found a function reference page
             preg_match_all('/<li class="active"><a href="(.*?)">(.*?)<\\/a><\\/li>/is', $site, $matches, PREG_PATTERN_ORDER);
             $response['library'] = $matches[2][0];
             $this->doCacheCheck($response);
             if ($line['toOther'] === TRUE) {
                 $this->ircClass->notice($line['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $line['fromNick'] . " wants you to know about " . $this->query . DARK);
             }
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - php.net response for " . $this->query . DARK);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['library'] . " Function Reference" . DARK);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['url'] . DARK);
         } elseif (preg_match('/Sorry, but the function <b>' . $this->query . '<\\/b> is not in the online manual/is', $site)) {
             // parse out the closest matches if there are any
             preg_match_all('/<a href="\\/manual\\/en\\/function.(.*?)"><b>(.*?)<\\/b><\\/a><br \\/>/is', $site, $matches);
             if (isset($matches[2]) && $matches[2] != "") {
                 $response['matches'] = serialize($matches[2]);
                 $response['matchCount'] = count($matches[2]);
             } else {
                 $response['matches'] = serialize(array());
                 $response['matchCount'] = 0;
             }
             $this->doCacheCheck($response);
             $message = DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - Could not find a perfect match for " . $this->query . ".";
             if ($response['matchCount'] > 0) {
                 $message .= " Maybe one of the following (" . $response['matchCount'] . ") suggestions: " . implode(', ', unserialize($response['matches'])) . "." . DARK;
             } else {
                 $message .= " I am unable to come up with any close matches, sorry." . DARK;
             }
             $this->ircClass->notice($line['toWho'], $message);
         } else {
             // Grab the rest of the info from the page
             preg_match_all("/<\\/A><P>(.*?)\\((.*?)\\)<\\/P>(.*?)--(.*?)<\\/DIV><DIVCLASS=\"(.*?)\"><ANAME=\"(.*?)\"><\\/A><H2>Description<\\/H2>(.*?)<BR>/is", $site, $matches, PREG_PATTERN_ORDER);
             $response['versions'] = isset($matches[2][0]) ? html_entity_decode($matches[2][0]) : null;
             $response['function'] = isset($matches[3][0]) ? trim(str_replace('&nbsp;', '', strip_tags($matches[3][0]))) : null;
             $response['description'] = isset($matches[4][0]) ? trim(str_replace('&nbsp;', '', strip_tags($matches[4][0]))) : null;
             $response['defenition'] = isset($matches[7][0]) ? trim(str_replace('&nbsp;', '', strip_tags($matches[7][0]))) : null;
             //$response['url'] = $this->parse_php_url($page_url);
             $this->doCacheCheck($response);
             if ($line['toOther'] === TRUE) {
                 $this->ircClass->notice($line['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $line['fromNick'] . " wants you to know about " . $this->query . DARK);
             }
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - php.net response for " . $this->query . DARK);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['function'] . ' -- ' . $response['description']);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['versions']);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['defenition']);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['url']);
         }
     }
 }