210 lines
5.6 KiB
PHP
Executable File
210 lines
5.6 KiB
PHP
Executable File
<?php
|
|
|
|
///////
|
|
// webirc-client - 2013-2020
|
|
// (C) Chris Dorman, GPL v3 - (C) Microchat devs
|
|
// https://github.com/Pentium44/cwchat
|
|
// https://git.minetest.org/Pentium44/webirc-client
|
|
///////
|
|
|
|
session_start();
|
|
include "config.php";
|
|
|
|
function loginForm(){
|
|
?>
|
|
<br>
|
|
<div class="login">
|
|
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post">
|
|
Username: <input style="padding: 2px;" class="text" type="text" name="username"><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['cwchat-user'] = null;
|
|
}
|
|
|
|
if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn'])){
|
|
$name = isset($_POST['username']) && ($_POST['username'] !== "") ? htmlentities(stripslashes($_POST['username'])) : "Unnamed";
|
|
$_SESSION['cwchat-user'] = $name;
|
|
}
|
|
|
|
//if(!isset($_SESSION['cwchat-user'])) { header("Location: ?do=login"); }
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
|
|
<html>
|
|
<head>
|
|
<title>CWChat</title>
|
|
<link href="style.css" rel="stylesheet" type="text/css" />
|
|
<script language="javascript" type="text/javascript">
|
|
<!--
|
|
var httpObject = null;
|
|
var link = "";
|
|
var pinglink = "";
|
|
var timerID = 0;
|
|
var nickName = "<?php echo $_SESSION['cwchat-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="+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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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 "CWChat " . $version . " ~ Connected to: " . $server . ":" . $port . " on " . $channels[0]; ?></div>
|
|
<?php
|
|
if (!isset($_SESSION['cwchat-user'])){
|
|
loginForm();
|
|
} else {
|
|
?>
|
|
<div class="logout"><a onclick="doLogout();" href="index.php?do=logout">Logout</a></div>
|
|
<div id="msgs">
|
|
<?php
|
|
echo "<div class=\"text\">";
|
|
$get = file_get_contents("." .$_SESSION['cwchat-user'] . ".socket");
|
|
echo $get;
|
|
echo "</div>";
|
|
?>
|
|
</div>
|
|
<div id="msgbox" onkeyup="keypressed(event);">
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
<textarea name="msg" style="width: 600px; height: 22px;" id="msg"></textarea>
|
|
</td>
|
|
<td>
|
|
<button style="width: 80px;" onclick="getInput();">Send</button>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<script type="text/javascript">
|
|
doLogin();
|
|
</script>
|
|
<?php
|
|
}
|
|
|
|
?>
|
|
</div>
|
|
</body>
|
|
</html>
|