Add /archive command for log control.

This commit is contained in:
Pentium44 2021-01-03 18:16:13 -08:00
parent f133f5c046
commit 8f8f09e7fe
2 changed files with 63 additions and 35 deletions

View File

@ -50,7 +50,7 @@ function loginForm(){
<br> <br>
<div class="form"> <div class="form">
<p> <p>
Welcome to <?php echo $GLOBALS['title'] . " " . $GLOBALS['version'] . ".<br /> " . $GLOBALS['desc']; ?><br /> <?php echo $GLOBALS['desc']; ?><br />
Don't have an account? <a href="index.php?register">Create one</a> here!<br /> Don't have an account? <a href="index.php?register">Create one</a> here!<br />
</p> </p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>?do=login" method="post">
@ -168,7 +168,7 @@ if (isset($_GET['do']) && $_GET['do']=="login" && isset($_POST['submitBtn']) &&
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title><?php echo $title . " " . $version ?></title> <title><?php echo $title . " " . $version; ?></title>
<link href="<?php echo $ui_theme; ?>.css" rel="stylesheet" type="text/css" /> <link href="<?php echo $ui_theme; ?>.css" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="description" content="<?php echo $desc; ?>" /> <meta name="description" content="<?php echo $desc; ?>" />
@ -448,7 +448,6 @@ if (!isset($_SESSION['idleirc-user'])) {
} }
} else if(isset($_GET['logs'])) { } else if(isset($_GET['logs'])) {
$username = $_SESSION['idleirc-user']; $username = $_SESSION['idleirc-user'];
$logcontents = file_get_contents("users/$username.log");
if(file_exists("users/$username.php")) { if(file_exists("users/$username.php")) {
include("users/$username.php"); include("users/$username.php");
} else { } else {
@ -456,8 +455,24 @@ if (!isset($_SESSION['idleirc-user'])) {
} }
if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) { if(isset($_SESSION['idleirc-pass']) && $userpass != "" && $userpass == $_SESSION['idleirc-pass']) {
echo "<div class='navbar'><a href='index.php'>Back to IRC</a> &bull; <a onclick='doClearLog();'>Clear IRC logs</a></div><br />\n"; echo "<div class='navbar'><a href='index.php'>Back to IRC</a> &bull; <a onclick='doClearLog();'>Clear IRC logs</a>";
echo "<div id='logmsgs'><table>\n" . $logcontents . "</table></div>\n";
if(file_exists("users/$username.logcount")) {
echo "<br />Archived: ";
$archivedLogCount = file_get_contents("users/$username.logcount");
for($x = $archivedLogCount ; $x > 0 ; $x--) {
echo "<a href='index.php?logs&page=$x'>$x</a>&nbsp;";
}
}
echo "</div><br />\n";
if(isset($_GET['page']) && $_GET['page']!="") {
$logcontents = file_get_contents("users/$username." . $_GET['page'] . ".log");
echo "<div id='logmsgs'><table>\n" . $logcontents . "</table></div>\n";
} else {
$logcontents = file_get_contents("users/$username.log");
echo "<div id='logmsgs'><table>\n" . $logcontents . "</table></div>\n";
}
} }
} else if(isset($_GET['settings'])) { } else if(isset($_GET['settings'])) {
$username = $_SESSION['idleirc-user']; $username = $_SESSION['idleirc-user'];

View File

@ -34,7 +34,7 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
$prvmsg = array_splice($cmd, 2); // grab private message from string $prvmsg = array_splice($cmd, 2); // grab private message from string
$line .= "PRIVMSG" . " " . trim($cmd[1]) . " :"; // set for push $line .= "PRIVMSG" . " " . trim($cmd[1]) . " :"; // set for push
$x = 0; $x = 0;
$logline .= "<tr><td class='userinfo'><b>$nick</b> -> " . trim($cmd[1]) . ": </td><td>"; $logline .= "<tr><td class='userinfo'><b>$nick</b>: " . trim($cmd[1]) . ": </td><td>";
foreach($prvmsg as $word) { foreach($prvmsg as $word) {
// Grab each word in the array after the privmsg username // Grab each word in the array after the privmsg username
if($x == 0) { if($x == 0) {
@ -72,25 +72,37 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
//$logline .= "<tr><td class='userinfo'><b>$nick</b>:</td><td>Joining " . $cmd[1] . "</td></tr>\n"; // push to client //$logline .= "<tr><td class='userinfo'><b>$nick</b>:</td><td>Joining " . $cmd[1] . "</td></tr>\n"; // push to client
$_SESSION['idleirc-channel'] = trim($cmd[1]); $_SESSION['idleirc-channel'] = trim($cmd[1]);
} else if ($cmd[0]=="/channel" || $cmd[0]=="/focused") { } else if ($cmd[0]=="/channel" || $cmd[0]=="/focused") {
doLog("$username: checking focused channel: " . $channel); doLog("$username: checking focused channel: " . $channel);
$logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Focused on $channel</td></tr>\n"; // push to client $logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Focused on $channel</td></tr>\n"; // push to client
} else if ($cmd[0]=="/nick") { } else if ($cmd[0]=="/nick") {
if($cmd[1]!="") { if($cmd[1]!="") {
doLog("$username: setting nick to " . $cmd[1]); doLog("$username: setting nick to " . $cmd[1]);
$line .= "NICK " . trim($cmd[1]) . "\n"; // set for push $line .= "NICK " . trim($cmd[1]) . "\n"; // set for push
$_SESSION['idleirc-nick'] = trim($cmd[1]); $_SESSION['idleirc-nick'] = trim($cmd[1]);
} else { } else {
$logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Joining " . $cmd[1] . "</td></tr>\n"; $logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Joining " . $cmd[1] . "</td></tr>\n";
} }
} else if ($cmd[0]=="/usermode") { } else if ($cmd[0]=="/usermode") {
if($cmd[1]!="") { if($cmd[1]!="") {
doLog("$username: setting usermode to " . $cmd[1]); doLog("$username: setting usermode to " . $cmd[1]);
$line .= "MODE $nick +x" . trim($cmd[1]) . "\n"; // set for push $line .= "MODE $nick +x" . trim($cmd[1]) . "\n"; // set for push
} else { } else {
$logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Missing User MODE flags<br /> /usermode [flag(s)]</td></tr>\n"; $logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Missing User MODE flags<br /> /usermode [flag(s)]</td></tr>\n";
} }
} else if ($cmd[0]=="/mode") { } else if ($cmd[0]=="/archive") {
if($cmd[1]!="") { if(file_exists("users/$username.logcount")) {
$archivedLogCount = file_get_contents("users/$username.logcount");
$archivedLogCount++;
file_put_contents("users/$username.logcount", $archivedLogCount);
rename("users/$username.log", "users/$username.$archivedLogCount.log");
$logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Logs are archived! View under 'IRC logs'</td></tr>\n";
} else {
file_put_contents("users/$username.logcount", "1");
rename("users/$username.log", "users/$username.1.log");
$logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Logs are archived! View under 'IRC logs'</td></tr>\n";
}
} else if ($cmd[0]=="/mode") {
if($cmd[1]!="") {
if($cmd[2]!="") { if($cmd[2]!="") {
doLog("$username: setting nick to " . $cmd[1]); doLog("$username: setting nick to " . $cmd[1]);
$line .= "MODE " . trim($cmd[1]) . " " . trim($cmd[2]) . "\n"; // set for push $line .= "MODE " . trim($cmd[1]) . " " . trim($cmd[2]) . "\n"; // set for push
@ -98,35 +110,35 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
$logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Missing MODE flags:<br /> /mode [channel] [flag(s)]</td></tr>\n"; $logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Missing MODE flags:<br /> /mode [channel] [flag(s)]</td></tr>\n";
} }
} else { } else {
$logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Missing channel and flags:<br /> /mode [channel] [flag(s)]</td></tr>\n"; $logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version</span> ~</td><td>Missing channel and flags:<br /> /mode [channel] [flag(s)]</td></tr>\n";
} }
} else if ($cmd[0]=="/list") { } else if ($cmd[0]=="/list") {
if($cmd[1]!="") { if($cmd[1]!="") {
doLog("$username: listing users for " . $cmd[1]); doLog("$username: listing users for " . $cmd[1]);
$line .= "NAMES " . trim($cmd[1]) . "\n"; // set for push $line .= "NAMES " . trim($cmd[1]) . "\n"; // set for push
} else { } else {
doLog("$username: listing users for $channel"); doLog("$username: listing users for $channel");
$line .= "NAMES $channel\n"; // set for push $line .= "NAMES $channel\n"; // set for push
} }
} else if ($cmd[0] == "/rejoin") { } else if ($cmd[0] == "/rejoin") {
doLog("$username: rejoining channel"); doLog("$username: rejoining channel");
if ($cmd[1] != "") { if ($cmd[1] != "") {
$line .= "PART " . trim($cmd[1]) . " :$username leaving...\n"; // push close command to IRC $line .= "PART " . trim($cmd[1]) . " :$username leaving...\n"; // push close command to IRC
$line .= "JOIN " . trim($cmd[1]) . "\n"; // set for push $line .= "JOIN " . trim($cmd[1]) . "\n"; // set for push
//$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving " . trim($cmd[1]) . "</td></tr>\n"; // push to client //$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving " . trim($cmd[1]) . "</td></tr>\n"; // push to client
} else { } else {
$line .= "PART $channel :$username leaving...\n"; // push close command to IRC $line .= "PART $channel :$username leaving...\n"; // push close command to IRC
$line .= "JOIN $channel\n"; // set for push $line .= "JOIN $channel\n"; // set for push
//$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving $channel</td></tr>\n"; // push to client //$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving $channel</td></tr>\n"; // push to client
} }
} else if ($cmd[0] == "/part") { } else if ($cmd[0] == "/part") {
doLog("$username: leaving " . trim($cmd[1])); doLog("$username: leaving " . trim($cmd[1]));
if ($cmd[1] != "") { if ($cmd[1] != "") {
$line .= "PART " . trim($cmd[1]) . " :$nick leaving...\n"; // push close command to IRC $line .= "PART " . trim($cmd[1]) . " :$nick leaving...\n"; // push close command to IRC
//$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving " . trim($cmd[1]) . "</td></tr>\n"; // push to client //$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving " . trim($cmd[1]) . "</td></tr>\n"; // push to client
} else { } else {
$line .= "PART $channel :$username leaving...\n"; // push close command to IRC $line .= "PART $channel :$username leaving...\n"; // push close command to IRC
//$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving $channel</td></tr>\n"; // push to client //$logline .= "<tr><td class='userinfo'><b>$nick</b>: </td><td>Leaving $channel</td></tr>\n"; // push to client
} }
} else if ($cmd[0] == "/focus" || $cmd[0] == "/switch" || $cmd[0] == "/query") { } else if ($cmd[0] == "/focus" || $cmd[0] == "/switch" || $cmd[0] == "/query") {
if(trim($cmd[1]) != $channel) { if(trim($cmd[1]) != $channel) {
@ -138,6 +150,7 @@ if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && $_GET['ni
} else if ($cmd[0] == "/help" || $cmd[0] == "/?") { } else if ($cmd[0] == "/help" || $cmd[0] == "/?") {
$logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version ~</span></td>"; $logline .= "<tr><td class='userinfo'><span style='color:$ipcolor;'>$title $version ~</span></td>";
$logline .= "<td>HELP: Information about $title<br />/join [channel] : Join IRC channel [channel]<br />"; $logline .= "<td>HELP: Information about $title<br />/join [channel] : Join IRC channel [channel]<br />";
$logline .= "/archive: Archive current log file, and clear current chat history.";
$logline .= "/focus [channel|user]: Funnel messages to specific channel or user (Alias: /switch; /query)<br />"; $logline .= "/focus [channel|user]: Funnel messages to specific channel or user (Alias: /switch; /query)<br />";
$logline .= "/part (channel): Part channel, part focused channel if none specified<br />"; $logline .= "/part (channel): Part channel, part focused channel if none specified<br />";
$logline .= "/rejoin (channel): Part, and join a channel; focused channel if none is specified<br />"; $logline .= "/rejoin (channel): Part, and join a channel; focused channel if none is specified<br />";