123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?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
- ///////
-
- // Start session for username saves.
- 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>
- Channel: <input style="padding: 2px;" class="text" type="text" name="channel"><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;
- $_SESSION['cwchat-channel'] = null;
- }
-
- // If web frontend is trying to login, process and connect
- if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn'])){
- $name = isset($_POST['username']) && ($_POST['username'] !== "") ? htmlentities(stripslashes($_POST['username'])) : "Unnamed";
- $channame = isset($_POST['channel']) && ($_POST['channel'] !== "") ? htmlentities(stripslashes($_POST['channel'])) : "#theroot";
- $_SESSION['cwchat-user'] = $name;
- $_SESSION['cwchat-channel'] = $channame;
- }
-
- //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>IRC Web Chat</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="+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);
- }
- }
-
- 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;
- if(isset($_SESSION['cwchat-user'])) { echo " on " . $_SESSION['cwchat-channel']; } ?></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>
|