From 21a6f3259d3cd9c9fc3c635610ad1584abd778bf Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 15 Jul 2011 16:04:35 +0100 Subject: [PATCH] Removed uneeded files/dirs --- README | 6 - class_irc.php | 415 ----------------------------------- class_ircconnection.php | 394 --------------------------------- class_session.php | 115 ---------- common.php | 24 -- dev_processClientMessage.php | 142 ------------ embed.php | 97 -------- index.html | 0 index.lighttpd.html | 57 ----- index_old.php | 130 ----------- inf.php | 5 - irc_session.php | 238 -------------------- js/front_backup.js | 143 ------------ layout.html | 107 --------- poll.php | 110 ---------- test.html | 25 --- ws.html | 11 - ws.php | 324 --------------------------- 18 files changed, 2343 deletions(-) delete mode 100644 README delete mode 100644 class_irc.php delete mode 100644 class_ircconnection.php delete mode 100644 class_session.php delete mode 100644 common.php delete mode 100644 dev_processClientMessage.php delete mode 100644 embed.php delete mode 100644 index.html delete mode 100644 index.lighttpd.html delete mode 100644 index_old.php delete mode 100644 inf.php delete mode 100644 irc_session.php delete mode 100644 js/front_backup.js delete mode 100644 layout.html delete mode 100644 poll.php delete mode 100644 test.html delete mode 100644 ws.html delete mode 100644 ws.php diff --git a/README b/README deleted file mode 100644 index 791171e..0000000 --- a/README +++ /dev/null @@ -1,6 +0,0 @@ -THOUGHTS - The session ID posted from the webclient needs to be parsed. Eg. only allow chars [A-Za-z0-9]{number_of_chars} - - -WEBIRC/CGIIRC NOTES - \ No newline at end of file diff --git a/class_irc.php b/class_irc.php deleted file mode 100644 index 9903031..0000000 --- a/class_irc.php +++ /dev/null @@ -1,415 +0,0 @@ -stream = @stream_socket_client("{$scheme}://$host:$port", $errno, $errstr, 4); - if(!$this->stream) - { - debug("Error creating socket: $host $errstr\n"); - return; - } -// socket_set_timeout($this->stream, 30); - stream_set_blocking($this->stream, $blocking); - } - function __destruct() - { - if($this->stream) - { - fclose($this->stream); - $this->stream = null; - } - } - function SetBlocking($blocking = true) - { - if(!$this->stream) - return false; - stream_set_blocking($this->stream, $blocking); - } - function SetTimeout($timeout, $ms=0) - { - if(!$this->stream) - return false; - stream_set_timeout($this->stream, $timeout, $ms); - } - function Eof() - { - if(!$this->stream) - return true; - $x = stream_get_meta_data($this->stream); - if($x['eof'] && $x['unread_bytes']==0 && feof($this->stream)) - return true; - return false; - } - function Read($length = 512, $type = PHP_BINARY_READ) - { - if(!$this->stream) return false; - if($type == PHP_NORMAL_READ){ - $ret = fgets($this->stream, $length); - } elseif($type == PHP_BINARY_READ) { - $ret = fread($this->stream, $length); - } - //file_put_contents('/home/wok/public_html/kiwi/rawlog', '> '.$ret, FILE_APPEND); - return $ret; - } - function Write($data) - { - global $totalup; - if(!$this->stream) return false; - - //file_put_contents('/home/wok/public_html/kiwi/rawlog', '< '.$data, FILE_APPEND); - $x = @fwrite($this->stream, $data); - return $x; - } - function GetInfo() - { - if(!$this->stream) - return false; - return array('local'=>stream_socket_get_name($this->stream,false),'remote'=>stream_socket_get_name($this->stream, true)); - } -} -class SocketStreamSSL extends SocketStream -{ - function __construct($host = null, $port = null, $blocking = true) - { - if(!$host && !$port) - return; - $this->stream = @stream_socket_client("ssl://$host:$port", $errno, $errstr, 4); - if(!$this->stream) - { - debug("Error creating socket: $host $errstr\n"); - return; - } -// socket_set_timeout($this->stream, 30); - stream_set_blocking($this->stream, $blocking); - } -} -class IRC -{ - var $stream; - var $url, $urlinfo; - var $nick; - protected $msgqueue = array(); - protected $dccs = array(); - private $reconnect=0; - private $nextping=0; - public $modes; - public $chanlist; - public $connected; - function __construct($url, $kiwi=null, $opts=array()){ - $this->url = $url; - $urlinfo = parse_url($url); - $this->urlinfo = $urlinfo; - if(!ereg("^ircs?$", $urlinfo['scheme'])) - return false; - $ssl = ($urlinfo['scheme']=='ircs'); - $host = $urlinfo['host']; - $port = isset($urlinfo['port'])?$urlinfo['port']:6667; - $this->nick = $nick = isset($urlinfo['user'])?$urlinfo['user']:'kiwi_user|'.(string)rand(0,9999); - //$ident = isset($urlinfo['pass'])?$urlinfo['pass']:$nick; - $ident = (isset($opts['ident'])) ? "{$opts['ident']}_kiwi" : "{$nick}_kiwi"; - $chans = false; - if(isset($urlinfo['path'])){ - $path = trim($urlinfo['path'], "/"); - $chans = explode(",", $path); //"#".str_replace(array(":", ","), array(" ", ",#"), $path); - } - $this->connected = false; - if($ssl) - $this->stream = new SocketStreamSSL($host, $port, false); - else - $this->stream = new SocketStream($host, $port, false); - if(!$this->stream || !$this->stream->stream){ - return false; - } - - // Send the login data - if($kiwi != null) $this->stream->Write($kiwi."\r\n"); - if(isset($urlinfo['fragment'])) $this->stream->Write("PASS {$urlinfo['fragment']}\r\n"); - - $this->stream->Write("NICK $nick\r\n"); - $this->stream->Write("USER $ident 0 0 :$nick\r\n"); - //if($chans){ - // foreach($chans as $chan) - // $this->stream->Write("JOIN ".str_replace(":", " ", $chan)."\r\n"); - //} else { - $chans = array(); - //} - $this->chans = $chans; - $this->connected = true; - return true; - } - function __destruct(){ - if($this->stream){ - $this->stream->Write("QUIT :kiwi\r\n"); - } - } - function Process(){ - if((!$this->stream || !$this->stream->stream)){ - if(time() > $this->reconnect) { - $this->__construct($this->url); - $this->reconnect = time() + 10; - } - usleep(50000); - return; - } - if($this->stream->Eof()){ - $this->stream = null; - return; - } - $r=array($this->stream->stream); - $w = $e = array(); - if(($num=@stream_select($r, $w,$e,0,50000))===false){ - - } elseif($num>0){ - $data=$this->stream->Read(512, PHP_NORMAL_READ); - //deb($data); - if(preg_match("/^(?::(?:([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)|([a-z0-9\x5B-\x60\x7B-\x7D\.\-]+)!([a-z0-9~\.\-_|]+)@([a-z0-9\.\-:]+)) )?([a-z0-9]+)(?:(?: ([^:]+))?(?: :(.+))?)$/i", $data, $regs)) - { - unset($prefix, $nick, $ident, $hostname, $command, $params, $trailing, $flarp); - $prefix = $regs[1]; - $nick = $regs[2]; - $ident = $regs[3]; - $hostname = $regs[4]; - $command = $regs[5]; - $params = isset($regs[6]) ? $regs[6] : ''; - $trailing = trim(isset($regs[7]) ? $regs[7] : ''); - $flarp = compact('prefix', 'nick', 'ident', 'hostname', 'command', 'params', 'trailing'); - $this->ProcessMessage($flarp); - } - } - else - { - if(sizeof($this->msgqueue) && (microtime(true)>($this->lastqueuewrite+0.1)) && ($msg=array_shift($this->msgqueue))) - { $this->lastqueuewrite = microtime(true); $this->stream->Write($msg); } - foreach($this->dccs as $k=>&$dcc) - { - if(!$dcc->Process()) - { - if($dcc->errorinfo) - $this->SendNotice($dcc->errorinfo['nick'], $dcc->errorinfo['text']); - unset($this->dccs[$k]); - } - } - if(($now=microtime(1))>$this->nextping) - { - $this->stream->Write("PONG x\r\n"); - $this->nextping = $now + 150; - } - } - } - function ProcessMessage($message) - { - //echo $message['command']."\n"; - switch($message['command']) - { - case "PING": - $this->stream->Write("PONG {$message['trailing']}\r\n"); - break; - case "PRIVMSG": - $this->ProcessPrivMsg($message); - break; - case "001": - if($this->chans) - foreach($this->chans as $chan) - $this->stream->Write("JOIN ".str_replace(":", " ", $chan)."\r\n"); - break; - case "443": - $newnick = 'kiwi_user|'.rand(0,99999); - $this->SendCmd("NICK ".$newnick); - $this->nick = $newnick; - break; - case "MODE": - $this->OnMODE($message); - break; - case "353": - $this->On353($message); - break; - case "QUIT": - $chan = $message['params']; - foreach($this->chanlist as &$chan){ - if(isset($chan['userlist'][$message['nick']])) - unset($chan['userlist'][$message['nick']]); - } - break; - case "PART": - $chan = $message['params']; - //debug("Parting {$message['nick']} from $chan"); - if(isset($this->chanlist[ltrim($chan, "#")])){ - unset($this->chanlist[ltrim($chan, "#")]['userlist'][$message['nick']]); - } - break; - case "JOIN": - $chan = $message['trailing']; - $nick = array($message['nick'] => ''); - $nicklist = is_array($this->chanlist[ltrim($chan, "#")]['userlist']) ? $this->chanlist[ltrim($chan, "#")]['userlist'] : - array(); - - $this->chanlist[ltrim($chan, "#")]['userlist'] = array_merge($nicklist, $nick); - break; - case "NICK": - if($message['nick'] == $this->nick){ - $this->nick = $message['trailing']; - } - foreach($this->chanlist as $chan_name => $chan){ - foreach($chan['userlist'] as $nick => $status){ - if($nick == $message['nick']){ - $this->chanlist[$chan_name]['userlist'][$message['trailing']] = $this->chanlist[$chan_name]['userlist'][$message['nick']]; - unset($this->chanlist[$chan_name]['userlist'][$message['nick']]); - break; - } - } - } - break; - } - } - function OnMODE($message){ - if($message['params'] == $this->nick) { - $modes = $message['trailing']; - $size = strlen($modes); - $add = 1; - for($i=0;$i<$size;$i++){ - if($modes{$i} == '+'){ - $add = 1; - continue; - } elseif($modes{$i} == '-'){ - $add = 0; - continue; - } - if($add && strpos($this->modes, $modes{$i}) === false) - $this->modes.=$modes{$i}; - if(!$add && strpos($this->modes, $modes{$i})) - $this->modes = str_replace($modes{$i}, "", $this->modes); - } - } - $params = $message['params']; - $chan = trim(strtok($params, ' ')); - if(in_array(trim($chan,'#'), $this->chans)){ - $modes = strtok(' '); - $therest = explode(" ", trim(strtok(''))); - $size = strlen($modes); - $add = 1; - $offset = 0; - for($i=0;$i<$size;$i++){ - if($modes{$i} == '+'){ - $add = 1; - $offset--; - continue; - } elseif($modes{$i} == '-'){ - $add = 0; - $offset--; - continue; - } - if($modes[$i]=='v') - { - $user = $therest[$i+$offset]; - if($add) - { - if(stripos($this->chanlist[trim($chan,'#')]['userlist'][$user], '+')===false) - $this->chanlist[trim($chan,'#')]['userlist'][$user] .= '+'; - } - else - $this->chanlist[trim($chan,'#')]['userlist'][$user] = str_replace('+','',$this->chanlist[trim($chan,'#')]['userlist'][$user]); - continue; - } - if($modes[$i]=='o') - { - $user = $therest[$i+$offset]; - if($add) - { - if(stripos($this->chanlist[trim($chan,'#')]['userlist'][$user], '@')===false) - $this->chanlist[trim($chan,'#')]['userlist'][$user] .= '@'; - } - else - $this->chanlist[trim($chan,'#')]['userlist'][$user] = str_replace('@','',$this->chanlist[trim($chan,'#')]['userlist'][$user]); - continue; - } - if($modes[$i]=='h') - { - $user = $therest[$i+$offset]; - if($add) - { - if(stripos($this->chanlist[trim($chan,'#')]['userlist'][$user], '%')===false) - $this->chanlist[trim($chan,'#')]['userlist'][$user] .= '%'; - } - else - $this->chanlist[trim($chan,'#')]['userlist'][$user] = str_replace('%','',$this->chanlist[trim($chan,'#')]['userlist'][$user]); - continue; - } - if($modes[$i]=='q') - { - $user = $therest[$i+$offset]; - if($add) - { - if(stripos($this->chanlist[trim($chan,'#')]['userlist'][$user], '~')===false) - $this->chanlist[trim($chan,'#')]['userlist'][$user] .= '~'; - } - else - $this->chanlist[trim($chan,'#')]['userlist'][$user] = str_replace('~','',$this->chanlist[trim($chan,'#')]['userlist'][$user]); - continue; - } - } - } - - } - function On353($message){ - // Response to NAMES command - list($nick,,$chan) = explode(" ", $message['params']); - $nicks = explode(" ", $message['trailing']); - $prefixes = array('~', '&', '@','%','+'); - $nicklist = array(); - foreach($nicks as $nick){ - if(in_array($nick{0}, $prefixes)){ - $prefix = $nick{0}; - $nick = substr($nick,1); - } - else - $prefix = ''; - $nicklist[$nick] = $prefix; - } - if(sizeof($nicklist)){ - // If we havn't got a list of nicks for this channel yet, create it - if(!isset($this->chanlist[ltrim($chan, "#")]['userlist'])){ - $this->chanlist[ltrim($chan, "#")]['userlist'] = array(); - } - $this->chanlist[ltrim($chan, "#")]['userlist'] = array_merge($this->chanlist[ltrim($chan, "#")]['userlist'], $nicklist); - } - } - function ProcessPrivMsg($message){ - //$cmd = strtok($message['trailing'], ' '); - //switch($cmd){ - //} - } - function SendMessage($dest, $text){ - if(!$this->stream) - return false; - $this->stream->Write("PRIVMSG $dest :$text\r\n"); - } - function Join($chan){ - $this->stream->Write("JOIN ".str_replace(":", " ", $chan)."\r\n"); - } - function SendNotice($dest, $text) - { - $this->stream->Write("NOTICE $dest :$text\r\n"); - } - function QueueMessage($dest, $text) - { - $this->msgqueue[] = "PRIVMSG $dest :$text\r\n"; - } - function QueueNotice($dest, $text) - { - $this->msgqueue[] = "NOTICE $dest :$text\r\n"; - } - function GetMainChan() - { - return '#'.$this->chans[0]; - } -} \ No newline at end of file diff --git a/class_ircconnection.php b/class_ircconnection.php deleted file mode 100644 index 62b8b2a..0000000 --- a/class_ircconnection.php +++ /dev/null @@ -1,394 +0,0 @@ -'connect', - 'connected'=>true, - 'host'=>$args['server'] - )); - break; - - case '005': - $opts = explode(' ', $message['params']); - $to_client = array(); - foreach($opts as $pair){ - $opt = explode('=', $pair, 2); - $name = strtoupper($opt[0]); - $val = isset($opt[1]) ? $opt[1] : true; - $this->server_options[$name] = $val; - - if(in_array($name, array('NETWORK', 'PREFIX', 'CHANTYPES'))){ - // Put the user prefixes (~&@ etc etc) into a more usable format - if($name == 'PREFIX'){ - $matches = null; - preg_match('/\(([^)]*)\)(.*)/', $val, $matches); - - $val = array(); - if(count($matches) == 3){ - for($i=0; $i 'options', - 'server' => '', - 'options' => $to_client - ); - $buffer[] = json_encode($data); - break; - - case RPL_WHOISUSER: - case RPL_WHOISSERVER: - case RPL_WHOISOPERATOR: - case RPL_WHOISIDLE: - case RPL_ENDOFWHOIS: - case RPL_WHOISCHANNELS: - case RPL_WHOISMODES: - $tmp = explode(' ', $message['params']); - $tmp = $tmp[1]; - $data = array( - 'event' => 'whois', - 'server' => '', - 'nick' => $tmp, - 'msg' => $message['trailing'] - ); - $buffer[] = json_encode($data); - break; - - case RPL_MOTD: - $data = array( - 'event' => 'motd', - 'server' => '', - 'msg' => $message['trailing'] - ); - $buffer[] = json_encode($data); - break; - - case "353": - // NAMES command reply - list($nick,,$chan) = explode(" ", $message['params']); - $nicks = explode(" ", $message['trailing']); - - $data = array( - 'event' => 'userlist', - 'server' => '', - 'users' => array(), - 'channel' => $chan - ); - - $prefixes = array('~', '&', '@','%','+'); - $nicklist = array(); - $i = 0; - foreach($nicks as $nick){ - if(in_array($nick{0}, $prefixes)){ - $prefix = $nick{0}; - $nick = substr($nick,1); - } else { - $prefix = ''; - } - $nicklist[$nick] = $prefix; - - if($i==50){ - $tmp = $data; - $tmp['users'] = $nicklist; - $buffer[] = json_encode($tmp); - unset($tmp); - $nicklist = array(); - } - - $i++; - } - - if(count($nicklist)){ - $tmp = $data; - $tmp['users'] = $nicklist; - $buffer[] = json_encode($tmp); - } - //deb(print_r($data, 1)); - break; - - case '366': - list(,$chan) = explode(' ', $message['params']); - $data = array( - 'event' => 'userlist_end', - 'server' => '', - 'channel' => $chan - ); - $buffer[] = json_encode($data); - break; - - case ERR_LINKCHANNEL: - list($nick, $source_chan, $dest_chan) = explode(' ', $message['params']); - $data = array( - 'event' => 'channel_redirect', - 'from' => $source_chan, - 'to' => $dest_chan - ); - $buffer[] = json_encode($data); - break; - - case ERR_NOSUCHNICK: - //TODO: shit - break; - - case "JOIN": - $data = array( - 'event' => 'join', - 'nick' => $message['nick'], - 'ident' => $message['ident'], - 'hostname' => $message['hostname'], - 'channel' => $message['trailing'], - ); - $buffer[] = json_encode($data); - - deb("JOIN: {$message['nick']} / {$this->nick}"); - if($message['nick'] == $this->nick){ - $this->stream->Write("NAMES {$message['trailing']}\r\n"); - } - - break; - - case "PART": - $data = array( - 'event' => 'part', - 'nick' => $message['nick'], - 'ident' => $message['ident'], - 'hostname' => $message['hostname'], - 'channel' => trim($message['params']), - 'message' => $message['trailing'], - ); - $buffer[] = json_encode($data); - break; - - case "KICK": - $tmp = explode(' ', $message['params']); - - $data = array( - 'event' => 'kick', - 'kicked' => $tmp[1], - 'nick' => $message['nick'], - 'ident' => $message['ident'], - 'hostname' => $message['hostname'], - 'channel' => trim($tmp[0]), - 'message' => $message['trailing'], - ); - $buffer[] = json_encode($data); - break; - - case "QUIT": - $data = array( - 'event' => 'quit', - 'nick' => $message['nick'], - 'ident' => $message['ident'], - 'hostname' => $message['hostname'], - 'message' => $message['trailing'], - ); - $buffer[] = json_encode($data); - break; - - case "NOTICE": - $data = array( - 'event' => 'notice', - 'nick' => $message['nick'], - 'ident' => $message['ident'], - 'hostname' => $message['hostname'], - 'msg' => $message['trailing'], - ); - $buffer[] = json_encode($data); - break; - - case "NICK": - $data = array( - 'event' => 'nick', - 'nick' => $message['nick'], - 'ident' => $message['ident'], - 'hostname' => $message['hostname'], - 'newnick' => $message['trailing'], - ); - $buffer[] = json_encode($data); - break; - - case 'TOPIC': - $data = array( - 'event' => 'topic', - 'nick' => $message['nick'], - 'channel' => $message['params'], - 'topic' => $message['trailing'] - ); - $buffer[] = json_encode($data); - break; - - case '332': - $tmp = explode(' ', $message['params']); - $data = array( - 'event' => 'topic', - 'nick' => '', - 'channel' => $tmp[1], - 'topic' => $message['trailing'] - ); - $buffer[] = json_encode($data); - break; - - case 'ACTION': - $data = array( - 'event' => 'action', - 'nick' => $message['nick'], - 'msg' => trim(substr($message['trailing'], 8), chr(1)), - 'channel' => $message['params'], - 'time' => time() - ); - $buffer[] = json_encode($data); - break; - - case 'CTCP': - $data = array( - 'event' => 'ctcp', - 'nick' => $message['nick'], - 'msg' => trim(substr($message['trailing'], 8), chr(1)), - 'channel' => $message['params'], - 'time' => time() - ); - $buffer[] = json_encode($data); - break; - - case 'MODE': - $opts = explode(' ', $message['params']); - if(count($opts) == 1){ - $effected_nick = $opts[0]; - $mode = $message['trailing']; - } elseif(count($opts) == 2){ - $channel = $opts[0]; - $mode = $opts[1]; - } else { - $channel = $opts[0]; - $mode = $opts[1]; - $effected_nick = $opts[2]; - } - - $data = array( - 'event' => 'mode', - 'nick' => $message['nick'], - 'mode' => $mode - ); - - if(isset($effected_nick)) $data['effected_nick'] = $effected_nick; - if(isset($channel)) $data['channel'] = $channel; - $buffer[] = json_encode($data); - - break; - } - - if($send_debug){ - $ret = str_replace('\n', ' ', print_r($message, 1)); - $data = array( - 'event' => 'debug', - 'msg' => $ret, - 'time' => time() - ); - $buffer[] = json_encode($data); - } - - parent::ProcessMessage($message); - } - - - - - function ProcessPrivMsg($message){ - global $buffer; - global $timeout; - global $config; - - $msg = $message['trailing']; - $cmd = strtok($msg, ' '); - //debug(print_r($message)); - //deb(print_r($message, 1)); - $data = array( - 'event' => 'msg', - 'nick' => $message['nick'], - 'msg' => $message['trailing'], - 'channel' => $message['params'], - 'time' => time() - ); - - // Save it into the scrollback - if($config['scrollback_size']){ - deb('Size: '.count($this->scrollback)); - if(count($this->scrollback) >= $config['scrollback_size']){ - - for($i=1; $iscrollback); $i++){ - $this->scrollback[$i-1] = $this->scrollback[$i]; - } - /* - for($j=$i; $jscrollback); $j++){ - unset($this->scrollback[$i]); - } - //unset($this->scrollback[$i]); - */ - $pos = count($this->scrollback)-1; - deb('Popped'); - } else { - $pos = count($this->scrollback); - } - - $this->scrollback[$pos] = $data; - } - - $buffer[] = json_encode($data); - parent::ProcessPrivMsg($message); - - return; - } - - - private function isChannel($name){ - return ($name[0] == "#"); - } - - - private function formatMsgToHtml($inp){ - $tmp = $inp; - - // Bold - if(strpos($tmp, chr(2))){ - $next = ''; - while(strpos($tmp, chr(2)) !== false){ - $pos = strpos($tmp, chr(2)); - $tmp = str_replace($tmp, chr(2), $next); - $next = ($next=='') ? '' : ''; - } - if($next == '') $tmp = $tmp . ''; - } - - return $tmp; - } - - } \ No newline at end of file diff --git a/class_session.php b/class_session.php deleted file mode 100644 index 2a31d5d..0000000 --- a/class_session.php +++ /dev/null @@ -1,115 +0,0 @@ -get('sid_'.$session_id) ? true : false; - return $ret; - } else { - $session_sok = $config['sok_dir'].$config['sok_prefix'].$session_id; - return file_exists($session_sok); - } - } - - - - static function create($client_key){ - global $config; - - $temp_id = md5(microtime().rand()); - - if($config['memcache_use']){ - $host_key = 'hostcount_'.$client_key; - $count = (int)GLOB::$mc->get($host_key); - if($count > $config['connections_per_host']) return false; - - // Save the sid into memcached for the ircbot to pick up - GLOB::$mc->add('sid_'.$temp_id, $temp_id); - } - - $session_cmd = "{$config['php_path']} {$config['session_script_path']} $temp_id $host_key -h$client_key"; - //die($session_cmd); - $session_status = `$session_cmd`; - - if($session_status != 'ok'){ - debug("Failed creating session socket with: $session_status"); - GLOB::$mc->delete('sid_'.$temp_id); - return false; - } - - if($config['memcache_use']){ - GLOB::$mc->add($host_key, 0); - GLOB::$mc->increment($host_key); - } - - return $temp_id; - } - - - - static function open($session_id){ - global $config; - - if($config['memcache_use']){ - $session_sok = GLOB::$mc->get('sid_'.$session_id); - if(!$session_sok) return false; - } else { - $session_sok = $session_id; - } - $session_sok = $config['sok_dir'].$config['sok_prefix'].$session_sok; - - $sok = @stream_socket_client('unix://'.$session_sok, $errno, $errstr); - - if(!$sok) return false; - return $sok; - } - - - - static function close($session){ - fclose($session); - } - - - static function read($session, $block=true){ - fwrite($session, json_encode(array('method'=>'read'))); - - if(!$block){ - stream_set_timeout($session, 0, 100000); - } else { - stream_set_timeout($session, 120, 0); - } - $data = fgets($session); - - return $data; - } - - - - - - static function clStart($session_id){ - global $config; - - if($config['memcache_use']){ - $session_sok = GLOB::$mc->get('sid_'.$session_id); - if(!$session_sok) return false; - } else { - $session_sok = $session_id; - } - $session_sok = $config['sok_dir'].$config['sok_prefix'].$session_sok; - - $sok = stream_socket_server('unix://'.$session_sok, $errno, $errstr); - if(!$sok) return false; - - return $sok; - - } - - - static function clStop($session){ - fclose($session); - } - } diff --git a/common.php b/common.php deleted file mode 100644 index 7085d76..0000000 --- a/common.php +++ /dev/null @@ -1,24 +0,0 @@ -addServer('localhost', 11211, true, 1); - } - - - - function deb($what){ - //if(DEBUG){ - // echo "$what\n"; - //} else { - file_put_contents('/tmp/kiwi_err.log', "$what\n", FILE_APPEND); - //} - } - function debug($what){ deb($what); } \ No newline at end of file diff --git a/dev_processClientMessage.php b/dev_processClientMessage.php deleted file mode 100644 index fffc041..0000000 --- a/dev_processClientMessage.php +++ /dev/null @@ -1,142 +0,0 @@ -'invalid_args')); - break; - } else { - $kiwi = null; - /*if($config['memcache_use']){ - $conf_key = 'kiwi_conf_'.$args['server']; - $conf = (int)GLOB::$mc->get($conf_key); - if($conf){ - $c = @unserialize($conf); - if($c){ - //$hostname = GET HOSTNAME HERE - //$ip = GET IP HERE - $kiwi = "WEBIRC {$c['password']} {$c['user']} $hostname $ip"; - } - } - }*/ - deb("ARGSLOL: ".print_r($app_args, 1)); - $opts = array(); - if(isset($app_args['remote_host'])) $opts['ident'] = md5($app_args['remote_host']); - - $bot = new IRCConnection("irc://{$args['nick']}@{$args['server']}:{$args['port']}", $kiwi, $opts); - if(isset($args['channels'])) $bot->chans = explode(',', $args['channels']); - if($bot->connected){ - // We're.. connected! - } else { - $buffer[] = json_encode(array('event'=>'server_connect', 'connected'=>false, 'host'=>$args['server'])); - unset($bot); - } - } - break; - - case 'join': - $args = $d['args']; - if(!isset($args['channel'])){ - $buffer[] = json_encode(array('error'=>'invalid_args')); - break; - } else { - $chans = explode(',', $args['channel']); - foreach($chans as $c) - $bot->Join($c); - } - break; - - case 'msg': - $args = $d['args']; - deb('msg with: '.print_r($args, 1)); - if(!isset($args['target'],$args['msg'])){ - $buffer[] = json_encode(array('error'=>'invalid_args')); - break; - } else { - $bot->SendMessage($args['target'], $args['msg']); - $buffer[] = json_encode($data); - } - break; - - case 'action': - $args = $d['args']; - deb('action with: '.print_r($args, 1)); - if(!isset($args['target'],$args['msg'])){ - $buffer[] = json_encode(array('error'=>'invalid_args')); - break; - } else { - $bot->SendMessage($args['target'], chr(1)."ACTION {$args['msg']}".chr(1)); - $buffer[] = json_encode($data); - } - break; - - case 'raw': - $args = $d['args']; - if(!isset($args['data'])){ - $buffer[] = json_encode(array('error'=>'invalid_args')); - break; - } else { - $bot->stream->Write("{$args['data']}\r\n"); - //$bot->SendMessage($args['target'], $args['msg']); - } - break; - - - case 'debug': - $send_debug = !$send_debug; - $data = array( - 'event' => 'debug', - 'msg' => 'Debugging '.($send_debug)?'on':'off', - 'time' => time() - ); - $buffer[] = json_encode($data); - break; - - - case 'sync': - // Clear the current buffer as we're gonna send only scrollback - $buffer = array(); - - // Send the settings and channels over - if($bot){ - $data = array('event'=>'sync'); - $data['nick'] = $bot->nick; - $data['tabviews'] = array(); - if($bot->chanlist){ - foreach($bot->chanlist as $chan_name => $chan){ - $data['tabviews'][] = array('name'=>$chan_name, 'userlist'=>$chan['userlist']); - } - $buffer[] = json_encode($data); - } - - // Send the message scrollback - foreach($bot->scrollback as $line) $buffer[] = json_encode($line); - //$bot->scrollback = array(); - } else { - $data = array('error'=>'no_data'); - } - - $buffer[] = json_encode($data); - - break; - } \ No newline at end of file diff --git a/embed.php b/embed.php deleted file mode 100644 index 3e286ae..0000000 --- a/embed.php +++ /dev/null @@ -1,97 +0,0 @@ - - - - -kiwi - - - - 0: - case stripos($_SERVER['HTTP_USER_AGENT'], 'iphone') > 0: - case stripos($_SERVER['HTTP_USER_AGENT'], 'ipod') > 0: -?> - - - - - - - - - - - - - - - -
-
-
- -
- - - - - - - - - - -
-
- - - - -
-
    -
    Powered by kiwi
    -
    - -
    -
      -
      - - -
      -
      -
      :
      - -
      - -
      -
      - - - diff --git a/index.html b/index.html deleted file mode 100644 index e69de29..0000000 diff --git a/index.lighttpd.html b/index.lighttpd.html deleted file mode 100644 index e639955..0000000 --- a/index.lighttpd.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - -Welcome page - - - -
      - -
      -

      You should replace this page with your own web pages as soon as possible.

      - Unless you changed its configuration, your new server is configured as follows: -
        -
      • Configuration files can be found in /etc/lighttpd. Please read /etc/lighttpd/conf-available/README file.
      • -
      • The DocumentRoot, which is the directory under which all your HTML files should exist, is set to /var/www.
      • -
      • CGI scripts are looked for in /usr/lib/cgi-bin, which is where Ubuntu packages will place their scripts. You can enable cgi module by using command "lighty-enable-mod cgi".
      • -
      • Log files are placed in /var/log/lighttpd, and will be rotated weekly. The frequency of rotation can be easily changed by editing /etc/logrotate.d/lighttpd.
      • -
      • The default directory index is index.html, meaning that requests for a directory /foo/bar/ will give the contents of the file /var/www/foo/bar/index.html if it exists (assuming that /var/www is your DocumentRoot).
      • -
      • You can enable user directories by using command "lighty-enable-mod userdir"
      • -
      -

      About this page

      -

      - This is a placeholder page installed by the Ubuntu release of the Lighttpd server package. -

      -

      - This computer has installed the Ubuntu operating system, but it has nothing to do with the Ubuntu Project. Please do not contact the Ubuntu Project about it. -

      -

      - If you find a bug in this Lighttpd package, or in Lighttpd itself, please file a bug report on it. Instructions on doing this, and the list of known bugs of this package, can be found in the - Ubuntu Bug Tracking System. -

      -

      - Valid XHTML 1.0 Transitional -

      -
      -
      - - - diff --git a/index_old.php b/index_old.php deleted file mode 100644 index 7f4d827..0000000 --- a/index_old.php +++ /dev/null @@ -1,130 +0,0 @@ - 0: - $agent = "android"; $touchscreen = true; - break; - - case stripos($_SERVER['HTTP_USER_AGENT'], 'iphone') > 0: - $agent = "iphone"; $touchscreen = true; - break; - - case stripos($_SERVER['HTTP_USER_AGENT'], 'ipod') > 0: - $agent = "ipod"; $touchscreen = true; - break; - - case stripos($_SERVER['HTTP_USER_AGENT'], 'ipad') > 0: - $agent = "ipad"; $touchscreen = true; - break; - - default: - $agent = "normal"; - $touchscreen = false; - } -?> - - - - - - - - - -kiwi - - - - - - - - - - - - - - - - - - - - - - - - -
      -
      -

      kiwi

      -

      An alternative to downloading an irc client. This web app is the best thing you'll use in the next couple years.

      - -
      - -
      -
      - -
      - - - - - - - - - - -
      -
      - - - -
      -
      Powered by kiwi
      -
        -
        - -
        -
          -
          - -
          - -
          -
          -
          :
          - -
          - -
          -
          - - - \ No newline at end of file diff --git a/inf.php b/inf.php deleted file mode 100644 index 9c66bb6..0000000 --- a/inf.php +++ /dev/null @@ -1,5 +0,0 @@ -= $config['timeout']) break; - } else { - $timeout = 0; - } - - processClients(); - - if($bot != null){ - // $bot handles the sleep time here - $bot->Process(); - } else { - usleep(5000); - } - } - - - // We've quit, lower the counter for this host - if($config['memcache_use']){ - @GLOB::$mc->decrement($host_key); - } - - deb('Exiting client'); - - - ############################################ - ## Functions / Classes - ############################################ - - - - function processClients(){ - global $ipc_srv; - global $ipc; - global $ipc_read; - global $buffer; - global $timeout; - - // Check for any new web client connections... - $read = array($ipc_srv); - $write = $excep = array(); - $read_changed = stream_select($read, $write, $excep, 0); - for($i=0; $i<$read_changed; $i++) { - if($read[$i] === $ipc_srv){ - $ipc[] = stream_socket_accept($ipc_srv); - deb("Connection..."); - } - } - - - // Check for any changed web clients.. - $read = $ipc; - $read_changed = (count($read)) ? stream_select($read, $write, $excep, 0) : array(); - if($read_changed){ - foreach($read as $cl){ - $data = fread($cl, 1024); - if(!$data){ - // Web client has disconnected - deb("Removing closed socket.."); - $key = array_search($cl, $ipc); - unset($ipc[$key]); - - $key = array_search($cl, $ipc_read); - if($key !== false) unset($ipc_read[$key]); - } else { - //deb('Got data: '.$data); - processClientMessage($data, $cl); - } - } - } - - - - // Send the buffer messages to any connected web clients.. - // 1 message at a time... - if(count($buffer) && count($ipc_read)){ - //deb(print_r($ipc_read, 1)); - $msg = array_shift($buffer); - //deb("Sending '$msg' to ".count($ipc_read)." clients.."); - foreach($ipc_read as $cl){ - if($cl) fwrite($cl, $msg."\n"); - } - } - - // The whole buffer at a time... - /* - while(count($buffer)){ - $msg = array_shift($buffer); - foreach($ipc as $cl) frwite($cl, $msg); - } - */ - - } - - - function processClientMessage($data, $cl){ - global $config; - global $buffer; - global $bot, $ipc_read; - global $timeout; - global $send_debug; - global $app_args; - - require('dev_processClientMessage.php'); - return true; - } - - - - - function errorHandler($errno, $errstr, $errfile, $errline){ - $ret = ''; - switch ($errno) { - case E_USER_ERROR: - $ret .= "USER [$errno] $errstr\n"; - $ret .= " Fatal error on line $errline in file $errfile"; - $ret .= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")\n"; - $ret .= "Aborting...
          \n"; - exit(1); - break; - - case E_USER_WARNING: - $ret .= "WARNING on line $errline in file $errfile: [$errno] $errstr\n"; - break; - - case E_USER_NOTICE: - $ret .= "NOTICE on line $errline in file $errfile: [$errno] $errstr\n"; - break; - - default: - $ret .= "UNKOWN ERR on line $errline in file $errfile: [$errno] $errstr\n"; - break; - } - - if(!empty($ret)) deb($ret); - - - /* Don't execute PHP internal error handler */ - return true; - } \ No newline at end of file diff --git a/js/front_backup.js b/js/front_backup.js deleted file mode 100644 index 920359d..0000000 --- a/js/front_backup.js +++ /dev/null @@ -1,143 +0,0 @@ -var front = { - cur_channel: '', - windows: {}, - - - init: function(){ - front.registerKeys(); - - gateway.nick = 'kiwiclone'; - gateway.session_id = null; - gateway.onMsg = front.onMsg; - gateway.onNotice = front.onNotice; - gateway.onMOTD = front.onMOTD; - gateway.onConnect = front.onConnect; - gateway.onUserList = front.onUserList; - - front.doLayout(); - front.windowAdd('server'); - gateway.poll(); - }, - - doLayout: function(){ - $('#kiwi .msginput .nick a').text(gateway.nick); - }, - - - onMsg: function(data){ - front.addMsg(null, data.nick,data.msg,data.channel); - }, - onNotice: function(data){ - front.addMsg(null, data.nick, '--> '+data.msg); - }, - onConnect: function(data){ - if(data.connected){ - front.addMsg(null, ' ', '--> Connected to '+data.host); - } else { - front.addMsg(null, ' ', '--> Failed to connect to '+data.host); - } - }, - onMOTD: function(data){ - front.addMsg(null, data.server, data.msg); - }, - onUserList: function(data){ - $.each(data.users, function(i,item){ - $('
        • '+i+'
        • ').appendTo('#kiwi .userlist ul'); - }); - }, - - registerKeys: function(){ - $('input').keypress(function(e){ - if(e.which == 13){ - var msg = $('#kiwi_msginput').val(); - if(msg.substring(0,1) == '/'){ - var parts = msg.split(' '); - switch(parts[0]){ - case '/join': - if(front.windows[parts[1]] == undefined){ - gateway.join(parts[1].replace('#', '')); - front.windowAdd(parts[1]); - } else { - front.windowShow(parts[1]); - } - break; - - case '/connect': - if(parts[1] == undefined){ - alert('Usage: /connect servername [port]'); - break; - } - - if(parts[2] == undefined) parts[2] = 6667; - front.addMsg(null, ' ', '--> Connecting to '+parts[1]+'...'); - gateway.connect(parts[1], parts[2], 0); - break; - - default: - front.addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1)); - } - - } else { - gateway.msg(front.cur_channel, msg); - var d = new Date(); - var d = d.getHours() + ":" + d.getMinutes(); - front.addMsg(d, gateway.nick, msg); - } - $('#kiwi_msginput').val(''); - } - }); - }, - - - - addMsg: function(time, nick, msg, channel){ - var html_nick = $('
          ').text(nick).html(); - var html_msg = $('
          ').text(msg).html()+' '; // Add the space so the styling always has at least 1 character to go from - if(time == null){ - var d = new Date(); - time = d.getHours() + ":" + d.getMinutes(); - } - - var msg = '
          '+time+'
          '+html_nick+'
          '+html_msg+'
          '; - if(channel == undefined){ - var messages = $("#kiwi_window_server"); - } else { - var messages = $("#kiwi_window_chan_"+channel.replace('#', '')); - } - messages.append(msg); - messages.attr({ scrollTop: messages.attr("scrollHeight") }); - }, - - - - windowExists: function(name){ - return !(front.windows[name] == undefined); - }, - windowAdd: function(v_name){ - var tmp_divname = 'kiwi_window_'+v_name.replace('#', 'chan_'); - front.windows[v_name] = { name: v_name, div_id: tmp_divname }; - $('#kiwi').append('
          '); - $('#kiwi .windowlist ul').append('
        • '+v_name+'
        • '); - //$('#kiwi .windowlist ul .window_'+v_name).click(function(){ front.windowShow(v_name); }); - front.windowShow(v_name); - - /* - var t = ""; - for (key in front.windows) - t += "Element value is " + front.windows[key].div_id + "\n"; - - alert(t); - */ - }, - windowDiv: function(name){ - if(!front.windowExists(name)) return false; - return $('#'+front.windows[name].div_id); - }, - windowShow: function(name){ - if(!front.windowExists(name)) return false; - $('#kiwi .messages').removeClass("active"); - var tmp = front.windowDiv(name); - tmp.addClass('active'); - front.cur_channel = name; - } -} \ No newline at end of file diff --git a/layout.html b/layout.html deleted file mode 100644 index 33dee7e..0000000 --- a/layout.html +++ /dev/null @@ -1,107 +0,0 @@ - - - - -Kiwi IRC - - - - - - - - -
          -

          Kiwi IRC

          -
          -
          -
          -
            -
          • -
          • -
          - Connect » -
          - -
          - More -
          -
            -
          • -
          • -
          • -
          • -
          - Connect » -
          -
          -
          -
          -
          - - - diff --git a/poll.php b/poll.php deleted file mode 100644 index 91a6a5f..0000000 --- a/poll.php +++ /dev/null @@ -1,110 +0,0 @@ -'session_error'))); - } - - // Session create OK, yay - die(gen_response(array('session_id'=>$new_session))); - } - - - - ############################################ - ## Existing sessions - ############################################ - - // Quit here if a session hasn't been specified - if(!isset($_POST['sid']) || empty($_POST['sid'])){ - die(gen_response(array('error'=>'session_not_set'))); - } - - $session_id = $_POST['sid']; - - // Make sure the session exists - if(!SESSIONS::exists($session_id)){ - die(gen_response(array('error'=>'no_session'))); - } - - // Connect to the IRC session - $ses = SESSIONS::open($session_id); - if(!$ses){ - die(gen_response(array('error'=>'session_error'))); - } - - if(!isset($_POST['data'])){ - // Read any commands to be sent to the web client - $data = array(); - - /* This was used for blocking the first call which caused a wait of timeout seconds if the user quits - // Make this read block - $tmp = json_decode(trim(SESSIONS::read($ses, true)),1); - if($tmp != null) $data[] = $tmp; - */ - - // Unblocked reads just incase only 1 message is actually available - $start_time = time(); - while(time() - $start_time < $config['max_time_per_poll'] && count($data) == 0 && !connection_aborted()){ - for($i=0; $i<$config['messages_per_poll']; $i++){ - if(connection_aborted()){ - deb("Connection aborted"); - break; - } - deb("Polling.."); - $tmp = json_decode(trim(SESSIONS::read($ses, false)),1); - if($tmp != null){ - $data[] = $tmp; - } else { - break; - } - - echo " "; - flush(); - } - - if(count($data) == 0) sleep(1); - } - deb("Polled"); - - if(!empty($data)){ - echo gen_response($data); - } else { - echo gen_response(array()); - } - } else { - fwrite($ses, $_POST['data']); - } - - // We're done here, close the session connection - SESSIONS::close($ses); - - - - - - - - - - ############################################ - ## Functions - ############################################ - - function gen_response($data){ - return json_encode($data); - } diff --git a/test.html b/test.html deleted file mode 100644 index 9a55f7a..0000000 --- a/test.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/ws.html b/ws.html deleted file mode 100644 index a4a38ad..0000000 --- a/ws.html +++ /dev/null @@ -1,11 +0,0 @@ - \ No newline at end of file diff --git a/ws.php b/ws.php deleted file mode 100644 index 315c137..0000000 --- a/ws.php +++ /dev/null @@ -1,324 +0,0 @@ -ircsocket - $pairs = array(); - - // Stores all sockets - $soks = array(); - - // Handshaken sockets - $handshakes = array(); - - - - require(dirname(__FILE__).'/config.php'); - require(dirname(__FILE__).'/common.php'); - require(dirname(__FILE__).'/class_session.php'); - - - error_reporting(E_ALL); - set_time_limit(0); - ob_implicit_flush(); - - $server = WebSocket($config['websocket']['bind_addr'], $config['websocket']['bind_port']); - $soks[(int)$server] = $server; - $last_dump = 0; - while(1){ - echo time()." - $last_dump (".(time() - $last_dump).")\n"; - if(time() - $last_dump >= 3){ - $last_dump = time(); - echo "\nPairs: "; - var_dump($pairs); - - echo "\nSoks: "; - var_dump($soks); - } - - $changed = $soks; - stream_select($changed, $write=NULL, $except=NULL, NULL); - - foreach($changed as $socket){ - // New connection? - if($socket == $server){ - $client = stream_socket_accept($server); - if($client<0){ - console("socket_accept() failed"); continue; - } else { - connect($client); - } - } else { - - $buffer = fread($socket, 2048); - if($buffer === false || $buffer == ''){ - // Disconnected - disconnect($socket); - } else { - //$buffer = substr($buffer, 0, strlen($buffer)); - //console("INCOMING:\n".$buffer."########\n"); - if(isset($handshakes[(int)$socket])){ - // websocket upgrade - dohandshake($socket, $buffer); - } else { - // Data transfering.. - transfer($socket, $buffer); - } - } - - } - } - } - - - - - function WebSocket($address,$port){ - //$master=socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("socket_create() failed"); - $master = stream_socket_server("tcp://$address:$port") or die("socket_create() failed"); - //socket_set_option($master, SOL_SOCKET, SO_REUSEADDR, 1) or die("socket_option() failed"); - //socket_bind($master, $address, $port) or die("socket_bind() failed"); - //socket_listen($master,20) or die("socket_listen() failed"); - echo "Server Started : ".date('Y-m-d H:i:s')."\n"; - echo "Master socket : ".$master."\n"; - echo "Listening on : ".$address." port ".$port."\n\n"; - return $master; - } - - - - - - function connect($socket){ - global $soks, $pairs, $handshakes; - - //$session_id = SESSIONS::create(); - //if(!$session_id) return false; - - //$pairs[$socket]= SESSION::open($session_id); - - $soks[(int)$socket] = $socket; - $handshakes[(int)$socket] = false; - //array_push($soks, $pairs[$socket]); - - console($socket." connection.."); - } - - function disconnect($sok){ - global $soks, $pairs; - console("disconnected?\n"); - - $pair = findPair($sok); - if($pair === false) return false; - foreach($pair as $websocket => $local_con){ - @fclose($soks[$websocket]); - unset($soks[$websocket]); - - @fclose($soks[$local_con]); - unset($soks[$local_con]); - - unset($pairs[$websocket]); - } - - console($sok." DISCONNECTED!"); - } - - function transfer($sok, $buffer){ - global $soks, $pairs; - console("Transfering data?\n"); - - $pair = findPair($sok); - if($pair === false) return false; - - console("Transfering ".strlen($buffer)." bytes.. '".$buffer."'"); - //$buffer = wrap($buffer); - foreach($pair as $websocket => $local_con){ - if($sok == $soks[$websocket]){ - // From websocket.. - fwrite($soks[$local_con], unwrap($buffer)); - break; - } elseif($sok == $soks[$local_con]){ - // From irc client - fwrite($soks[$websocket], chr(0).$buffer.chr(255)); - break; - } - } - } - - function findPair($socket){ - global $soks, $pairs; - console("Finding pair: ".(int)$socket."\n"); - - // If it's a websocket, then this will find it.. - if(isset($pairs[(int)$socket])) - return array((int)$socket=>$pairs[(int)$socket]); - - // If it's an irc client socket, then we will find it when flipped.. - $flipped = array_flip($pairs); - if(isset($flipped[(int)$socket])) - return array($flipped[(int)$socket] => (int)$socket); - - return false; - } - - function dohandshake($sok, $buffer){ - global $handshakes, $soks, $pairs; - console("\nRequesting handshake..."); - - console("Handshaking..."); - /* - list($resource, $host, $origin) = getheaders($buffer); - $upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . - "Upgrade: WebSocket\r\n" . - "Connection: Upgrade\r\n" . - "WebSocket-Origin: " . $origin . "\r\n" . - "WebSocket-Location: ws://" . $host . $resource . "\r\n" . - "\r\n"; - */ - if(!strpos($buffer, 'WebSocket-Key1:')){ - $upgrade = (string)new WebSocket75($buffer); - } else { - $upgrade = (string)new WebSocket76($buffer); - } - - fwrite($sok, $upgrade.chr(0)); - - // Done the handshake so remove it from the handshaking array - unset($handshakes[(int)$sok]); - - console("Done handshaking..."); - - //socket_getsockname($sok, $sok_name); - $sok_name = stream_socket_get_name($sok, true); - $session_id = SESSIONS::create($sok_name); - if(!$session_id) return false; - $irc_client_sok = SESSIONS::open($session_id); - - $soks[(int)$irc_client_sok] = $irc_client_sok; - $pairs[(int)$sok] = (int)$irc_client_sok; - - fwrite($irc_client_sok, json_encode(array('method'=>'read'))); - - console($sok." CONNECTED!"); - return true; - } - - - - - - class WebSocket75 { - private $__value__; - - public function __toString() { - return $this->__value__; - } - - public function __construct($buffer){ - list($resource, $host, $origin) = $this->getheaders($buffer); - $upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . - "Upgrade: WebSocket\r\n" . - "Connection: Upgrade\r\n" . - "WebSocket-Origin: " . $origin . "\r\n" . - "WebSocket-Location: ws://" . $host . $resource . "\r\n" . - "\r\n"; - - $this->__value__ = $upgrade; - } - - private function getheaders($req){ - $r=$h=$o=null; - if(preg_match("/GET (.*) HTTP/" ,$req,$match)){ $r=$match[1]; } - if(preg_match("/Host: (.*)\r\n/" ,$req,$match)){ $h=$match[1]; } - if(preg_match("/Origin: (.*)\r\n/",$req,$match)){ $o=$match[1]; } - return array($r,$h,$o); - } - } - - - class WebSocket76 { - - /*! Easy way to handshake a WebSocket via draft-ietf-hybi-thewebsocketprotocol-00 - * @link http://www.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-00.txt - * @author Andrea Giammarchi - * @blog webreflection.blogspot.com - * @date 4th June 2010 - * @example - * // via function call ... - * $handshake = WebSocketHandshake($buffer); - * // ... or via class - * $handshake = (string)new WebSocketHandshake($buffer); - * - * socket_write($socket, $handshake, strlen($handshake)); - */ - - private $__value__; - - public function __construct($buffer) { - $resource = $host = $origin = $key1 = $key2 = $protocol = $code = $handshake = null; - preg_match('#GET (.*?) HTTP#', $buffer, $match) && $resource = $match[1]; - preg_match("#Host: (.*?)\r\n#", $buffer, $match) && $host = $match[1]; - preg_match("#Sec-WebSocket-Key1: (.*?)\r\n#", $buffer, $match) && $key1 = $match[1]; - preg_match("#Sec-WebSocket-Key2: (.*?)\r\n#", $buffer, $match) && $key2 = $match[1]; - preg_match("#Sec-WebSocket-Protocol: (.*?)\r\n#", $buffer, $match) && $protocol = $match[1]; - preg_match("#Origin: (.*?)\r\n#", $buffer, $match) && $origin = $match[1]; - preg_match("#\r\n(.*?)\$#", $buffer, $match) && $code = $match[1]; - $this->__value__ = - "HTTP/1.1 101 WebSocket Protocol Handshake\r\n". - "Upgrade: WebSocket\r\n". - "Connection: Upgrade\r\n". - "Sec-WebSocket-Origin: {$origin}\r\n". - "Sec-WebSocket-Location: ws://{$host}{$resource}\r\n". - ($protocol ? "Sec-WebSocket-Protocol: {$protocol}\r\n" : ""). - "\r\n". - $this->_createHandshakeThingy($key1, $key2, $code) - ; - } - - public function __toString() { - return $this->__value__; - } - - private function _doStuffToObtainAnInt32($key) { - return preg_match_all('#[0-9]#', $key, $number) && preg_match_all('# #', $key, $space) ? - implode('', $number[0]) / count($space[0]) : - '' - ; - } - - private function _createHandshakeThingy($key1, $key2, $code) { - return md5( - pack('N', $this->_doStuffToObtainAnInt32($key1)). - pack('N', $this->_doStuffToObtainAnInt32($key2)). - $code, - true - ); - } - } - - -function say($msg=""){ echo $msg."\n"; } -function wrap($msg=""){ return chr(0).$msg.chr(255); } -function unwrap($msg=""){ return substr($msg,1,strlen($msg)-2); } -function console($msg=""){ global $debug; if($debug){ echo time().' '.trim($msg)."\n"; } } -- 2.25.1