$nick: " . trim($cmd[1]) . ": "; foreach($prvmsg as $word) { // Grab each word in the array after the privmsg username if($x == 0) { $line .= $word; $logline .= $word; } else { $line .= " " . $word; $logline .= " " . $word; } $x++; } $line .= "\n"; $logline .= "\n"; } else if($cmd[0]=="/me") { // If using /msg, push private message $prvmsg = array_splice($cmd, 1); // grab private message from string $line .= "PRIVMSG" . " " . $channel . " :\x01ACTION "; // set for push $x = 0; $logline .= "$channel: $nick "; foreach($prvmsg as $word) { // Grab each word in the array after the privmsg username if($x == 0) { $line .= $word; $logline .= $word; } else { $line .= " " . $word; $logline .= " " . $word; } $x++; } $logline .= "\n"; $line .= "\x01\n"; } else if ($cmd[0]=="/join") { doLog("$username: joining " . $cmd[1]); $line .= "JOIN " . trim($cmd[1]) . "\n"; // set for push //$logline .= "$nick:Joining " . $cmd[1] . "\n"; // push to client $_SESSION['idleirc-channel'] = trim($cmd[1]); } else if ($cmd[0]=="/channel" || $cmd[0]=="/focused") { doLog("$username: checking focused channel: " . $channel); $logline .= "$title $version ~Focused on $channel\n"; // push to client } else if ($cmd[0]=="/nick") { if($cmd[1]!="") { doLog("$username: setting nick to " . $cmd[1]); $line .= "NICK " . trim($cmd[1]) . "\n"; // set for push $_SESSION['idleirc-nick'] = trim($cmd[1]); } else { $logline .= "$title $version ~Joining " . $cmd[1] . "\n"; } } else if ($cmd[0]=="/usermode") { if($cmd[1]!="") { doLog("$username: setting usermode to " . $cmd[1]); $line .= "MODE $nick +x" . trim($cmd[1]) . "\n"; // set for push } else { $logline .= "$title $version ~Missing User MODE flags
/usermode [flag(s)]\n"; } } else if ($cmd[0]=="/archive") { if(file_exists("users/$username.logcount")) { $archivedLogCount = file_get_contents("users/$username.logcount"); $archivedLogCount++; file_put_contents("users/$username.logcount", $archivedLogCount); rename("users/$username.log", "users/$username.$archivedLogCount.log"); $logline .= "$title $version ~Logs are archived! View under 'IRC logs'\n"; } else { file_put_contents("users/$username.logcount", "1"); rename("users/$username.log", "users/$username.1.log"); $logline .= "$title $version ~Logs are archived! View under 'IRC logs'\n"; } } else if ($cmd[0]=="/mode") { if($cmd[1]!="") { if($cmd[2]!="") { doLog("$username: setting nick to " . $cmd[1]); $line .= "MODE " . trim($cmd[1]) . " " . trim($cmd[2]) . "\n"; // set for push } else { $logline .= "$title $version ~Missing MODE flags:
/mode [channel] [flag(s)]\n"; } } else { $logline .= "$title $version ~Missing channel and flags:
/mode [channel] [flag(s)]\n"; } } else if ($cmd[0]=="/list") { if($cmd[1]!="") { doLog("$username: listing users for " . $cmd[1]); $line .= "NAMES " . trim($cmd[1]) . "\n"; // set for push } else { doLog("$username: listing users for $channel"); $line .= "NAMES $channel\n"; // set for push } } else if ($cmd[0] == "/rejoin") { doLog("$username: rejoining channel"); if ($cmd[1] != "") { $line .= "PART " . trim($cmd[1]) . " :$username leaving...\n"; // push close command to IRC $line .= "JOIN " . trim($cmd[1]) . "\n"; // set for push //$logline .= "$nick: Leaving " . trim($cmd[1]) . "\n"; // push to client } else { $line .= "PART $channel :$username leaving...\n"; // push close command to IRC $line .= "JOIN $channel\n"; // set for push //$logline .= "$nick: Leaving $channel\n"; // push to client } } else if ($cmd[0] == "/part") { doLog("$username: leaving " . trim($cmd[1])); if ($cmd[1] != "") { $line .= "PART " . trim($cmd[1]) . " :$nick leaving...\n"; // push close command to IRC //$logline .= "$nick: Leaving " . trim($cmd[1]) . "\n"; // push to client } else { $line .= "PART $channel :$username leaving...\n"; // push close command to IRC //$logline .= "$nick: Leaving $channel\n"; // push to client } } else if ($cmd[0] == "/focus" || $cmd[0] == "/switch" || $cmd[0] == "/query") { if(trim($cmd[1]) != $channel) { $_SESSION['idleirc-channel'] = trim($cmd[1]); $logline .= "$title $version ~" . trim($cmd[1]) . " is focused, all messages will be sent to " . trim($cmd[1]) . "\n"; // push to client } else { $logline .= "$title $version ~You're already focused on $channel\n"; } } else if ($cmd[0] == "/help" || $cmd[0] == "/?") { $logline .= "$title $version ~"; $logline .= "HELP: Information about $title
/join [channel] : Join IRC channel [channel]
"; $logline .= "/archive: Archive current log file, and clear current chat history.
"; $logline .= "/focus [channel|user]: Funnel messages to specific channel or user (Alias: /switch; /query)
"; $logline .= "/part (channel): Part channel, part focused channel if none specified
"; $logline .= "/rejoin (channel): Part, and join a channel; focused channel if none is specified
"; $logline .= "/nick [nickname]: Change your nickname
"; $logline .= "/list [channel]: List users in a channel
"; $logline .= "/msg [channel|user] [msg]: Message channel, or PM 'user'
"; $logline .= "/usermode [flag(s): Sets MODE flag(s) to user
"; $logfile .= "/mode [channel] [flag(s)]: Sets MODE flag(s) for [channel]
"; $logline .= "/channel: Prints focused channel / user (Alias: /focused)\n"; } else { // @@ This is a work in progress // Sends every channel message to each channel :[ $line .= "PRIVMSG $channel :$msg\n"; $logline .= "$nick to $channel: $msg\n"; } // Get original content $content = file_get_contents("users/$username.log"); echo "" . nl2br(stripslashes($content)) . "
"; // Grab all contents, and push to socket output file. file_put_contents("users/$username.log", $content . $logline); // Grab user message and push to IRC client file_put_contents("users/.$username.push", $line); // Throw out your user message //echo nl2br(stripslashes($line)); // DONE } else if (isset($_GET['userlist'])) { // Generate userlist if(file_exists("users/$username.userlist")) { $userListContent = file_get_contents("users/$username.userlist"); echo $userListContent; } else { echo " "; } } else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") { $nick = stripslashes(htmlentities($_GET['nick'])); // Username // Grab IRC client output $content = file_get_contents("users/$nick.log"); if($_GET['get']=="") { // Push content to the web frontend echo "" . nl2br(stripslashes($content)) . "
"; // DONE } else if($_GET['get']=="notificationmentionexists") { if(file_exists("users/.$nick.mentioned")) { echo "true"; } else { echo "false"; } } else if($_GET['get']=="notificationpmedexists") { if(file_exists("users/.$nick.pmed")) { echo "true"; } else { echo "false"; } } else if($_GET['get']=="notificationmention") { $mentionuser = file_get_contents("users/.$nick.mentioned"); unlink("users/.$nick.mentioned"); echo $mentionuser; } else if($_GET['get']=="notificationpmed") { $pmuser = file_get_contents("users/.$nick.pmed"); unlink("users/.$nick.pmed"); echo $pmuser; } } else if (isset($_GET['do']) && isset($_GET['nick']) && $_GET['nick']!="") { $nick = stripslashes(htmlentities($_GET['nick'])); include("users/" . $nick . ".php"); if ($_GET['do']=="clearlog") { if(file_exists("users/" . $nick . ".log") && ($acctpass == $userpass)) { unlink("users/$nick.log"); } if(file_exists("users/" . $nick . ".logcount") && ($acctpass == $userpass)) { $archived = file_get_contents("users/$nick.logcount"); for($x = 1; $x <= $archived; $x++) { if(file_exists("users/$nick.$x.log")) { unlink("users/$nick.$x.log"); } } unlink("users/$nick.logcount"); } } else if($_GET['do']=="login" && !file_exists("users/.$username.pingfile") && ($acctpass == $userpass)) { // Is user asking for login? // Join channel $isachannel = substr_count($_SESSION['idleirc-channel'],'#') > 1 ? TRUE : FALSE ; if(!isset($_SESSION['idleirc-channel']) || $isachannel == FALSE) { file_put_contents("users/.$username.push", "JOIN " . $userchannel . "\n"); } else { file_put_contents("users/.$username.push", "JOIN " . $userchannel . "\n"); } // Make sure users DB is clean, put nothing into socket read file if(!file_exists("users/$username.log")) { file_put_contents("users/$username.log", ""); chmod("users/$username.log", 0755); // file permissions for read / write } // start pingfile - determines if webclient is active via write timestamp file_put_contents("users/.$username.pingfile", "pong"); chmod("users/.$username.pingfile", 0755); // file permissions for read / write // Execute IRC client in background // IRC server will die when either 1) pingfile is deleted, or // 2) if pingfile is older than 10 seconds of current sys time $realpath = realpath("./irc.php"); // get full file path // Execute IRC client shell_exec("/usr/bin/php $realpath $username $servaddr $servport > /dev/null 2>/dev/null &"); } else if($_GET['do']=="logout" && ($acctpass == $userpass)) { // Is user asking for logout? // Remove ping file if user logs out. IRC server will close $content = file_get_contents("users/$nick.log"); file_put_contents("users/$nick.log", $content . "$usernick ~ left the server...\n"); unlink("users/.$nick.pingfile"); } } ?>