Add support for disabling channel logging
This commit is contained in:
parent
549c84c6ef
commit
6c2bf4aacf
@ -1,7 +1,8 @@
|
||||
create table channels(id int primary key not null,
|
||||
server_id int not null, -- foreign key in servers table
|
||||
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,
|
||||
@ -13,7 +14,8 @@ create table users(id int primary key not null,
|
||||
create table servers(id int primary key not null,
|
||||
name 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
|
||||
|
@ -129,16 +129,17 @@ sub handlePath {
|
||||
$userbar.="</form>";
|
||||
}
|
||||
|
||||
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;));
|
||||
my $query = $aConnection->prepare(qq(select channels.id, channels.name, channels.enabled, servers.name from channels inner join servers on channels.server_id=servers.id where channels.public=1;));
|
||||
$query->execute();
|
||||
my $table = "";
|
||||
while(my @row = $query->fetchrow_array()) {
|
||||
my $channelID = $row[0];
|
||||
my $channelName = $row[1];
|
||||
my $serverName = $row[2];
|
||||
my $channelEnabled = $row[2];
|
||||
my $serverName = $row[3];
|
||||
$channelName =~ s/%23/#/;
|
||||
|
||||
$table.="<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>";
|
||||
$table.="<tr><td><a href=\"view_logs?channel=$channelID\">$channelName</a></td><td>$serverName</td><td>$status</td></tr>";
|
||||
}
|
||||
|
||||
my $privateChannels = "";
|
||||
@ -158,13 +159,15 @@ sub handlePath {
|
||||
}
|
||||
while(@row = $query->fetchrow_array()) {
|
||||
my $channelID = $row[0];
|
||||
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;));
|
||||
my $channelQuery = $aConnection->prepare(qq(select channels.name, channels.enabled, servers.name from channels inner join servers on channels.server_id=servers.id where channels.id=$channelID;));
|
||||
$channelQuery->execute();
|
||||
@row = $channelQuery->fetchrow_array();
|
||||
my $channelName = $row[0];
|
||||
$channelName =~ s/%23/#/;
|
||||
my $serverName = $row[1];
|
||||
$privateChannels.="<tr><td><a href=\"view_logs?channel=$channelID\">$channelName</a></td><td>$serverName</td></tr>";
|
||||
my $channelEnabled = $row[1];
|
||||
my $serverName = $row[2];
|
||||
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>";
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,6 +307,7 @@ sub handlePath {
|
||||
$updateChannel.="<form action=\"update_channel_action\" method=\"POST\">";
|
||||
$updateChannel.=enumerateChannels($aConnection)."<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.="</form>";
|
||||
}
|
||||
@ -495,7 +499,7 @@ sub handlePath {
|
||||
$lastID = $row[0]+1;
|
||||
}
|
||||
|
||||
$query = $aConnection->prepare(qq(insert into servers values($lastID, ?, ?, ?);));
|
||||
$query = $aConnection->prepare(qq(insert into servers values($lastID, ?, ?, ?, 1);));
|
||||
$query->execute($parameters{"name"}, $parameters{"address"}, $port);
|
||||
frontend::redirect($aClient, "/server_added.html");
|
||||
logger::createLogger($parameters{"name"}, $parameters{"address"}, $port, ());
|
||||
@ -541,7 +545,7 @@ sub handlePath {
|
||||
$lastID = $row[0]+1;
|
||||
}
|
||||
|
||||
$query = $aConnection->prepare(qq(insert into channels values($lastID, ?, ?, ?);));
|
||||
$query = $aConnection->prepare(qq(insert into channels values($lastID, ?, ?, ?, 1);));
|
||||
$query->execute($parameters{"server"}, $parameters{"channel"}, defined($parameters{"public"})?1:0);
|
||||
my $actionQueue = logger::getActionQueueByServerName($serverName);
|
||||
push(@$actionQueue, "JOIN", $parameters{"channel"});
|
||||
@ -558,15 +562,28 @@ sub handlePath {
|
||||
frontend::sendBadRequest($aClient, "Channel required");
|
||||
return 1;
|
||||
}
|
||||
my $query = $aConnection->prepare(qq(select id from channels where id=?;));
|
||||
my $query = $aConnection->prepare(qq(select name, server_id, enabled from channels where id=?;));
|
||||
$query->execute($parameters{"channel"});
|
||||
my @row = $query->fetchrow_array();
|
||||
if(scalar(@row)==0) {
|
||||
frontend::sendBadRequest($aClient, "Channel with ID $parameters{'channel'} doesn't exist");
|
||||
return 1;
|
||||
}
|
||||
$query = $aConnection->prepare(qq(update channels set public=? where id=?;));
|
||||
$query->execute(defined($parameters{"public"})?1:0, $parameters{"channel"});
|
||||
my $channel = $row[0];
|
||||
my $channelEnabled = $row[2];
|
||||
$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);
|
||||
print("Joining\n");
|
||||
}
|
||||
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");
|
||||
return 1;
|
||||
}
|
||||
|
22
logger.pm
22
logger.pm
@ -354,6 +354,13 @@ sub joinChannels {
|
||||
}
|
||||
}
|
||||
|
||||
sub partChannel {
|
||||
my $aStream = $_[0];
|
||||
my $aChannel = $_[1];
|
||||
|
||||
$aStream->send(sprintf("PART %s\r\n", $aChannel));
|
||||
}
|
||||
|
||||
sub handleNames {
|
||||
my $aCommand = $_[0];
|
||||
my $aChannels = $_[1];
|
||||
@ -415,9 +422,8 @@ sub connectionWorker {
|
||||
while(!eof($stream)) {
|
||||
if(scalar(@actionQueue)>0) {
|
||||
given($actionQueue[0]) {
|
||||
when("JOIN") {
|
||||
joinChannel($stream, $actionQueue[1]);
|
||||
}
|
||||
when("JOIN") { joinChannel($stream, $actionQueue[1]); }
|
||||
when("PART") { partChannel($stream, $actionQueue[1]); }
|
||||
}
|
||||
@actionQueue = ();
|
||||
}
|
||||
@ -483,12 +489,20 @@ while(my @row = $query->fetchrow_array()) {
|
||||
my $name = $row[1];
|
||||
my $host = $row[2];
|
||||
my $port = $row[3];
|
||||
my $enabled = $row[4];
|
||||
|
||||
my $channelQuery = $db->prepare(qq(select name from channels where server_id=$id;));
|
||||
if(!$enabled) {
|
||||
next;
|
||||
}
|
||||
my $channelQuery = $db->prepare(qq(select name, enabled from channels where server_id=$id;));
|
||||
$channelQuery->execute();
|
||||
my @channels;
|
||||
while(my @channelsRow = $channelQuery->fetchrow_array()) {
|
||||
my $name = $channelsRow[0];
|
||||
my $enabled = $channelsRow[1];
|
||||
if(!$enabled) {
|
||||
next;
|
||||
}
|
||||
push(@channels, $name);
|
||||
}
|
||||
createLogger($name, $host, $port, \@channels);
|
||||
|
@ -7,7 +7,7 @@
|
||||
{{userbar}}
|
||||
<h2>Channel list</h2>
|
||||
<table border>
|
||||
<tr><th>Channel</th><th>Network</th></tr>
|
||||
<tr><th>Channel</th><th>Network</th><th>Status</th></tr>
|
||||
{{publicChannels}}
|
||||
{{privateChannels}}
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user