Call this v1.3.0

This commit is contained in:
Pentium44 2020-12-11 20:55:13 -08:00
parent bcbc40468c
commit 713dfeb130
7 changed files with 134 additions and 98 deletions

3
.gitignore vendored
View File

@ -1,6 +1,3 @@
*.log
*.txt *.txt
*.pingfile
*.push
/users /users

View File

@ -60,6 +60,17 @@ Read-Write access for working directory
#### Changelog #### Changelog
* v1.3.0:
* CSS changes / fixes + cleanup
* Added server/port set ability on register + settings (Can toggle on or off in config.php as $allowMultiServer == "false")
* More HTML fixes + cleanup
* Bugfixes in IRC protocol parsing
* Added user QUIT parsing to irc.php
* Removed unneeded ping code from server.php from previous project.
* Pushed cycle speed up in irc.php for more snappy responses
* Removed client passed messages from idleirc log
* Moved all client needed files to users/ directory for better file management
* v1.2.3: * v1.2.3:
* CSS fixes and updates * CSS fixes and updates
* HTML format fixes within server.php and irc.php generation * HTML format fixes within server.php and irc.php generation

View File

@ -9,16 +9,16 @@ $title = "IdleIRC"; // Chat title
$desc = "IdleIRC is a simple web based IRC client & bouncer service."; // Chat description $desc = "IdleIRC is a simple web based IRC client & bouncer service."; // Chat description
$server = "cddo.cf"; // IRC server connected to (for information display panel and client) $server = "cddo.cf"; // IRC server connected to (for information display panel and client)
$port = "1337"; // IRC server port (for information display panel) $port = "1337"; // IRC server port (for information display panel)
$server_msgcount = "80"; // Number of messages to leave at the end of the server database
$default_channel = "#theroot"; // Default channel to push users into $default_channel = "#theroot"; // Default channel to push users into
$logfile = "irclog.txt"; // Log instances for each bouncer $logfile = "irclog.txt"; // Log instances for each bouncer
$allowMultiServer = "true"; // [true/false] Allow users to set other IRC servers for bouncer connect
//$maxloglength = "10"; // Max line length for flatfile IRC logger ~ bouncer. //$maxloglength = "10"; // Max line length for flatfile IRC logger ~ bouncer.
///// WEBCLIENT LAYOUT ///// ///// WEBCLIENT LAYOUT /////
$ipcolor = "#00FF00"; $ipcolor = "#00FF00";
///// NO TOUCHY SECTION ///// ///// NO TOUCHY SECTION /////
$version = "1.2.3"; // CWChat version $version = "1.3.0"; // CWChat version
function doLog($string) { function doLog($string) {
file_put_contents($GLOBALS['logfile'], $string . "\r\n", FILE_APPEND); file_put_contents($GLOBALS['logfile'], $string . "\r\n", FILE_APPEND);

View File

@ -18,30 +18,48 @@ if(!file_exists("users"))
function registerForm() { function registerForm() {
?> ?>
<br> <br>
<div class="login"> <div class="form">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?register=go" method="post"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>?register=go" method="post">
Username: <input style="padding: 2px; width: 300px;" class="text" type="text" name="username"><br /> <table>
Password: <input style="padding: 2px; width: 300px;" class="text" type="password" name="password"><br />
Password again: <input style="padding: 2px;width: 300px;" class="text" type="password" name="password-again"><br /><br /> <tr><td>Username:</td><td> <input style="padding: 2px; width: 300px;" class="text" type="text" name="username"></td></tr>
Default Nickname: <input style="padding: 2px; width: 300px;" class="text" type="text" name="nick"><br /> <tr><td>Password:</td><td> <input style="padding: 2px; width: 300px;" class="text" type="password" name="password"></td></tr>
Autoconnect/focus channel: <input style="padding: 2px; width: 300px;" class="text" type="text" name="channel"><br /> <tr><td>Password again:</td><td> <input style="padding: 2px;width: 300px;" class="text" type="password" name="password-again"></td></tr>
<tr><td>Below forms:</td><td> The nickname form can be left blank and<br /> will be substituted with your username.</td></tr>
<tr><td>Default Nickname:</td><td> <input style="padding: 2px; width: 300px;" class="text" type="text" name="nick"></td></tr>
<tr><td>Autoconnect/focus channel:</td><td> <input style="padding: 2px; width: 300px;" class="text" type="text" name="channel" value="<?php echo $GLOBALS['default_channel']; ?>"></td></tr>
<?php
if($GLOBALS['allowMultiServer'] == "true") {
?>
<tr><td>Server (IP:Port)</td><td> <input style="padding: 2px; width: 236px;" class="text" type="text" name="servaddr" value="<?php echo $GLOBALS['server']; ?>">:<input style="padding: 2px; width: 50px;" class="text" type="text" name="servport" value="<?php echo $GLOBALS['port']; ?>"></td></tr>
<?php
}
?>
</table>
<br />
<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Create account"> <input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Create account">
</form> </form>
</div> </div>
<br />
<?php <?php
} }
function loginForm(){ function loginForm(){
?> ?>
<br> <br>
<div class="login"> <div class="form">
<p> <p>
Welcome to <?php echo $GLOBALS['title'] . " " . $GLOBALS['version'] . ".<br /> " . $GLOBALS['desc']; ?><br /> Welcome to <?php echo $GLOBALS['title'] . " " . $GLOBALS['version'] . ".<br /> " . $GLOBALS['desc']; ?><br />
Don't have an account? <a href="index.php?register">Create one</a> here!<br /> Don't have an account? <a href="index.php?register">Create one</a> here!<br />
</p> </p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post">
Username: <input style="padding: 2px; width: 200px;" class="text" type="text" name="username"><br /> <table>
Password: <input style="padding: 2px; width: 200px;" class="text" type="password" name="password"><br />
<tr><td>Username:</td><td> <input style="padding: 2px; width: 200px;" class="text" type="text" name="username"></td></tr>
<tr><td>Password:</td><td> <input style="padding: 2px; width: 200px;" class="text" type="password" name="password"></td></tr>
</table>
<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Login"> <input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Login">
</form> </form>
</div> </div>
@ -58,28 +76,40 @@ if (isset($_GET['do']) && $_GET['do']=="settings") {
$username = $_SESSION['idleirc-user']; $username = $_SESSION['idleirc-user'];
$password = $_SESSION['idleirc-pass']; $password = $_SESSION['idleirc-pass'];
if(file_exists("users/$username.php")) { if (file_exists("users/$username.php")) {
include("users/$username.php"); include("users/$username.php");
} else { } else {
$userpass = ""; $userpass = "";
} }
if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) { if (isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) {
if(isset($_POST['nick']) && $_POST['nick']!="") { if (isset($_POST['nick']) && $_POST['nick']!="") {
file_put_contents("users/$username.php", "<?php \$usernickname='" . stripslashes(htmlentities($_POST['nick'])) . "'; ?>\n", FILE_APPEND); file_put_contents("users/$username.php", "<?php \$usernickname='" . stripslashes(htmlentities($_POST['nick'])) . "'; ?>\n", FILE_APPEND);
$_SESSION['idleirc-nick'] = stripslashes(htmlentities($_POST['nick'])); $_SESSION['idleirc-nick'] = stripslashes(htmlentities($_POST['nick']));
} }
if(isset($_POST['channel']) && $_POST['channel']!="") { if (isset($_POST['channel']) && $_POST['channel']!="") {
file_put_contents("users/$username.php", "<?php \$userchannel='" . stripslashes(htmlentities($_POST['channel'])) . "'; ?>\n", FILE_APPEND); file_put_contents("users/$username.php", "<?php \$userchannel='" . stripslashes(htmlentities($_POST['channel'])) . "'; ?>\n", FILE_APPEND);
$_SESSION['idleirc-channel'] = stripslashes(htmlentities($_POST['channel'])); $_SESSION['idleirc-channel'] = stripslashes(htmlentities($_POST['channel']));
} }
if(isset($_POST['password']) && $_POST['password']!="") { if (isset($_POST['password']) && $_POST['password']!="") {
file_put_contents("users/$username.php", "<?php \$userpass='" . md5($_POST['password']) . "'; ?>\n", FILE_APPEND); file_put_contents("users/$username.php", "<?php \$userpass='" . md5($_POST['password']) . "'; ?>\n", FILE_APPEND);
$_SESSION['idleirc-pass'] = md5($_POST['password']); $_SESSION['idleirc-pass'] = md5($_POST['password']);
} }
if ($allowMultiServer == "true") {
if (isset($_POST['servaddr']) && $_POST['servaddr']!="") {
file_put_contents("users/$username.php", "<?php \$userserver='" . stripslashes(htmlentities($_POST['servaddr'])) . "'; ?>\n", FILE_APPEND);
$_SESSION['idleirc-servaddr'] = stripslashes(htmlentities($_POST['servaddr']));
}
if (isset($_POST['servport']) && $_POST['servport']!="") {
file_put_contents("users/$username.php", "<?php \$userserverport='" . stripslashes(htmlentities($_POST['servport'])) . "'; ?>\n", FILE_APPEND);
$_SESSION['idleirc-servport'] = stripslashes(htmlentities($_POST['servport']));
}
}
header("refresh: 0;url=index.php"); header("refresh: 0;url=index.php");
} else { } else {
header("refresh: 0;url=index.php"); header("refresh: 0;url=index.php");
@ -95,7 +125,7 @@ if (isset($_GET['register']) && $_GET['register'] == "go") {
$nickname = isset($_POST['nick']) && ($_POST['nick'] !== "") ? htmlentities(stripslashes($_POST['nick'])) : $username; $nickname = isset($_POST['nick']) && ($_POST['nick'] !== "") ? htmlentities(stripslashes($_POST['nick'])) : $username;
$servaddr = isset($_POST['servaddr']) && ($_POST['servaddr'] !== "") ? htmlentities(stripslashes($_POST['servaddr'])) : $server; $servaddr = isset($_POST['servaddr']) && ($_POST['servaddr'] !== "") ? htmlentities(stripslashes($_POST['servaddr'])) : $server;
$servport = isset($_POST['servport']) && ($_POST['servport'] !== "") ? htmlentities(stripslashes($_POST['servport'])) : $port; $servport = isset($_POST['servport']) && ($_POST['servport'] !== "") ? htmlentities(stripslashes($_POST['servport'])) : $port;
file_put_contents("users/$username.php", "<?php \$userpass = '" . $password . "'; \$userchannel='" . $channame . "'; \$usernickname='" . $nickname . "'; ?>\n"); file_put_contents("users/$username.php", "<?php \$userpass = '" . $password . "'; \$userchannel='" . $channame . "'; \$usernickname='" . $nickname . "'; \$userserver='" . $servaddr . "'; \$userserverport='" . $servport . "'; ?>\n");
file_put_contents("users/.$username.first", "First time, start up\n"); file_put_contents("users/.$username.first", "First time, start up\n");
$_SESSION['idleirc-user'] = $username; $_SESSION['idleirc-user'] = $username;
$_SESSION['idleirc-nick'] = $nickname; $_SESSION['idleirc-nick'] = $nickname;
@ -115,8 +145,6 @@ if (isset($_GET['register']) && $_GET['register'] == "go") {
// If web frontend is trying to login, process and connect // If web frontend is trying to login, process and connect
if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn']) && isset($_POST['password']) && $_POST['password']!=""){ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn']) && isset($_POST['password']) && $_POST['password']!=""){
$name = isset($_POST['username']) && ($_POST['username'] !== "") && file_exists("users/" . $_POST['username'] . ".php") ? htmlentities(stripslashes($_POST['username'])) : "Unnamed"; $name = isset($_POST['username']) && ($_POST['username'] !== "") && file_exists("users/" . $_POST['username'] . ".php") ? htmlentities(stripslashes($_POST['username'])) : "Unnamed";
$servaddr = isset($_POST['servaddr']) && ($_POST['servaddr'] !== "") ? htmlentities(stripslashes($_POST['servaddr'])) : $server;
$servport = isset($_POST['servport']) && ($_POST['servport'] !== "") ? htmlentities(stripslashes($_POST['servport'])) : $port;
if(file_exists("users/$name.php")) { if(file_exists("users/$name.php")) {
include("users/$name.php"); include("users/$name.php");
if(md5($_POST['password']) == $userpass) { if(md5($_POST['password']) == $userpass) {
@ -124,8 +152,8 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn']) &&
$_SESSION['idleirc-nick'] = $usernickname; $_SESSION['idleirc-nick'] = $usernickname;
$_SESSION['idleirc-pass'] = $userpass; $_SESSION['idleirc-pass'] = $userpass;
$_SESSION['idleirc-channel'] = $userchannel; $_SESSION['idleirc-channel'] = $userchannel;
$_SESSION['idleirc-servaddr'] = $servaddr; $_SESSION['idleirc-servaddr'] = $userserver;
$_SESSION['idleirc-servport'] = $servport; $_SESSION['idleirc-servport'] = $userserverport;
header("refresh: 0;url=index.php"); header("refresh: 0;url=index.php");
} else { } else {
echo "ERROR: Failed to login: password incorrect."; echo "ERROR: Failed to login: password incorrect.";
@ -300,7 +328,7 @@ if (!isset($_SESSION['idleirc-user'])) {
} }
} else if(isset($_GET['logs'])) { } else if(isset($_GET['logs'])) {
$username = $_SESSION['idleirc-user']; $username = $_SESSION['idleirc-user'];
$logcontents = file_get_contents("$username.log"); $logcontents = file_get_contents("users/$username.log");
if(file_exists("users/$username.php")) { if(file_exists("users/$username.php")) {
include("users/$username.php"); include("users/$username.php");
} else { } else {
@ -308,12 +336,12 @@ if (!isset($_SESSION['idleirc-user'])) {
} }
if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) { if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) {
echo "<div class='logout'><a href='index.php'>Back to IRC</a></div>\n"; echo "<div class='navbar'><a href='index.php'>Back to IRC</a></div>\n";
echo "<div id='logmsgs'><table>\n" . $logcontents . "</table></div>\n"; echo "<div id='logmsgs'><table>\n" . $logcontents . "</table></div>\n";
} }
} else if(isset($_GET['settings'])) { } else if(isset($_GET['settings'])) {
$username = $_SESSION['idleirc-user']; $username = $_SESSION['idleirc-user'];
$logcontents = file_get_contents("$username.log"); $logcontents = file_get_contents("users/$username.log");
if(file_exists("users/$username.php")) { if(file_exists("users/$username.php")) {
include("users/$username.php"); include("users/$username.php");
} else { } else {
@ -321,7 +349,7 @@ if (!isset($_SESSION['idleirc-user'])) {
} }
if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) { if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) {
echo "<div class='logout'><a href='index.php'>Back to IRC</a></div>\n"; echo "<div class='navbar'><a href='index.php'>Back to IRC</a></div>\n";
?> ?>
<br> <br>
@ -333,6 +361,11 @@ if (!isset($_SESSION['idleirc-user'])) {
<tr><td>Default Nickname: </td><td> <input style="padding: 2px; width: 300px;" class="text" type="text" name="nick"></td></tr> <tr><td>Default Nickname: </td><td> <input style="padding: 2px; width: 300px;" class="text" type="text" name="nick"></td></tr>
<tr><td>Autoconnect/focus channel: </td><td> <input style="padding: 2px; width: 300px;" class="text" type="text" name="channel"></td></tr> <tr><td>Autoconnect/focus channel: </td><td> <input style="padding: 2px; width: 300px;" class="text" type="text" name="channel"></td></tr>
<tr><td>New password: </td><td> <input style="padding: 2px; width: 300px;" class="text" type="password" name="password"></td></tr> <tr><td>New password: </td><td> <input style="padding: 2px; width: 300px;" class="text" type="password" name="password"></td></tr>
<?php
if($allowMultiServer == "true") {
?> <tr><td>Server (IP:Port)</td><td> <input style="padding: 2px; width: 236px;" class="text" type="text" name="servaddr" value="<?php echo $server; ?>">:<input style="padding: 2px; width: 50px;" class="text" type="text" name="servport" value="<?php echo $port; ?>"></td></tr><?php
}
?>
</table> </table>
<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Set"> <input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Set">
@ -344,17 +377,17 @@ if (!isset($_SESSION['idleirc-user'])) {
} }
} else { } else {
?> ?>
<div class="logout"> <div class="navbar">
<a href="index.php?do=logout">Logout</a> <a href="index.php?do=logout">Logout</a>
<?php <?php
// If this is the first login, make sure to start the bouncer! From there, the user will have toggle control. // If this is the first login, make sure to start the bouncer! From there, the user will have toggle control.
if (!file_exists("." . $_SESSION['idleirc-user'] . ".pingfile") && file_exists("users/." . $_SESSION['idleirc-user'] . ".first")) { if (!file_exists("users/." . $_SESSION['idleirc-user'] . ".pingfile") && file_exists("users/." . $_SESSION['idleirc-user'] . ".first")) {
unlink("users/." . $_SESSION['idleirc-user'] . ".first"); unlink("users/." . $_SESSION['idleirc-user'] . ".first");
echo "<script language='javascript' type='text/javascript'>doLogin();</script>"; echo "<script language='javascript' type='text/javascript'>doLogin();</script>";
} }
if (!file_exists("." . $_SESSION['idleirc-user'] . ".pingfile")) if (!file_exists("users/." . $_SESSION['idleirc-user'] . ".pingfile"))
{ {
echo "<a onclick='doLogin();'>Connect to server</a>\n"; echo "<a onclick='doLogin();'>Connect to server</a>\n";
} else { } else {
@ -368,7 +401,7 @@ if (!isset($_SESSION['idleirc-user'])) {
<div id="msgs"> <div id="msgs">
<?php <?php
echo "<table>"; echo "<table>";
$get = file_get_contents($_SESSION['idleirc-user'] . ".log"); $get = file_get_contents("users/" . $_SESSION['idleirc-user'] . ".log");
echo $get; echo $get;
echo "</table>"; echo "</table>";
?> ?>

33
irc.php
View File

@ -68,38 +68,31 @@ while($bytes = socket_recv($socket, $r_data, 3068, MSG_DONTWAIT) !== '') {
} }
// If client sent something, push it to the IRC server! // If client sent something, push it to the IRC server!
if(file_exists(".$username.push")) { if(file_exists("users/.$username.push")) {
// Grab IRC command from server.php // Grab IRC command from server.php
$pushFile = file_get_contents(".$username.push"); $pushFile = file_get_contents("users/.$username.push");
// Push this / these commands to socket // Push this / these commands to socket
socket_write($socket, $pushFile, strlen($pushFile)); socket_write($socket, $pushFile, strlen($pushFile));
// Remove the push file // Remove the push file
unlink(".$username.push"); unlink("users/.$username.push");
} }
// Check if web client still up, if no pong after 15 seconds, connection closed. // Check if web client still up, if no pong after 15 seconds, connection closed.
if(!file_exists(".$username.pingfile")) { // If file is missing, quit if(!file_exists("users/.$username.pingfile")) { // If file is missing, quit
// Debug logging, check if IRC is exiting properly // Debug logging, check if IRC is exiting properly
doLog("Exiting, $username logged out..."); doLog("Exiting, $username logged out...");
$quitline = "QUIT :$username toggled disconnect; webirc\n"; // IRC QUIT line $quitline = "QUIT :$username toggled disconnect; webirc\n"; // IRC QUIT line
socket_write($socket, $quitline, strlen($quitline)); // Push to socket socket_write($socket, $quitline, strlen($quitline)); // Push to socket
socket_close($socket); // Close the socket socket_close($socket); // Close the socket
exit(0); // Exit the script, nothing to do. exit(0); // Exit the script, nothing to do.
} /*else if (date("YmdHis.", filemtime(".$username.pingfile"))<(date("YmdHis.", filemtime(".$username.pingfile"))-10)) { }
// Debug logging, check if IRC is exiting properly
doLog("Exiting, $username timed out...");
$quitline = "QUIT :$username's web session timed out\n"; // IRC QUIT line
socket_write($socket, $quitline, strlen($quitline)); // Push to socket
socket_close($socket); // Close the socket
exit(1); // Exit the script, nothing to do.
}*/
// If data variable is set and buffer has data to recieve // If data variable is set and buffer has data to recieve
// RECIEVE IT! // RECIEVE IT!
if(isset($data)) { // If data variable is set, there's data from socket if(isset($data)) { // If data variable is set, there's data from socket
$stringMsg = explode('PRIVMSG', $data); // Strip IRC commands $stringMsg = explode('PRIVMSG', $data); // Strip IRC commands
// Get original contents from socket // Get original contents from socket
$socketFileContents = file_get_contents("$username.log"); $socketFileContents = file_get_contents("users/$username.log");
$ex = explode(' ', $data); $ex = explode(' ', $data);
$data = htmlentities($data); $data = htmlentities($data);
@ -115,16 +108,16 @@ while($bytes = socket_recv($socket, $r_data, 3068, MSG_DONTWAIT) !== '') {
$senderIp = get_string_between($data, "@", " "); $senderIp = get_string_between($data, "@", " ");
$exitMsg = explode('PART', $data); $exitMsg = explode('PART', $data);
$msgline = "<tr><td class='userinfo'><b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> left " . stripslashes(trim($exitMsg[1])) . "</td></tr>"; $msgline = "<tr><td class='userinfo'><b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> left " . stripslashes(trim($exitMsg[1])) . "</td></tr>";
file_put_contents("$username.log", $socketFileContents . $msgline); file_put_contents("users/$username.log", $socketFileContents . $msgline);
} else if ($ex[1] == "JOIN") { } else if ($ex[1] == "JOIN") {
$senderNick = get_string_between($data, ":", "!"); $senderNick = get_string_between($data, ":", "!");
$senderIp = get_string_between($data, "@", " "); $senderIp = get_string_between($data, "@", " ");
if($senderNick != $usernickname) { if($senderNick != $usernickname) {
$msgline = "<tr><td class='userinfo'><b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> joined the channel</td></tr>\n"; $msgline = "<tr><td class='userinfo'><b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> joined the channel</td></tr>\n";
file_put_contents("$username.log", $socketFileContents . $msgline); file_put_contents("users/$username.log", $socketFileContents . $msgline);
} else { } else {
$msgline = "<tr><td class='userinfo'><span style='color:$ipcolor;'>" . $server_address . "</span> ~ </td><td> " . $data . "</td></tr>\n"; $msgline = "<tr><td class='userinfo'><span style='color:$ipcolor;'>" . $server_address . "</span> ~ </td><td> " . $data . "</td></tr>\n";
file_put_contents("$username.log", $socketFileContents . $msgline); file_put_contents("users/$username.log", $socketFileContents . $msgline);
} }
} else if ($ex[1] == "NICK") { } else if ($ex[1] == "NICK") {
$senderNick = get_string_between($data, ":", "!"); $senderNick = get_string_between($data, ":", "!");
@ -150,7 +143,7 @@ while($bytes = socket_recv($socket, $r_data, 3068, MSG_DONTWAIT) !== '') {
} }
$msgline = "<tr><td class='userinfo'>PM from: <b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> " . htmlentities(stripslashes(trim($msg))) . "</td></tr>\n"; $msgline = "<tr><td class='userinfo'>PM from: <b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> " . htmlentities(stripslashes(trim($msg))) . "</td></tr>\n";
file_put_contents("$username.log", $socketFileContents . $msgline); file_put_contents("users/$username.log", $socketFileContents . $msgline);
$msg = ""; $msg = "";
} else if ($stringMsg[1] != "") { } else if ($stringMsg[1] != "") {
$senderNick = get_string_between($data, ":", "!"); $senderNick = get_string_between($data, ":", "!");
@ -158,15 +151,15 @@ while($bytes = socket_recv($socket, $r_data, 3068, MSG_DONTWAIT) !== '') {
$channel = explode(" :", $stringMsg[1]); $channel = explode(" :", $stringMsg[1]);
$msg = explode($channel[0] . " :", $stringMsg[1]); $msg = explode($channel[0] . " :", $stringMsg[1]);
$msgline = "<tr><td class='userinfo'><b>$senderNick</b>:" . $channel[0] . "<br /><span style='color:$ipcolor;'>$senderIp</span></td><td> " . htmlentities(stripslashes(trim($msg[1]))) . "</td></tr>\n"; $msgline = "<tr><td class='userinfo'><b>$senderNick</b>:" . $channel[0] . "<br /><span style='color:$ipcolor;'>$senderIp</span></td><td> " . htmlentities(stripslashes(trim($msg[1]))) . "</td></tr>\n";
file_put_contents("$username.log", $socketFileContents . $msgline); file_put_contents("users/$username.log", $socketFileContents . $msgline);
} else if ($ex[0] != "PING") { } else if ($ex[0] != "PING") {
$msgline = "<tr><td class='userinfo'><span style='color:$ipcolor;'>" . $server_address . "</span> ~ </td><td> " . $data . "</td></tr>\n"; $msgline = "<tr><td class='userinfo'><span style='color:$ipcolor;'>" . $server_address . "</span> ~ </td><td> " . $data . "</td></tr>\n";
file_put_contents("$username.log", $socketFileContents . $msgline); file_put_contents("users/$username.log", $socketFileContents . $msgline);
} }
} }
// second sleep to prevent insane CPU load // second sleep to prevent insane CPU load
usleep(1000); usleep(600);
} }
?> ?>

View File

@ -14,10 +14,6 @@ include_once("config.php");
session_start(); session_start();
if(isset($_GET['msg'])) {
doLog("Msg information: " . trim($_GET['msg']));
}
$username = $_SESSION['idleirc-user']; $username = $_SESSION['idleirc-user'];
$usernick = $_SESSION['idleirc-nick']; $usernick = $_SESSION['idleirc-nick'];
$acctpass = $_SESSION['idleirc-pass']; $acctpass = $_SESSION['idleirc-pass'];
@ -158,12 +154,12 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
} }
// Get original content // Get original content
$content = file_get_contents("$username.log"); $content = file_get_contents("users/$username.log");
echo "<table>" . nl2br(stripslashes($content)) . "</table>"; echo "<table>" . nl2br(stripslashes($content)) . "</table>";
// Grab all contents, and push to socket output file. // Grab all contents, and push to socket output file.
file_put_contents("$username.log", $content . $logline); file_put_contents("users/$username.log", $content . $logline);
// Grab user message and push to IRC client // Grab user message and push to IRC client
file_put_contents(".$username.push", $line); file_put_contents("users/.$username.push", $line);
// Throw out your user message // Throw out your user message
//echo nl2br(stripslashes($line)); //echo nl2br(stripslashes($line));
// DONE // DONE
@ -171,35 +167,35 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
} else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") { } else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") {
$nick = stripslashes(htmlentities($_GET['nick'])); // Username $nick = stripslashes(htmlentities($_GET['nick'])); // Username
// Grab IRC client output // Grab IRC client output
$content = file_get_contents("$nick.log"); $content = file_get_contents("users/$nick.log");
// Push content to the web frontend // Push content to the web frontend
echo "<table>" . nl2br(stripslashes($content)) . "</table"; echo "<table>" . nl2br(stripslashes($content)) . "</table>";
// DONE // DONE
} else if (isset($_GET['do']) && isset($_GET['nick']) && $_GET['nick']!="") { } else if (isset($_GET['do']) && isset($_GET['nick']) && $_GET['nick']!="") {
$nick = stripslashes(htmlentities($_GET['nick'])); $nick = stripslashes(htmlentities($_GET['nick']));
include("users/" . $nick . ".php"); include("users/" . $nick . ".php");
if ($_GET['do']=="clearlog") { if ($_GET['do']=="clearlog") {
if(file_exists($nick . ".log") && ($acctpass == $userpass)) { if(file_exists("users/" . $nick . ".log") && ($acctpass == $userpass)) {
unlink($nick . ".log"); unlink("users/" . $nick . ".log");
} }
} else if($_GET['do']=="login" && !file_exists(".$username.pingfile") && ($acctpass == $userpass)) { // Is user asking for login? } else if($_GET['do']=="login" && !file_exists("users/.$username.pingfile") && ($acctpass == $userpass)) { // Is user asking for login?
// Join channel // Join channel
$isachannel = substr_count($_SESSION['idleirc-channel'],'#') > 1 ? TRUE : FALSE ; $isachannel = substr_count($_SESSION['idleirc-channel'],'#') > 1 ? TRUE : FALSE ;
if(!isset($_SESSION['idleirc-channel']) || $isachannel == FALSE) { if(!isset($_SESSION['idleirc-channel']) || $isachannel == FALSE) {
file_put_contents(".$username.push", "JOIN " . $default_channel . "\n"); file_put_contents("users/.$username.push", "JOIN " . $default_channel . "\n");
} else { } else {
file_put_contents(".$username.push", "JOIN " . $channel . "\n"); file_put_contents("users/.$username.push", "JOIN " . $channel . "\n");
} }
// Make sure users DB is clean, put nothing into socket read file // Make sure users DB is clean, put nothing into socket read file
if(!file_exists("$username.log")) { if(!file_exists("users/$username.log")) {
file_put_contents("$username.log", ""); file_put_contents("users/$username.log", "");
chmod("$username.log", 0755); // file permissions for read / write chmod("users/$username.log", 0755); // file permissions for read / write
} }
// start pingfile - determines if webclient is active via write timestamp // start pingfile - determines if webclient is active via write timestamp
file_put_contents(".$username.pingfile", "pong"); file_put_contents("users/.$username.pingfile", "pong");
chmod(".$username.pingfile", 0755); // file permissions for read / write chmod("users/.$username.pingfile", 0755); // file permissions for read / write
// Execute IRC client in background // Execute IRC client in background
// IRC server will die when either 1) pingfile is deleted, or // IRC server will die when either 1) pingfile is deleted, or
@ -210,12 +206,9 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
shell_exec("/usr/bin/php $realpath $username $servaddr $servport > /dev/null 2>/dev/null &"); 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? } else if($_GET['do']=="logout" && ($acctpass == $userpass)) { // Is user asking for logout?
// Remove ping file if user logs out. IRC server will close // Remove ping file if user logs out. IRC server will close
$content = file_get_contents("$nick.log"); $content = file_get_contents("users/$nick.log");
file_put_contents("$nick.log", $content . "<tr><td class='userinfo'><b>$usernick</b> ~ </td><td> left the server...</td></tr>\n"); file_put_contents("users/$nick.log", $content . "<tr><td class='userinfo'><b>$usernick</b> ~ </td><td> left the server...</td></tr>\n");
unlink(".$nick.pingfile"); unlink("users/.$nick.pingfile");
} else if($_GET['do']=="keepup") { // Client asking for keepup ping.
// PONG to server.
//file_put_contents(".$nick.pingfile", "ping");
} }
} }
?> ?>

View File

@ -29,8 +29,6 @@ body {
text-align: center; text-align: center;
} }
.logout { padding: 5px; padding-bottom: 10px; text-align: center; }
a { a {
color: #0080ff; color: #0080ff;
text-decoration: none; text-decoration: none;
@ -50,11 +48,20 @@ input, button, select, textarea{
padding: 4px; padding: 4px;
} }
.login { .form {
text-align: center; text-align: center;
margin: auto;
min-width: 400px;
} }
.logout a { .form table {
width: 60%;
margin: auto;
}
.form td:nth-child(odd) { width: 160px; }
.navbar a {
background-color: #282828; background-color: #282828;
color: #ffffff; color: #ffffff;
padding: 3px 5px 3px 5px; padding: 3px 5px 3px 5px;
@ -64,10 +71,12 @@ input, button, select, textarea{
text-decoration: none; text-decoration: none;
} }
.logout a:hover { .navbar a:hover {
background-color: #353535; background-color: #353535;
} }
.navbar { padding: 5px; padding-bottom: 10px; text-align: center; }
.text { font-size: 14px; } .text { font-size: 14px; }
@media only screen and (min-height: 2001px) { #msgs { height: 1700px; } } @media only screen and (min-height: 2001px) { #msgs { height: 1700px; } }