Call this v1.6.0

master
Pentium44 2021-01-03 20:38:53 -08:00
parent 4e61ea317b
commit 45e9577a11
8 changed files with 363 additions and 31 deletions

View File

@ -62,6 +62,13 @@ Read-Write access for working directory
#### Changelog
* v1.6.0:
* Forced a good amount of JS from index.php to core.js
* User list is live, and working along with web client
* CSS modifications to dark/light.css for user list
* Autofill /msg [username] for input box on nickname click in userlist
* Ignore some IRC server client flags that are not needed in the chat logs. (NAMES, and MOTD EOF lines)
* v1.5.1:
* Add /archive, allows to keep IRC logs while clearing chat history.
* Minor fixes / tweaks

237
core.js Normal file
View File

@ -0,0 +1,237 @@
var httpObject = null;
var link = "";
var link2 = "";
var link3 = "";
var pinglink = "";
var ScrollDown = 0;
var msgBox = document.getElementById('msgs');
var timerID = 0;
// 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;
}
}
// MSGBOX input
function UserPM(tag) {
var msgInput = document.getElementById('msg');
var content = msgInput.value;
msgInput.value = '/msg ' + tag + ' ' + content;
}
// 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;
ScrollDown = 0;
MsgScrollDown();
}
}
// 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;
ScrollDown = 0;
MsgScrollDown();
}
}
// Getting and generating user list.
function genUserlist() {
if(ajaxUserlist.readyState == 4){
var response = ajaxUserlist.responseText;
var userlist = document.getElementById('userlist');
userlist.innerHTML = response;
}
}
function getUserlist() {
ajaxUserlist = getHTTPObject();
//var randomnumber=Math.floor(Math.random()*10000);
if (ajaxUserlist != null) {
link = "server.php?userlist&nick="+nickName;
ajaxUserlist.open("GET", link , true);
ajaxUserlist.onreadystatechange = genUserlist;
ajaxUserlist.send(null);
}
}
function doNotificationPm() {
if(ajaxVar4.readyState == 4){
var mentionUser = ajaxVar4.responseText;
if(Notification.permission==="granted") {
var notify = new Notification("Private message from " + mentionUser, { body: ""});
}
}
}
function getPmUser() {
ajaxVar4 = getHTTPObject();
//var randomnumber=Math.floor(Math.random()*10000);
if (ajaxVar4 != null) {
link4 = "server.php?get=notificationpmed&nick="+nickName;
ajaxVar4.open("GET", link4 , true);
ajaxVar4.onreadystatechange = doNotificationPm;
ajaxVar4.send(null);
}
}
function checkNotificationPm() {
if(ajaxVar5.readyState == 4){
var returnMsg = ajaxVar5.responseText;
var compareString = "true";
//console.log(returnMsg);
if(returnMsg.trim() === compareString.trim()) {
getPmUser();
}
}
}
function checkPmUrl() {
ajaxVar5 = getHTTPObject();
//var randomnumber=Math.floor(Math.random()*10000);
if (ajaxVar5 != null) {
link5 = "server.php?get=notificationpmedexists&nick="+nickName;
ajaxVar5.open("GET", link5 , true);
ajaxVar5.onreadystatechange = checkNotificationPm;
ajaxVar5.send(null);
}
}
function doNotificationMention() {
if(ajaxVar2.readyState == 4){
var mentionUser = ajaxVar2.responseText;
if(Notification.permission==="granted") {
var notify = new Notification("You were mentioned by " + mentionUser, { body: ""});
}
}
}
function getMentionUser() {
ajaxVar2 = getHTTPObject();
//var randomnumber=Math.floor(Math.random()*10000);
if (ajaxVar2 != null) {
link2 = "server.php?get=notificationmention&nick="+nickName;
ajaxVar2.open("GET", link2 , true);
ajaxVar2.onreadystatechange = doNotificationMention;
ajaxVar2.send(null);
}
}
function checkNotificationMention() {
if(ajaxVar3.readyState == 4){
var returnMsg = ajaxVar3.responseText;
var compareString = "true";
//console.log(returnMsg);
if(returnMsg.trim() === compareString.trim()) {
getMentionUser();
}
}
}
function checkMentionUrl() {
ajaxVar3 = getHTTPObject();
//var randomnumber=Math.floor(Math.random()*10000);
if (ajaxVar3 != null) {
link3 = "server.php?get=notificationmentionexists&nick="+nickName;
ajaxVar3.open("GET", link3 , true);
ajaxVar3.onreadystatechange = checkNotificationMention;
ajaxVar3.send(null);
}
}
// 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);
}
}
// Implement business logic
function serverReload() {
ajaxVar = getHTTPObject();
//var randomnumber=Math.floor(Math.random()*10000);
if (ajaxVar != null) {
link = "server.php?get&nick="+nickName;
ajaxVar.open("GET", link , true);
ajaxVar.onreadystatechange = setAll;
ajaxVar.send(null);
}
}
function MsgScrollDown() {
if(ScrollDown != 1) {
var msgBox = document.getElementById("msgs");
msgBox.scrollTop = msgBox.scrollHeight;
ScrollDown = 1;
}
}
function UpdateTimer() {
serverReload();
MsgScrollDown();
getUserlist();
checkPmUrl();
checkMentionUrl();
setTimeout(UpdateTimer, 1000);
}
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);
}
}
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;
}

