Call this v1.0.0
This commit is contained in:
parent
ebd812cc6a
commit
16345c35d5
27
README.md
Normal file → Executable file
27
README.md
Normal file → Executable file
@ -1,3 +1,26 @@
|
|||||||
# idleirc
|
=== IdleIRC ===
|
||||||
|
This is a simple ajax frontend with a very small footprint on web servers. IdleIRC uses a IRC backend
|
||||||
|
written in PHP to communicate with IRC servers. With that being said, it's not secured by TLS or
|
||||||
|
anything like that. This is in working condition!
|
||||||
|
|
||||||
A simple JS / HTML IRC client frontend with a simple PHP irc client backend that operates as a bouncer as well.
|
---Requirements:
|
||||||
|
PHP 5.2+
|
||||||
|
Read-Write access for working directory
|
||||||
|
|
||||||
|
---Installation:
|
||||||
|
~Download IdleIRC
|
||||||
|
~Extract it to desired web server / htdocs directory
|
||||||
|
~Customize config.php to your liking
|
||||||
|
~Use it!
|
||||||
|
|
||||||
|
---Changelog:
|
||||||
|
v1.0.0:
|
||||||
|
-Functioning web based front end with PHP based backend
|
||||||
|
-irc.php performs as an IRC bouncer when web client disconnects
|
||||||
|
-Controls to start / stop irc.php within web panel
|
||||||
|
-server.php is used by the AJAX frontend to communicate with irc.php
|
||||||
|
-Client supports: /join, /msg, and /me currently
|
||||||
|
-Multi user support
|
||||||
|
|
||||||
|
Legal stuff:
|
||||||
|
License: GPLv3
|
||||||
|
26
config.php
Executable file
26
config.php
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
///////
|
||||||
|
// IdleIRC - 2020
|
||||||
|
// (C) Chris Dorman, GPLv3
|
||||||
|
// https://github.com/Pentium44/idleirc
|
||||||
|
///////
|
||||||
|
|
||||||
|
$title = "IdleIRC"; // Chat title
|
||||||
|
$desc = "IdleIRC, a simple PHP based IRC client & bouncer."; // Chat description
|
||||||
|
$server = "cddo.cf"; // IRC server connected to (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";
|
||||||
|
$logfile = "irclog.txt";
|
||||||
|
|
||||||
|
///// WEBCLIENT LAYOUT /////
|
||||||
|
$ipcolor = "#00FF00";
|
||||||
|
|
||||||
|
///// NO TOUCHY SECTION /////
|
||||||
|
$version = "1.0.0"; // CWChat version
|
||||||
|
|
||||||
|
function doLog($string) {
|
||||||
|
file_put_contents($GLOBALS['logfile'], $string . "\r\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
306
index.php
Executable file
306
index.php
Executable file
@ -0,0 +1,306 @@
|
|||||||
|
<?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['cwchat-user'] = null;
|
||||||
|
$_SESSION['cwchat-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'])) : "#theroot";
|
||||||
|
$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-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'])) : "#theroot";
|
||||||
|
$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-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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//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><?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 {
|
||||||
|
?>
|
||||||
|
<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>
|
||||||
|
</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>
|
||||||
|
</body>
|
||||||
|
</html>
|
157
irc.php
Executable file
157
irc.php
Executable file
@ -0,0 +1,157 @@
|
|||||||
|
<?php
|
||||||
|
///////
|
||||||
|
// IdleIRC - 2020
|
||||||
|
// (C) Chris Dorman, GPLv3
|
||||||
|
// https://notabug.org/Pentium44/idleirc
|
||||||
|
///////
|
||||||
|
|
||||||
|
// irc.php - used to push and pull data from IRC server.
|
||||||
|
// Currently supports PING / PONG, data receive, and data push
|
||||||
|
// Done via PHP sockets.
|
||||||
|
|
||||||
|
// Prevent PHP from stopping the script after 30 sec
|
||||||
|
set_time_limit(0);
|
||||||
|
|
||||||
|
// Include variables
|
||||||
|
include_once("config.php");
|
||||||
|
|
||||||
|
// Get username from command line argument / PHP-CLI
|
||||||
|
$username = $argv[1];
|
||||||
|
$servaddr = $argv[2]; // If server address is specified
|
||||||
|
$servport = $argv[3]; // If server port is specified
|
||||||
|
|
||||||
|
$server_address = isset($servaddr) ? $servaddr : $server;
|
||||||
|
$server_port = isset($servport) ? $servport : $port;
|
||||||
|
|
||||||
|
// Function to search for username
|
||||||
|
function get_string_between($string, $start, $end){
|
||||||
|
$string = ' ' . $string;
|
||||||
|
$ini = strpos($string, $start);
|
||||||
|
if ($ini == 0) return '';
|
||||||
|
$ini += strlen($start);
|
||||||
|
$len = strpos($string, $end, $ini) - $ini;
|
||||||
|
return substr($string, $ini, $len);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If username isn't set, exit with error.
|
||||||
|
if(!isset($username) || $username == "") {
|
||||||
|
echo "Username not given...";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a socket to use
|
||||||
|
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||||
|
|
||||||
|
// Connect to IRC server via socket above
|
||||||
|
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";
|
||||||
|
|
||||||
|
// Pass NICK and USER back to IRC server over socket
|
||||||
|
socket_write($socket, $nickline, strlen($nickline));
|
||||||
|
socket_write($socket, $userline, strlen($userline));
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
// Continue the rest of the script here
|
||||||
|
// While script will continue as long as socket continues to be active
|
||||||
|
while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') {
|
||||||
|
if($bytes !== FALSE) {
|
||||||
|
//$data = socket_read($socket, 2048, PHP_NORMAL_READ);
|
||||||
|
$data = $r_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If client sent something, push it to the IRC server!
|
||||||
|
if(file_exists(".$username.push")) {
|
||||||
|
// Grab IRC command from server.php
|
||||||
|
$pushFile = file_get_contents(".$username.push");
|
||||||
|
// Push this / these commands to socket
|
||||||
|
socket_write($socket, $pushFile, strlen($pushFile));
|
||||||
|
// Remove the push file
|
||||||
|
unlink(".$username.push");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if web client still up, if no pong after 15 seconds, connection closed.
|
||||||
|
if(!file_exists(".$username.pingfile")) { // If file is missing, quit
|
||||||
|
// Debug logging, check if IRC is exiting properly
|
||||||
|
doLog("Exiting, $username logged out...");
|
||||||
|
$quitline = "QUIT :$username toggled disconnect; webirc\n"; // IRC QUIT line
|
||||||
|
socket_write($socket, $quitline, strlen($quitline)); // Push to socket
|
||||||
|
socket_close($socket); // Close the socket
|
||||||
|
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
|
||||||
|
// RECIEVE IT!
|
||||||
|
if(isset($data)) { // If data variable is set, there's data from socket
|
||||||
|
$stringMsg = explode('PRIVMSG', $data); // Strip IRC commands
|
||||||
|
// Get original contents from socket
|
||||||
|
$socketFileContents = file_get_contents("$username.log");
|
||||||
|
$ex = explode(' ', $data);
|
||||||
|
$data = htmlentities($data);
|
||||||
|
|
||||||
|
// Send PONG back to the server
|
||||||
|
if ($ex[0] == "PING") {
|
||||||
|
// Log pong
|
||||||
|
doLog("PONG, $username response...");
|
||||||
|
$pongline = "PONG " . $ex[1] . "\n"; // PONG IRC CMD
|
||||||
|
// Push to IRC server via socket.
|
||||||
|
socket_write($socket, $pongline, strlen($pongline));
|
||||||
|
} else if ($ex[1] == "PART") {
|
||||||
|
$senderNick = get_string_between($data, ":", "!");
|
||||||
|
$senderIp = get_string_between($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>";
|
||||||
|
file_put_contents("$username.log", $socketFileContents . $msgline);
|
||||||
|
} else if ($ex[1] == "JOIN") {
|
||||||
|
$senderNick = get_string_between($data, ":", "!");
|
||||||
|
$senderIp = get_string_between($data, "@", " ");
|
||||||
|
$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 if ($ex[1] == "NICK") {
|
||||||
|
$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";
|
||||||
|
file_put_contents("$username.log", $socketFileContents . $msgline);
|
||||||
|
} else if ($ex[2] == $username && (count(explode(":", $stringMsg[1])) > 1)) {
|
||||||
|
$senderNick = get_string_between($data, ":", "!");
|
||||||
|
$senderIp = get_string_between($data, "@", " ");
|
||||||
|
$privMsg = explode(":", $stringMsg[1]);
|
||||||
|
$posprivMsg = array_splice($privMsg, 1);
|
||||||
|
$msg;
|
||||||
|
|
||||||
|
foreach($posprivMsg as $msgchunk) {
|
||||||
|
$msg .= $msgchunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
$msgline = "<tr><td class='userinfo'>PM from: <b>$senderNick</b><br /><span style='color:$ipcolor;'>$senderIp</span></td><td> " . stripslashes(trim($msg)) . "</td></tr>\n";
|
||||||
|
file_put_contents("$username.log", $socketFileContents . $msgline);
|
||||||
|
$msg = "";
|
||||||
|
} else if ($stringMsg[1] != "") {
|
||||||
|
$senderNick = get_string_between($data, ":", "!");
|
||||||
|
$senderIp = get_string_between($data, "@", " ");
|
||||||
|
$channel = explode(" :", $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> " . stripslashes(trim($msg[1])) . "</td></tr>\n";
|
||||||
|
file_put_contents("$username.log", $socketFileContents . $msgline);
|
||||||
|
} else if ($ex[0] != "PING") {
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// second sleep to prevent insane CPU load
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
145
server.php
Executable file
145
server.php
Executable file
@ -0,0 +1,145 @@
|
|||||||
|
<?php
|
||||||
|
///////
|
||||||
|
// IdleIRC - 2020
|
||||||
|
// (C) Chris Dorman, GPLv3
|
||||||
|
// https://notabug.org/Pentium44/idleirc
|
||||||
|
///////
|
||||||
|
|
||||||
|
// server.php - used to communicate between web frontend and irc client
|
||||||
|
// Grabs from IRC client output
|
||||||
|
// Pushes to IRC client input
|
||||||
|
|
||||||
|
// Include PHP config file with server, title, and channel settings
|
||||||
|
include_once("config.php");
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
if(isset($_GET['msg'])) {
|
||||||
|
doLog("Msg information: " . trim($_GET['msg']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$acctpass = $_SESSION['idleirc-pass'];
|
||||||
|
$channel = $_SESSION['idleirc-channel'];
|
||||||
|
$servaddr = $_SESSION['idleirc-servaddr'];
|
||||||
|
$servport = $_SESSION['idleirc-servport'];
|
||||||
|
|
||||||
|
// If we have a message; grab user and content and push to IRC client
|
||||||
|
if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['nick']!=""){
|
||||||
|
$nick = stripslashes(htmlentities($_GET['nick'])); // Usernick
|
||||||
|
$msg = urldecode(stripslashes(trim($_GET['msg']))); // User message content
|
||||||
|
$line = ""; // start with nothing
|
||||||
|
$logline = ""; // start with nothing
|
||||||
|
|
||||||
|
// Seperate message input via space
|
||||||
|
$cmd = explode(" ", $msg);
|
||||||
|
if($cmd[0]=="/msg") { // If using /msg, push private message
|
||||||
|
$prvmsg = array_splice($cmd, 2); // grab private message from string
|
||||||
|
$line .= "PRIVMSG" . " " . $cmd[1] . " "; // set for push
|
||||||
|
$x = 0;
|
||||||
|
$logline .= "<tr><td class='userinfo'><b>$nick</b> -> " . $cmd[1] . ": </td><td>";
|
||||||
|
foreach($prvmsg as $word) {
|
||||||
|
// Grab each word in the array after the privmsg username
|
||||||
|
if($x == 0) {
|
||||||
|
$line .= ":" . $word;
|
||||||
|
$logline .= $word;
|
||||||
|
} else {
|
||||||
|
$line .= " " . $word;
|
||||||
|
$logline .= " " . $word;
|
||||||
|
}
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
$line .= "\n";
|
||||||
|
$logline .= "</td></tr>\n";
|
||||||
|
} else if($cmd[0]=="/me") { // If using /msg, push private message
|
||||||
|
$prvmsg = array_splice($cmd, 1); // grab private message from string
|
||||||
|
$line .= "PRIVMSG" . " " . $channel . " :\x01ACTION "; // set for push
|
||||||
|
$x = 0;
|
||||||
|
$logline .= "<tr><td class='userinfo'><b>$channel:</b></td><td> $nick ";
|
||||||
|
foreach($prvmsg as $word) {
|
||||||
|
// Grab each word in the array after the privmsg username
|
||||||
|
if($x == 0) {
|
||||||
|
$line .= $word;
|
||||||
|
$logline .= $word;
|
||||||
|
} else {
|
||||||
|
$line .= " " . $word;
|
||||||
|
$logline .= " " . $word;
|
||||||
|
}
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
$logline .= "</td></tr>\n";
|
||||||
|
$line .= "\x01\n";
|
||||||
|
} else if ($cmd[0]=="/join") {
|
||||||
|
doLog("$username: channel switch from $channel to" . $cmd[1] . "($msg)");
|
||||||
|
$line .= "PART $channel\n"; // push close command to IRC
|
||||||
|
$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving $channel</td></tr>\n"; // push to client
|
||||||
|
$line .= "JOIN" . " " . $cmd[1] . "\n"; // set for push
|
||||||
|
$logline .= "<tr><td class='userinfo'><b>$nick</b>:</td><td>Joining " . $cmd[1] . "</td></tr>\n"; // push to client
|
||||||
|
$_SESSION['cwchat-channel'] = trim($cmd[1]);
|
||||||
|
} else {
|
||||||
|
// @@ This is a work in progress
|
||||||
|
// Sends every channel message to each channel :[
|
||||||
|
$line .= "PRIVMSG $channel :$msg\n";
|
||||||
|
$logline .= "<tr><td class='userinfo'><b>$nick</b> in $channel:</td><td> $msg</td></tr>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get original content
|
||||||
|
$content = file_get_contents("$nick.log");
|
||||||
|
echo "<table>" . nl2br(stripslashes($content)) . "</table>";
|
||||||
|
// Grab all contents, and push to socket output file.
|
||||||
|
file_put_contents("$nick.log", $content . $logline);
|
||||||
|
// Grab user message and push to IRC client
|
||||||
|
file_put_contents(".$nick.push", $line);
|
||||||
|
// Throw out your user message
|
||||||
|
//echo nl2br(stripslashes($line));
|
||||||
|
// DONE
|
||||||
|
|
||||||
|
} else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") {
|
||||||
|
$nick = stripslashes(htmlentities($_GET['nick'])); // Username
|
||||||
|
// Grab IRC client output
|
||||||
|
$content = file_get_contents("$nick.log");
|
||||||
|
// Push content to the web frontend
|
||||||
|
echo "<table>" . nl2br(stripslashes($content)) . "</table";
|
||||||
|
// DONE
|
||||||
|
} else if (isset($_GET['do']) && isset($_GET['nick']) && $_GET['nick']!="") {
|
||||||
|
$nick = stripslashes(htmlentities($_GET['nick']));
|
||||||
|
include("users/" . $nick . ".php");
|
||||||
|
if ($_GET['do']=="clearlog") {
|
||||||
|
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?
|
||||||
|
// Join channel
|
||||||
|
if(!isset($_SESSION['cwchat-channel'])) {
|
||||||
|
file_put_contents(".$nick.push", "JOIN " . $default_channel . "\n");
|
||||||
|
} else {
|
||||||
|
file_put_contents(".$nick.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", "");
|
||||||
|
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");
|
||||||
|
chmod(".$username.pingfile", 0755); // file permissions for read / write
|
||||||
|
|
||||||
|
// Execute IRC client in background
|
||||||
|
// IRC server will die when either 1) pingfile is deleted, or
|
||||||
|
// 2) if pingfile is older than 10 seconds of current sys time
|
||||||
|
$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 &");
|
||||||
|
} 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");
|
||||||
|
unlink(".$nick.pingfile");
|
||||||
|
} else if($_GET['do']=="keepup") { // Client asking for keepup ping.
|
||||||
|
// PONG to server.
|
||||||
|
//file_put_contents(".$nick.pingfile", "ping");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
100
style.css
Normal file
100
style.css
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
@import url('https://fonts.googleapis.com/css2?family=Ubuntu+Mono&display=swap');
|
||||||
|
|
||||||
|
@media only screen and (min-width: 2001px) { body { max-width: 1000px; } #msg { width: 780px; } }
|
||||||
|
@media only screen and (max-width: 2000px) { body { max-width: 1000px; } #msg { width: 780px; } }
|
||||||
|
@media only screen and (max-width: 1500px) { body { max-width: 800px; } #msg { width: 660px; } }
|
||||||
|
@media only screen and (max-width: 900px) { body { max-width: 800px; } #msg { width: 660px; } }
|
||||||
|
@media only screen and (max-width: 800px) { body { max-width: 700px; } #msg { width: 570px; } }
|
||||||
|
@media only screen and (max-width: 700px) { body { max-width: 600px; } #msg { width: 480px; } }
|
||||||
|
@media only screen and (max-width: 600px) { body { max-width: 500px; } #msg { width: 380px; } }
|
||||||
|
/* small windows and phones */
|
||||||
|
@media only screen and (max-width: 500px) { body { max-width: 450px; } #msg { width: 330px; } }
|
||||||
|
@media only screen and (max-width: 400px) { body { max-width: 350px; } #msg { width: 230px; } }
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-family: "Ubuntu Mono", Arial, sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
background: #202020;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
color:#f3f3f3;
|
||||||
|
margin: 0 auto;
|
||||||
|
background-color: #545454;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
padding: 2px;
|
||||||
|
font-size: 18px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout { padding: 5px; text-align: center; }
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #0080ff;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: #0099ff;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
input, button, select, textarea{
|
||||||
|
background-color: #222222;
|
||||||
|
border: solid 1px #323232;
|
||||||
|
outline: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
color: #d7d7d7;
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text { font-size: 14px; }
|
||||||
|
|
||||||
|
@media only screen and (max-height: 2000px) { #msgs { height: 1600px; } }
|
||||||
|
@media only screen and (max-height: 1800px) { #msgs { height: 1500px; } }
|
||||||
|
@media only screen and (max-height: 1400px) { #msgs { height: 1100px; } }
|
||||||
|
@media only screen and (max-height: 1200px) { #msgs { height: 1000px; } }
|
||||||
|
@media only screen and (max-height: 1000px) { #msgs { height: 800px; } }
|
||||||
|
@media only screen and (max-height: 900px) { #msgs { height: 700px; } }
|
||||||
|
@media only screen and (max-height: 800px) { #msgs { height: 600px; } }
|
||||||
|
@media only screen and (max-height: 700px) { #msgs { height: 500px; } }
|
||||||
|
@media only screen and (max-height: 600px) { #msgs { height: 400px; } }
|
||||||
|
@media only screen and (max-height: 500px) { #msgs { height: 300px; } }
|
||||||
|
@media only screen and (max-height: 400px) { #msgs { height: 200px; } }
|
||||||
|
|
||||||
|
#msg {
|
||||||
|
height: 21px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#msgbox {
|
||||||
|
background-color: #323232;
|
||||||
|
border: solid 1px #454545;
|
||||||
|
max-width: 90%;
|
||||||
|
padding: 8px;
|
||||||
|
height: 32px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#msgs {
|
||||||
|
background-color: #323232;
|
||||||
|
border: solid 1px #454545;
|
||||||
|
padding: 8px;
|
||||||
|
max-width: 90%;
|
||||||
|
margin: 0 auto;
|
||||||
|
overflow-y: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#msgs tr:nth-child(even) { background-color: #262626; border: solid 1px #454545; }
|
||||||
|
#msgs tr:nth-child(odd) { background-color: #141414; border: solid 1px #454545; }
|
||||||
|
#msgs td { padding: 4px; }
|
||||||
|
|
||||||
|
td.userinfo {
|
||||||
|
min-width: 120px;
|
||||||
|
max-width: 200px;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user