Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class blowfish {
- public function bytetob64($ec) {
- $dc = "";
- $k = 0 - 1;
- do {
- if (!($k < strlen($ec) - 1)) {
- break;
- } else {
- ++$k;
- $left = ord($ec[$k]) << 24;
- ++$k;
- $left+= ord($ec[$k]) << 16;
- ++$k;
- $left+= ord($ec[$k]) << 8;
- ++$k;
- $left+= ord($ec[$k]);
- ++$k;
- $right = ord($ec[$k]) << 24;
- ++$k;
- $right+= ord($ec[$k]) << 16;
- ++$k;
- $right+= ord($ec[$k]) << 8;
- ++$k;
- $right+= ord($ec[$k]);
- $i = 0;
- }
- while ($i < 6) {
- $dc.= $this->B64[$right & 63];
- $right = $right >> 6;
- ++$i;
- }
- $i = 0;
- do {
- }
- while (!($i < 6));
- $dc.= $this->B64[$left & 63];
- $left = $left >> 6;
- ++$i;
- }
- while (1);
- return $dc;
- }
- public function b64tobyte($ec) {
- $dc = "";
- $k = 0 - 1;
- do {
- if (!($k < strlen($ec) - 1)) {
- break;
- } else {
- $right = 0;
- $left = 0;
- $i = 0;
- }
- while ($i < 6) {
- ++$k;
- $right|= @strpos(@$this->B64, @$ec[$k]) << $i * 6;
- ++$i;
- }
- $i = 0;
- while ($i < 6) {
- ++$k;
- $left|= @strpos(@$this->B64, @$ec[$k]) << $i * 6;
- ++$i;
- }
- $i = 0;
- while ($i < 4) {
- $dc.= chr(($left & 255 << (3 - $i) * 8) >> (3 - $i) * 8);
- ++$i;
- }
- $i = 0;
- do {
- }
- while (!($i < 4));
- $dc.= chr(($right & 255 << (3 - $i) * 8) >> (3 - $i) * 8);
- ++$i;
- }
- while (1);
- return $dc;
- }
- public function encrypt($text, $key) {
- $td = mcrypt_module_open(MCRYPT_BLOWFISH, "", MCRYPT_MODE_ECB, "");
- $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
- $text.= str_repeat(chr(0), 8 - strlen($text) % 8);
- mcrypt_generic_init($td, $key, $iv);
- $ec = mcrypt_generic($td, $text);
- mcrypt_module_close($td);
- return bytetoB64($ec);
- }
- public function decrypt($text, $key) {
- $td = mcrypt_module_open(MCRYPT_BLOWFISH, "", MCRYPT_MODE_ECB, "");
- $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
- mcrypt_generic_init($td, $key, $iv);
- $tmp = mdecrypt_generic($td, B64tobyte($text));
- $tmp = str_replace(chr(0), "", $tmp);
- mcrypt_module_close($td);
- return $tmp;
- }
- }
- function mquery($query) {
- if (debugoutput == 1) {
- if (!($sql = mysql_query($query))) {
- exit(mysql_error());
- }
- echo "MySQL -> " . $query . "\r\n";
- } else {
- $sql = mysql_query($query);
- }
- return $sql;
- }
- function cw($data, $word) {
- if (strtolower(substr($data, 0, strlen($word))) == $word) {
- return true;
- }
- return false;
- }
- function checkadmin($uid, $reqlvl) {
- $userlvl = mysql_result(mquery("select admin from users where id='" . $uid . "'"), 0);
- if ($reqlvl <= $userlvl) {
- return true;
- }
- return false;
- }
- function escape($text) {
- $text = str_replace("\\", "\\\\", $text);
- $text = str_replace("-", "\\-", $text);
- $text = str_replace("^", "\\^", $text);
- $text = str_replace("`", "\\`", $text);
- $text = str_replace("[", "\\[", $text);
- $text = str_replace("]", "\\]", $text);
- $text = str_replace("}", "\\}", $text);
- $text = str_replace("{", "\\}", $text);
- $text = str_replace("|", "\\|", $text);
- $text = str_replace("_", "\\_", $text);
- return $text;
- }
- define("starttime", time());
- define("version", "0.18-beta");
- $lastpingrequest = time();
- include ("./config.php");
- if (license != "ACCEPT") {
- echo "You have to accept the license before you can use this software, see the config.\r\n";
- exit();
- }
- $versioncheck = @file_get_contents("http://78.108.54.18/phpbnc.php?version=status");
- if ($versioncheck == false) {
- echo "Cant contact beta server, please make sure you can reach 78.108.54.18 on port 80 tcp.\r\n";
- exit();
- } else if (substr($versioncheck, 0, 4) == "LIVE") {
- echo "The live version of phpBNC has been released, you wont be able to use this beta version anymore.\r\n";
- exit();
- } else if (substr(version, 0, 4) < substr($versioncheck, strlen($versionchecker) - 4, 4)) {
- echo "There has been a new version released for phpBNC, I suggest you upgrade to that.\r\n";
- sleep(5);
- }
- unset($versioncheck);
- echo "Connecting to MySQL...\r\n";
- if (!($connecta = mysql_connect(myhost, myuser, mypwd))) {
- exit(mysql_error());
- }
- if (!mysql_select_db(mydb)) {
- exit(mysql_error());
- }
- echo "Connected to MySQL.\r\n";
- mquery("TRUNCATE TABLE `tempchannels`");
- mquery("update users set net_name=''");
- mquery("update users set currentnick=nick");
- $sockets = array();
- echo "Starting listening sockets...\r\n";
- foreach($listen as $ipet) {
- if (substr($ipet, 0, 3) == "ssl") {
- $context = stream_context_create();
- stream_context_set_option($context, "ssl", "local_cert", sslcert);
- stream_context_set_option($context, "ssl", "passphrase", sslkey);
- stream_context_set_option($context, "ssl", "allow_self_signed", true);
- stream_context_set_option($context, "ssl", "verify_peer", false);
- $sock = stream_socket_server($ipet, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);
- stream_set_blocking($sock, false);
- echo $errno . " " . $errstr . "\r\n";
- $sockets[] = $sock;
- unset($sock);
- } else {
- $sock = stream_socket_server($ipet, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN);
- echo $errno . " " . $errstr . "\r\n";
- $sockets[] = $sock;
- unset($sock);
- }
- unset($errno);
- unset($errstr);
- }
- unset($listen);
- unset($ipt);
- if (enableident) {
- $sock3 = stream_socket_server("tcp://" . identdip . ":" . identdport, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN);
- echo $errno . " " . $errstr . "\r\n";
- }
- echo "Sockets up and runnning.\r\n";
- $clients = array();
- if (enableident) {
- $identd = array($sock3);
- }
- $authed = array();
- $net_clients = array();
- $ident_ports = array();
- $admins = array();
- $tempnicks = array();
- $queue = array();
- $userconmem = array();
- echo "Loading usersettings into memory...\r\n";
- $usersettings = array();
- $sql = mquery("select * from users order by id asc");
- while ($RS = mysql_fetch_array($sql)) {
- $usersettings[$RS['id']]['nick'] = $RS['nick'];
- $usersettings[$RS['id']]['nickreq'] = "";
- $usersettings[$RS['id']]['currentnick'] = $RS['currentnick'];
- $usersettings[$RS['id']]['tempnick'] = $RS['nick'];
- $usersettings[$RS['id']]['username'] = $RS['username'];
- $usersettings[$RS['id']]['host'] = $RS['host'];
- $usersettings[$RS['id']]['away_nick'] = $RS['away_nick'];
- $usersettings[$RS['id']]['away_msg'] = $RS['away_msg'];
- $usersettings[$RS['id']]['admin'] = $RS['admin'];
- $usersettings[$RS['id']]['net_name'] = $RS['net_name'];
- $usersettings[$RS['id']]['trailed'] = $RS['trailed'];
- $usersettings[$RS['id']]['channellog'] = $RS['channellog'];
- $usersettings[$RS['id']]['flood'] = $RS['flood'];
- $usersettings[$RS['id']]['lastlogin'] = "";
- $usersettings[$RS['id']]['lastcommand'] = time();
- $usersettings[$RS['id']]['delay'] = 0;
- $usersettings[$RS['id']]['lastcontry'] = time();
- }
- echo "Loaded usersettings into memory.\r\n";
- echo "Loading blowfish keys into memory...\r\n";
- $bfkeys = array();
- $sql = mquery("select * from blowfish_keys order by id asc");
- while ($RS = mysql_fetch_array($sql)) {
- $bfkeys[$RS['uid']][$RS['target']]['name'] = $RS['target'];
- $bfkeys[$RS['uid']][$RS['target']]['target_nick'] = $RS['target_nick'];
- $bfkeys[$RS['uid']][$RS['target']]['key'] = $RS['key'];
- }
- echo "Loaded blowfish keys into memory.\r\n";
- $Var_8328->blowfish();
- $crypt = $Var_8328;
- echo "Im good to go, phpBNC v." . version . ", http://www.phpBNC.se/\r\n";
- echo "Starting in..";
- sleep(1);
- echo "5..";
- sleep(1);
- echo "4..";
- sleep(1);
- echo "3..";
- sleep(1);
- echo "2..";
- sleep(1);
- echo "1..\r\n";
- $lastmysqlcheck = time();
- $mysql_connection = "up";
- while (true) {
- unset($uid);
- usleep(10000);
- if (0 < count($queue)) {
- foreach($queue as $key => $qval1) {
- foreach($qval1 as $uid => $qval2) {
- foreach($qval2 as $sendtime => $qval3) {
- if (!($sendtime < time())) {
- continue;
- } else if (array_key_exists($uid, $net_clients)) {
- fwrite($net_clients[$uid], $qval3['command']);
- unset($queue[$key]);
- unset($key);
- unset($qval1);
- unset($qval2);
- unset($qval3);
- unset($sendtime);
- } else {
- unset($queue[$key]);
- unset($key);
- unset($qval1);
- unset($qval2);
- unset($qval3);
- unset($sendtime);
- }
- }
- }
- }
- }
- if ($lastmysqlcheck < time() - 60 || $mysql_connection == "down" && $lastmysqlcheck < time() - 15) {
- if (!mysql_ping($connecta)) {
- $mysql_connection = "down";
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "4MySQL:" . chr(3) . chr(2) . " Lost connection to mysql server.\r\n");
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "4MySQL:" . chr(3) . chr(2) . " Trying to reconnect..\r\n");
- }
- }
- }
- mysql_close($connecta);
- unset($connecta);
- $connecta = mysql_connect(myhost, myuser, mypwd);
- mysql_select_db(mydb);
- if (!mysql_ping($connecta)) {
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "4MySQL:" . chr(3) . chr(2) . " Can´t connect to mysql again, seems to be down.. testing again in 30 seconds\r\n");
- }
- }
- }
- $mysql_connection = "down";
- } else {
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "3MySQL:" . chr(3) . chr(2) . " Connected to mysql server again, updating usermemory and bfkeys incase its out of sync.\r\n");
- unset($usersettings);
- $usersettings = array();
- $sql = mquery("select * from users order by id asc");
- while ($RS = mysql_fetch_array($sql)) {
- $usersettings[$RS['id']]['nick'] = $RS['nick'];
- $usersettings[$RS['id']]['nick'] = $RS['currentnick'];
- $usersettings[$RS['id']]['username'] = $RS['username'];
- $usersettings[$RS['id']]['host'] = $RS['host'];
- $usersettings[$RS['id']]['away_nick'] = $RS['away_nick'];
- $usersettings[$RS['id']]['away_msg'] = $RS['away_msg'];
- $usersettings[$RS['id']]['admin'] = $RS['admin'];
- $usersettings[$RS['id']]['net_name'] = $RS['net_name'];
- $usersettings[$RS['id']]['trailed'] = $RS['trailed'];
- $usersettings[$RS['id']]['channellog'] = $RS['channellog'];
- $usersettings[$RS['id']]['flood'] = $RS['flood'];
- $usersettings[$RS['id']]['lastlogin'] = "";
- $usersettings[$RS['id']]['lastcommand'] = time();
- $usersettings[$RS['id']]['delay'] = 0;
- }
- unset($bfkeys);
- $bfkeys = array();
- $sql = mquery("select * from blowfish_keys order by id asc");
- do {
- if ($RS = mysql_fetch_array($sql)) {
- $bfkeys[$RS['uid']][$RS['target']]['name'] = $RS['target'];
- $bfkeys[$RS['uid']][$RS['target']]['target_nick'] = $RS['target_nick'];
- $bfkeys[$RS['uid']][$RS['target']]['key'] = $RS['key'];
- }
- }
- while (1);
- }
- }
- }
- $mysql_connection = "up";
- }
- } else {
- $mysql_connection = "up";
- }
- $lastmysqlcheck = time();
- }
- if (enableident) {
- $read = array_merge(array_values($clients), array_values($sockets), array_values($net_clients), array_values($identd));
- } else {
- $read = array_merge(array_values($clients), array_values($sockets), array_values($net_clients));
- }
- if (0 < stream_select($read, $write = NULL, $except = NULL, 0)) {
- foreach($sockets as $sock) {
- if (@(in_array($sock, $read) && !in_array($sock, $net_clients) && !in_array(@$sock, @$identd))) {
- $clients[] = $newsock = @stream_socket_accept(@$sock);
- stream_set_timeout($newsock, 5);
- stream_set_blocking($newsock, false);
- $currentonline = count($clients);
- @fwrite(@$newsock, @":phpBNC 375 you : \r\n" . (":phpBNC 372 you : \r\n") . ":phpBNC 372 you : _ ___ __ ___ \r\n" . ":phpBNC 372 you : _ __ | |__ _ __ / __\\ /\\ \\ \\ / __\\ \r\n" . ":phpBNC 372 you : | '_ \\ | '_ \\ | '_ \\ /__\\// / \\/ // / \r\n" . ":phpBNC 372 you : | |_) || | | || |_) |/ \\/ \\/ /\\ // /___ \r\n" . ":phpBNC 372 you : | .__/ |_| |_|| .__/ \\_____/\\_\\ \\/ \\____/ \r\n" . ":phpBNC 372 you : |_| |_| \r\n" . ":phpBNC 372 you : By Daniel \"blodan\" Ylitalo \r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 372 you : www.phpBNC.se / .com / .org / .eu / .net / .nu\r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 372 you : There are " . @$currentonline . " client(s) connected to the BNC server.\r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 372 you : Please login using /login <username> <password>\r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 372 you : \r\n" . ":phpBNC 376 you : \r\n" . ":phpBNC NOTICE you :If you have skip MOTD activated i suggest you deactivate it now.\r\n");
- unset($currentonline);
- $ip = explode(":", @stream_socket_get_name(@$newsock, @true));
- echo "New client connected: " . $ip[0] . "\r\n";
- unset($ip);
- $key = array_search($sock, $read);
- unset($read[$key]);
- unset($key);
- unset($newsock);
- }
- }
- if (in_array($sock3, $read) && !in_array($sock3, $net_clients) && !in_array($sock3, $clients) && enableident == true) {
- $identd[] = $newsock = @stream_socket_accept(@$sock3);
- stream_set_blocking($newsock, 0);
- $ip = explode(":", @stream_socket_get_name(@$newsock, @true));
- echo "New identd connection: " . $ip[0] . "\r\n";
- unset($ip);
- $key = array_search($sock3, $read);
- unset($read[$key]);
- unset($key);
- unset($newsock);
- }
- foreach($read as $read_sock) {
- unset($data);
- unset($uid);
- $nfo = stream_get_meta_data($read_sock);
- $data = fgets($read_sock);
- if (preg_match("/^ERROR :Closing Link: (.*)$/", $data, $m)) {
- $online = 0;
- $uid = array_search($read_sock, $net_clients);
- foreach($authed as $cliID) {
- if (@array_key_exists(@$uid, @$cliID)) {
- $online = 1;
- fwrite($cliID[$uid], ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :You got disconnected from the IRC server you were connected to due to: " . $m[1] . "\r\n");
- fwrite($cliID[$uid], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$uid]['currentnick'] . " :You got disconnected from the IRC server you were connected to due to: " . $m[1] . "\r\n");
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("You got disconnected from the IRC server you were connected to due to: " . $m[1]) . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($uid) . "')");
- }
- unset($online);
- }
- if (preg_match("/^NICK (.*)$/", $data, $m) && !in_array($read_sock, $authed)) {
- $tempnicks = array_merge(array($m[1] => $read_sock), $tempnicks);
- }
- if (preg_match("/^:(.*) 001 (.*) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
- $uid = array_search($read_sock, $net_clients);
- if ($usersettings[$uid]['currentnick'] != trim($m[2])) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$uid, @$cliID)) {
- fwrite($cliID[$uid], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :" . trim(substr($m[2], 0, 15)) . "][" . $usersettings[$uid]['username'] . "\r\n");
- }
- }
- mquery("update users set currentnick='" . mysql_real_escape_string(trim(substr($m[2], 0, 15))) . "' where id='" . mysql_real_escape_string($uid) . "'");
- $usersettings[$uid]['currentnick'] = trim(substr($m[2], 0, 15));
- }
- unset($m);
- unset($uid);
- }
- if (preg_match("/^:(.*) 005 (.*) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
- $string = explode(" ", $m[2]);
- unset($string[0]);
- foreach($string as $jadu) {
- $exist = false;
- if (preg_match("/^NETWORK=(.*)$/", $jadu, $z)) {
- mquery("update users set net_name='" . $z[1] . "' where id='" . array_search($read_sock, $net_clients) . "'");
- $usersettings[array_search(@$read_sock, @$net_clients) ]['net_name'] = $z[1];
- }
- if (preg_match("/^CHANTYPES=(.*?)$/", $jadu, $z)) {
- $i = 0;
- while ($i < strlen($z[1])) {
- if ($z[1][$i] == "&") {
- $exist = true;
- }
- ++$i;
- }
- if ($exist == false) {
- $data = str_replace("CHANTYPES=" . $z[1], "CHANTYPES=" . $z[1] . "&", $data);
- }
- }
- }
- unset($exist);
- unset($temp);
- unset($jadu);
- unset($string);
- unset($z);
- }
- if (!$nfo['timed_out'] && !$nfo['eof']) {
- $data = trim($data);
- if (!empty("data")) {
- if (strtolower(substr($data, 0, 4)) == "ping") {
- strtok($data, ":");
- $pingrequest = strtok(":");
- fwrite($read_sock, "PONG :{$pingrequest}\r\n");
- unset($pingrequest);
- continue;
- }
- if (strtolower(substr($data, 0, 4)) == "quit") {
- continue;
- }
- $command = 0;
- $commands = array("pb", "bconnect", "login", "pass", "bhelp", "breconnect", "brestore", "bclear", "bquit", "readlog", "dellog");
- foreach($commands as $checkthis) {
- if (cw($data, $checkthis) == true) {
- $command = 1;
- }
- }
- if (@in_array(@$read_sock, @$net_clients)) {
- $uid = array_search($read_sock, $net_clients);
- $versionreq = false;
- if (debugoutput == 1) {
- echo "SERVER <-" . $data . "\r\n";
- }
- if (preg_match("/^:(.*?) PONG (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
- continue;
- }
- if (preg_match("/^:(.*?) 001 (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
- $userconmem[$uid][] = ":" . $m[1] . " 001 %nick% :" . $m[3];
- unset($m);
- }
- if (preg_match("/^:(.*?) 002 (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
- $userconmem[$uid][] = ":" . $m[1] . " 002 %nick% :" . $m[3];
- unset($m);
- }
- if (preg_match("/^:(.*?) 003 (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
- $userconmem[$uid][] = ":" . $m[1] . " 003 %nick% :" . $m[3];
- unset($m);
- }
- if (preg_match("/^:(.*?) 004 (.*?) (.*)$/", $data, $m) && in_array($read_sock, $net_clients)) {
- $userconmem[$uid][] = ":" . $m[1] . " 004 %nick% " . $m[3];
- unset($m);
- }
- if (preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG (.*?) :" . chr(1) . "VERSION" . chr(1) . "$/", $data, $m)) {
- if ($m[4][0] != "#") {
- fwrite($read_sock, "NOTICE " . $m[1] . " :" . chr(1) . "VERSION This user is using phpBNC v." . version . ", www.phpBNC.se" . chr(1) . "\r\n");
- $versionreq = true;
- }
- unset($m);
- }
- if (preg_match("/^:(.*?) 433 (.*?) (.*?) :(.*)$/", $data, $m) && in_array($read_sock, $net_clients) && $m[2] != $usersettings[$uid]['currentnick']) {
- if (time() - $usersettings[$uid]['lastcontry'] < 15) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$uid, @$cliID)) {
- fwrite($cliID[$uid], ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :_" . $usersettings[$uid]['tempnick'] . "\r\n");
- $online = 1;
- }
- }
- }
- fwrite($read_sock, "NICK _" . $usersettings[$uid]['tempnick'] . "\r\n");
- $usersettings[$uid]['tempnick'] = "_" . $usersettings[$uid]['tempnick'];
- }
- if (preg_match("/^:(.*?) (.*?) " . escape($usersettings[$uid]['currentnick']) . " #(.*?) :Cannot join channel(.*)$/", $data, $m)) {
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='#" . mysql_real_escape_string($m[3]) . "'");
- unset($m);
- }
- if (preg_match("/^:" . escape($usersettings[$uid]['currentnick']) . "!" . escape($usersettings[$uid]['username']) . "@" . escape($usersettings[$uid]['host']) . " JOIN #(.*)$/", $data, $m)) {
- mquery("update tempchannels set channel='#" . mysql_real_escape_string($m[1]) . "' where uid='" . mysql_real_escape_string($uid) . "' and channel='#" . mysql_real_escape_string($m[1]) . "'");
- }
- if (preg_match("/^:" . escape($usersettings[$uid]['currentnick']) . "!" . escape($usersettings[$uid]['username']) . "@" . escape($usersettings[$uid]['host']) . " NICK :(.*)$/", $data, $m)) {
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :" . $m[1] . "][" . $usersettings[$uid]['username'] . "\r\n");
- }
- }
- }
- if ($usersettings[$uid]['nickreq'] == $m[1]) {
- mquery("update users set currentnick='" . mysql_real_escape_string($m[1]) . "', nick='" . mysql_real_escape_string($m[1]) . "' where id='" . mysql_real_escape_string($uid) . "'");
- $usersettings[$uid]['nickreq'] = "";
- $usersettings[$uid]['nick'] = $m[1];
- $usersettings[$uid]['tempnick'] = $m[1];
- } else {
- mquery("update users set currentnick='" . mysql_real_escape_string($m[1]) . "' where id='" . mysql_real_escape_string($uid) . "'");
- }
- $usersettings[$uid]['currentnick'] = $m[1];
- if (0 < $usersettings[$uid]['admin']) {
- $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
- $ucounter = 0;
- foreach($authed as $cliID) {
- if (40 <= $ucounter) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$uid, @$cliID)) {
- fwrite($cliID[$uid], $alltheusers . "\r\n");
- }
- }
- $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :";
- $ucounter = 0;
- }
- $user = array_keys($cliID);
- $user = $user[0];
- $fore = "";
- if ($usersettings[$user]['admin'] == 1) {
- $fore = "+";
- } else if ($usersettings[$user]['admin'] == 2) {
- $fore = "@";
- }
- if ($ucounter == 0) {
- $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- } else {
- $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- }
- ++$ucounter;
- }
- foreach($authed as $cliID) {
- if (@array_key_exists(@$uid, @$cliID)) {
- fwrite($cliID[$uid], $alltheusers . "\r\n");
- fwrite($cliID[$uid], ":phpBNC 366 " . $usersettings[$uid]['currentnick'] . " &system :End of /NAMES list.\r\n");
- }
- }
- unset($ucounter);
- }
- unset($useridet2);
- unset($cliID2);
- unset($m);
- }
- if (preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG " . escape($usersettings[$uid]['currentnick']) . " :\\+OK (.*)$/", $data, $m)) {
- if (@array_key_exists(@$m[2] . "@" . @$m[3], @$bfkeys[$uid])) {
- $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " PRIVMSG " . $usersettings[$uid]['currentnick'] . " :" . decrypt($m[4], $bfkeys[$uid][$m[2] . "@" . $m[3]]['key']) . "\r\n";
- mquery("update blowfish_keys set target_nick='" . mysql_real_escape_string($m[1]) . "' where uid='" . mysql_real_escape_string($uid) . "' and target='" . mysql_real_escape_string($m[2] . "@" . $m[3]) . "'");
- $bfkeys[$uid][$m[2] . "@" . $m[3]]['target_nick'] = $m[1];
- }
- unset($m);
- } else if (preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG #(.*?) :\\+OK (.*)$/", $data, $m)) {
- if (@array_key_exists(@"#" . @$m[4], @$bfkeys[$uid])) {
- $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " PRIVMSG #" . $m[4] . " :" . decrypt($m[5], $bfkeys[$uid]["#" . $m[4]]['key']) . "\r\n";
- }
- unset($m);
- } else if (preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG (.*?) :(.*)$/", $data, $m)) {
- $counter = false;
- if (@($m[4][0] == "#" && array_key_exists(@$m[4], @$bfkeys[$uid]))) {
- $counter = true;
- }
- if (@array_key_exists(@$m[2] . "@" . @$m[3], @$bfkeys[$uid])) {
- $counter = true;
- }
- if (substr($m[5], 0, 3) != "+OK" && $counter == true && strtolower(substr($m[5], 0, 7)) != chr(1) . "action") {
- $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " PRIVMSG " . $m[4] . " :" . chr(3) . "4!" . chr(3) . " " . $m[5] . "\r\n";
- if ($m[4][0] != "#") {
- mquery("update blowfish_keys set target_nick='" . mysql_real_escape_string($m[1]) . "' where uid='" . mysql_real_escape_string($uid) . "' and target='" . mysql_real_escape_string($m[2] . "@" . $m[3]) . "'");
- $bfkeys[$uid][$m[2] . "@" . $m[3]]['target_nick'] = $m[1];
- }
- }
- unset($m);
- unset($counter);
- }
- if (preg_match("/^:(.*?) 332 (.*?) (.*?) :\\+OK (.*)$/", $data, $m)) {
- if (@array_key_exists(@$m[3], @$bfkeys[$uid])) {
- $data = ":" . $m[1] . " 332 " . $m[2] . " " . $m[3] . " :" . decrypt($m[4], $bfkeys[$uid][$m[3]]['key']) . "\r\n";
- }
- unset($m);
- } else if (preg_match("/^:(.*?)!(.*?)@(.*?) TOPIC (.*?) :\\+OK (.*)$/", $data, $m)) {
- if (@array_key_exists(@$m[4], @$bfkeys[$uid])) {
- $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " TOPIC " . $m[4] . " :" . decrypt($m[5], $bfkeys[$uid][$m[4]]['key']) . "\r\n";
- }
- unset($m);
- } else if (preg_match("/^:(.*?) 332 (.*?) (.*?) :(.*)$/", $data, $m)) {
- if (array_key_exists(@$m[3], @$bfkeys[$uid]) && substr($m[4], 0, 3) != "+OK") {
- $data = ":" . $m[1] . " 332 " . $m[2] . " " . $m[3] . " :" . chr(3) . "4!" . chr(3) . " " . $m[4] . "\r\n";
- }
- unset($m);
- } else if (preg_match("/^:(.*?)!(.*?)@(.*?) TOPIC (.*?) :(.*)$/", $data, $m)) {
- if (array_key_exists(@$m[4], @$bfkeys[$uid]) && substr($m[5], 0, 3) != "+OK") {
- $data = ":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " TOPIC " . $m[4] . " :" . chr(3) . "4!" . chr(3) . " " . $m[5] . "\r\n";
- }
- unset($m);
- }
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$uid, @$cliID)) {
- fwrite($cliID[$uid], $data . "\r\n");
- $online = 1;
- }
- }
- if ($online == 0 && $versionreq == false && preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG (.*?) :(.*)$/", $data, $m)) {
- if ($m[4] == $usersettings[$uid]['away_nick']) {
- mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string($m[1] . ": " . mysql_real_escape_string($m[5])) . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($uid) . "')");
- if (strlen($usersettings[$uid]['away_msg']) != 0) {
- fwrite($read_sock, "PRIVMSG " . $m[1] . " :" . $usersettings[$uid]['away_msg'] . "\r\n");
- }
- } else if ($m[4][0] == "#" && $usersettings[$uid]['channellog'] == 1) {
- mquery("insert into channellogs (uid, date, text) Values('" . mysql_real_escape_string($uid) . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string(":" . $m[1] . "!" . $m[2] . "@" . $m[3] . " PRIVMSG " . $m[4] . " :PHPBNC_SAVE_" . time() . "_" . $m[5]) . "')");
- }
- }
- if ($usersettings[$uid]['trailed'] == 1) {
- $nujeflar = fopen("trail/" . $usersettings[$uid]['username'] . ".txt", "a");
- fwrite($nujeflar, "SERVER <- " . $data . "\r\n");
- fclose($nujeflar);
- unset($nujeflar);
- }
- unset($online);
- unset($uid);
- unset($versionreq);
- } else {
- if (array_key_exists(@array_search(@$read_sock, @$clients), @$authed) && $command != 1) {
- $uid = array_search($read_sock, $authed[array_search($read_sock, $clients) ]);
- if (debugoutput == 1) {
- echo "USER ->" . $data . "\r\n";
- }
- if (preg_match("/^PONG :(.*)$/", $data, $m) && in_array($read_sock, $clients)) {
- continue;
- }
- if (preg_match("/^[Ll][Ii][Ss][Tt](.*)$/", $data, $m) && in_array($read_sock, $clients)) {
- continue;
- }
- if (cw($data, "mode &system")) {
- fwrite($read_sock, ":phpBNC 324 " . $usersettings[$uid]['currentnick'] . " &system +stnCN\r\n");
- fwrite($read_sock, ":phpBNC 329 " . $usersettings[$uid]['currentnick'] . " &system " . starttime . "\r\n");
- } else {
- if (cw($data, "privmsg &system :") && in_array($uid, $admins)) {
- preg_match("/^PRIVMSG &system :(.*)$/", $data, $m);
- foreach($admins as $adminid) {
- if ($adminid != $uid) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$adminid, @$cliID)) {
- fwrite($cliID[$adminid], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " PRIVMSG &system :" . $m[1] . "\r\n");
- }
- }
- }
- }
- unset($adminid);
- unset($cliID);
- unset($m);
- } else {
- if (cw($data, "who &system") && 0 < $usersettings[$uid]['admin']) {
- $sql = mquery("select * from users order by id desc");
- while ($RS = mysql_fetch_array($sql)) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$RS['id'], @$cliID)) {
- if ($RS['admin'] == 2) {
- $add = "@";
- } else if ($RS['admin'] == 1) {
- $add = "+";
- } else {
- $add = "";
- }
- if ($uid == $RS['id']) {
- fwrite($read_sock, ":phpBNC 352 " . $usersettings[$uid]['currentnick'] . " &system " . $RS['username'] . " " . $RS['host'] . " phpBNC.se " . $RS['currentnick'] . "][" . $RS['username'] . " H" . $add . " :0 " . $RS['realname'] . "\r\n");
- } else {
- fwrite($read_sock, ":phpBNC 352 " . $usersettings[$uid]['currentnick'] . " &system " . $RS['username'] . " " . $RS['host'] . " phpBNC.se " . $RS['currentnick'] . "][" . $RS['username'] . " H" . $add . " :3 " . $RS['realname'] . "\r\n");
- }
- }
- }
- }
- fwrite($read_sock, ":phpBNC 352 " . $usersettings[$uid]['currentnick'] . " &system phpBNC phpBNC.se phpBNC.se phpBNC H*@d :0 " . $RS['realname'] . "\r\n");
- fwrite($read_sock, ":phpBNC 315 " . $usersettings[$uid]['currentnick'] . " &system :End of /WHO list.\r\n");
- continue;
- }
- if (cw($data, "names &system") && 0 < $usersettings[$uid]['admin']) {
- $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
- $ucounter = 0;
- foreach($authed as $cliID) {
- if (40 <= $ucounter) {
- fwrite($read_sock, $alltheusers . "\r\n");
- $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :";
- $ucounter = 0;
- }
- $user = array_keys($cliID);
- $user = $user[0];
- $fore = "";
- if ($usersettings[$user]['admin'] == 1) {
- $fore = "+";
- } else if ($usersettings[$user]['admin'] == 2) {
- $fore = "@";
- }
- if ($ucounter == 0) {
- $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- } else {
- $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- }
- ++$ucounter;
- }
- fwrite($read_sock, $alltheusers . "\r\n");
- fwrite($read_sock, ":phpBNC 366 " . $usersettings[$uid]['currentnick'] . " &system :End of /NAMES list.\r\n");
- unset($ucounter);
- continue;
- }
- if (preg_match("/^USER (.*)$/", $data, $m)) {
- continue;
- }
- if (preg_match("/^NOTICE (.*?) :LAGCHK (.*)$/", $data, $m)) {
- fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NOTICE " . $usersettings[$uid]['currentnick'] . " :LAGCHK " . $m[2] . "\r\n");
- unset($m);
- continue;
- }
- if (preg_match("/^NOTICE (.*?) :lag(.*)$/", $data, $m)) {
- fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NOTICE " . $usersettings[$uid]['currentnick'] . " :lag" . $m[2] . "\r\n");
- unset($m);
- continue;
- }
- if (cw($data, "join &system") || cw($data, "part &system")) {
- continue;
- }
- if (cw($data, "who #") && time() - $usersettings[$uid]['lastlogin'] < 240) {
- continue;
- }
- if (preg_match("/^[Jj][Oo][Ii][Nn] (.*?) (.*)$/", $data, $m)) {
- if (0 < strpos("." . $m[1], ",")) {
- $channels = explode(",", $m[1]);
- $pwd = explode(",", $m[2]);
- foreach($channels as $arkey => $chan) {
- $sql = mquery("select reason, until, channel, network from banned_channels where channel='" . mysql_real_escape_string($chan) . "' and network='*' or channel='" . mysql_real_escape_string($chan) . "' and network='" . $usersettings[$uid]['net_name'] . "'");
- if (0 < mysql_num_rows($sql)) {
- do {
- if ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :Channel " . $RS['channel'] . " on " . $RS['network'] . " is banned until " . date("Y-m-d H:i:s", $RS['until']) . " due to: " . $RS['reason'] . "\r\n");
- }
- }
- while (1);
- } else {
- $proceed[$arkey] = $chan;
- $keyproceed[$arkey] = $pwd[$arkey];
- }
- }
- $data = "JOIN " . implode(",", $proceed) . " " . implode(",", $keyproceed);
- unset($sql);
- unset($RS);
- unset($proceed);
- unset($chan);
- unset($channels);
- unset($pwd);
- unset($m);
- } else {
- $sql = mquery("select reason, until, channel, network from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='*' or channel='" . mysql_real_escape_string($m[1]) . "' and network='" . $usersettings[$uid]['net_name'] . "'");
- if (0 < mysql_num_rows($sql)) {
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :Channel " . $RS['channel'] . " on " . $RS['network'] . " is banned until " . date("Y-m-d H:i:s", $RS['until']) . " due to: " . $RS['reason'] . "\r\n");
- }
- continue;
- }
- unset($sql);
- unset($RS);
- }
- } else if (preg_match("/^[Jj][Oo][Ii][Nn] (.*)$/", $data, $m)) {
- if (0 < strpos("." . $m[1], ",")) {
- $channels = explode(",", $m[1]);
- foreach($channels as $chan) {
- $sql = mquery("select reason, until, channel, network from banned_channels where channel='" . mysql_real_escape_string($chan) . "' and network='*' or channel='" . mysql_real_escape_string($chan) . "' and network='" . $usersettings[$uid]['net_name'] . "'");
- if (0 < mysql_num_rows($sql)) {
- do {
- if ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :Channel " . $RS['channel'] . " on " . $RS['network'] . " is banned until " . date("Y-m-d H:i:s", $RS['until']) . " due to: " . $RS['reason'] . "\r\n");
- }
- }
- while (1);
- } else {
- $proceed[] = $chan;
- }
- }
- $data = "JOIN " . implode(",", $proceed);
- unset($proceed);
- unset($chan);
- unset($channels);
- unset($sql);
- unset($RS);
- unset($m);
- } else {
- $sql = mquery("select reason, until, channel, network from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='*' or channel='" . mysql_real_escape_string($m[1]) . "' and network='" . $usersettings[$uid]['net_name'] . "'");
- if (0 < mysql_num_rows($sql)) {
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :Channel " . $RS['channel'] . " on " . $RS['network'] . " is banned until " . date("Y-m-d H:i:s", $RS['until']) . " due to: " . $RS['reason'] . "\r\n");
- }
- continue;
- }
- }
- }
- if ($usersettings[$uid]['trailed'] == 1) {
- $nujeflar = fopen("trail/" . $usersettings[$uid]['username'] . ".txt", "a");
- fwrite($nujeflar, "USER -> " . $data . "\r\n");
- fclose($nujeflar);
- unset($nujeflar);
- }
- if (@array_key_exists(@$uid, @$net_clients)) {
- if (preg_match("/^PRIVMSG (.*?) :(.*)$/", $data, $m)) {
- $therecheck = false;
- if ($m[1][0] == "#") {
- if (@array_key_exists(@$m[1], @$bfkeys[$uid])) {
- $therecheck = true;
- $wherecheck = $m[1];
- }
- } else {
- foreach($bfkeys[$uid] as $key => $val) {
- if (array_search($m[1], $val)) {
- $wherecheck = $key;
- $therecheck = true;
- }
- }
- }
- if ($therecheck == true) {
- if (strtolower(substr($m[2], 0, 7)) != chr(1) . "action" && substr($m[2], 0, 2) != "+p") {
- $data = "PRIVMSG " . $m[1] . " :+OK " . encrypt($m[2], $bfkeys[$uid][$wherecheck]['key']) . "\r\n";
- }
- if (substr($m[2], 0, 2) == "+p") {
- $data = "PRIVMSG " . $m[1] . " :" . substr($m[2], 2, strlen($m[2]) - 2) . "\r\n";
- }
- }
- unset($therecheck);
- unset($wherecheck);
- }
- if (preg_match("/^TOPIC (.*?) :(.*)$/", $data, $m)) {
- $therecheck = false;
- if ($m[1][0] == "#") {
- if (@array_key_exists(@$m[1], @$bfkeys[$uid])) {
- $therecheck = true;
- $wherecheck = $m[1];
- }
- } else {
- foreach($bfkeys[$uid] as $key => $val) {
- if (array_search($m[1], $val)) {
- $wherecheck = $key;
- $therecheck = true;
- }
- }
- }
- if ($therecheck == true) {
- if (substr($m[2], 0, 2) != "+p") {
- $data = "TOPIC " . $m[1] . " :+OK " . encrypt($m[2], $bfkeys[$uid][$wherecheck]['key']) . "\r\n";
- }
- if (substr($m[2], 0, 2) == "+p") {
- $data = "TOPIC " . $m[1] . " :" . substr($m[2], 2, strlen($m[2]) - 2) . "\r\n";
- }
- }
- unset($therecheck);
- unset($wherecheck);
- }
- if (cw($data, "part")) {
- strtok($data, " ");
- $channel = strtok(" ");
- $network = mysql_fetch_array(mquery("select net_name from users where id='" . mysql_real_escape_string($uid) . "'"));
- mquery("delete from userchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($channel) . "' and network='" . mysql_real_escape_string($network['net_name']) . "'");
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($channel) . "'");
- unset($channel);
- unset($network);
- } else if (cw($data, "join")) {
- strtok($data, " ");
- $channel = strtok(" ");
- $pw = strtok(" ");
- if (0 < strpos("." . $channel, ",")) {
- $channels = explode(",", $channel);
- $pwd = explode(",", $pw);
- $network = mysql_fetch_array(mquery("select net_name from users where id='" . mysql_real_escape_string($uid) . "'"));
- foreach($channels as $keyen => $kanalen) {
- mquery("delete from userchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($kanalen) . "' and network='" . mysql_real_escape_string($network['net_name']) . "'");
- mquery("insert into userchannels (uid, channel, pw, network) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($kanalen) . "', '" . mysql_real_escape_string($pwd[$keyen]) . "', '" . mysql_real_escape_string($network['net_name']) . "')");
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($kanalen) . "'");
- mquery("insert into tempchannels (uid, channel, pw) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($kanalen) . "', '" . mysql_real_escape_string($pwd[$keyen]) . "')");
- unset($kanalen);
- unset($keyen);
- }
- unset($network);
- unset($channels);
- unset($channel);
- unset($pw);
- } else {
- $network = mysql_fetch_array(mquery("select net_name from users where id='" . mysql_real_escape_string($uid) . "'"));
- mquery("delete from userchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($channel) . "' and network='" . mysql_real_escape_string($network['net_name']) . "'");
- mquery("insert into userchannels (uid, channel, pw, network) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($channel) . "', '" . mysql_real_escape_string($pw) . "', '" . mysql_real_escape_string($network['net_name']) . "')");
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($channel) . "'");
- mquery("insert into tempchannels (uid, channel, pw) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($channel) . "', '" . mysql_real_escape_string($pw) . "')");
- unset($channel);
- unset($network);
- unset($pw);
- }
- }
- if (2 < time() - $usersettings[$uid]['lastcommand'] || $usersettings[$uid]['flood'] == 0) {
- fwrite($net_clients[$uid], $data . "\r\n");
- $usersettings[$uid]['lastcommand'] = time();
- $usersettings[$uid]['delay'] = 0;
- } else {
- if (7 < $usersettings[$uid]['delay']) {
- $adder = 2;
- } else {
- $adder = 1;
- }
- $queue[][$uid][mktime(date("H"), date("i"), date("s") + $usersettings[$uid]['delay'], date("m"), date("d"), date("Y")) ]['command'] = $data . "\r\n";
- $usersettings[$uid]['delay'] = $usersettings[$uid]['delay'] + $adder;
- }
- unset($adder);
- unset($channel);
- unset($pw);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :You are NOT connected to a IRC server yet, use /bconnect to connect.\r\n");
- }
- }
- }
- } else {
- if (in_array(@$read_sock, @$identd) && enableident == true) {
- if (debugoutput == 1) {
- echo "IDENTD -> " . $data . "\r\n";
- }
- if (preg_match("/^(.*) , (.*)$/", $data, $m)) {
- $uid = array_search($m[1], $ident_ports);
- fwrite($read_sock, $m[2] . ", " . $m[1] . " : USERID : UNIX : " . $usersettings[$uid]['username'] . "\r\n");
- unset($ident_ports[$uid]);
- if (debugoutput == 1) {
- echo "IDENT RESPONSE -> " . $m[2] . ", " . $m[1] . " : USERID : UNIX : " . $usersettings[$uid]['username'] . "\r\n";
- }
- }
- } else {
- if (cw($data, "login") || cw($data, "pass")) {
- $clientKEY = array_search($read_sock, $clients);
- if (@in_array(@$read_sock, @$authed[$clientKEY])) {
- $uid = array_search($read_sock, $authed[array_search($read_sock, $clients) ]);
- fwrite($read_sock, ":phpBNC NOTICE " . $usersettings[$uid]['currentnick'] . " :You are already logged in as " . $usersettings[$uid]['username'] . " smartass!\r\n");
- } else {
- if (preg_match("/^PASS (.*?):(.*)$/", $data, $m)) {
- $username = $m[1];
- $unamecheck = md5(strtolower($m[1]));
- $password = md5(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out"));
- } else if (preg_match("/^pass (.*?):(.*)$/", $data, $m)) {
- $username = $m[1];
- $unamecheck = md5(strtolower($m[1]));
- $password = md5(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out"));
- } else if (preg_match("/^LOGIN (.*) (.*)$/", $data, $m)) {
- $username = $m[1];
- $unamecheck = md5(strtolower($m[1]));
- $password = md5(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out"));
- } else if (preg_match("/^login (.*) (.*)$/", $data, $m)) {
- $username = $m[1];
- $unamecheck = md5(strtolower($m[1]));
- $password = md5(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out"));
- }
- $ip = explode(":", stream_socket_get_name($read_sock, true));
- $ip = $ip[0];
- $hosten = gethostbyaddr($ip);
- $sql = mquery("select id,banned,banned_until,network from users where md5(lower(username))='{$unamecheck}' and md5(password)='{$password}'");
- if (mysql_num_rows($sql) == 1) {
- $RS = mysql_fetch_array($sql);
- $uid = $RS['id'];
- $alreadyloggedin = 0;
- foreach($authed as $cliID) {
- $useridet = array_keys($cliID);
- if ($useridet[0] == $uid) {
- $alreadyloggedin = 1;
- break;
- break;
- }
- }
- if ($alreadyloggedin == 1) {
- fwrite($read_sock, ":phpBNC NOTICE you :Someone has already logged in as " . $usersettings[$uid]['username'] . ", please wait until that client disconnects.\r\n");
- } else {
- if (0 < strlen($RS['banned']) && time() < $RS['banned_until']) {
- fwrite($read_sock, ":phpBNC NOTICE you :You are banned until " . date("Y-m-d H:i:s", $RS['banned_until']) . " due to: " . $RS['banned'] . ".\r\n");
- } else {
- if (@array_key_exists(@$uid, @$net_clients)) {
- $currentnick = $usersettings[$uid]['currentnick'];
- } else {
- $currentnick = $usersettings[$uid]['nick'];
- $usersettings[$uid]['currentnick'] = $usersettings[$uid]['nick'];
- mquery("update users set currentnick=nick where id='" . mysql_real_escape_string($uid) . "'");
- }
- fwrite($read_sock, ":phpBNC NOTICE " . $currentnick . " :You are now logged in as " . $usersettings[$uid]['username'] . ".\r\n" . ":phpBNC NOTICE :For list of commands use /bhelp\r\n");
- if (array_search($read_sock, $tempnicks) != $currentnick) {
- fwrite($read_sock, ":" . array_search($read_sock, $tempnicks) . " NICK " . $currentnick . "\r\n");
- }
- $authed[$clientKEY] = array($uid => $read_sock);
- if (@!array_key_exists(@$uid, @$net_clients)) {
- fwrite($read_sock, ":" . $RS['network'] . " 001 " . $currentnick . " :Welcome to the " . $RS['network'] . " IRC Network " . $currentnick . "\r\n");
- } else {
- fwrite($read_sock, "NOTICE AUTH :*** Looking up your hostname\r\n");
- fwrite($read_sock, "NOTICE AUTH :*** Checking Ident\r\n");
- fwrite($read_sock, "NOTICE AUTH :*** Found your hostname\r\n");
- fwrite($read_sock, "NOTICE AUTH :*** Got ident response\r\n");
- foreach($userconmem[$uid] as $sendline) {
- fwrite($read_sock, str_replace("%nick%", $currentnick, $sendline) . "\r\n");
- }
- fwrite($net_clients[$uid], "VERSION\r\n");
- fwrite($net_clients[$uid], "LUSERS\r\n");
- }
- unset($tempnicks[array_search($read_sock, $tempnicks) ]);
- if (0 < strlen($usersettings[$uid]['net_name'])) {
- $currentnetwork = $usersettings[$uid]['net_name'];
- } else {
- $currentnetwork = "phpBNC";
- }
- if ($usersettings[$uid]['trailed'] == 1) {
- fwrite($read_sock, ":phpBNC NOTICE you :An admin has activated trail for your account, that means that everything you send and receive is logged in a textfile, REMEMBER THIS.\r\n");
- }
- if (0 < $usersettings[$uid]['admin']) {
- $admins[] = $uid;
- fwrite($read_sock, ":" . $currentnick . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " JOIN &system\r\n");
- fwrite($read_sock, ":phpBNC 332 " . $currentnick . " &system :System channel for phpBNC v." . version . "\r\n");
- fwrite($read_sock, ":phpBNC 333 " . $currentnick . " &system phpBNC " . starttime . "\r\n");
- $alltheusers = ":phpBNC 353 " . $currentnick . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
- $ucounter = 0;
- foreach($authed as $cliID) {
- if (40 <= $ucounter) {
- fwrite($read_sock, $alltheusers . "\r\n");
- $alltheusers = ":phpBNC 353 " . $currentnick . "][" . $usersettings[$uid]['username'] . " = &system :";
- $ucounter = 0;
- }
- $user = array_keys($cliID);
- $user = $user[0];
- $fore = "";
- if ($user != $uid) {
- if ($usersettings[$user]['admin'] == 1) {
- $fore = "+";
- } else if ($usersettings[$user]['admin'] == 2) {
- $fore = "@";
- }
- }
- if ($ucounter == 0) {
- $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- } else {
- $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- }
- ++$ucounter;
- }
- fwrite($read_sock, $alltheusers . "\r\n");
- fwrite($read_sock, ":phpBNC 366 " . $currentnick . " &system :End of /NAMES list.\r\n");
- unset($ucounter);
- }
- $foere = "";
- if ($usersettings[$uid]['admin'] == 1) {
- $foere = "+v";
- } else if ($usersettings[$uid]['admin'] == 2) {
- $foere = "+o";
- }
- fwrite($read_sock, ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $currentnick . "][" . $usersettings[$uid]['username'] . "\r\n");
- foreach($admins as $useridet) {
- if ($useridet != $uid) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$useridet, @$cliID)) {
- fwrite($cliID[$useridet], ":[email protected] PRIVMSG &system :" . chr(2) . "USER:" . chr(2) . " " . $usersettings[$uid]['username'] . " logged in from {$hosten}({$ip})\r\n");
- fwrite($cliID[$useridet], ":" . $currentnick . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " JOIN &system\r\n");
- if ($foere != "") {
- fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $currentnick . "][" . $usersettings[$uid]['username'] . "\r\n");
- }
- }
- }
- }
- }
- $msgcount = mysql_result(mquery("select count(*) from userlogs where toid='" . mysql_real_escape_string($uid) . "'"), 0);
- if (0 < $msgcount) {
- fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG " . $currentnick . " :You got " . $msgcount . " message(s) in your log, type /readlog to read them or /dellog to delete them.\r\n");
- }
- $usersettings[$uid]['lastlogin'] = time();
- if (@array_key_exists(@$uid, @$net_clients)) {
- fwrite($net_clients[$uid], "MODE " . $currentnick . "\r\n");
- if ($usersettings[$uid]['channellog'] == 0) {
- fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['currentnick'] . " -d\r\n");
- fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['away_nick'] . " -d\r\n");
- fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['nick'] . " -d\r\n");
- }
- fwrite($net_clients[$uid], "NICK :" . $usersettings[$uid]['nick'] . "\r\n");
- if ($usersettings[$uid]['away_msg'] != "") {
- fwrite($net_clients[$uid], "AWAY\r\n");
- }
- $chancounter = 0;
- $sql = mquery("select channel from tempchannels where uid='" . mysql_real_escape_string($uid) . "' order by channel asc");
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " JOIN " . $RS['channel'] . "\r\n");
- if (2 < time() - $usersettings[$uid]['lastcommand'] || $usersettings[$uid]['flood'] == 0) {
- fwrite($net_clients[$uid], "TOPIC " . $RS['channel'] . "\r\n");
- fwrite($net_clients[$uid], "NAMES " . $RS['channel'] . "\r\n");
- $usersettings[$uid]['lastcommand'] = time();
- $usersettings[$uid]['delay'] = 0;
- } else {
- $adder = 1;
- $queue[][$uid][mktime(date("H"), date("i"), date("s") + $usersettings[$uid]['delay'], date("m"), date("d"), date("Y")) ]['command'] = "NAMES " . $RS['channel'] . "\r\n";
- $queue[][$uid][mktime(date("H"), date("i"), date("s") + $usersettings[$uid]['delay'], date("m"), date("d"), date("Y")) ]['command'] = "TOPIC " . $RS['channel'] . "\r\n";
- if ($chancounter++ % 2 == 0) {
- $usersettings[$uid]['delay'] = $usersettings[$uid]['delay'] + $adder;
- }
- }
- }
- unset($adder);
- unset($chancounter);
- unset($sql);
- unset($RS);
- if ($usersettings[$uid]['channellog'] == 1) {
- $sql = mquery("select * from channellogs where uid='" . mysql_real_escape_string($uid) . "' order by date asc");
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, $RS['text'] . "\r\n");
- }
- mquery("delete from channellogs where uid='" . mysql_real_escape_string($uid) . "'");
- }
- }
- }
- }
- } else {
- if (0 < mysql_result(mquery("select count(*) from users where md5(lower(username))='{$unamecheck}'"), 0)) {
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . chr(3) . "4WARNING:" . chr(3) . chr(2) . " {$username} tried to login with wrong password from {$hosten}({$ip})\r\n");
- }
- }
- }
- }
- fwrite($read_sock, ":phpBNC NOTICE you :Wrong username or password, remember the password is CaSeSeNsiTivE!\r\n");
- $key = array_search($read_sock, $clients);
- unset($clients[$key]);
- fclose($read_sock);
- echo "client disconnected.\r\n";
- }
- unset($sql);
- unset($RS);
- unset($currentnick);
- unset($alreadyloggedin);
- }
- } else {
- if (@in_array(@$read_sock, @$authed[array_search(@$read_sock, @$clients) ])) {
- $uid = array_search($read_sock, $authed[array_search($read_sock, $clients) ]);
- $nick = $usersettings[$uid]['currentnick'];
- if (cw($data, "bconnect")) {
- $userinfo = mysql_fetch_array(mquery("select username, nick, host, port, `ssl`, network, realname from users where id='{$uid}'"));
- if (@array_key_exists(@$uid, @$net_clients)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :You are already connected to a network..\r\n");
- } else if (strlen($userinfo['host']) == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :You have to select a v-host before you can connect..\r\n");
- } else if (strlen($userinfo['realname']) == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please enter a realname before you connect..\r\n");
- } else if (strlen($userinfo['network']) == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please specify a server before you connect..\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Trying to connect you to " . $userinfo['network'] . "..\r\n");
- $tempcontext = stream_context_create();
- stream_context_set_option($tempcontext, "socket", "bindto", gethostbyname($userinfo['host']) . ":0");
- if ($userinfo['ssl'] == 1) {
- $ssladd = "ssl://";
- } else {
- $ssladd = "tcp://";
- }
- $netsocket = stream_socket_client($ssladd . $userinfo['network'] . ":" . $userinfo['port'], $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $tempcontext);
- if (!$netsocket) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :A error occured, could not connect to " . $userinfo['network'] . ", error: " . $errstr . ".\r\n");
- } else {
- stream_set_timeout($netsocket, 1200);
- stream_set_blocking($netsocket, false);
- $net_clients = array($uid => $netsocket) + $net_clients;
- if (enableident) {
- $tempp = explode(":", stream_socket_get_name($netsocket, false));
- $ident_ports[$uid] = $tempp[1];
- unset($tempp);
- }
- fwrite($netsocket, "NICK " . $userinfo['nick'] . "\r\n");
- fwrite($netsocket, "USER " . $userinfo['username'] . " \"" . $userinfo['nick'] . "\" \"" . $userinfo['host'] . "\" :" . $userinfo['realname'] . "\r\n");
- }
- if (0 < $usersettings[$uid]['admin']) {
- $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
- $ucounter = 0;
- foreach($authed as $cliID) {
- if (40 <= $ucounter) {
- fwrite($read_sock, $alltheusers . "\r\n");
- $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :";
- $ucounter = 0;
- }
- $user = array_keys($cliID);
- $user = $user[0];
- $fore = "";
- if ($usersettings[$user]['admin'] == 1) {
- $fore = "+";
- } else if ($usersettings[$user]['admin'] == 2) {
- $fore = "@";
- }
- if ($ucounter == 0) {
- $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- } else {
- $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- }
- ++$ucounter;
- }
- fwrite($read_sock, $alltheusers . "\r\n");
- fwrite($read_sock, ":phpBNC 366 " . $usersettings[$uid]['currentnick'] . " &system :End of /NAMES list.\r\n");
- unset($ucounter);
- }
- }
- $usersettings[$uid]['lastcontry'] = time();
- } else {
- if (cw($data, "brestore")) {
- if (@array_key_exists(@$uid, @$net_clients)) {
- $sql = mquery("select channel,pw from userchannels where uid='{$uid}' order by channel asc");
- if (mysql_num_rows($sql) == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :There was no stored channels for you, for some reason.\r\n");
- }
- if ($RS = mysql_fetch_array($sql)) {
- if (0 < strlen($RS['pw'])) {
- fwrite($net_clients[$uid], "JOIN " . $RS['channel'] . " " . $RS['pw'] . "\r\n");
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($RS['channel']) . "'");
- mquery("insert into tempchannels (uid, channel, pw) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($RS['channel']) . "', '" . mysql_real_escape_string($RS['pw']) . "')");
- } else {
- fwrite($net_clients[$uid], "JOIN " . $RS['channel'] . "\r\n");
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "' and channel='" . mysql_real_escape_string($RS['channel']) . "'");
- mquery("insert into tempchannels (uid, channel, pw) Values('" . mysql_real_escape_string($uid) . "', '" . mysql_real_escape_string($RS['channel']) . "', '')");
- continue;
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :You aren´t even connected to a network, use /bconnect to connect.\r\n");
- }
- } else {
- if (cw($data, "bclear")) {
- mquery("delete from userchannels where uid='" . mysql_real_escape_string($uid) . "'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your channel memory has been deleted.\r\n");
- } else {
- if (cw($data, "breconnect")) {
- if (@array_key_exists(@$uid, @$net_clients)) {
- fwrite($net_clients[$uid], "QUIT\r\n");
- fclose($net_clients[$uid]);
- unset($net_clients[$uid]);
- unset($userconmem[$uid]);
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "'");
- $userinfo = mysql_fetch_array(mquery("select username, nick, host, port, `ssl`, network, realname from users where id='{$uid}'"));
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Disconnected you from current network..\r\n");
- if (strlen($userinfo['realname']) == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please enter a realname before you connect..\r\n");
- } else if (strlen($userinfo['host']) == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please choose a host before you connect..\r\n");
- } else {
- if (strlen($userinfo['network']) == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Please specify a server before you connect..\r\n");
- } else {
- if ($usersettings[$uid]['currentnick'] != $userinfo['nick']) {
- fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :" . $userinfo['nick'] . "\r\n");
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " NICK :" . $userinfo['nick'] . "][" . $usersettings[$uid]['username'] . "\r\n");
- }
- }
- }
- $usersettings[$uid]['currentnick'] = $userinfo['nick'];
- mquery("update users set currentnick=nick where id='" . mysql_real_escape_string($uid) . "'");
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Trying to connect you to " . $userinfo['network'] . "..\r\n");
- sleep(1);
- $tempcontext = stream_context_create();
- stream_context_set_option($tempcontext, "socket", "bindto", gethostbyname($userinfo['host']) . ":0");
- if ($userinfo['ssl'] == 1) {
- $ssladd = "ssl://";
- } else {
- $ssladd = "tcp://";
- }
- $netsocket = stream_socket_client($ssladd . $userinfo['network'] . ":" . $userinfo['port'], $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $tempcontext);
- if (!$netsocket) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :A error occured, could not connect to " . $userinfo['network'] . ", error: " . $errstr . ".\r\n");
- } else {
- stream_set_timeout($netsocket, 1200);
- stream_set_blocking($netsocket, false);
- $net_clients = array($uid => $netsocket) + $net_clients;
- if (enableident) {
- $tempp = explode(":", stream_socket_get_name($netsocket, false));
- $ident_ports[$uid] = $tempp[1];
- unset($tempp);
- }
- fwrite($netsocket, "NICK " . $userinfo['nick'] . "\r\n");
- fwrite($netsocket, "USER " . $userinfo['username'] . " \"" . $userinfo['nick'] . "\" \"" . $userinfo['host'] . "\" :" . $userinfo['realname'] . "\r\n");
- if (0 < $usersettings[$uid]['admin']) {
- $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :@phpBNC ";
- $ucounter = 0;
- foreach($authed as $cliID) {
- if (40 <= $ucounter) {
- fwrite($read_sock, $alltheusers . "\r\n");
- $alltheusers = ":phpBNC 353 " . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . " = &system :";
- $ucounter = 0;
- }
- $user = array_keys($cliID);
- $user = $user[0];
- $fore = "";
- if ($usersettings[$user]['admin'] == 1) {
- $fore = "+";
- } else if ($usersettings[$user]['admin'] == 2) {
- $fore = "@";
- }
- if ($ucounter == 0) {
- $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- } else {
- $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- }
- ++$ucounter;
- }
- fwrite($read_sock, $alltheusers . "\r\n");
- fwrite($read_sock, ":phpBNC 366 " . $usersettings[$uid]['currentnick'] . " &system :End of /NAMES list.\r\n");
- unset($ucounter);
- }
- }
- }
- }
- $usersettings[$uid]['lastcontry'] = time();
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :You aren´t even connected to a network, use /bconnect to connect.\r\n");
- }
- } else {
- if (cw($data, "bquit")) {
- if (@array_key_exists(@$uid, @$net_clients)) {
- fwrite($net_clients[$uid], "QUIT\r\n");
- fclose($net_clients[$uid]);
- unset($net_clients[$uid]);
- unset($userconmem[$uid]);
- mquery("update users set net_name='' where id='" . mysql_real_escape_string($uid) . "'");
- $sql = mquery("select * from tempchannels where uid='" . mysql_real_escape_string($uid) . "'");
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":" . $usersettings[$uid]['currentnick'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " PART " . $RS['channel'] . "\r\n");
- }
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($uid) . "'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Disconnected you from current network..\r\n");
- unset($sql);
- unset($RS);
- $usersettings[$uid]['lastcontry'] = time();
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :You aren´t even connected to a network, use /bconnect to connect.\r\n");
- }
- } else {
- if (cw($data, "readlog")) {
- $sql = mquery("select * from userlogs where toid='" . mysql_real_escape_string($uid) . "' order by date asc");
- if (mysql_num_rows($sql) == 0) {
- fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :You got no messages.\r\n");
- } else {
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} :" . chr(2) . date("Y-m-d H:i:s", $RS['date']) . chr(2) . "> " . $RS['msg'] . "\r\n");
- }
- }
- } else {
- if (cw($data, "dellog")) {
- mquery("delete from userlogs where toid='" . mysql_real_escape_string($uid) . "'");
- fwrite($read_sock, ":phpBNC PRIVMSG {$nick} :Private message(s) deleted.\r\n");
- } else {
- if (cw($data, "bhelp") || cw($data, "pb help")) {
- if (in_array($uid, $admins)) {
- $adminadd = ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | _____________________________________________________________________________________ | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : /´ `\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | As a admin you get a bit more fancy commands ;) | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | " . chr(2) . "Explanations" . chr(2) . " | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | <duration> - can be specified in minutes or days with m and d, ex. 10d or 50m | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | <network> - the network name the server reports when you are connected, | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | for ex. QuakeNet.org the network name would be QuakeNet (use * for | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | all networks) | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | <number> - number of connections thats allowed on that specific v-host | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | " . chr(2) . "Commands" . chr(2) . " | \r\n";
- $normaladmin = ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Normal-admin commands | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb stats - shows some stats | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb kick <username> - kick a user, username is the same as the ident | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb aset <username> <option> <value> - set a users values | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb banchan <channel> <network> <duration> <reason> - ban a channel | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb unbanchan <channel> <network> - unban a channel | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb find <string> - search for a user | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb check <channel> <network> - lists what bncusers currently in the specified chan | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb info <username> - same as myinfo but with little more candy ;) | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb ban <username> <duration> <reason> - ban a user | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb unban <username> - unban a user | \r\n";
- $superadmin = ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Super-admin commands | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb addhost <number> <hostname> - adds a v-host | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb delhost <hostname> - deletes a v-host | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb allmsg <msg> - sends a message to every user online, incl you | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb trail <username> - dumps a copy of everything the user says/receives to | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | trails/<username>.txt, the user however will be notified | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | of this action | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb untrail <username> | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb admin <username> <newlevel> - make someone admin. levels 0, 1, 2 are available | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb adduser <username> <password> - add a user | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb deluser <username> - delete a user | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | */pb createlink <ip> - create a link to another phpBNC server | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | */pb dellink <ip> - delete a link | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | */pb listlinks - lists all links | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | */pb addtrust <ip> - add a ip thats allowed to link to you | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | */pb removetrust <ip> - remove a ip from the allowed link list | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | */pb listtrusts - lists all trusted ips | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | */pb allowglobaladmin <ip> - allows a linked server to control this phpBNC | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | */pb delglobaladmin <ip> - deletes the linked server from globaladmin | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | * = not included in this version | \r\n";
- $adminlvl = mysql_fetch_array(mquery("select admin from users where id='" . mysql_real_escape_string($uid) . "'"));
- if (1 <= $adminlvl['admin']) {
- $adminadd = $adminadd . $normaladmin;
- }
- if ($adminlvl['admin'] == 2) {
- $adminadd = $adminadd . $superadmin;
- }
- } else {
- $adminadd = "";
- }
- fwrite($read_sock, ":phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : _ ___ __ ___ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : _ __ | |__ _ __ / __\\ /\\ \\ \\ / __\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | '_ \\ | '_ \\ | '_ \\ /__\\// / \\/ // / \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | |_) || | | || |_) |/ \\/ \\/ /\\ // /___ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | .__/ |_| |_|| .__/ \\_____/\\_\\ \\/ \\____/ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : |_| |_| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : By Daniel \"blodan\" Ylitalo\r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : There are " . count($clients) . " client(s) connected to the BNC server.\r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : www.phpBNC.se / www.phpBNC.com / www.phpBNC.eu / www.phpBNC.net / www.phpBNC.org \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : _____________________________________________________________________________________ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : /´ `\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /bhelp or /pb help - shows this menu | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /bconnect - connects you to the IRC server you have specified | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /breconnect - reconnects you to the IRC server you are connected to | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /bquit - disconnects you from the IRC network you are connected to | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /brestore - joins all the channels you were in before the BNC died or | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | you decided to do a /breconnect (ofc not invite channels) | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /bclear - clears your restore memory of channels | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /readlog - shows your saved messages | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /dellog - deletes your saved messages | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set awaynick <awaynick> - sets the nick the bnc will change to after being | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | disconnected | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set awaymsg <awaymsg> - sets your awaymsg, for nothing enter '' | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set nick <nick> - sets your nick | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set host <host> - sets your host, you will have to /breconnect before | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | changes takes effect. | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb list hosts - lists all available v-hosts | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set channellog <on/off> - enables or disables channel logging | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set floodcontrol <on/off> - enables or disables flood control | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set password <new password> - sets a new password for your account. | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set realname <realname> - sets your realname, same as above. | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set server <server> - hmm i wonder what this does? | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set port <port> - sets the port, use + if you want SSL (ex. +7000) | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb set key <channel or ident@host> <key> -set blowfish key | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb del key <channel or ident@host> -delete blowfish key | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb list keys - lists your keys | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb list channels - lists banned channels | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb myinfo - shows your info/settings | \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | /pb uptime - shows the bncs uptime #phpBNC @ QuakeNet.org | \r\n" . $adminadd . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : `\\_____________________________________________________________________________________/´ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Remember to always configure your bnc in the query window, that way no \"miss-pastes\" can happen!\r\n");
- } else {
- if (cw($data, "pb")) {
- strtok($data, " ");
- $whattodo = strtolower(strtok(" "));
- if ($whattodo == "set") {
- if (preg_match("/^[Pp][Bb] [Ss][Ee][Tt] (.*?) (.*)$/", $data, $m)) {
- $section = $m[1];
- $info = $m[2];
- if ($section == "realname") {
- if (!preg_match("/^[ a-z0-9\\\\,\\'\\.\\~\\_\\!\\@\\#$\\%\\^\\*\\(\\)\\_\\+\\=\\-\\|\\?\\<\\>\\/åäöæø]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your realname contains an invalid character.\r\n");
- } else {
- mquery("update users set realname='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your realname has been updated.\r\n");
- }
- } else {
- if ($section == "awaynick") {
- if (!preg_match("/^[a-z0-9\\\\`\\^\\_\\-\\|\\[\\]{\\}]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-nick contains an invalid character.\r\n");
- } else {
- mquery("update users set away_nick='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
- $usersettings[$uid]['away_nick'] = $info;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-nick has been updated.\r\n");
- }
- } else {
- if ($section == "password") {
- mquery("update users set password='" . mysql_real_escape_string(sha1("wonder_if" . md5("someone" . $info . "will") . "figure_this_one_out")) . "' where id='{$uid}'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your password has been updated.\r\n");
- } else {
- if ($section == "nick") {
- if (!preg_match("/^[a-z0-9\\\\`\\^\\_\\-\\|\\[\\]{\\}]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your nick contains an invalid character.\r\n");
- } else {
- if (@array_key_exists(@$uid, @$net_clients)) {
- fwrite($net_clients[$uid], "NICK " . $info . "\r\n");
- $usersettings[$uid]['nickreq'] = $info;
- } else {
- $myinfo = mysql_fetch_array(mquery("select currentnick,username,host from users where id='{$uid}'"));
- foreach($authed as $cliID) {
- if (@array_key_exists(@$uid, @$cliID)) {
- fwrite($cliID[$uid], ":" . $myinfo['currentnick'] . "!" . $myinfo['username'] . "@" . $myinfo['host'] . " NICK :" . substr($info, 0, 15) . "\r\n");
- break;
- break;
- }
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":" . $myinfo['currentnick'] . "][" . $myinfo['username'] . "!" . $myinfo['username'] . "@" . $myinfo['host'] . " NICK :" . substr($info, 0, 15) . "][" . $myinfo['username'] . "\r\n");
- }
- }
- }
- mquery("update users set currentnick='" . mysql_real_escape_string(substr($info, 0, 15)) . "', nick='" . mysql_real_escape_string(substr($info, 0, 15)) . "' where id='{$uid}'");
- $usersettings[$uid]['currentnick'] = substr();
- $usersettings[$uid]['nick'] = substr($info, 0, 15);
- $usersettings[$uid]['tempnick'] = substr($info, 0, 15);
- fwrite($read_sock, ":phpBNC NOTICE " . substr($info, 0, 15) . " :Your nick has been updated.\r\n");
- unset($myinfo);
- }
- }
- } else {
- if ($section == "awaymsg") {
- if (!preg_match("/^[ a-z0-9\\\\[\\]\\(\\)\\_\\-\\#\\`\\'\\,\\.\\+\\åäöæø]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg contains an invalid character.\r\n");
- } else {
- if ($info == "''") {
- $info = "";
- }
- mquery("update users set away_msg='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
- $usersettings[$uid]['away_msg'] = $info;
- if ($info != "") {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg has been updated.\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg has been unset.\r\n");
- }
- }
- } else {
- if ($section == "channellog") {
- if ($info == "on") {
- mquery("update users set channellog='1' where id='" . mysql_real_escape_string($uid) . "'");
- $usersettings[$uid]['channellog'] = 1;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel logging has been switched on.\r\n");
- } else {
- if ($info == "off") {
- mquery("update users set channellog='0' where id='" . mysql_real_escape_string($uid) . "'");
- $usersettings[$uid]['channellog'] = 0;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel logging has been switched off.\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb set channellog <on/off>\r\n");
- }
- }
- } else {
- if ($section == "floodcontrol") {
- if ($info == "on") {
- mquery("update users set flood='1' where id='" . mysql_real_escape_string($uid) . "'");
- $usersettings[$uid]['flood'] = 1;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Flood protection has been switched on.\r\n");
- } else {
- if ($info == "off") {
- mquery("update users set flood='0' where id='" . mysql_real_escape_string($uid) . "'");
- $usersettings[$uid]['flood'] = 0;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Flood protection has been switched off.\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb set floodcontrol <on/off>\r\n");
- }
- }
- } else {
- if ($section == "server") {
- if (!preg_match("/^[a-z0-9\\-\\.]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your serveraddress contains an invalid character.\r\n");
- } else {
- mquery("update users set network='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your server has been updated.\r\n");
- }
- } else {
- if ($section == "key") {
- $stuff = explode(" ", $info);
- mquery("delete from blowfish_keys where uid='{$uid}' and target='" . mysql_real_escape_string($stuff[0]) . "'");
- mquery("insert into blowfish_keys (uid, `target`, `key`) Values('{$uid}', '" . mysql_real_escape_string($stuff[0]) . "', '" . mysql_real_escape_string($stuff[1]) . "')");
- $bfkeys[$uid][$stuff[0]]['name'] = $stuff[0];
- $bfkeys[$uid][$stuff[0]]['target_nick'] = "";
- $bfkeys[$uid][$stuff[0]]['key'] = $stuff[1];
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Key for " . $stuff[0] . " has been set.\r\n");
- unset($stuff);
- } else {
- if ($section == "port") {
- if (!preg_match("/^[0-9\\+]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your port can only contain numbers.\r\n");
- } else {
- if ($info[0] == "+") {
- $ssl = 1;
- $info = substr($info, 1, strlen($info) - 1);
- } else {
- $ssl = 0;
- }
- mquery("update users set port='{$info}', `ssl`='{$ssl}' where id='{$uid}'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your port has been updated.\r\n");
- }
- } else {
- if ($section == "host") {
- $finns = mysql_fetch_array(mquery("select `count` from `v-hosts` where `host`='" . mysql_real_escape_string($info) . "'"));
- $finns2 = mysql_fetch_array(mquery("select count(*) from `v-hosts` where `host`='" . mysql_real_escape_string($info) . "'"));
- if ($finns2['count(*)'] == 1) {
- if (mysql_result(mquery("select count(*) from users where host='" . mysql_real_escape_string($info) . "'"), 0) == $finns['count']) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :The userlimit for that v-host has been reached, please choose another one.\r\n");
- } else {
- mquery("update users set host='" . mysql_real_escape_string($info) . "' where id='{$uid}'");
- $usersettings[$uid]['host'] = $info;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :V-host changed to " . $info . ", please do a /breconnect for it to change.\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That v-host doesnt exist.\r\n");
- }
- unset($finns);
- unset($finns2);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb set <option> <value>\r\n");
- }
- unset($m);
- unset($section);
- unset($info);
- } else {
- if ($whattodo == "aset" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Aa][Ss][Ee][Tt] (.*?) (.*?) (.*)$/", $data, $m)) {
- $usrname = $m[1];
- $section = $m[2];
- $info = $m[3];
- $checker = mquery("select id from users where md5(lower(username))='" . mysql_real_escape_string(md5(strtolower($usrname))) . "'");
- if (mysql_num_rows($checker) == 1) {
- $usrid = mysql_fetch_array($checker);
- $usrid = $usrid['id'];
- if ($section == "realname") {
- if (!preg_match("/^[ a-z0-9\\\\,\\'\\.\\~\\_\\!\\@\\#$\\%\\^\\*\\(\\)\\_\\+\\=\\-\\|\\?\\<\\>\\/åäöæø]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That realname contains an invalid character.\r\n");
- } else {
- mquery("update users set realname='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That realname has been updated.\r\n");
- }
- } else {
- if ($section == "awaynick") {
- if (!preg_match("/^[a-z0-9\\\\`\\^\\_\\-\\|\\[\\]{\\}]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That away-nick contains an invalid character.\r\n");
- } else {
- mquery("update users set away_nick='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
- $usersettings[$usrid]['away_nick'] = $info;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That away-nick has been updated.\r\n");
- }
- } else {
- if ($section == "password") {
- mquery("update users set password='" . mysql_real_escape_string(sha1("wonder_if" . md5("someone" . $info . "will") . "figure_this_one_out")) . "' where id='" . $usrid . "'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That password has been updated.\r\n");
- } else {
- if ($section == "nick") {
- if (!preg_match("/^[a-z0-9\\\\`\\^\\_\\-\\|\\[\\]{\\}]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That nick contains an invalid character.\r\n");
- } else {
- if (@array_key_exists(@$usrid, @$net_clients)) {
- fwrite($net_clients[$usrid], "NICK " . $info . "\r\n");
- $usersettings[$usrid]['nickreq'] = $info;
- } else {
- $myinfo = mysql_fetch_array(mquery("select currentnick,username,host from users where id='" . $usrid . "'"));
- foreach($authed as $cliID) {
- if (@array_key_exists(@$usrid, @$cliID)) {
- fwrite($cliID[$usrid], ":" . $myinfo['currentnick'] . "!" . $myinfo['username'] . "@" . $myinfo['host'] . " NICK :" . substr($info, 0, 15) . "\r\n");
- break;
- break;
- }
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":" . $myinfo['currentnick'] . "][" . $myinfo['username'] . "!" . $myinfo['username'] . "@" . $myinfo['host'] . " NICK :" . substr($info, 0, 15) . "][" . $myinfo['username'] . "\r\n");
- }
- }
- }
- mquery("update users set currentnick='" . mysql_real_escape_string(substr($info, 0, 15)) . "', nick='" . mysql_real_escape_string(substr($info, 0, 15)) . "' where id='" . $usrid . "'");
- $usersettings[$usrid]['currentnick'] = substr($info, 0, 15);
- $usersettings[$usrid]['nick'] = substr($info, 0, 15);
- fwrite($read_sock, ":phpBNC NOTICE " . substr($info, 0, 15) . " :That nick has been updated.\r\n");
- unset($myinfo);
- }
- }
- } else {
- if ($section == "awaymsg") {
- if (!preg_match("/^[ a-z0-9\\\\[\\]\\(\\)\\_\\-\\#\\`\\'\\,\\.\\+\\åäöæø]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That away-msg contains an invalid character.\r\n");
- } else {
- if ($info == "''") {
- $info = "";
- }
- mquery("update users set away_msg='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
- $usersettings[$usrid]['away_msg'] = $info;
- if ($info != "") {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg has been updated.\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your away-msg has been unset.\r\n");
- }
- }
- } else {
- if ($section == "channellog") {
- if ($info == "on") {
- mquery("update users set channellog='1' where id='" . mysql_real_escape_string($usrid) . "'");
- $usersettings[$usrid]['channellog'] = 1;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel logging has been switched on.\r\n");
- } else {
- if ($info == "off") {
- mquery("update users set channellog='0' where id='" . mysql_real_escape_string($usrid) . "'");
- $usersettings[$usrid]['channellog'] = 0;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel logging has been switched off.\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb aset <username> channellog <on/off>\r\n");
- }
- }
- } else {
- if ($section == "floodcontrol") {
- if ($info == "on") {
- mquery("update users set flood='1' where id='" . mysql_real_escape_string($usrid) . "'");
- $usersettings[$usrid]['flood'] = 1;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Flood protection has been switched on.\r\n");
- } else {
- if ($info == "off") {
- mquery("update users set flood='0' where id='" . mysql_real_escape_string($usrid) . "'");
- $usersettings[$usrid]['flood'] = 0;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Flood protection has been switched off.\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb aset <username> floodcontrol <on/off>\r\n");
- }
- }
- } else {
- if ($section == "server") {
- if (!preg_match("/^[a-z0-9\\-\\.]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That serveraddress contains an invalid character.\r\n");
- } else {
- mquery("update users set network='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That server has been updated.\r\n");
- }
- } else {
- if ($section == "key") {
- $stuff = explode(" ", $info);
- mquery("delete from blowfish_keys where uid='" . $usrid . "' and target='" . mysql_real_escape_string($stuff[0]) . "'");
- mquery("insert into blowfish_keys (uid, `target`, `key`) Values('" . $usrid . "', '" . mysql_real_escape_string($stuff[0]) . "', '" . mysql_real_escape_string($stuff[1]) . "')");
- $bfkeys[$usrid][$stuff[0]]['name'] = $stuff[0];
- $bfkeys[$usrid][$stuff[0]]['target_nick'] = "";
- $bfkeys[$usrid][$stuff[0]]['key'] = $stuff[1];
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Key for " . $stuff[0] . " has been set.\r\n");
- unset($stuff);
- } else {
- if ($section == "port") {
- if (!preg_match("/^[0-9\\+]+$/i", $info)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :The port can only contain numbers.\r\n");
- } else {
- if ($info[0] == "+") {
- $ssl = 1;
- $info = substr($info, 1, strlen($info) - 1);
- } else {
- $ssl = 0;
- }
- mquery("update users set port='{$info}', `ssl`='{$ssl}' where id='" . $usrid . "'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Your port has been updated.\r\n");
- }
- } else {
- if ($section == "host") {
- $finns = mysql_fetch_array(mquery("select `count` from `v-hosts` where `host`='" . mysql_real_escape_string($info) . "'"));
- $finns2 = mysql_fetch_array(mquery("select count(*) from `v-hosts` where `host`='" . mysql_real_escape_string($info) . "'"));
- if ($finns2['count(*)'] == 1) {
- if (mysql_result(mquery("select count(*) from users where host='" . mysql_real_escape_string($info) . "'"), 0) == $finns['count']) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :The userlimit for that v-host has been reached, please choose another one.\r\n");
- } else {
- mquery("update users set host='" . mysql_real_escape_string($info) . "' where id='" . $usrid . "'");
- $usersettings[$usrid]['host'] = $info;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :V-host changed to " . $info . ", please tell the user to do a /breconnect for it to change.\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That v-host doesnt exist.\r\n");
- }
- unset($finns);
- unset($finns2);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user doesn´t exist.\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb aset <username> <option> <value>\r\n");
- }
- unset($m);
- unset($section);
- unset($info);
- } else {
- if ($whattodo == "del") {
- if (preg_match("/^[Pp][Bb] [Dd][Ee][Ll] (.*?) (.*)$/", $data, $m)) {
- if ($m[1] == "key") {
- mquery("delete from blowfish_keys where uid='{$uid}' and target='" . mysql_real_escape_string($m[2]) . "'");
- unset($bfkeys[$uid][$m[2]]);
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :The key for " . $m[2] . " has been deleted.\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb del <option> <value>\r\n");
- }
- unset($m);
- } else {
- if ($whattodo == "list") {
- if (preg_match("/^[Pp][Bb] [Ll][Ii][Ss][Tt] (.*)$/", $data, $m)) {
- if ($m[1] == "keys") {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Blowfish keys for " . $usersettings[$uid]['username'] . "\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
- $sql = mquery("select target, `key` from blowfish_keys where uid='{$uid}'");
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $RS['target'] . " has key " . $RS['key'] . "\r\n");
- }
- unset($sql);
- unset($RS);
- } else {
- if ($m[1] == "hosts") {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Available v-hosts\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :[number] [in use/limit] [host]\r\n");
- $counter = 1;
- $sql = mquery("select `host`, `count` from `v-hosts` order by `host` desc");
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :#" . $counter . " " . mysql_result(mquery("select count(*) from users where host='" . mysql_real_escape_string($RS['host']) . "'"), 0) . "/" . $RS['count'] . " " . $RS['host'] . "\r\n");
- ++$counter;
- }
- unset($counter);
- unset($sql);
- unset($RS);
- } else {
- if ($m[1] == "channels") {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Banned channels\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} : [Channel] [Network] [Expires] [Reason]\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
- $sql = mquery("select * from banned_channels order by until desc");
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :[" . $RS['channel'] . "] [" . $RS['network'] . "] [" . date("Y-m-d H:i:s", $RS['until']) . "] [" . $RS['reason'] . "]\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, that list option doesnt exist\r\n");
- }
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb list <option>\r\n");
- }
- unset($m);
- } else {
- if ($whattodo == "myinfo") {
- $info = mysql_fetch_array(mquery("select * from users where id='" . mysql_real_escape_string($uid) . "'"));
- if ($info['ssl'] == 1) {
- $info['port'] = "+" . $info['port'];
- }
- $ulength = 20 - strlen($info['username']);
- $nlength = 24 - strlen($info['nick']);
- $rlength = 20 - strlen($info['realname']);
- $anlength = 20 - strlen($info['away_nick']);
- $amlength = 21 - strlen($info['away_msg']);
- $hlength = 37 - strlen($info['host']);
- $plength = 37 - strlen($info['port']);
- $netlength = 35 - strlen($info['network']);
- $netnamelength = 29 - strlen($info['net_name']);
- if ($info['channellog'] == 1) {
- $info['channellog'] = "On";
- } else {
- $info['channellog'] = "Off";
- }
- if ($info['flood'] == 1) {
- $info['flood'] = "On";
- } else {
- $info['flood'] = "Off";
- }
- $chanlength = 31 - strlen($info['channellog']);
- $floodlength = 29 - strlen($info['flood']);
- $uspaces = "";
- $nspaces = "";
- $rspaces = "";
- $anspaces = "";
- $amspaces = "";
- $hspaces = "";
- $pspaces = "";
- $netspaces = "";
- $netnamespaces = "";
- $chanspaces = "";
- $floodspaces = "";
- $i = 0;
- while ($i < $ulength) {
- $uspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $netnamelength) {
- $netnamespaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $nlength) {
- $nspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $rlength) {
- $rspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $anlength) {
- $anspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $amlength) {
- $amspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $hlength) {
- $hspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $plength) {
- $pspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $netlength) {
- $netspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $chanlength) {
- $chanspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $floodlength) {
- $floodspaces.= " ";
- ++$i;
- }
- fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : _______________________________________________________________________________ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : /´ | `\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Username: " . $info['username'] . "{$uspaces}| Server: " . $info['network'] . "{$netspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Nick: " . $info['nick'] . "{$nspaces}| Network name: " . $info['net_name'] . "{$netnamespaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Realname: " . $info['realname'] . "{$rspaces}| Port: " . $info['port'] . "{$pspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Awaynick: " . $info['away_nick'] . "{$anspaces}| Host: " . $info['host'] . "{$hspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Awaymsg: " . $info['away_msg'] . "{$amspaces}| Floodcontrol: " . $info['flood'] . "{$floodspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | | Channellog: " . $info['channellog'] . "{$chanspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : `\\_________________________________|______________________________________________/´ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n");
- unset($ulength);
- unset($nlength);
- unset($rlength);
- unset($anlength);
- unset($amlength);
- unset($hlength);
- unset($plength);
- unset($netlength);
- unset($netnamelength);
- unset($uspaces);
- unset($nspaces);
- unset($rspaces);
- unset($anspaces);
- unset($amspaces);
- unset($hspaces);
- unset($pspaces);
- unset($netspaces);
- unset($netnamespaces);
- unset($chanlength);
- unset($chanspaces);
- unset($floodlength);
- unset($floodspaces);
- unset($info);
- } else {
- if ($whattodo == "uptime") {
- $time = time() - starttime;
- $weeks = floor($time / 604800);
- $time = $time - $weeks * 604800;
- $days = floor($time / 86400);
- $time = $time - $days * 86400;
- $hours = floor($time / 3600);
- $time = $time - $hours * 3600;
- $min = floor($time / 60);
- $sec = $time - $min * 60;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :I have been up for " . $weeks . " week(s), " . $days . " day(s), " . $hours . " hour(s), " . $min . " minute(s) and " . $sec . " second(s)\r\n");
- unset($sec);
- unset($hours);
- unset($min);
- unset($time);
- unset($weeks);
- unset($days);
- } else {
- if ($whattodo == "stats" && checkadmin($uid, 1)) {
- $time = time() - starttime;
- $weeks = floor($time / 604800);
- $time = $time - $weeks * 604800;
- $days = floor($time / 86400);
- $time = $time - $days * 86400;
- $hours = floor($time / 3600);
- $time = $time - $hours * 3600;
- $min = floor($time / 60);
- $sec = $time - $min * 60;
- $totsupadmins = 0;
- $supadminsonline = 0;
- $sql = mquery("select id from users where admin='2'");
- $totsupadmins = mysql_num_rows($sql);
- while ($RS = mysql_fetch_array($sql)) {
- if (in_array($RS['id'], $admins)) {
- ++$supadminsonline;
- }
- }
- $totnormadmins = 0;
- $normadminsonline = 0;
- $sql = mquery("select id from users where admin='1'");
- $totnormadmins = mysql_num_rows($sql);
- while ($RS = mysql_fetch_array($sql)) {
- if (in_array($RS['id'], $admins)) {
- ++$normadminsonline;
- }
- }
- $banned = mysql_result(mquery("select count(*) from users where banned != ''"), 0);
- $totusers = mysql_result(mquery("select count(*) from users"), 0);
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :[ Users online: " . count($clients) . "/" . $totusers . " ][ Super-admins: " . $supadminsonline . "/" . $totsupadmins . " ][ Admins: " . $normadminsonline . "/" . $totnormadmins . " ][ Banned: " . $banned . " ][ Uptime: " . $weeks . " week(s), " . $days . " day(s), " . $hours . " hour(s), " . $min . " minute(s) and " . $sec . " second(s) ]\r\n");
- unset($sec);
- unset($hours);
- unset($min);
- unset($time);
- unset($weeks);
- unset($days);
- unset($totnormadmins);
- unset($normadminsonline);
- unset($totsupadmins);
- unset($supadminsonline);
- unset($banned);
- unset($sql);
- unset($RS);
- unset($totusers);
- } else {
- if ($whattodo == "kick" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Kk][Ii][Cc][Kk] (.*)$/", $data, $m)) {
- $online = 0;
- $usid = mysql_fetch_array(mquery("select id from users where username='" . mysql_real_escape_string($m[1]) . "'"));
- foreach($authed as $cliID) {
- $useridet = array_keys($cliID);
- if ($useridet[0] == $usid['id']) {
- $online = 1;
- break;
- break;
- }
- }
- if ($online == 1) {
- $res = $cliID[$useridet[0]];
- $key = array_search($res, $clients);
- unset($clients[$key]);
- unset($authed[$key]);
- if (@array_key_exists(@$useridet[0], @$net_clients)) {
- fwrite($net_clients[$useridet[0]], "NICK :" . $usersettings[$useridet[0]]['away_nick'] . "\r\n");
- if ($usersettings[$useridet[0]]['channellog'] == 0) {
- fwrite($net_clients[$useridet[0]], "MODE " . $usersettings[$useridet[0]]['away_nick'] . " +d\r\n");
- }
- if ($usersettings[$useridet[0]]['away-msg'] != "") {
- fwrite($net_clients[$useridet[0]], "AWAY :" . $usersettings[$useridet[0]]['away_msg'] . "\r\n");
- }
- }
- if (in_array($useridet[0], $admins)) {
- $key3 = array_search($useridet[0], $admins);
- unset($admins[$key3]);
- unset($key3);
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":" . $usersettings[$useridet[0]]['currentnick'] . "][" . $usersettings[$useridet[0]]['username'] . "!" . $usersettings[$useridet[0]]['username'] . "@" . $usersettings[$useridet[0]]['host'] . " PART &system\r\n");
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " kicked " . $usersettings[$useridet[0]]['username'] . "\r\n");
- }
- }
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :User has been kicked of the bouncer.\r\n");
- fwrite($res, ":phpBNC NOTICE " . $usersettings[$useridet[0]]['currentnick'] . " :You got kicked from the bouncer by " . $usersettings[$uid]['username'] . ".\r\n");
- fclose($res);
- echo $usersettings[$useridet[0]]['username'] . "s client disconnected.\r\n";
- unset($res);
- unset($key);
- unset($useridet);
- unset($useridet2);
- unset($cliID);
- unset($cliID2);
- unset($online);
- unset($usid);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :User isn´t online.\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb kick <username>\r\n");
- }
- unset($m);
- } else {
- if ($whattodo == "find" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Ff][Ii][Nn][Dd] (.*)$/", $data, $m)) {
- $counter = 1;
- $sql = mquery("select id, username, nick, admin from users where username like '%" . mysql_real_escape_string(str_replace("*", "%", $m[1])) . "%'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Found " . mysql_num_rows($sql) . " result(s).\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
- while ($RS = mysql_fetch_array($sql)) {
- $online = "";
- foreach($authed as $cliID) {
- $useridet = array_keys($cliID);
- if ($useridet[0] == $RS['id']) {
- $online = chr(3) . "3ONLINE" . chr(3);
- break;
- break;
- }
- }
- if (strlen($online) == 0) {
- $online = chr(3) . "4OFFLINE" . chr(3);
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :#" . $counter . " " . chr(2) . "nick" . chr(2) . ": " . $RS['currentnick'] . " " . chr(2) . "username" . chr(2) . ": " . $RS['username'] . " - " . $online . " - " . chr(2) . "level" . chr(2) . ": " . $RS['admin'] . "\r\n");
- ++$counter;
- }
- unset($sql);
- unset($RS);
- unset($counter);
- unset($online);
- unset($useridet);
- unset($cliID);
- unset($m);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb find <username>\r\n");
- }
- } else {
- if ($whattodo == "banchan" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Bb][Aa][Nn][Cc][Hh][Aa][Nn] (.*?) (.*?) (.*?) (.*)$/", $data, $m)) {
- if (strtolower($m[3][strlen($m[3]) - 1]) == "d") {
- $newtime = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + substr($m[3], 0, strlen($m[3]) - 1), date("Y"));
- } else if (strtolower($m[3][strlen($m[3]) - 1]) == "m") {
- $newtime = mktime(date("H"), date("i") + substr($m[3], 0, strlen($m[3]) - 1), date("s"), date("m"), date("d"), date("Y"));
- }
- $counter = mysql_result(mquery("select count(*) from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='" . mysql_real_escape_string($m[2]) . "'"), 0);
- if ($counter == 1) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :This channel is already banned.\r\n");
- } else {
- mquery("insert into banned_channels (channel, network, until, reason, byid) Values('" . mysql_real_escape_string($m[1]) . "', '" . mysql_real_escape_string($m[2]) . "', '" . $newtime . "', '" . mysql_real_escape_string($m[4]) . "', '" . $uid . "')");
- $sql = mquery("select uid from tempchannels where channel='" . mysql_real_escape_string($m[1]) . "'");
- while ($RS = mysql_fetch_array($sql)) {
- $samenetwork = false;
- if ($m[2] != "*") {
- $net_name = mysql_fetch_array(mquery("select net_name from users where id='" . $RS['uid'] . "'"));
- if ($m[2] == $net_name['net_name']) {
- $samenetwork = true;
- }
- } else {
- $samenetwork = true;
- }
- if ($samenetwork == true) {
- fwrite($net_clients[$RS['uid']], "PART " . $m[1] . "\r\n");
- foreach($authed as $cliID) {
- if (@array_key_exists(@$RS['uid'], @$cliID)) {
- fwrite($cliID[$RS['uid']], ":phpBNC NOTICE " . $usersettings[$RS['uid']]['currentnick'] . " :The channel " . $m[1] . " you were in has been banned by an admin due to: " . $m[4] . ".\r\n");
- }
- }
- }
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel is now banned.\r\n");
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " banned channel " . $m[1] . " on network " . $m[2] . " due to: " . $m[4] . ".\r\n");
- }
- }
- }
- }
- unset($m);
- unset($samenetwork);
- unset($cliID);
- unset($net_name);
- unset($sql);
- unset($RS);
- unset($counter);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb banchan <channel> <network> <duration> <reason>\r\n");
- }
- } else {
- if ($whattodo == "unbanchan" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Uu][Nn][Bb][Aa][Nn][Cc][Hh][Aa][Nn] (.*?) (.*)$/", $data, $m)) {
- if ($m[2] == "*") {
- $counter = mysql_result(mquery("select count(*) from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "'"), 0);
- } else {
- $counter = mysql_result(mquery("select count(*) from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='" . mysql_real_escape_string($m[2]) . "'"), 0);
- }
- if (0 < $counter) {
- if ($m[2] == "*") {
- mquery("delete from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "'");
- } else {
- mquery("delete from banned_channels where channel='" . mysql_real_escape_string($m[1]) . "' and network='" . mysql_real_escape_string($m[2]) . "'");
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel " . $m[1] . " is now unbanned.\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Channel " . $m[1] . " isnt even banned.\r\n");
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " unbanned channel " . $m[1] . ".\r\n");
- }
- }
- }
- unset($m);
- unset($counter);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb unbanchan <channel> <network>\r\n");
- }
- } else {
- if ($whattodo == "check" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Cc][Hh][Ee][Cc][Kk] (.*)$/", $data, $m)) {
- $sql = mquery("select uid, channel from tempchannels where channel='" . $m[1] . "'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Found " . mysql_num_rows($sql) . " user(s) in " . $m[1] . ".\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :------------------------------------------\r\n");
- $counter = 0;
- while ($RS = mysql_fetch_array($sql)) {
- $online = "";
- foreach($authed as $cliID) {
- $useridet = array_keys($cliID);
- if ($useridet[0] == $RS['uid']) {
- $online = chr(3) . "3ONLINE" . chr(3);
- break;
- break;
- }
- }
- if (strlen($online) == 0) {
- $online = chr(3) . "4OFFLINE" . chr(3);
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :#" . $counter . " " . chr(2) . "nick" . chr(2) . ": " . $usersettings[$RS['uid']]['currentnick'] . " " . chr(2) . "username" . chr(2) . ": " . $usersettings[$RS['uid']]['username'] . " - " . $online . " - " . chr(2) . "level" . chr(2) . ": " . $usersettings[$RS['uid']]['admin'] . "\r\n");
- ++$counter;
- }
- unset($sql);
- unset($RS);
- unset($counter);
- unset($online);
- unset($useridet);
- unset($cliID);
- unset($m);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb check <channel>\r\n");
- }
- } else {
- if ($whattodo == "info" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Ii][Nn][Ff][Oo] (.*)$/", $data, $m)) {
- $info = mysql_fetch_array(mquery("select * from users where username='" . mysql_real_escape_string($m[1]) . "'"));
- if ($info['ssl'] == 1) {
- $info['port'] = "+" . $info['port'];
- }
- $ulength = 20 - strlen($info['username']);
- $nlength = 24 - strlen($info['nick']);
- $rlength = 20 - strlen($info['realname']);
- $anlength = 20 - strlen($info['away_nick']);
- $amlength = 21 - strlen($info['away_msg']);
- $hlength = 37 - strlen($info['host']);
- $plength = 37 - strlen($info['port']);
- $netlength = 35 - strlen($info['network']);
- $netnamelength = 29 - strlen($info['net_name']);
- if ($info['channellog'] == 1) {
- $info['channellog'] = "On";
- } else {
- $info['channellog'] = "Off";
- }
- if ($info['flood'] == 1) {
- $info['flood'] = "On";
- } else {
- $info['flood'] = "Off";
- }
- $chanlength = 31 - strlen($info['channellog']);
- $floodlength = 29 - strlen($info['flood']);
- $uspaces = "";
- $nspaces = "";
- $rspaces = "";
- $anspaces = "";
- $amspaces = "";
- $hspaces = "";
- $pspaces = "";
- $netspaces = "";
- $netnamespaces = "";
- $i = 0;
- while ($i < $ulength) {
- $uspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $netnamelength) {
- $netnamespaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $nlength) {
- $nspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $rlength) {
- $rspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $anlength) {
- $anspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $amlength) {
- $amspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $hlength) {
- $hspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $plength) {
- $pspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $netlength) {
- $netspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $chanlength) {
- $chanspaces.= " ";
- ++$i;
- }
- $i = 0;
- while ($i < $floodlength) {
- $floodspaces.= " ";
- ++$i;
- }
- fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : _______________________________________________________________________________ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : /´ | `\\ \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Username: " . $info['username'] . "{$uspaces}| Server: " . $info['network'] . "{$netspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Nick: " . $info['nick'] . "{$nspaces}| Network name: " . $info['net_name'] . "{$netnamespaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Realname: " . $info['realname'] . "{$rspaces}| Port: " . $info['port'] . "{$pspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Awaynick: " . $info['away_nick'] . "{$anspaces}| Host: " . $info['host'] . "{$hspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | Awaymsg: " . $info['away_msg'] . "{$amspaces}| Floodcontrol: " . $info['flood'] . "{$floodspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : | | Channellog: " . $info['channellog'] . "{$chanspaces}| \r\n" . ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : `\\_________________________________|______________________________________________/´ \r\n");
- $sql = mquery("select channel from tempchannels where uid='" . $info['id'] . "'");
- while ($RS = mysql_fetch_array($sql)) {
- $channels = $channels . $RS['channel'] . ", ";
- }
- fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : Hes currently in these channels: " . $channels . "\r\n");
- $channels = "";
- $sql = mquery("select channel, network from userchannels where uid='" . $info['id'] . "'");
- while ($RS = mysql_fetch_array($sql)) {
- $channels = $channels . $RS['channel'] . " (" . $RS['network'] . "), ";
- }
- fwrite($read_sock, ":phpBNC!phpBNC@phpBNC PRIVMSG {$nick} : He has these channels stored: " . $channels . "\r\n");
- unset($ulength);
- unset($nlength);
- unset($rlength);
- unset($anlength);
- unset($amlength);
- unset($hlength);
- unset($plength);
- unset($netlength);
- unset($netnamelength);
- unset($uspaces);
- unset($nspaces);
- unset($rspaces);
- unset($anspaces);
- unset($amspaces);
- unset($hspaces);
- unset($pspaces);
- unset($netspaces);
- unset($netnamespaces);
- unset($chanlength);
- unset($chanspaces);
- unset($floodlength);
- unset($floodspaces);
- unset($info);
- unset($sql);
- unset($channels);
- unset($RS);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb info <username>\r\n");
- }
- } else {
- if ($whattodo == "ban" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Bb][Aa][Nn] (.*?) (.*?) (.*)$/", $data, $m)) {
- if (strtolower($m[2][strlen($m[2]) - 1]) == "d") {
- $newtime = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + substr($m[2], 0, strlen($m[2]) - 1), date("Y"));
- } else if (strtolower($m[2][strlen($m[2]) - 1]) == "m") {
- $newtime = mktime(date("H"), date("i") + substr($m[2], 0, strlen($m[2]) - 1), date("s"), date("m"), date("d"), date("Y"));
- }
- $sql = mquery("select id, banned, banned_until from users where username='" . mysql_real_escape_string($m[1]) . "'");
- if (mysql_num_rows($sql) == 1) {
- $RS = mysql_fetch_array($sql);
- if (0 < strlen($RS['banned']) && time() < $RS['banned_until']) {
- fwrite($read_sock, "phpBNC NOTICE {$nick} :This user is already banned due to: " . $RS['banned'] . " until: " . date("Y-m-d H:i:s", $RS['banned_until']) . "\r\n");
- } else {
- mquery("update users set banned='" . mysql_real_escape_string($m[3]) . "', banned_until='" . $newtime . "' where id='" . mysql_real_escape_string($RS['id']) . "'");
- if (@array_key_exists(@$RS['id'], @$net_clients)) {
- fwrite($net_clients[$RS['id']], "QUIT\r\n");
- fclose($net_clients[$RS['id']]);
- unset($net_clients[$RS['id']]);
- }
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$RS['id'], @$cliID)) {
- fwrite($cliID[$RS['id']], ":phpBNC NOTICE " . $usersettings[$RS['id']]['currentnick'] . " :You got banned due to: " . $m[3] . " until: " . date("Y-m-d H:i:s", $newtime) . "\r\n");
- $online = 1;
- break;
- break;
- }
- }
- if ($online == 1) {
- $res = $cliID[$RS['id']];
- $key = array_search($res, $clients);
- unset($clients[$key]);
- unset($authed[$key]);
- if (in_array($RS['id'], $admins)) {
- $key3 = array_search($RS['id'], $admins);
- unset($admins[$key3]);
- unset($key3);
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":" . $usersettings[$RS['id']]['currentnick'] . "][" . $usersettings[$RS['id']]['username'] . "!" . $usersettings[$RS['id']]['username'] . "@" . $usersettings[$RS['id']]['host'] . " PART &system\r\n");
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " " . chr(2) . "BANNED" . chr(2) . " " . $usersettings[$RS['id']]['username'] . " until " . date("Y-m-d H:i:s", $newtime) . " due to: " . $m[3] . "\r\n");
- }
- }
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :User has been banned until " . date("Y-m-d H:i:s", $newtime) . ".\r\n");
- fwrite($res, ":phpBNC NOTICE " . $usersettings[$RS['id']]['currentnick'] . " :You got banned from the bouncer by " . $usersettings[$uid]['username'] . " until " . date("Y-m-d H:i:s", $newtime) . " due to: " . $m[3] . ".\r\n");
- fclose($res);
- echo $usersettings[$RS['id']]['username'] . "s client disconnected.\r\n";
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user didn´t exist.\r\n");
- }
- unset($m);
- unset($sql);
- unset($RS);
- unset($cliID);
- unset($res);
- unset($online);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb ban <username> <duration> <reason>\r\n");
- }
- } else {
- if ($whattodo == "unban" && checkadmin($uid, 1)) {
- if (preg_match("/^[Pp][Bb] [Uu][Nn][Bb][Aa][Nn] (.*)$/", $data, $m)) {
- $counter = mquery("select banned, banned_until from users where username='" . mysql_real_escape_string($m[1]) . "'");
- if (mysql_num_rows($counter) == 1) {
- if (0 < strlen($counter['banned']) && time() < $counter['banned_until']) {
- mquery("update users set banned='', banned_until='0' where username='" . mysql_real_escape_string($m[1]) . "'");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " has been unbanned now.\r\n");
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :This user isn´t banned.\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user didn´t exist.\r\n");
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " unbanned " . $usersettings[$RS['id']]['username'] . ".\r\n");
- }
- }
- }
- unset($m);
- unset($useridet2);
- unset($cliID2);
- unset($counter);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb unban <username>\r\n");
- }
- } else {
- if ($whattodo == "addhost" && checkadmin($uid, 2)) {
- if (preg_match("/^[Pp][Bb] [Aa][Dd][Dd][Hh][Oo][Ss][Tt] (.*) (.*)$/", $data, $m)) {
- $counter = mysql_result(mquery("select count(*) from `v-hosts` where host='" . mysql_real_escape_string($m[2]) . "'"), 0);
- if (0 < $counter) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That host is already added?.\r\n");
- } else if (!is_numeric($m[1])) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :The count syntax needs to be a number.\r\n");
- } else {
- mquery("insert into `v-hosts` (count, host) Values('" . mysql_real_escape_string($m[1]) . "', '" . mysql_real_escape_string($m[2]) . "')");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :V-host added.\r\n");
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " added the v-host " . $m[2] . " with a limit of " . $m[1] . " user(s).\r\n");
- }
- }
- }
- }
- unset($counter);
- unset($m);
- unset($useridet2);
- unset($cliID2);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb addhost <number> <hostname>\r\n");
- }
- } else {
- if ($whattodo == "delhost" && checkadmin($uid, 2)) {
- if (preg_match("/^[Pp][Bb] [Dd][Ee][Ll][Hh][Oo][Ss][Tt] (.*)$/", $data, $m)) {
- $counter = mysql_result(mquery("select count(*) from `v-hosts` where host='" . mysql_real_escape_string($m[1]) . "'"), 0);
- if ($counter == 1) {
- mquery("delete from `v-hosts` where host='" . $m[1] . "'");
- $sql = mquery("select * from users where host='" . mysql_real_escape_string($m[1]) . "'");
- while ($RS = mysql_fetch_array($sql)) {
- $online = 0;
- foreach($authed as $cliID) {
- $useridet = array_keys($cliID);
- if ($useridet[0] == $RS['id']) {
- fwrite($cliID[$useridet[0]], ":phpBNC NOTICE " . $usersettings[$useridet[0]]['currentnick'] . " :The v-host you were using got deleted, please pick a new one.\r\n");
- $online = 1;
- break;
- break;
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("The v-host you were using got deleted, please pick a new one.") . "', UNIX_TIMESTAMP(), '" . $RS['id'] . "')");
- }
- $usersettings[$RS['id']]['host'] = "";
- }
- mquery("update users set host='' where host='" . mysql_real_escape_string($m[1]) . "'");
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " deleted the v-host " . $m[1] . ".\r\n");
- }
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That host doesn´t exist.\r\n");
- }
- unset($m);
- unset($online);
- unset($useridet2);
- unset($cliID2);
- unset($cliID);
- unset($useridet);
- unset($sql);
- unset($RS);
- unset($counter);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb delhost <hostname>\r\n");
- }
- } else {
- if ($whattodo == "adduser" && checkadmin($uid, 2)) {
- if (preg_match("/^[Pp][Bb] [Aa][Dd][Dd][Uu][Ss][Ee][Rr] (.*?) (.*)$/", $data, $m)) {
- $counter = mysql_result(mquery("select count(*) from users where id='" . mysql_real_escape_string($m[1]) . "'"), 0);
- if ($counter == 1) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That username is already taken.\r\n");
- } else if (!preg_match("/^[a-z0-9\\_\\-]+$/i", $m[1])) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :A username can only contain a-z, 0-9 _ -\r\n");
- } else if (10 < strlen($m[1])) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :A username can only be 10 characters long.\r\n");
- } else {
- mquery("insert into users (username, password, network, nick, currentnick, host, realname, away_nick, net_name, banned) Values('" . mysql_real_escape_string($m[1]) . "', '" . mysql_real_escape_string(sha1("wonder_if" . md5("someone" . $m[2] . "will") . "figure_this_one_out")) . "', '', '" . mysql_real_escape_string($m[1]) . "', '" . mysql_real_escape_string($m[1]) . "', '', '', '" . mysql_real_escape_string($m[1]) . "', '', '')");
- $useridd = mysql_insert_id();
- $usersettings[$useridd]['nick'] = $m[1];
- $usersettings[$useridd]['currentnick'] = $m[1];
- $usersettings[$useridd]['username'] = $m[1];
- $usersettings[$useridd]['host'] = "";
- $usersettings[$useridd]['away_nick'] = $m[1];
- $usersettings[$useridd]['away_msg'] = "disconnected";
- $usersettings[$useridd]['admin'] = 0;
- $usersettings[$useridd]['net_name'] = "";
- $usersettings[$useridd]['trailed'] = 0;
- $usersettings[$useridd]['channellog'] = 0;
- $usersettings[$useridd]['lastlogin'] = "";
- $usersettings[$useridd]['lastcommand'] = time();
- $usersettings[$useridd]['delay'] = 0;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :User added.\r\n");
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " added user " . $m[1] . ".\r\n");
- }
- }
- }
- }
- unset($useridd);
- unset($counter);
- unset($m);
- unset($useridet2);
- unset($cliID2);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb adduser <username> <password>\r\n");
- }
- } else {
- if ($whattodo == "deluser" && checkadmin($uid, 2)) {
- if (preg_match("/^PB deluser (.*)$/", $data, $m)) {
- $online = 0;
- $sql = mquery("select id from users where username='" . mysql_real_escape_string($m[1]) . "'");
- if (mysql_num_rows($sql) == 1) {
- $usid = mysql_fetch_array($sql);
- foreach($authed as $cliID) {
- $useridet = array_keys($cliID);
- if ($useridet[0] == $usid['id']) {
- $online = 1;
- break;
- break;
- }
- }
- if ($online == 1) {
- $res = $cliID[$useridet[0]];
- $key = array_search($res, $clients);
- unset($clients[$key]);
- unset($authed[$key]);
- if (@array_key_exists(@$useridet[0], @$net_clients)) {
- fwrite($net_clients[$useridet[0]], "QUIT\r\n");
- fclose($net_clients[$useridet[0]]);
- unset($net_clients[$useridet[0]]);
- }
- if (in_array($useridet[0], $admins)) {
- $key3 = array_search($useridet[0], $admins);
- unset($admins[$key3]);
- unset($key3);
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":" . $usersettings[$useridet[0]]['currentnick'] . "][" . $usersettings[$useridet[0]]['username'] . "!" . $usersettings[$useridet[0]]['username'] . "@" . $usersettings[$useridet[0]]['host'] . " PART &system\r\n");
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " deleted " . $usersettings[$useridet[0]]['username'] . "\r\n");
- }
- }
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :User has been deleted of the bouncer.\r\n");
- fwrite($res, ":phpBNC NOTICE " . $usersettings[$useridet[0]]['currentnick'] . " :You got deleted from the bouncer by " . $usersettings[$uid]['username'] . ".\r\n");
- fclose($res);
- echo $usersettings[$useridet[0]]['username'] . "s client disconnected.\r\n";
- unset($usersettings[$useridet[0]]);
- unset($res);
- unset($key);
- unset($useridet);
- unset($useridet2);
- unset($cliID);
- unset($cliID2);
- unset($online);
- } else {
- if (@array_key_exists(@$usid['id'], @$net_clients)) {
- fwrite($net_clients[$usid['id']], "QUIT\r\n");
- fclose($net_clients[$usid['id']]);
- unset($net_clients[$usid['id']]);
- }
- if (in_array($usid['id'], $admins)) {
- $key3 = array_search($usid['id'], $admins);
- unset($admins[$key3]);
- unset($key3);
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":[email protected] PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " deleted " . $usersettings[$usid['id']]['username'] . "\r\n");
- }
- }
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :User has been deleted of the bouncer.\r\n");
- echo $usersettings[$usid['id']]['username'] . "s client disconnected.\r\n";
- unset($usersettings[$usid['id']]);
- unset($key);
- unset($useridet);
- unset($useridet2);
- unset($cliID);
- unset($cliID2);
- unset($online);
- }
- mquery("delete from users where id='" . $usid['id'] . "'");
- unset($usid);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user doesn´t exist\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb deluser <username>\r\n");
- }
- unset($m);
- } else {
- if ($whattodo == "allmsg" && checkadmin($uid, 2)) {
- if (preg_match("/^[Pp][Bb] [Aa][Ll][Ll][Mm][Ss][Gg] (.*)$/", $data, $m)) {
- $sql = mquery("select id from users order by id asc");
- while ($RS = mysql_fetch_array($sql)) {
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$RS['id'], @$cliID)) {
- fwrite($cliID[$RS['id']], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$RS['id']]['currentnick'] . " :" . chr(2) . "ALLMSG" . chr(2) . ": " . $m[1] . ".\r\n");
- $online = 1;
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string(chr(2) . "ALLMSG" . chr(2) . ": " . $m[1]) . "', UNIX_TIMESTAMP(), '" . $RS['id'] . "')");
- }
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " sent an AMSG.\r\n");
- }
- }
- }
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Message has been sent.\r\n");
- unset($m);
- unset($sql);
- unset($RS);
- unset($online);
- unset($cliID);
- unset($cliID2);
- unset($useridet2);
- }
- } else {
- if ($whattodo == "trail" && checkadmin($uid, 2)) {
- if (preg_match("/^[Pp][Bb] [Tt][Rr][Aa][Ii][Ll] (.*)$/", $data, $m)) {
- $sql = mquery("select id, trailed from users where username='" . mysql_real_escape_string($m[1]) . "'");
- if (mysql_num_rows($sql) == 1) {
- $result = mysql_fetch_array($sql);
- if ($result['trailed'] == 1) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :That user is already being trailed.\r\n");
- } else {
- mquery("update users set trailed='1' where id='" . $result['id'] . "'");
- $usersettings[$result['id']]['trailed'] = 1;
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$result['id'], @$cliID)) {
- fwrite($cliID[$result['id']], ":phpBNC NOTICE " . $usersettings[$result['id']]['currentnick'] . " :You are now being trailed, this mean that everything you write and receive is being logged to a textfile, " . chr(2) . "REMEBER THIS" . chr(2) . ".\r\n");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " is now being trailed.\r\n");
- $online = 1;
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('An Admin has put a trail on you, that means that everything you write and receive are logged in a textfile, " . chr(2) . "REMEMBER THIS" . chr(2) . ".', UNIX_TIMESTAMP(), '" . $result['id'] . "')");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " is now being trailed.\r\n");
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " decided to trail " . $m[1] . ".\r\n");
- }
- }
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Can´t find user.\r\n");
- }
- unset($m);
- unset($sql);
- unset($result);
- unset($online);
- unset($cliID2);
- unset($useridet2);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb trail <username>\r\n");
- }
- } else {
- if ($whattodo == "untrail" && checkadmin($uid, 2)) {
- if (preg_match("/^[Pp][Bb] [Uu][Nn][Tt][Rr][Aa][Ii][Ll] (.*)$/", $data, $m)) {
- $sql = mquery("select id, trailed from users where username='" . mysql_real_escape_string($m[1]) . "'");
- if (mysql_num_rows($sql) == 1) {
- $result = mysql_fetch_array($sql);
- if ($result['trailed'] == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :This user isn´t being trailed stupid!!!.\r\n");
- } else {
- mquery("update users set trailed='0' where id='" . $result['id'] . "'");
- $usersettings[$result['id']]['trailed'] = 0;
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$result['id'], @$cliID)) {
- fwrite($cliID[$result['id']], ":phpBNC NOTICE " . $usersettings[$result['id']]['currentnick'] . " :You are " . chr(2) . "NOT" . chr(2) . " being trailed anymore.\r\n");
- $online = 1;
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " is not being trailed anymore.\r\n");
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('You are " . chr(2) . "NOT" . chr(2) . " being trailed anymore.', UNIX_TIMESTAMP(), '" . $result['id'] . "')");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . " is not being trailed anymore.\r\n");
- }
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " untrailed " . $m[1] . ".\r\n");
- }
- }
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Can´t find user.\r\n");
- }
- unset($m);
- unset($sql);
- unset($result);
- unset($online);
- unset($cliID2);
- unset($useridet2);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb untrail <username>\r\n");
- }
- } else {
- if ($whattodo == "admin" && checkadmin($uid, 2)) {
- if (preg_match("/^[Pp][Bb] [Aa][Dd][Mm][Ii][Nn] (.*) (.*)$/", $data, $m)) {
- if (is_numeric($m[2])) {
- $sql = mquery("select id, admin from users where username='" . mysql_real_escape_string($m[1]) . "'");
- if (mysql_num_rows($sql) == 1) {
- $result = mysql_fetch_array($sql);
- if ($result['admin'] == 0 && $m[2] == 0) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $usersettings[$result['id']]['username'] . " already is a normal user.\r\n");
- } else {
- if ($result['admin'] == 1 && $m[2] == 1) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $usersettings[$result['id']]['username'] . " already is a normal-admin.\r\n");
- } else {
- if ($result['admin'] == 2 && $m[2] == 2) {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $usersettings[$result['id']]['username'] . " already is a super-admin.\r\n");
- } else {
- foreach($admins as $useridet2) {
- foreach($authed as $cliID2) {
- if (@array_key_exists(@$useridet2, @$cliID2)) {
- fwrite($cliID2[$useridet2], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :" . chr(2) . "ADMIN:" . chr(2) . " " . $usersettings[$uid]['username'] . " changed adminlevel on " . $usersettings[$result['id']]['username'] . " from " . $usersettings[$result['id']]['admin'] . " to " . $m[2] . ".\r\n");
- }
- }
- }
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$result['id'], @$cliID)) {
- fwrite($cliID[$result['id']], ":phpBNC NOTICE " . $usersettings[$result['id']]['currentnick'] . " :Your adminlevel has been changed to " . mysql_real_escape_string($m[2]) . ".\r\n");
- $online = 1;
- $hissocket = $cliID[$result['id']];
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . "s adminlevel has now been changed.\r\n");
- }
- }
- if ($m[2] == 0 && 0 < $usersettings[$result['id']]['admin']) {
- unset($admins[array_search($result['id'], $admins) ]);
- if ($online == 1) {
- fwrite($hissocket, ":" . $usersettings[$result['id']]['currentnick'] . "!" . $usersettings[$result['id']]['username'] . "@" . $usersettings[$result['id']]['host'] . " PART &system\r\n");
- }
- $foere = "";
- if ($usersettings[$result['id']]['admin'] == 1) {
- $foere = "-v";
- } else if ($usersettings[$result['id']]['admin'] == 2) {
- $foere = "-o";
- }
- foreach($admins as $useridet) {
- if ($useridet != $result['id']) {
- foreach($authed as $cliID) {
- if (@!array_key_exists(@$useridet, @$cliID) || !($foere != "")) {
- fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
- }
- }
- }
- }
- } else if (0 < $m[2] && $usersettings[$result['id']]['admin'] == 0) {
- if ($online == 1) {
- fwrite($hissocket, ":" . $usersettings[$result['id']]['currentnick'] . "!" . $usersettings[$result['id']]['username'] . "@" . $usersettings[$result['id']]['host'] . " JOIN &system\r\n");
- fwrite($hissocket, ":phpBNC 332 " . $usersettings[$result['id']]['currentnick'] . " &system :System channel for phpBNC v." . version . "\r\n");
- fwrite($hissocket, ":phpBNC 333 " . $usersettings[$result['id']]['currentnick'] . " &system phpBNC " . starttime . "\r\n");
- $alltheusers = ":phpBNC 353 " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . " = &system :@phpBNC ";
- foreach($authed as $cliID) {
- $user = array_keys($cliID);
- $user = $user[0];
- $fore = "";
- if ($user != $result['id']) {
- if ($usersettings[$user]['admin'] == 1) {
- $fore = "+";
- } else if ($usersettings[$user]['admin'] == 2) {
- $fore = "@";
- }
- }
- $alltheusers.= "{$fore}" . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'] . " ";
- }
- fwrite($hissocket, $alltheusers . "\r\n");
- fwrite($hissocket, ":phpBNC 366 " . $usersettings[$result['id']]['currentnick'] . " &system :End of /NAMES list.\r\n");
- $foere = "";
- if ($m[2] == 1) {
- $foere = "+v";
- } else if ($m[2] == 2) {
- $foere = "+o";
- }
- fwrite($hissocket, ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
- foreach($admins as $useridet) {
- if ($useridet != $result['id']) {
- foreach($authed as $cliID) {
- if (@!array_key_exists(@$useridet, @$cliID) || !($foere != "")) {
- fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
- }
- }
- }
- }
- }
- $admins[] = $result['id'];
- } else if (0 < $m[2] && 0 < $usersettings[$result['id']]['admin']) {
- $oldfoere = "";
- if ($usersettings[$result['id']]['admin'] == 1) {
- $oldfoere = "-v";
- } else if ($usersettings[$result['id']]['admin'] == 2) {
- $oldfoere = "-o";
- }
- $foere = "";
- if ($m[2] == 1) {
- $foere = "+v";
- } else if ($m[2] == 2) {
- $foere = "+o";
- }
- if ($online == 1) {
- fwrite($hissocket, ":phpBNC!phpBNC@phpBNC MODE &system " . $oldfoere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
- fwrite($hissocket, ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
- }
- foreach($admins as $useridet) {
- if ($useridet != $result['id']) {
- foreach($authed as $cliID) {
- if (@!array_key_exists(@$useridet, @$cliID) || !($foere != "")) {
- fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $oldfoere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
- fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC MODE &system " . $foere . " " . $usersettings[$result['id']]['currentnick'] . "][" . $usersettings[$result['id']]['username'] . "\r\n");
- }
- }
- }
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('Your adminlevel has been changed to " . mysql_real_escape_string($m[2]) . ".', UNIX_TIMESTAMP(), '" . $result['id'] . "')");
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :" . $m[1] . "s adminlevel has now been changed.\r\n");
- }
- mquery("update users set admin='" . mysql_real_escape_string($m[2]) . "' where id='" . $result['id'] . "'");
- $usersettings[$result['id']]['admin'] = $m[2];
- }
- }
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Can´t find user.\r\n");
- }
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :You can only choose between 0, 1 and 2.\r\n");
- }
- unset($m);
- unset($online);
- unset($sql);
- unset($foere);
- unset($oldfoere);
- unset($result);
- unset($cliID2);
- unset($useridet2);
- unset($hissocket);
- } else {
- fwrite($read_sock, ":phpBNC NOTICE {$nick} :Wrong syntax, use /pb admin <username> <newlevel>\r\n");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } else if (@in_array(@$read_sock, @$net_clients)) {
- $netID = array_search($read_sock, $net_clients);
- fclose($net_clients[$netID]);
- unset($net_clients[$netID]);
- unset($userconmem[$netID]);
- mquery("update users set net_name='' where id='" . mysql_real_escape_string($netID) . "'");
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$netID, @$cliID)) {
- fwrite($cliID[$netID], ":phpBNC NOTICE " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
- fwrite($cliID[$netID], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
- $sql = mquery("select * from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($cliID[$netID], ":" . $usersettings[$netID]['currentnick'] . "!" . $usersettings[$netID]['username'] . "@" . $usersettings[$netID]['host'] . " PART " . $RS['channel'] . "\r\n");
- }
- $online = 1;
- break;
- break;
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("You got disconnected from the network you were connected to.") . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($netID) . "')");
- }
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
- echo $usersettings[$netID]['username'] . " got disconnected from irc-network\r\n";
- unset($sql);
- unset($RS);
- unset($online);
- unset($netID);
- unset($cliID);
- } else if (in_array(@$read_sock, @$identd) && enableident == true) {
- $netID = array_search($read_sock, $identd);
- fclose($identd[$netID]);
- unset($identd[$netID]);
- echo "identd connection got disconnected\r\n";
- unset($netID);
- } else if (@in_array(@$read_sock, @$clients)) {
- $cliID = array_search($read_sock, $clients);
- $key = $cliID;
- $uid = @array_search(@$read_sock, @$authed[$cliID]);
- if ($uid != false) {
- fclose($clients[$key]);
- unset($clients[$key]);
- unset($authed[$key]);
- if (@array_key_exists(@$uid, @$net_clients)) {
- fwrite($net_clients[$uid], "NICK :" . $usersettings[$uid]['away_nick'] . "\r\n");
- if ($usersettings[$uid]['channellog'] == 0) {
- fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['away_nick'] . " +d\r\n");
- }
- if ($usersettings[$uid]['away_msg'] != "") {
- fwrite($net_clients[$uid], "AWAY :" . $usersettings[$uid]['away_msg'] . "\r\n");
- }
- }
- if (in_array($uid, $admins)) {
- $key3 = array_search($uid, $admins);
- unset($admins[$key3]);
- unset($key3);
- }
- foreach($admins as $useridet) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$useridet, @$cliID)) {
- fwrite($cliID[$useridet], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " PART &system\r\n");
- }
- }
- }
- echo $usersettings[$uid]['username'] . "s client disconnected.\r\n";
- unset($key);
- unset($uid);
- unset($cliID);
- } else {
- $ip = explode(":", stream_socket_get_name($read_sock, true));
- $ip = $ip[0];
- $hosten = gethostbyaddr($ip);
- foreach($admins as $useridet) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$useridet, @$cliID)) {
- fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :Someone connected and disconnected from " . $hosten . "(" . $ip . ")\r\n");
- }
- }
- }
- echo "Client disconnected without logging in: " . $ip . "\r\n";
- fclose($clients[$key]);
- unset($clients[$key]);
- unset($ip);
- unset($hosten);
- }
- }
- unset($nfo);
- }
- }
- $discCli = array_keys($clients, "");
- $discNet = array_keys($net_clients, "");
- if (enableident) {
- $discIdent = array_keys($identd, "");
- if (0 < count($discIdent)) {
- foreach($discIdent as $netID) {
- fclose($identd[$netID]);
- unset($identd[$netID]);
- }
- echo "identd request got disconnected\r\n";
- }
- }
- if (0 < count($discNet)) {
- foreach($discNet as $netID) {
- fclose($net_clients[$netID]);
- unset($net_clients[$netID]);
- unset($userconmem[$netID]);
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
- mquery("update users set net_name='' where id='" . mysql_real_escape_string($netID) . "'");
- unset($userconmem[$netID]);
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$netID, @$cliID)) {
- fwrite($cliID[$netID], ":phpBNC NOTICE " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
- fwrite($cliID[$netID], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
- $online = 1;
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("You got disconnected from the network you were connected to.") . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($netID) . "')");
- }
- }
- echo "got disconnected from network\r\n";
- }
- if (0 < count($discCli)) {
- foreach($discCli as $cliID) {
- $key = $cliID;
- $uid = @array_search(@$read_sock, @$authed[$cliID]);
- fclose($clients[$key]);
- unset($clients[$key]);
- unset($authed[$key]);
- if (@array_key_exists(@$uid, @$net_clients)) {
- fwrite($net_clients[$uid], "NICK :" . $usersettings[$uid]['away_nick'] . "\r\n");
- if ($usersettings[$uid]['channellog'] == 0) {
- fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['away_nick'] . " +d\r\n");
- }
- if ($usersettings[$uid]['away_msg'] != "") {
- fwrite($net_clients[$uid], "AWAY :" . $usersettings[$uid]['away_msg'] . "\r\n");
- }
- }
- if (in_array($uid, $admins)) {
- $key3 = array_search($uid, $admins);
- unset($admins[$key3]);
- foreach($admins as $useridet) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$useridet, @$cliID)) {
- fwrite($cliID[$useridet], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings['host'] . " PART &system\r\n");
- }
- }
- }
- }
- echo "client disconnected.\r\n";
- }
- unset($key);
- unset($uid);
- unset($key3);
- }
- unset($online);
- unset($discNet);
- unset($discCli);
- unset($discIdent);
- foreach($net_clients as $ircnet) {
- $nfonet = stream_get_meta_data($ircnet);
- if ($nfonet['eof'] == true || $nfonet['timed_out'] == true) {
- $netID = array_search($ircnet, $net_clients);
- fclose($net_clients[$netID]);
- unset($net_clients[$netID]);
- unset($userconmem[$netID]);
- mquery("update users set net_name='' where id='" . mysql_real_escape_string($netID) . "'");
- $online = 0;
- foreach($authed as $cliID) {
- if (@array_key_exists(@$netID, @$cliID)) {
- fwrite($cliID[$netID], ":phpBNC NOTICE " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
- fwrite($cliID[$netID], ":phpBNC!phpBNC@phpBNC PRIVMSG " . $usersettings[$netID]['currentnick'] . " :You got disconnected from the IRC server you were connected to.\r\n");
- $sql = mquery("select * from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
- while ($RS = mysql_fetch_array($sql)) {
- fwrite($cliID[$netID], ":" . $usersettings[$netID]['currentnick'] . "!" . $usersettings[$netID]['username'] . "@" . $usersettings[$netID]['host'] . " PART " . $RS['channel'] . "\r\n");
- }
- $online = 1;
- break;
- break;
- }
- }
- if ($online == 0) {
- mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("You got disconnected from the network you were connected to.") . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($netID) . "')");
- }
- mquery("delete from tempchannels where uid='" . mysql_real_escape_string($netID) . "'");
- echo $usersettings[$netID]['username'] . " got disconnected from irc-network\r\n";
- unset($sql);
- unset($RS);
- unset($online);
- unset($netID);
- unset($cliID);
- }
- unset($nfonet);
- }
- unset($ircnet);
- foreach($clients as $usernet) {
- $nfonet = stream_get_meta_data($usernet);
- if ($nfonet['eof'] == true || $nfonet['timed_out'] == true) {
- $cliID = array_search($usernet, $clients);
- $key = $cliID;
- $uid = @array_search(@$usernet, @$authed[$cliID]);
- if ($uid != false) {
- fclose($clients[$key]);
- unset($clients[$key]);
- unset($authed[$key]);
- if (@array_key_exists(@$uid, @$net_clients)) {
- fwrite($net_clients[$uid], "NICK :" . $usersettings[$uid]['away_nick'] . "\r\n");
- if ($usersettings[$uid]['channellog'] == 0) {
- fwrite($net_clients[$uid], "MODE " . $usersettings[$uid]['away_nick'] . " +d\r\n");
- }
- if ($usersettings[$uid]['away_msg'] != "") {
- fwrite($net_clients[$uid], "AWAY :" . $usersettings[$uid]['away_msg'] . "\r\n");
- }
- }
- if (in_array($uid, $admins)) {
- $key3 = array_search($uid, $admins);
- unset($admins[$key3]);
- unset($key3);
- }
- foreach($admins as $useridet) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$useridet, @$cliID)) {
- fwrite($cliID[$useridet], ":" . $usersettings[$uid]['currentnick'] . "][" . $usersettings[$uid]['username'] . "!" . $usersettings[$uid]['username'] . "@" . $usersettings[$uid]['host'] . " PART &system\r\n");
- }
- }
- }
- echo $usersettings[$uid]['username'] . "s client disconnected.\r\n";
- unset($key);
- unset($uid);
- unset($cliID);
- } else {
- $ip = explode(":", stream_socket_get_name($read_sock, true));
- $ip = $ip[0];
- $hosten = gethostbyaddr($ip);
- foreach($admins as $useridet) {
- foreach($authed as $cliID) {
- if (@array_key_exists(@$useridet, @$cliID)) {
- fwrite($cliID[$useridet], ":phpBNC!phpBNC@phpBNC PRIVMSG &system :Someone connected and disconnected from " . $hosten . "(" . $ip . ")\r\n");
- }
- }
- }
- echo "Client disconnected without logging in: " . $ip . "\r\n";
- fclose($clients[$key]);
- unset($clients[$key]);
- unset($ip);
- unset($hosten);
- }
- }
- unset($nfonet);
- }
- unset($usernet);
- if (120 < time() - $lastpingrequest) {
- foreach($clients as $usernet) {
- fwrite($usernet, "PING :" . time() . "\r\n");
- }
- unset($usernet);
- foreach($net_clients as $ircnets) {
- fwrite($ircnets, "PING :" . time() . "\r\n");
- }
- unset($ircnets);
- $lastpingrequest = time();
- }
- foreach($usersettings as $usid => $val) {
- if (@(120 <= time() - $usersettings[$usid]['lastcontry'] && !array_key_exists(@$usid, @$net_clients))) {
- $userinfo = mysql_fetch_array(mquery("select username, nick, host, port, `ssl`, network, realname from users where id='{$usid}'"));
- $nick = $userinfo['nick'];
- $online = 0;
- foreach($authed as $cliID) {
- $useridet = array_keys($cliID);
- if ($useridet[0] == $usid) {
- $online = 1;
- $onlinesocket = $cliID[$useridet[0]];
- break;
- break;
- }
- }
- if (strlen($userinfo['host']) != 0 && strlen($userinfo['realname']) != 0 && strlen($userinfo['network']) != 0) {
- if ($online == 1) {
- fwrite($onlinesocket, ":phpBNC NOTICE {$nick} :Trying to connect you to " . $userinfo['network'] . "..\r\n");
- }
- $tempcontext = stream_context_create();
- stream_context_set_option($tempcontext, "socket", "bindto", gethostbyname($userinfo['host']) . ":0");
- if ($userinfo['ssl'] == 1) {
- $ssladd = "ssl://";
- } else {
- $ssladd = "tcp://";
- }
- $netsocket = stream_socket_client($ssladd . $userinfo['network'] . ":" . $userinfo['port'], $errno, $errstr, 2, STREAM_CLIENT_CONNECT, $tempcontext);
- if (!$netsocket) {
- if ($online == 1) {
- fwrite($onlinesocket, ":phpBNC NOTICE {$nick} :A error occured, could not connect to " . $userinfo['network'] . ", error: " . $errstr . ".\r\n");
- } else {
- mquery("insert into userlogs (msg, date, toid) Values('" . mysql_real_escape_string("A error occured, could not connect to " . $userinfo['network'] . ", error: " . $errstr . ".") . "', UNIX_TIMESTAMP(), '" . mysql_real_escape_string($usid) . "')");
- }
- } else {
- stream_set_timeout($netsocket, 1200);
- stream_set_blocking($netsocket, 0);
- $net_clients = array($usid => $netsocket) + $net_clients;
- if (enableident) {
- $tempp = explode(":", stream_socket_get_name($netsocket, false));
- $ident_ports[$usid] = $tempp[1];
- unset($tempp);
- }
- fwrite($netsocket, "NICK " . $userinfo['nick'] . "\r\n");
- fwrite($netsocket, "USER " . $userinfo['username'] . " \"" . $userinfo['nick'] . "\" \"" . $userinfo['host'] . "\" :" . $userinfo['realname'] . "\r\n");
- }
- if (0 < $usersettings[$usid]['admin'] && $online == 1) {
- $alltheusers = ":phpBNC 353 " . $usersettings[$usid]['currentnick'] . "][" . $usersettings[$usid]['username'] . " = &system :@phpBNC ";
- $ucounter = 0;
- foreach($authed as $cliID) {
- if (40 <= $ucounter) {
- fwrite($onlinesocket, $alltheusers . "\r\n");
- $alltheusers = ":phpBNC 353 " . $usersettings[$usid]['currentnick'] . "][" . $usersettings[$usid]['username'] . " = &system :";
- $ucounter = 0;
- }
- $user = array_keys($cliID);
- $user = $user[0];
- $fore = "";
- if ($usersettings[$user]['admin'] == 1) {
- $fore = "+";
- } else if ($usersettings[$user]['admin'] == 2) {
- $fore = "@";
- }
- if ($ucounter == 0) {
- $alltheusers.= $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- } else {
- $alltheusers.= " " . $fore . $usersettings[$user]['currentnick'] . "][" . $usersettings[$user]['username'];
- }
- ++$ucounter;
- }
- fwrite($onlinesocket, $alltheusers . "\r\n");
- fwrite($onlinesocket, ":phpBNC 366 " . $usersettings[$usid]['currentnick'] . " &system :End of /NAMES list.\r\n");
- unset($ucounter);
- }
- }
- $usersettings[$usid]['lastcontry'] = time();
- unset($onlinesocket);
- unset($online);
- unset($usid);
- }
- }
- }
- foreach($sockets as $socket) {
- fclose($socket);
- }
- fclose($identd);
- mysql_close($connecta);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement