Added user settings panel for default channel and nickname options... v1.3 in the works I tell ya
This commit is contained in:
parent
07c31c718d
commit
995d9fe54a
97
index.php
97
index.php
@ -20,10 +20,12 @@ function registerForm() {
|
||||
<br>
|
||||
<div class="login">
|
||||
<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 />
|
||||
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 />
|
||||
<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Create account">
|
||||
Username: <input style="padding: 2px; width: 300px;" class="text" type="text" name="username"><br />
|
||||
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 />
|
||||
Default Nickname: <input style="padding: 2px; width: 300px;" class="text" type="text" name="nick"><br />
|
||||
Autoconnect/focus channel: <input style="padding: 2px; width: 300px;" class="text" type="text" name="channel"><br />
|
||||
<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Create account">
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
@ -52,17 +54,51 @@ if (isset($_GET['do']) && $_GET['do']=="logout") {
|
||||
$_SESSION['idleirc-channel'] = null;
|
||||
}
|
||||
|
||||
if (isset($_GET['do']) && $_GET['do']=="settings") {
|
||||
$username = $_SESSION['idleirc-user'];
|
||||
$password = $_SESSION['idleirc-pass'];
|
||||
|
||||
if(file_exists("users/$username.php")) {
|
||||
include("users/$username.php");
|
||||
} else {
|
||||
$userpass = "";
|
||||
}
|
||||
|
||||
if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) {
|
||||
if(isset($_POST['nick']) && $_POST['nick']!="") {
|
||||
file_put_contents("users/$username.php", "<?php \$usernickname='" . stripslashes(htmlentities($_POST['nick'])) . "'; ?>\n", FILE_APPEND);
|
||||
$_SESSION['idleirc-nick'] = stripslashes(htmlentities($_POST['nick']));
|
||||
}
|
||||
|
||||
if(isset($_POST['channel']) && $_POST['channel']!="") {
|
||||
file_put_contents("users/$username.php", "<?php \$userchannel='" . stripslashes(htmlentities($_POST['channel'])) . "'; ?>\n", FILE_APPEND);
|
||||
$_SESSION['idleirc-channel'] = stripslashes(htmlentities($_POST['channel']));
|
||||
}
|
||||
|
||||
if(isset($_POST['password']) && $_POST['password']!="") {
|
||||
file_put_contents("users/$username.php", "<?php \$userpass='" . md5($_POST['password']) . "'; ?>\n", FILE_APPEND);
|
||||
$_SESSION['idleirc-pass'] = md5($_POST['password']);
|
||||
}
|
||||
|
||||
header("refresh: 0;url=index.php");
|
||||
} else {
|
||||
header("refresh: 0;url=index.php");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['register']) && $_GET['register'] == "go") {
|
||||
if(isset($_POST['password']) && $_POST['password'] != "" && isset($_POST['password-again']) && $_POST['password-again'] != "" && $_POST['password'] == $_POST['password-again']) {
|
||||
if(isset($_POST['username']) && $_POST['username'] != "") {
|
||||
$username = stripslashes(htmlentities($_POST['username']));
|
||||
$password = md5($_POST['password']);
|
||||
$channame = isset($_POST['channel']) && ($_POST['channel'] !== "") ? htmlentities(stripslashes($_POST['channel'])) : $default_channel;
|
||||
$nickname = isset($_POST['nick']) && ($_POST['nick'] !== "") ? htmlentities(stripslashes($_POST['nick'])) : $username;
|
||||
$servaddr = isset($_POST['servaddr']) && ($_POST['servaddr'] !== "") ? htmlentities(stripslashes($_POST['servaddr'])) : $server;
|
||||
$servport = isset($_POST['servport']) && ($_POST['servport'] !== "") ? htmlentities(stripslashes($_POST['servport'])) : $port;
|
||||
file_put_contents("users/$username.php", "<?php \$userpass = '" . $password . "'; ?>\n");
|
||||
file_put_contents("users/$username.php", "<?php \$userpass = '" . $password . "'; \$userchannel='" . $channame . "'; \$usernickname='" . $nickname . "'; ?>\n");
|
||||
file_put_contents("users/.$username.first", "First time, start up\n");
|
||||
$_SESSION['idleirc-user'] = $username;
|
||||
$_SESSION['idleirc-nick'] = $username;
|
||||
$_SESSION['idleirc-nick'] = $nickname;
|
||||
$_SESSION['idleirc-pass'] = $password;
|
||||
$_SESSION['idleirc-channel'] = $channame;
|
||||
$_SESSION['idleirc-servaddr'] = $servaddr;
|
||||
@ -79,16 +115,15 @@ if (isset($_GET['register']) && $_GET['register'] == "go") {
|
||||
// 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']!=""){
|
||||
$name = isset($_POST['username']) && ($_POST['username'] !== "") && file_exists("users/" . $_POST['username'] . ".php") ? htmlentities(stripslashes($_POST['username'])) : "Unnamed";
|
||||
$channame = isset($_POST['channel']) && ($_POST['channel'] !== "") ? htmlentities(stripslashes($_POST['channel'])) : $default_channel;
|
||||
$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")) {
|
||||
include("users/$name.php");
|
||||
if(md5($_POST['password']) == $userpass) {
|
||||
$_SESSION['idleirc-user'] = $name;
|
||||
$_SESSION['idleirc-nick'] = $name;
|
||||
$_SESSION['idleirc-nick'] = $usernickname;
|
||||
$_SESSION['idleirc-pass'] = $userpass;
|
||||
$_SESSION['idleirc-channel'] = $channame;
|
||||
$_SESSION['idleirc-channel'] = $userchannel;
|
||||
$_SESSION['idleirc-servaddr'] = $servaddr;
|
||||
$_SESSION['idleirc-servport'] = $servport;
|
||||
header("refresh: 0;url=index.php");
|
||||
@ -273,22 +308,62 @@ if (!isset($_SESSION['idleirc-user'])) {
|
||||
}
|
||||
|
||||
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 id='logmsgs'><table>\n" . $logcontents . "</table></div>\n";
|
||||
}
|
||||
} else if(isset($_GET['settings'])) {
|
||||
$username = $_SESSION['idleirc-user'];
|
||||
$logcontents = file_get_contents("$username.log");
|
||||
if(file_exists("users/$username.php")) {
|
||||
include("users/$username.php");
|
||||
} else {
|
||||
$userpass = "";
|
||||
}
|
||||
|
||||
if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) {
|
||||
echo "<div class='logout'><a href='index.php'>Back to IRC</a></div>\n";
|
||||
?>
|
||||
|
||||
<br>
|
||||
<div style="width: 500px; margin: 0 auto; text-align: center;">
|
||||
<p>Leave fields blank that you'd not like set. Fill in what you'd want to change and hit set. Settings will be saved and session will be updated</p>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=settings" method="post">
|
||||
|
||||
<table>
|
||||
<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>New password: </td><td> <input style="padding: 2px; width: 300px;" class="text" type="password" name="password"></td></tr>
|
||||
</table>
|
||||
<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Set">
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
?>
|
||||
<div class="logout">
|
||||
<a href="index.php?do=logout">Logout</a>
|
||||
<?php
|
||||
|
||||
// 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")) {
|
||||
unlink("users/." . $_SESSION['idleirc-user'] . ".first");
|
||||
echo "<script language='javascript' type='text/javascript'>doLogin();</script>";
|
||||
}
|
||||
|
||||
if (!file_exists("." . $_SESSION['idleirc-user'] . ".pingfile"))
|
||||
{
|
||||
echo "<a onclick='doLogin();'>Connect to server</a>";
|
||||
echo "<a onclick='doLogin();'>Connect to server</a>\n";
|
||||
} else {
|
||||
echo "<a onclick='doLogout();'>Disconnect from server</a>";
|
||||
echo "<a onclick='doLogout();'>Disconnect from server</a>\n";
|
||||
}
|
||||
?>
|
||||
<a onclick="doClearLog();">Clear IRC logs</a>
|
||||
<a href="index.php?logs">IRC Logs</a>
|
||||
<a href="index.php?settings">Settings</a>
|
||||
</div>
|
||||
<div id="msgs">
|
||||
<?php
|
||||
|
16
irc.php
16
irc.php
@ -20,6 +20,10 @@ $username = $argv[1];
|
||||
$servaddr = $argv[2]; // If server address is specified
|
||||
$servport = $argv[3]; // If server port is specified
|
||||
|
||||
if(file_exists("users/$username.php")) {
|
||||
include("users/$username.php");
|
||||
}
|
||||
|
||||
$server_address = isset($servaddr) ? $servaddr : $server;
|
||||
$server_port = isset($servport) ? $servport : $port;
|
||||
|
||||
@ -46,8 +50,8 @@ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
socket_connect($socket, $server_address, $server_port);
|
||||
|
||||
// NICK and USER calls to IRC
|
||||
$nickline = "NICK " . $username . "\n";
|
||||
$userline = "USER " . $username . " 0 * :" . $username . "'s Bot\n";
|
||||
$nickline = "NICK " . $usernickname . "\n";
|
||||
$userline = "USER " . $usernickname . " 0 * :" . $username . "'s $title $version client\n";
|
||||
|
||||
// Pass NICK and USER back to IRC server over socket
|
||||
socket_write($socket, $nickline, strlen($nickline));
|
||||
@ -115,7 +119,7 @@ while($bytes = socket_recv($socket, $r_data, 3068, MSG_DONTWAIT) !== '') {
|
||||
} else if ($ex[1] == "JOIN") {
|
||||
$senderNick = get_string_between($data, ":", "!");
|
||||
$senderIp = get_string_between($data, "@", " ");
|
||||
if($senderNick != $username) {
|
||||
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";
|
||||
file_put_contents("$username.log", $socketFileContents . $msgline);
|
||||
} else {
|
||||
@ -126,15 +130,15 @@ while($bytes = socket_recv($socket, $r_data, 3068, MSG_DONTWAIT) !== '') {
|
||||
$senderNick = get_string_between($data, ":", "!");
|
||||
$senderIp = get_string_between($data, "@", " ");
|
||||
$nickMsg = explode('NICK', $data);
|
||||
$msgline = "<tr><td class='userinfo'><b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> $senderNick is now known as" . $nickMsg[1] . "</td></tr>\n";
|
||||
$msgline = "<tr><td class='userinfo'><b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> $senderNick is now known as" . trim($nickMsg[1]) . "</td></tr>\n";
|
||||
file_put_contents("$username.log", $socketFileContents . $msgline);
|
||||
} else if ($ex[1] == "QUIT") {
|
||||
$senderNick = get_string_between($data, ":", "!");
|
||||
$senderIp = get_string_between($data, "@", " ");
|
||||
$quitMsg = explode('QUIT :', $data);
|
||||
$msgline = "<tr><td class='userinfo'><span style='color:$ipcolor;'>$server_address</span> ~</td><td> $senderNick left: " . $quitMsg[1] . "</td></tr>\n";
|
||||
$msgline = "<tr><td class='userinfo'><span style='color:$ipcolor;'>$server_address</span> ~</td><td> $senderNick left: " . trim($quitMsg[1]) . "</td></tr>\n";
|
||||
file_put_contents("$username.log", $socketFileContents . $msgline);
|
||||
} else if ($ex[2] == $username && $ex[1] == "PRIVMSG") {
|
||||
} else if ($ex[2] == $usernickname && $ex[1] == "PRIVMSG") {
|
||||
$senderNick = get_string_between($data, ":", "!");
|
||||
$senderIp = get_string_between($data, "@", " ");
|
||||
$privMsg = explode(" :", $stringMsg[1]);
|
||||
|
16
server.php
16
server.php
@ -182,23 +182,23 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
|
||||
if(file_exists($nick . ".log") && ($acctpass == $userpass)) {
|
||||
unlink($nick . ".log");
|
||||
}
|
||||
} else if($_GET['do']=="login" && !file_exists(".$nick.pingfile") && ($acctpass == $userpass)) { // Is user asking for login?
|
||||
} else if($_GET['do']=="login" && !file_exists(".$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(".$nick.push", "JOIN " . $default_channel . "\n");
|
||||
file_put_contents(".$username.push", "JOIN " . $default_channel . "\n");
|
||||
} else {
|
||||
file_put_contents(".$nick.push", "JOIN " . $channel . "\n");
|
||||
file_put_contents(".$username.push", "JOIN " . $channel . "\n");
|
||||
}
|
||||
|
||||
// Make sure users DB is clean, put nothing into socket read file
|
||||
if(!file_exists("$nick.log")) {
|
||||
file_put_contents("$nick.log", "");
|
||||
if(!file_exists("$username.log")) {
|
||||
file_put_contents("$username.log", "");
|
||||
chmod("$username.log", 0755); // file permissions for read / write
|
||||
}
|
||||
|
||||
// start pingfile - determines if webclient is active via write timestamp
|
||||
file_put_contents(".$nick.pingfile", "pong");
|
||||
file_put_contents(".$username.pingfile", "pong");
|
||||
chmod(".$username.pingfile", 0755); // file permissions for read / write
|
||||
|
||||
// Execute IRC client in background
|
||||
@ -207,11 +207,11 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
|
||||
$realpath = realpath("./irc.php"); // get full file path
|
||||
|
||||
// Execute IRC client
|
||||
shell_exec("/usr/bin/php $realpath $nick $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?
|
||||
// Remove ping file if user logs out. IRC server will close
|
||||
$content = file_get_contents("$nick.log");
|
||||
file_put_contents("$nick.log", $content . "<tr><td class='userinfo'><b>$nick</b> ~ </td><td> left the server...</td></tr>\n");
|
||||
file_put_contents("$nick.log", $content . "<tr><td class='userinfo'><b>$usernick</b> ~ </td><td> left the server...</td></tr>\n");
|
||||
unlink(".$nick.pingfile");
|
||||
} else if($_GET['do']=="keepup") { // Client asking for keepup ping.
|
||||
// PONG to server.
|
||||
|
Loading…
x
Reference in New Issue
Block a user