View File

@ -1,19 +1,19 @@
@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,400;0,500;1,400&display=swap');
@media only screen and (min-width: 2201px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 2200px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 1900px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 1700px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 1500px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 1300px) { body { max-width: 1090px; } #msg { width: 920px; } }
@media only screen and (max-width: 1100px) { body { max-width: 890px; } #msg { width: 740px; } }
@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; } }
@media only screen and (min-width: 2201px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 2200px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 1900px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 1700px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 1500px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 1300px) { body { max-width: 1090px; } #msg { width: 780px; } }
@media only screen and (max-width: 1100px) { body { max-width: 890px; } #msg { width: 600px; } }
@media only screen and (max-width: 900px) { body { max-width: 800px; } #msg { width: 520px; } }
@media only screen and (max-width: 800px) { body { max-width: 700px; } #msg { width: 430px; } }
@media only screen and (max-width: 700px) { body { max-width: 600px; } #msg { width: 340px; } }
@media only screen and (max-width: 600px) { body { max-width: 500px; } #msg { width: 240px; } }
/* 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; } }
@media only screen and (max-width: 500px) { body { max-width: 450px; } #msg { width: 230px; } }
@media only screen and (max-width: 400px) { body { max-width: 350px; } #msg { width: 170px; } }
html {
font-family: "DM Mono", Arial, sans-serif;
@ -141,6 +141,28 @@ input, button, select, textarea{
overflow-x: auto;
}
.clientcontain {
padding: 0px 0px 0px 22px;
margin: 0 auto;
}
#userlist {
min-width: 110px;
width: 110px;
font-size: 14px;
background-color: #292929;
padding: 2px 5px 2px 5px;
border-radius: 3px;
border: solid 1px #333333;
margin: 0;
vertical-align: top;
}
#client {
width: 100%;
margin: 0;
}
#msgs tr:nth-child(even) { background-color: #333333; }
#msgs tr:nth-child(odd) { background-color: #262626; }
#msgs td:nth-child(even) { width: 80%; max-width: 950px; min-width: 320px; }

View File

@ -173,7 +173,15 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn']) &&
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="description" content="<?php echo $desc; ?>" />
<meta name="viewport" content="width=device-width, initial-scale=.5, shrink-to-fit=yes">
<!--Needed for urls -->
<script language="javascript" type="text/javascript">
var nickName = "<?php echo $_SESSION['idleirc-user']; ?>";
</script>
<script language="javascript" type="text/javascript" src="core.js"></script>
<script language="javascript" type="text/javascript">
<?php
if($hellFreezedOver == "yes") {
?>
<!--
var httpObject = null;
var link = "";
@ -182,8 +190,8 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn']) &&
var pinglink = "";
var ScrollDown = 0;
var msgBox = document.getElementById('msgs');
var userlist = document.getElementById('userlist');
var timerID = 0;
var nickName = "<?php echo $_SESSION['idleirc-user']; ?>";
// Get the HTTP Object
function getHTTPObject() {
@ -387,6 +395,8 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn']) &&
}
<?php
// Lets test this
}
if(file_exists("users/." . $_SESSION['idleirc-user'] . ".pingfile"))
{
@ -434,6 +444,7 @@ if(file_exists("users/." . $_SESSION['idleirc-user'] . ".pingfile"))
</script>
</head>
<body <?php if(!isset($_GET['register']) && !isset($_GET['logs']) && !isset($_GET['settings']) && isset($_SESSION['idleirc-user']) && file_exists("users/." . $_SESSION['idleirc-user'] . ".pingfile")) { echo 'onload="UpdateTimer();"'; } ?>>
<div class="info"><?php echo $pagetitle;
if(isset($_SESSION['idleirc-user'])) { echo " ~ " . $_SESSION['idleirc-servaddr'] . ":" . $_SESSION['idleirc-servport'] . " on " . $_SESSION['idleirc-channel']; } ?></div>
<?php
@ -444,7 +455,7 @@ if (isset($_GET['register'])) {
if (!isset($_SESSION['idleirc-user'])) {
if(!isset($_GET['register'])) {
loginForm();
loginForm();
}
} else if(isset($_GET['logs'])) {
$username = $_SESSION['idleirc-user'];
@ -534,6 +545,10 @@ if (!isset($_SESSION['idleirc-user'])) {
&bull;
<a href="index.php?settings">Settings</a>
</div><br />
<table class="clientcontain">
<tr><td id="userlist">
</td><td id="client">
<div id="msgs">
<?php
echo "<table>";
@ -558,6 +573,9 @@ if (!isset($_SESSION['idleirc-user'])) {
}
?>
</td>
</tr></table>
<div id="footer">Powered by <a href='https://notabug.org/Pentium44/idleirc'><?php echo $title . " " . $version; ?></a></div>
</div>
</body>

22
irc.php
View File

@ -122,6 +122,8 @@ while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') {
$ex = explode(' ', $data);
$data = htmlentities($data);
if($ex[1] == "376" || $ex[1] == "366") { continue; }
// Send PONG back to the server
if ($ex[0] == "PING") {
// Log pong
@ -129,12 +131,26 @@ while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') {
$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") {
} else if ($ex[1] == "353") {
// Userlist has been captured, lets generate it for the client.
// Grabs raw user list
$userlistContent = "<b>" . $ex[4] . "</b><br />";
$userlistRaw = explode($ex[4] . " :", $data);
$userArray = explode(" ", $userlistRaw[1]);
// Generate a list of users, in HTML format for userlist
foreach($userArray as $usi) {
$userlistContent .= "<a onclick='UserPM(\"$usi\");' href='#'>$usi</a> <br />";
}
file_put_contents("users/$username.userlist", $userlistContent);
} else if ($ex[1] == "PART") {
$senderNick = get_string_between($data, ":", "!");
$senderIp = get_string_between($data, "@", " ");
$exitMsg = explode('PART', $data);
$partChannel = explode(' :', $exitMsg[1]);
$msgline = "<tr><td class='userinfo'><b>$senderNick</b>: Leaving<br /><span style='color:$ipcolor;font-size:9px;'>$senderIp</span></td><td> left " . stripslashes(trim($exitMsg[1])) . "</td></tr>";
file_put_contents("users/$username.log", $socketFileContents . $msgline);
file_put_contents("users/.$username.push", "NAMES " . $partChannel[0] . "\n");
} else if ($ex[1] == "JOIN") {
$senderNick = get_string_between($data, ":", "!");
$senderIp = get_string_between($data, "@", " ");
@ -146,10 +162,11 @@ while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') {
$msgline = "<tr><td class='userinfo'><span style='color:$ipcolor;'>" . $server_address . "</span> ~ </td><td>Joining " . $joinChannel[1] . "</td></tr>\n";
file_put_contents("users/$username.log", $socketFileContents . $msgline);
}
file_put_contents("users/.$username.push", "NAMES " . $joinChannel[1] . "\n");
} else if ($ex[1] == "NICK") {
$senderNick = get_string_between($data, ":", "!");
$senderIp = get_string_between($data, "@", " ");
$nickMsg = explode('NICK', $data);
$nickMsg = explode('NICK :', $data);
$msgline = "<tr><td class='userinfo'><b>$senderNick</b>:" . trim($nickMsg[1]);
$msgline .= "<br /><span style='color:$ipcolor;font-size:9px;'>$senderIp</span>";
$msgline .= "</td><td> $senderNick is now known as" . trim($nickMsg[1]);
@ -161,6 +178,7 @@ while($bytes = socket_recv($socket, $r_data, 2048, MSG_DONTWAIT) !== '') {
$quitMsg = explode('QUIT :', $data);
$msgline = "<tr><td class='userinfo'><b>$senderNick</b><br /><span style='color:$ipcolor;font-size:9px;'>$senderIp</span></td><td> $senderNick left: " . trim($quitMsg[1]) . "</td></tr>\n";
file_put_contents("users/$username.log", $socketFileContents . $msgline);
file_put_contents("users/.$username.push", "NAMES");
} else if ($ex[2] == $usernickname && $ex[1] == "PRIVMSG") {
$senderNick = get_string_between($data, ":", "!");
$senderIp = get_string_between($data, "@", " ");

View File

@ -1,19 +1,19 @@
@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,400;0,500;1,400&display=swap');
@media only screen and (min-width: 2201px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 2200px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 1900px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 1700px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 1500px) { body { max-width: 1290px; } #msg { width: 1100px; } }
@media only screen and (max-width: 1300px) { body { max-width: 1090px; } #msg { width: 920px; } }
@media only screen and (max-width: 1100px) { body { max-width: 890px; } #msg { width: 740px; } }
@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; } }
@media only screen and (min-width: 2201px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 2200px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 1900px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 1700px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 1500px) { body { max-width: 1290px; } #msg { width: 960px; } }
@media only screen and (max-width: 1300px) { body { max-width: 1090px; } #msg { width: 780px; } }
@media only screen and (max-width: 1100px) { body { max-width: 890px; } #msg { width: 600px; } }
@media only screen and (max-width: 900px) { body { max-width: 800px; } #msg { width: 520px; } }
@media only screen and (max-width: 800px) { body { max-width: 700px; } #msg { width: 430px; } }
@media only screen and (max-width: 700px) { body { max-width: 600px; } #msg { width: 340px; } }
@media only screen and (max-width: 600px) { body { max-width: 500px; } #msg { width: 240px; } }
/* 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; } }
@media only screen and (max-width: 500px) { body { max-width: 450px; } #msg { width: 230px; } }
@media only screen and (max-width: 400px) { body { max-width: 350px; } #msg { width: 170px; } }
html {
font-family: "DM Mono", Arial, sans-serif;
@ -140,6 +140,28 @@ input, button, select, textarea{
overflow-x: auto;
}
.clientcontain {
padding: 0px 0px 0px 22px;
margin: 0 auto;
}
#userlist {
min-width: 110px;
width: 110px;
font-size: 14px;
background-color: #b7b7b7;
padding: 2px 5px 2px 5px;
border-radius: 3px;
border: solid 1px #cccccc;
margin: 0;
vertical-align: top;
}
#client {
width: 100%;
margin: 0;
}
#msgs tr:nth-child(even) { background-color: #bbbbbb; color: #000000; }
#msgs tr:nth-child(odd) { background-color: #b1b1b1; color: #000000; }
#msgs td:nth-child(even) { width: 80%; max-width: 950px; min-width: 320px; }

View File

@ -178,6 +178,14 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
//echo nl2br(stripslashes($line));
// DONE
} else if (isset($_GET['userlist'])) {
// Generate userlist
if(file_exists("users/$username.userlist")) {
$userListContent = file_get_contents("users/$username.userlist");
echo $userListContent;
} else {
echo " ";
}
} else if (isset($_GET['get']) && isset($_GET['nick']) && $_GET['nick']!="") {
$nick = stripslashes(htmlentities($_GET['nick'])); // Username
// Grab IRC client output

View File

@ -5,6 +5,6 @@
// https://github.com/Pentium44/idleirc
///////
$version = "1.5.1"; // IdleIRC version
$version = "1.6.0"; // IdleIRC version
?>