Compare commits

..

No commits in common. "1a9299bc9c61706361e192c99662288f42b88aff" and "c41173c06f59972e8cd87de0c0dc3b20e996164f" have entirely different histories.

11 changed files with 38 additions and 363 deletions

View File

@ -2,7 +2,7 @@
irclogger_web is a highly configurable IRC logger with web frontend. It's written in Perl. irclogger_web is a highly configurable IRC logger with web frontend. It's written in Perl.
## Installation ## Installation
1. You need to have Perl interpreter and SQLite3 installed. 1. You need to have Perl and SQLite3 interpreter installed.
2. Following Perl packages have to be installed: [DBI](https://metacpan.org/pod/DBI), [DBD::SQLite](https://metacpan.org/pod/DBD::SQLite). 2. Following Perl packages have to be installed: [DBI](https://metacpan.org/pod/DBI), [DBD::SQLite](https://metacpan.org/pod/DBD::SQLite).
3. Run `./prepare_database.sh` to create SQLite3 database for storing users, servers and logged channels. 3. Run `./prepare_database.sh` to create SQLite3 database for storing users, servers and logged channels.
4. See `configuration.pm` and adjust it to your needs. 4. See `configuration.pm` and adjust it to your needs.

View File

@ -1,8 +1,7 @@
create table channels(id int primary key not null, create table channels(id int primary key not null,
server_id int not null, -- foreign key in servers table server_id int not null, -- foreign key in servers table
name text not null, name text not null,
public int not null, public int not null
enabled int not null
); );
create table users(id int primary key not null, create table users(id int primary key not null,
@ -14,8 +13,7 @@ create table users(id int primary key not null,
create table servers(id int primary key not null, create table servers(id int primary key not null,
name text not null, name text not null,
host text not null, host text not null,
port int not null, port int not null
enabled int not null
); );
create table accessors(user_id int not null, -- foreign key in users table create table accessors(user_id int not null, -- foreign key in users table

View File

@ -495,16 +495,6 @@ sub createUser {
$query->execute($aName, $password, $aPrivileges); $query->execute($aName, $password, $aPrivileges);
} }
sub deleteUser {
my $aID = $_[0];
my $aConnection = $_[1];
my $query = $aConnection->prepare(qq(delete from users where id=?;));
$query->execute($aID);
$query = $aConnection->prepare(qq(delete from accessors where user_id=?;));
$query->execute($aID);
}
sub httpServerWorker { sub httpServerWorker {
my $db = DBI->connect("DBI:SQLite:dbname=$configuration::database", "", "", {RaiseError=>1}); my $db = DBI->connect("DBI:SQLite:dbname=$configuration::database", "", "", {RaiseError=>1});
my $query = $db->prepare(qq(select id from users;)); my $query = $db->prepare(qq(select id from users;));

View File

@ -86,21 +86,6 @@ sub verifyChannelAccess {
return 1; return 1;
} }
sub enumerateServers {
my $aConnection = $_[0];
my $output = "<select name=\"server\">";
my $query = $aConnection->prepare(qq(select id, name from servers;));
$query->execute();
while(my @row = $query->fetchrow_array()) {
my $serverID = $row[0];
my $server = $row[1];
$output.="<option value=\"$serverID\">$server</option>";
}
$output.="</select>";
return $output;
}
sub enumerateChannels { sub enumerateChannels {
my $aConnection = $_[0]; my $aConnection = $_[0];
@ -117,25 +102,6 @@ sub enumerateChannels {
return $output; return $output;
} }
sub enumerateUsers {
my $aConnection = $_[0];
my $aSession = $_[1];
my $output = "<select name=\"user\">";
my $query = $aConnection->prepare(qq(select id, name from users;));
$query->execute();
while(my @row = $query->fetchrow_array()) {
my $id = $row[0];
my $name = $row[1];
if($name eq $aSession->{"username"}) {
next;
}
$output.="<option value=\"$id\">$name</option>";
}
$output.="</select>";
return $output;
}
sub handlePath { sub handlePath {
my $aClient = $_[0]; my $aClient = $_[0];
my $aPath = $_[1]; my $aPath = $_[1];
@ -163,17 +129,16 @@ sub handlePath {
$userbar.="</form>"; $userbar.="</form>";
} }
my $query = $aConnection->prepare(qq(select channels.id, channels.name, channels.enabled, servers.name, servers.enabled from channels inner join servers on channels.server_id=servers.id where channels.public=1;)); my $query = $aConnection->prepare(qq(select channels.id, channels.name, servers.name from channels inner join servers on channels.server_id=servers.id where channels.public=1;));
$query->execute(); $query->execute();
my $table = ""; my $table = "";
while(my @row = $query->fetchrow_array()) { while(my @row = $query->fetchrow_array()) {
my $channelID = $row[0]; my $channelID = $row[0];
my $channelName = $row[1]; my $channelName = $row[1];
my $channelEnabled = $row[2] && $row[4]; my $serverName = $row[2];
my $serverName = $row[3];
$channelName =~ s/%23/#/; $channelName =~ s/%23/#/;
my $status = $channelEnabled?"<span style=\"color:green\">Enabled</span>":"<span style=\"color:gray\">Disabled</span>";
$table.="<tr><td><a href=\"view_logs?channel=$channelID\">$channelName</a></td><td>$serverName</td><td>$status</td></tr>"; $table.="<tr><td><a href=\"view_logs?channel=$channelID\">$channelName</a></td><td>$serverName</td></tr>";
} }
my $privateChannels = ""; my $privateChannels = "";
@ -181,10 +146,6 @@ sub handlePath {
$query = $aConnection->prepare(qq(select id, privileges from users where name=?;)); $query = $aConnection->prepare(qq(select id, privileges from users where name=?;));
$query->execute($frontend_session::sessions{$aRequest->{"cookies"}{"session"}}{"username"}); $query->execute($frontend_session::sessions{$aRequest->{"cookies"}{"session"}}{"username"});
my @row = $query->fetchrow_array(); my @row = $query->fetchrow_array();
if(scalar(@row)==0) {
frontend::redirect($aClient, "/");
return 1;
}
my $id = $row[0]; my $id = $row[0];
my $privileges = $row[1]; my $privileges = $row[1];
if($privileges>0) { if($privileges>0) {
@ -197,15 +158,13 @@ sub handlePath {
} }
while(@row = $query->fetchrow_array()) { while(@row = $query->fetchrow_array()) {
my $channelID = $row[0]; my $channelID = $row[0];
my $channelQuery = $aConnection->prepare(qq(select channels.name, channels.enabled, servers.name, servers.enabled from channels inner join servers on channels.server_id=servers.id where channels.id=$channelID;)); my $channelQuery = $aConnection->prepare(qq(select channels.name, servers.name from channels inner join servers on channels.server_id=servers.id where channels.id=$channelID;));
$channelQuery->execute(); $channelQuery->execute();
@row = $channelQuery->fetchrow_array(); @row = $channelQuery->fetchrow_array();
my $channelName = $row[0]; my $channelName = $row[0];
$channelName =~ s/%23/#/; $channelName =~ s/%23/#/;
my $channelEnabled = $row[1] && $row[3]; my $serverName = $row[1];
my $serverName = $row[2]; $privateChannels.="<tr><td><a href=\"view_logs?channel=$channelID\">$channelName</a></td><td>$serverName</td></tr>";
my $status = $channelEnabled?"<span style=\"color:green\">Enabled</span>":"<span style=\"color:gray\">Disabled</span>";
$privateChannels.="<tr><td><a href=\"view_logs?channel=$channelID\">$channelName</a></td><td>$serverName</td><td>$status</td></tr>";
} }
} }
@ -257,7 +216,7 @@ sub handlePath {
my $response = frontend::getBaseResponse(301, "OK"); my $response = frontend::getBaseResponse(301, "OK");
$response.="Location: /\r\n"; $response.="Location: /\r\n";
$response.="Content-Length: 0\r\n"; $response.="Content-Length: 0\r\n";
$response.="Set-Cookie: session=$token;expires=".localtime(time()+7*24*3600)."\r\n\r\n"; $response.="Set-Cookie: session=$token\r\n\r\n";
$aClient->send($response); $aClient->send($response);
return 1; return 1;
} }
@ -277,19 +236,25 @@ sub handlePath {
my $query = $aConnection->prepare(qq(select privileges from users where name=?;)); my $query = $aConnection->prepare(qq(select privileges from users where name=?;));
$query->execute($session->{"username"}); $query->execute($session->{"username"});
my @row = $query->fetchrow_array(); my @row = $query->fetchrow_array();
if(scalar(@row)==0) {
frontend::redirect($aClient, "/");
return 1;
}
my $privileges = $row[0]; my $privileges = $row[0];
my $manageChannelAccess = ""; my $manageChannelAccess = "";
my $addUser = ""; my $addUser = "";
my $updateUser = "";
if($privileges>=1) { # moderator if($privileges>=1) { # moderator
$manageChannelAccess.="<h3>Manage channel access</h3>"; $manageChannelAccess.="<h3>Manage channel access</h3>";
$manageChannelAccess.="<form action=\"manage_access_action\" method=\"POST\">"; $manageChannelAccess.="<form action=\"manage_access_action\" method=\"POST\">";
$manageChannelAccess.=enumerateUsers($aConnection, $session)." "; $manageChannelAccess.="<select name=\"user\">";
$query = $aConnection->prepare(qq(select id, name from users;));
$query->execute();
while(@row = $query->fetchrow_array()) {
my $id = $row[0];
my $name = $row[1];
if($name eq $session->{"username"}) {
next;
}
$manageChannelAccess.="<option value=\"$id\">$name</option>";
}
$manageChannelAccess.="</select>";
$manageChannelAccess.=enumerateChannels($aConnection)."<br />"; $manageChannelAccess.=enumerateChannels($aConnection)."<br />";
$manageChannelAccess.="<input name=\"grant\" type=\"submit\" value=\"Grant access\" /> "; $manageChannelAccess.="<input name=\"grant\" type=\"submit\" value=\"Grant access\" /> ";
$manageChannelAccess.="<input name=\"revoke\" type=\"submit\" value=\"Revoke access\" />"; $manageChannelAccess.="<input name=\"revoke\" type=\"submit\" value=\"Revoke access\" />";
@ -303,18 +268,9 @@ sub handlePath {
$addUser.="<input name=\"operator\" type=\"checkbox\" />Operator<br />"; $addUser.="<input name=\"operator\" type=\"checkbox\" />Operator<br />";
$addUser.="<input type=\"submit\" value=\"Add\" />"; $addUser.="<input type=\"submit\" value=\"Add\" />";
$addUser.="</form>"; $addUser.="</form>";
$updateUser.="<h3>Update user</h3>";
$updateUser.="<form action=\"update_user_action\" method=\"POST\">";
$updateUser.=enumerateUsers($aConnection, $session)."<br />";
$updateUser.="<input name=\"operator\" type=\"checkbox\" />Operator<br />";
$updateUser.="<input name=\"update\" type=\"submit\" value=\"Update\" /> ";
$updateUser.="<input name=\"delete\" type=\"submit\" value=\"Delete\" />";
$updateUser.="</form>";
} }
my $addServer = ""; my $addServer = "";
my $updateServer = "";
if($privileges==2) { if($privileges==2) {
$addServer.="<h3>Add server</h3>"; $addServer.="<h3>Add server</h3>";
$addServer.="<form action=\"add_server_action\" method=\"POST\">"; $addServer.="<form action=\"add_server_action\" method=\"POST\">";
@ -323,12 +279,6 @@ sub handlePath {
$addServer.="<input name=\"port\" type=\"number\" placeholder=\"Server port (optional)\" /><br />"; $addServer.="<input name=\"port\" type=\"number\" placeholder=\"Server port (optional)\" /><br />";
$addServer.="<input type=\"submit\" value=\"Add\" />"; $addServer.="<input type=\"submit\" value=\"Add\" />";
$addServer.="</form>"; $addServer.="</form>";
$updateServer.="<h3>Update server</h3>";
$updateServer.="<form action=\"update_server_action\" method=\"POST\">";
$updateServer.=enumerateServers($aConnection)."<br />";
$updateServer.="<input name=\"enabled\" type=\"checkbox\" checked=\"true\" />Enabled<br />";
$updateServer.="<input type=\"submit\" value=\"Update\" />";
$updateServer.="</form>";
} }
my $addChannel = ""; my $addChannel = "";
@ -354,21 +304,11 @@ sub handlePath {
$updateChannel.="<form action=\"update_channel_action\" method=\"POST\">"; $updateChannel.="<form action=\"update_channel_action\" method=\"POST\">";
$updateChannel.=enumerateChannels($aConnection)."<br />"; $updateChannel.=enumerateChannels($aConnection)."<br />";
$updateChannel.="<input name=\"public\" type=\"checkbox\" />Public<br />"; $updateChannel.="<input name=\"public\" type=\"checkbox\" />Public<br />";
$updateChannel.="<input name=\"enabled\" type=\"checkbox\" checked=\"true\" />Enabled<br />";
$updateChannel.="<input type=\"submit\" value=\"Update\" />"; $updateChannel.="<input type=\"submit\" value=\"Update\" />";
$updateChannel.="</form>"; $updateChannel.="</form>";
} }
frontend::sendTemplate("templates/panel.html", $aClient, { frontend::sendTemplate("templates/panel.html", $aClient, {"username"=>$session->{"username"}, "manageChannelAccess"=>$manageChannelAccess, "addUser"=>$addUser, "addServer"=>$addServer, "addChannel"=>$addChannel, "updateChannel"=>$updateChannel});
"username"=>$session->{"username"},
"manageChannelAccess"=>$manageChannelAccess,
"addUser"=>$addUser,
"updateUser"=>$updateUser,
"addServer"=>$addServer,
"updateServer"=>$updateServer,
"addChannel"=>$addChannel,
"updateChannel"=>$updateChannel
});
return 1; return 1;
} }
when("/change_password_action") { when("/change_password_action") {
@ -415,35 +355,6 @@ sub handlePath {
return 1; return 1;
} }
when("/delete_account_action") {
if(!defined($aRequest->{"cookies"}{"session"}) || !frontend_session::isValidSession($aRequest->{"cookies"}{"session"})) {
frontend::redirect($aClient, "/");
return 1;
}
my $session = $frontend_session::sessions{$aRequest->{"cookies"}{"session"}};
my %parameters = frontend::parsePathParameters($aRequest->{"content"});
if(!defined($parameters{"password"})) {
frontend::sendBadRequest($aClient, "Password parameter required");
return 1;
}
my $query = $aConnection->prepare(qq(select id, password from users where name=?;));
$query->execute($session->{"username"});
my @row = $query->fetchrow_array();
my $id = $row[0];
my $password = $row[1];
if($id==0) {
frontend::sendBadRequest($aClient, "Cannot delete user with ID 0 (admin)");
return 1;
}
if($password ne Digest::SHA::sha256_hex($parameters{"password"})) {
frontend::sendBadRequest($aClient, "Wrong password");
return 1;
}
frontend::deleteUser($id, $aConnection);
frontend_session::deleteSession($aRequest->{"cookies"}{"session"});
frontend::redirect($aClient, "/account_deleted.html");
return 1;
}
when("/manage_access_action") { when("/manage_access_action") {
if(!verifyRequestPrivileges($aRequest, $aClient, 1, $aConnection)) { if(!verifyRequestPrivileges($aRequest, $aClient, 1, $aConnection)) {
return 1; return 1;
@ -550,39 +461,6 @@ sub handlePath {
frontend::redirect($aClient, "/user_added.html"); frontend::redirect($aClient, "/user_added.html");
return 1; return 1;
} }
when("/update_user_action") {
if(!verifyRequestPrivileges($aRequest, $aClient, 1, $aConnection)) {
return 1;
}
my %parameters = frontend::parsePathParameters($aRequest->{"content"});
if(!defined($parameters{"user"}) || length($parameters{"user"})==0) {
frontend::sendBadRequest($aClient, "User required");
return 1;
}
my $query = $aConnection->prepare(qq(select privileges from users where id=?;));
$query->execute($parameters{"user"});
my @row = $query->fetchrow_array();
if(scalar(@row)==0) {
frontend::sendBadRequest($aClient, "User with ID $parameters{'user'} doesn't exist");
return 1;
}
if($row[0]>1 && !verifyRequestPrivileges($aRequest, $aClient, 2, $aConnection)) {
return 1;
}
if(defined($parameters{"update"})) {
$query = $aConnection->prepare(qq(update users set privileges=? where id=?;));
$query->execute(defined($parameters{"operator"})?1:0, $parameters{"user"});
}
elsif(defined($parameters{"delete"})) {
frontend::deleteUser($parameters{"user"}, $aConnection);
}
else {
frontend::sendBadRequest($aClient, "Action (update or delete) required");
return 1;
}
frontend::redirect($aClient, "/user_updated.html");
return 1;
}
when("/add_server_action") { when("/add_server_action") {
if(!verifyRequestPrivileges($aRequest, $aClient, 2, $aConnection)) { if(!verifyRequestPrivileges($aRequest, $aClient, 2, $aConnection)) {
return 1; return 1;
@ -617,53 +495,12 @@ sub handlePath {
$lastID = $row[0]+1; $lastID = $row[0]+1;
} }
$query = $aConnection->prepare(qq(insert into servers values($lastID, ?, ?, ?, 1);)); $query = $aConnection->prepare(qq(insert into servers values($lastID, ?, ?, ?);));
$query->execute($parameters{"name"}, $parameters{"address"}, $port); $query->execute($parameters{"name"}, $parameters{"address"}, $port);
frontend::redirect($aClient, "/server_added.html"); frontend::redirect($aClient, "/server_added.html");
logger::createLogger($parameters{"name"}, $parameters{"address"}, $port, ()); logger::createLogger($parameters{"name"}, $parameters{"address"}, $port, ());
return 1; return 1;
} }
when("/update_server_action") {
if(!verifyRequestPrivileges($aRequest, $aClient, 2, $aConnection)) {
return 1;
}
my %parameters = frontend::parsePathParameters($aRequest->{"content"});
if(!defined($parameters{"server"}) || length($parameters{"server"})==0) {
frontend::sendBadRequest($aClient, "Server required");
return 1;
}
my $query = $aConnection->prepare(qq(select name, host, port, enabled from servers where id=?;));
$query->execute($parameters{"server"});
my @row = $query->fetchrow_array();
if(scalar(@row)==0) {
frontend::sendBadRequest($aClient, "Server with ID $parameters{'server'} doesn't exist");
return 1;
}
my $server = $row[0];
my $serverEnabled = $row[3];
if(defined($parameters{"enabled"}) && !$serverEnabled) {
my $host = $row[1];
my $port = $row[2];
$query = $aConnection->prepare(qq(select name, enabled from channels where server_id=?;));
$query->execute($parameters{"server"});
my @channels;
while(@row = $query->fetchrow_array()) {
if(!$row[1]) {
next;
}
push(@channels, $row[0]);
}
logger::createLogger($server, $host, $port, \@channels);
}
elsif($serverEnabled) {
my $actionQueue = logger::getActionQueueByServerName($server);
push(@$actionQueue, "QUIT");
}
$query = $aConnection->prepare(qq(update servers set enabled=? where id=?;));
$query->execute(defined($parameters{"enabled"})?1:0, $parameters{"server"});
frontend::redirect($aClient, "/server_updated.html");
return 1;
}
when("/add_channel_action") { when("/add_channel_action") {
if(!verifyRequestPrivileges($aRequest, $aClient, 2, $aConnection)) { if(!verifyRequestPrivileges($aRequest, $aClient, 2, $aConnection)) {
return 1; return 1;
@ -704,7 +541,7 @@ sub handlePath {
$lastID = $row[0]+1; $lastID = $row[0]+1;
} }
$query = $aConnection->prepare(qq(insert into channels values($lastID, ?, ?, ?, 1);)); $query = $aConnection->prepare(qq(insert into channels values($lastID, ?, ?, ?);));
$query->execute($parameters{"server"}, $parameters{"channel"}, defined($parameters{"public"})?1:0); $query->execute($parameters{"server"}, $parameters{"channel"}, defined($parameters{"public"})?1:0);
my $actionQueue = logger::getActionQueueByServerName($serverName); my $actionQueue = logger::getActionQueueByServerName($serverName);
push(@$actionQueue, "JOIN", $parameters{"channel"}); push(@$actionQueue, "JOIN", $parameters{"channel"});
@ -721,27 +558,15 @@ sub handlePath {
frontend::sendBadRequest($aClient, "Channel required"); frontend::sendBadRequest($aClient, "Channel required");
return 1; return 1;
} }
my $query = $aConnection->prepare(qq(select name, server_id, enabled from channels where id=?;)); my $query = $aConnection->prepare(qq(select id from channels where id=?;));
$query->execute($parameters{"channel"}); $query->execute($parameters{"channel"});
my @row = $query->fetchrow_array(); my @row = $query->fetchrow_array();
if(scalar(@row)==0) { if(scalar(@row)==0) {
frontend::sendBadRequest($aClient, "Channel with ID $parameters{'channel'} doesn't exist"); frontend::sendBadRequest($aClient, "Channel with ID $parameters{'channel'} doesn't exist");
return 1; return 1;
} }
my $channel = $row[0]; $query = $aConnection->prepare(qq(update channels set public=? where id=?;));
my $channelEnabled = $row[2]; $query->execute(defined($parameters{"public"})?1:0, $parameters{"channel"});
$query = $aConnection->prepare(qq(select name from servers where id=?;));
$query->execute($row[1]);
@row = $query->fetchrow_array();
my $actionQueue = logger::getActionQueueByServerName($row[0]);
if(defined($parameters{"enabled"}) && !$channelEnabled) {
push(@$actionQueue, "JOIN", $channel);
}
elsif($channelEnabled) {
push(@$actionQueue, "PART", $channel);
}
$query = $aConnection->prepare(qq(update channels set public=?, enabled=? where id=?;));
$query->execute(defined($parameters{"public"})?1:0, defined($parameters{"enabled"})?1:0, $parameters{"channel"});
frontend::redirect($aClient, "/channel_updated.html"); frontend::redirect($aClient, "/channel_updated.html");
return 1; return 1;
} }

View File

@ -22,12 +22,9 @@ use strict;
use warnings; use warnings;
our %sessions; our %sessions;
my %sessionAccess;
sub newSessionToken { sub newSessionToken {
my $session = Digest::SHA::sha256_hex(sprintf("%x", rand(0xFFFFFFFF))); return Digest::SHA::sha256_hex(sprintf("%x", rand(0xFFFFFFFF)));
$sessionAccess{$session} = time();
return $session;
} }
sub deleteSession { sub deleteSession {
@ -35,23 +32,13 @@ sub deleteSession {
if(isValidSession($aSession)) { if(isValidSession($aSession)) {
delete $sessions{$aSession}; delete $sessions{$aSession};
delete $sessionAccess{$aSession};
} }
} }
sub isValidSession { sub isValidSession {
my $aSession = $_[0]; my $aSession = $_[0];
foreach my $key (keys(%sessionAccess)) { return defined($sessions{$aSession});
if(time()-$sessionAccess{$key}>7*24*3600) {
deleteSession($key);
}
}
if(defined($sessions{$aSession})) {
$sessionAccess{$aSession} = time();
return 1;
}
return 0;
} }
1; 1;

100
logger.pm
View File

@ -308,36 +308,6 @@ sub handlePart {
$aLogFiles->{$aCommand->[1]}{"file"}->flush(); $aLogFiles->{$aCommand->[1]}{"file"}->flush();
} }
sub handleNick {
my $aCommand = $_[0];
my $aServerName = $_[1];
my $aLogFiles = $_[2];
my $aCommandLength = scalar(@$aCommand);
if($aCommandLength!=3) {
print("[error] Encountered invalid NICK command (3 arguments expected, $aCommandLength provided)\n");
return;
}
my $username = getUsernameFromHost($aCommand->[2]);
foreach my $channel (keys(%$aLogFiles)) {
my $found = 0;
my $i = 0;
foreach $i (0..scalar(@{$aLogFiles->{$channel}{"names"}})-1) {
my $name = \$aLogFiles->{$channel}{"names"}[$i];
if($$name eq $username) {
$found = 1;
$$name = $aCommand->[1];
last;
}
}
if(!$found || !prepareLogFile($aLogFiles, $aServerName, $channel)) {
next;
}
$aLogFiles->{$channel}{"file"}->print(sprintf("(%s) %s is now known as %s\n", localtime->strftime("%H:%M:%S"), $username, $aCommand->[1]));
$aLogFiles->{$channel}{"file"}->flush();
}
}
sub joinChannel { sub joinChannel {
my $aStream = $_[0]; my $aStream = $_[0];
my $aChannel = $_[1]; my $aChannel = $_[1];
@ -354,19 +324,6 @@ sub joinChannels {
} }
} }
sub partChannel {
my $aStream = $_[0];
my $aChannel = $_[1];
$aStream->send(sprintf("PART %s\r\n", $aChannel));
}
sub quitFromServer {
my $aStream = $_[0];
$aStream->send("QUIT\r\n");
}
sub handleNames { sub handleNames {
my $aCommand = $_[0]; my $aCommand = $_[0];
my $aChannels = $_[1]; my $aChannels = $_[1];
@ -384,30 +341,6 @@ sub handleNames {
push(@{$aLogFiles->{$aCommand->[3]}{"names"}}, @names); push(@{$aLogFiles->{$aCommand->[3]}{"names"}}, @names);
} }
sub handleTopic {
my $aCommand = $_[0];
my $aServerName = $_[1];
my $aLogFiles = $_[2];
my $aChangedByUser = $_[3];
my $aCommandLength = scalar(@$aCommand);
if($aCommandLength!=5) {
print("[error] Encountered invalid TOPIC command (5 arguments expected, $aCommandLength provided)\n");
return;
}
if(!prepareLogFile($aLogFiles, $aServerName, $aCommand->[2])) {
return;
}
if($aChangedByUser) {
my $username = getUsernameFromHost($aCommand->[4]);
$aLogFiles->{$aCommand->[2]}{"file"}->print(sprintf("(%s) %s changed topic for channel %s to: %s\n", localtime->strftime("%H:%M:%S"), $username, $aCommand->[2], $aCommand->[3]));
}
else {
$aLogFiles->{$aCommand->[2]}{"file"}->print(sprintf("(%s) Topic for channel %s: %s\n", localtime->strftime("%H:%M:%S"), $aCommand->[2], $aCommand->[3]));
}
$aLogFiles->{$aCommand->[2]}{"file"}->flush();
}
our @connections :shared; our @connections :shared;
our $running :shared = 1; our $running :shared = 1;
@ -419,21 +352,17 @@ sub connectionWorker {
my $buffer = ""; my $buffer = "";
my @actionQueue :shared; my @actionQueue :shared;
my $running = 1;
my @connection :shared = ($aServerName, \@actionQueue); my @connection :shared = ($aServerName, \@actionQueue);
push(@connections, \@connection); push(@connections, \@connection);
my %logFiles; my %logFiles;
while($running) { while($running) {
my $stream = connectToServer($aHost, $aPort, $aServerName); my $stream = connectToServer($aHost, $aPort, $aServerName);
my $streamSelect = IO::Select->new($stream); my $streamSelect = IO::Select->new($stream);
while(!eof($stream) && $running) { while(!eof($stream)) {
if(scalar(@actionQueue)>0) { if(scalar(@actionQueue)>0) {
given($actionQueue[0]) { given($actionQueue[0]) {
when("JOIN") { joinChannel($stream, $actionQueue[1]); } when("JOIN") {
when("PART") { partChannel($stream, $actionQueue[1]); } joinChannel($stream, $actionQueue[1]);
when("QUIT") {
quitFromServer($stream);
$running = 0;
} }
} }
@actionQueue = (); @actionQueue = ();
@ -459,11 +388,8 @@ sub connectionWorker {
when("JOIN") { handleJoin(\@command, $aServerName, \%logFiles); } when("JOIN") { handleJoin(\@command, $aServerName, \%logFiles); }
when("QUIT") { handleQuit(\@command, $aServerName, \%logFiles); } when("QUIT") { handleQuit(\@command, $aServerName, \%logFiles); }
when("PART") { handlePart(\@command, $aServerName, \%logFiles); } when("PART") { handlePart(\@command, $aServerName, \%logFiles); }
when("NICK") { handleNick(\@command, $aServerName, \%logFiles); }
when("TOPIC") { handleTopic(\@command, $aServerName, \%logFiles, 1); }
when("376") { joinChannels($stream, $aChannels); } # end of MOTD when("376") { joinChannels($stream, $aChannels); } # end of MOTD
when("353") { handleNames(\@command, $aChannels, \%logFiles); } # NAMES reply when("353") { handleNames(\@command, $aChannels, \%logFiles); } # NAMES reply
when("332") { handleTopic(\@command, $aServerName, \%logFiles, 0); } # TOPIC reply
} }
($line, $remaining) = readLineFromBuffer($buffer); ($line, $remaining) = readLineFromBuffer($buffer);
$buffer = $remaining; $buffer = $remaining;
@ -471,12 +397,6 @@ sub connectionWorker {
} }
close($stream); close($stream);
} }
foreach my $i (0..scalar(@connections)-1) {
if($connections[$i][0] eq $aServerName) {
$connections[$i][0] = "";
last;
}
}
} }
sub createLogger { sub createLogger {
@ -506,20 +426,12 @@ while(my @row = $query->fetchrow_array()) {
my $name = $row[1]; my $name = $row[1];
my $host = $row[2]; my $host = $row[2];
my $port = $row[3]; my $port = $row[3];
my $enabled = $row[4];
if(!$enabled) { $query = $db->prepare(qq(select name from channels where server_id=$id;));
next; $query->execute();
}
my $channelQuery = $db->prepare(qq(select name, enabled from channels where server_id=$id;));
$channelQuery->execute();
my @channels; my @channels;
while(my @channelsRow = $channelQuery->fetchrow_array()) { while(my @channelsRow = $query->fetchrow_array()) {
my $name = $channelsRow[0]; my $name = $channelsRow[0];
my $enabled = $channelsRow[1];
if(!$enabled) {
next;
}
push(@channels, $name); push(@channels, $name);
} }
createLogger($name, $host, $port, \@channels); createLogger($name, $host, $port, \@channels);

View File

@ -1,10 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Account deleted</title>
</head>
<body>
<p>Your account successfully deleted</p>
<a href="/">Return to index</a>
</body>
</html>

View File

@ -1,10 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Server updated</title>
</head>
<body>
<p>Server successfully updated</p>
<a href="/panel">Return to user panel</a>
</body>
</html>

View File

@ -1,10 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>User updated</title>
</head>
<body>
<p>User successfully updated</p>
<a href="/panel">Return to user panel</a>
</body>
</html>

View File

@ -7,7 +7,7 @@
{{userbar}} {{userbar}}
<h2>Channel list</h2> <h2>Channel list</h2>
<table border> <table border>
<tr><th>Channel</th><th>Network</th><th>Status</th></tr> <tr><th>Channel</th><th>Network</th></tr>
{{publicChannels}} {{publicChannels}}
{{privateChannels}} {{privateChannels}}
</table> </table>

View File

@ -12,16 +12,9 @@
<input name="newPassword" type="password" placeholder="New password"><br /> <input name="newPassword" type="password" placeholder="New password"><br />
<input type="submit" value="Change" /> <input type="submit" value="Change" />
</form> </form>
<h3>Delete this account</h3>
<form action="delete_account_action" method="POST">
<input name="password" type="password" placeholder="Password" /><br />
<input type="submit" value="Delete (this operation cannot be reverted!)" />
</form>
{{manageChannelAccess}} {{manageChannelAccess}}
{{addUser}} {{addUser}}
{{updateUser}}
{{addServer}} {{addServer}}
{{updateServer}}
{{addChannel}} {{addChannel}}
{{updateChannel}} {{updateChannel}}
</body> </body>