321 lines
11 KiB
PHP
Executable File
321 lines
11 KiB
PHP
Executable File
<?php
|
|
|
|
///////
|
|
// IdleIRC 2020
|
|
// (C) Chris Dorman, GPLv3
|
|
// https://notabug.org/Pentium44/idleirc
|
|
///////
|
|
|
|
// Start session for username saves.
|
|
session_start();
|
|
include "config.php";
|
|
|
|
if(!file_exists("users"))
|
|
{
|
|
mkdir("users", 0777);
|
|
}
|
|
|
|
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">
|
|
</form>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
function loginForm(){
|
|
?>
|
|
<br>
|
|
<div class="login">
|
|
<p>
|
|
Welcome to the WebIRC client / bouncer!<br />
|
|
Don't have an account? <a href="index.php?register">Create one</a> here!<br />
|
|
</p>
|
|
<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 />
|
|
Password: <input style="padding: 2px; width: 200px;" class="text" type="password" name="password"><br />
|
|
<input style="padding: 2px;" class="text" type="submit" name="submitBtn" value="Login">
|
|
</form>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
//Logout
|
|
if (isset($_GET['do']) && $_GET['do']=="logout") {
|
|
$_SESSION['idleirc-user'] = null;
|
|
$_SESSION['idleirc-channel'] = null;
|
|
}
|
|
|
|
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;
|
|
$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");
|
|
$_SESSION['idleirc-user'] = $username;
|
|
$_SESSION['idleirc-nick'] = $username;
|
|
$_SESSION['idleirc-pass'] = $password;
|
|
$_SESSION['idleirc-channel'] = $channame;
|
|
$_SESSION['idleirc-servaddr'] = $servaddr;
|
|
$_SESSION['idleirc-servport'] = $servport;
|
|
header("refresh: 0;url=index.php");
|
|
} else {
|
|
echo "Please prove a username...";
|
|
}
|
|
} else {
|
|
echo "ERROR: Passwords did not match...";
|
|
}
|
|
}
|
|
|
|
// 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-pass'] = $userpass;
|
|
$_SESSION['idleirc-channel'] = $channame;
|
|
$_SESSION['idleirc-servaddr'] = $servaddr;
|
|
$_SESSION['idleirc-servport'] = $servport;
|
|
header("refresh: 0;url=index.php");
|
|
} else {
|
|
echo "ERROR: Failed to login: password incorrect.";
|
|
}
|
|
} else {
|
|
echo "ERROR: Password for $name does not match";
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
|
|
<html>
|
|
<head>
|
|
<title><?php echo $title . " " . $version ?></title>
|
|
<link href="style.css" rel="stylesheet" type="text/css" />
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=.65, shrink-to-fit=yes">
|
|
<script language="javascript" type="text/javascript">
|
|
<!--
|
|
var httpObject = null;
|
|
var link = "";
|
|
var pinglink = "";
|
|
var timerID = 0;
|
|
var nickName = "<?php echo $_SESSION['idleirc-user']; ?>";
|
|
|
|
// Get the HTTP Object
|
|
function getHTTPObject() {
|
|
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
|
|
else if (window.XMLHttpRequest) return new XMLHttpRequest();
|
|
else {
|
|
alert("Your browser does not support AJAX.");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// Change the value of the outputText field
|
|
function setHtml() {
|
|
if(ajaxVar.readyState == 4){
|
|
var response = ajaxVar.responseText;
|
|
var msgBox = document.getElementById("msgs");
|
|
msgBox.innerHTML += response;
|
|
msgBox.scrollTop = msgBox.scrollHeight;
|
|
}
|
|
}
|
|
|
|
// Change the value of the outputText field
|
|
function setAll() {
|
|
if(ajaxVar.readyState == 4){
|
|
var response = ajaxVar.responseText;
|
|
var msgBox = document.getElementById("msgs");
|
|
msgBox.innerHTML = response;
|
|
msgBox.scrollTop = msgBox.scrollHeight;
|
|
}
|
|
}
|
|
|
|
// Implement business logic
|
|
function serverWrite() {
|
|
ajaxVar = getHTTPObject();
|
|
if (ajaxVar != null) {
|
|
link = "server.php?nick="+nickName+"&msg="+encodeURIComponent(document.getElementById('msg').value);
|
|
ajaxVar.open("GET", link , true);
|
|
ajaxVar.send(null);
|
|
}
|
|
}
|
|
|
|
function getInput() {
|
|
// Send the server function the input
|
|
var userInput = document.getElementById('msg');
|
|
serverWrite(userInput.value);
|
|
|
|
// Clean out the input values
|
|
var msgBar = document.getElementById("msg");
|
|
msgBar.value = "";
|
|
msgBar.focus();
|
|
}
|
|
|
|
// Implement business logic
|
|
function serverReload() {
|
|
ajaxVar = getHTTPObject();
|
|
//var randomnumber=Math.floor(Math.random()*10000);
|
|
if (ajaxVar != null) {
|
|
link = "server.php?get=all&nick="+nickName;
|
|
ajaxVar.open("GET", link , true);
|
|
ajaxVar.onreadystatechange = setAll;
|
|
ajaxVar.send(null);
|
|
}
|
|
}
|
|
|
|
// Implement business logic
|
|
function serverPing() {
|
|
ajaxPing = getHTTPObject();
|
|
if (ajaxPing != null) {
|
|
pinglink = "server.php?do=keepup&nick="+nickName;
|
|
ajaxPing.open("GET", pinglink , true);
|
|
ajaxPing.send(null);
|
|
}
|
|
}
|
|
|
|
function UpdateTimer() {
|
|
serverReload();
|
|
serverPing();
|
|
setTimeout(UpdateTimer, 1000);
|
|
}
|
|
|
|
function keypressed(e) {
|
|
if(e.keyCode=='13'){
|
|
getInput();
|
|
}
|
|
}
|
|
|
|
function doLogin() {
|
|
ajaxVar = getHTTPObject();
|
|
if(ajaxVar != null) {
|
|
link = "server.php?do=login&nick="+nickName;
|
|
ajaxVar.open("GET", link, true);
|
|
ajaxVar.onreadystatechange = setHtml;
|
|
ajaxVar.send(null);
|
|
setTimeout(function() { window.location.reload(); },1000);
|
|
}
|
|
}
|
|
|
|
function doClearLog() {
|
|
ajaxVar = getHTTPObject();
|
|
if(ajaxVar != null) {
|
|
link = "server.php?do=clearlog&nick="+nickName;
|
|
ajaxVar.open("GET", link, true);
|
|
ajaxVar.onreadystatechange = setHtml;
|
|
ajaxVar.send(null);
|
|
setTimeout(function() { window.location.reload(); },1000);
|
|
}
|
|
}
|
|
|
|
function doLogout() {
|
|
ajaxVar = getHTTPObject();
|
|
if(ajaxVar != null) {
|
|
link = "server.php?do=logout&nick="+nickName;
|
|
ajaxVar.open("GET", link, true);
|
|
ajaxVar.onreadystatechange = setHtml;
|
|
ajaxVar.send(null);
|
|
setTimeout(function() { window.location.reload(); },1000);
|
|
}
|
|
}
|
|
|
|
/*window.onbeforeunload = function (e) {
|
|
doLogout();
|
|
};*/
|
|
|
|
function wrapBBCode(tag) {
|
|
var msgInput = document.getElementById('msg');
|
|
var content = msgInput.value;
|
|
var selectedContent = content.substring(msgInput.selectionStart, msgInput.selectionEnd);
|
|
var beforeContent = content.substring(0, msgInput.selectionStart);
|
|
var afterContent = content.substring(msgInput.selectionEnd, content.length);
|
|
msgInput.value = beforeContent + '[' + tag + ']' + selectedContent + '[/' + tag + ']' + afterContent;
|
|
}
|
|
//-->
|
|
</script>
|
|
</head>
|
|
<body onload="UpdateTimer();">
|
|
<div class="info"><?php echo $title . " " . $version;
|
|
if(isset($_SESSION['idleirc-user'])) { echo " ~ Connected to: " . $_SESSION['idleirc-servaddr'] . ":" . $_SESSION['idleirc-servport'] . " on " . $_SESSION['idleirc-channel']; } ?></div>
|
|
<?php
|
|
|
|
if (isset($_GET['register'])) {
|
|
registerForm();
|
|
}
|
|
|
|
if (!isset($_SESSION['idleirc-user'])) {
|
|
if(!isset($_GET['register'])) {
|
|
loginForm();
|
|
}
|
|
} else if(isset($_GET['logs'])) {
|
|
$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 id='logmsgs'><table>\n" . $logcontents . "</table></div>\n";
|
|
}
|
|
} else {
|
|
?>
|
|
<div class="logout">
|
|
<a href="index.php?do=logout">Logout</a>
|
|
<?php
|
|
if (!file_exists("." . $_SESSION['idleirc-user'] . ".pingfile"))
|
|
{
|
|
echo "<a onclick='doLogin();'>Connect to server</a>";
|
|
} else {
|
|
echo "<a onclick='doLogout();'>Disconnect from server</a>";
|
|
}
|
|
?>
|
|
<a onclick="doClearLog();">Clear IRC logs</a>
|
|
<a href="index.php?logs">IRC Logs</a>
|
|
</div>
|
|
<div id="msgs">
|
|
<?php
|
|
echo "<table>";
|
|
$get = file_get_contents($_SESSION['idleirc-user'] . ".log");
|
|
echo $get;
|
|
echo "</table>";
|
|
?>
|
|
</div>
|
|
<div id="msgbox" onkeyup="keypressed(event);">
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
<textarea name="msg" id="msg"></textarea>
|
|
</td>
|
|
<td>
|
|
<button onclick="getInput();">Send</button>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
?>
|
|
<div id="footer">Powered by <a href='https://notabug.org/Pentium44/idleirc'><?php echo $title . " " . $version; ?></a></div>
|
|
</div>
|
|
</body>
|
|
</html>
|