Commit Diff
Diff:
7435271743bcc02de7ae03458bec65305bc4f974
625b854ff8288e828bcb27bfd13d448345095d69
Commit:
625b854ff8288e828bcb27bfd13d448345095d69
Tree:
8081e6a18ae873429104b068fe768ee8a42444d5
Author:
jrmu <jrmu@ircnow.org>
Committer:
jrmu <jrmu@ircnow.org>
Date:
Thu Nov 5 08:20:38 2020 UTC
Message:
Added taillog and lastseen
blob - c09df7abc79b5e393d4d22f936b7885d52eb88f2
blob + 3b556c8f58c023ddc8c08b4a36bb786cbc25a55f
--- BNC.pm
+++ BNC.pm
@@ -13,6 +13,7 @@ use lib './';
use SQLite;
use Hash;
+my %conf;
my $chans;
my $teamchans;
my @teamchans;
@@ -23,7 +24,7 @@ my $captchaURL = "https://guava.ircnow.org/captcha.php
my $hostname;
my $terms;
my @logs;
-my $time = "600";
+my $expires;
my $sslport;
my $plainport;
my $mailfrom;
@@ -38,25 +39,28 @@ my $zncconfpath;
my $znctree = { Node => "root" };
sub init {
- $chans = $main::conf{chans};
- $teamchans = $main::conf{teamchans};
+ %conf = %main::conf;
+ $chans = $conf{chans};
+ $teamchans = $conf{teamchans};
@teamchans = split /[,\s]+/m, $teamchans;
- $staff = $main::conf{staff};
- $zncdir = $main::conf{zncdir};
- $znclog = $main::conf{znclog} || "$zncdir/.znc/moddata/adminlog/znc.log";
- $zncconfpath = $main::conf{zncconfpath} || "$zncdir/.znc/configs/znc.conf";
+ $staff = $conf{staff};
+ $zncdir = $conf{zncdir};
+ $znclog = $conf{znclog} || "$zncdir/.znc/moddata/adminlog/znc.log";
+ $zncconfpath = $conf{zncconfpath} || "$zncdir/.znc/configs/znc.conf";
+ $expires = $conf{expires};
#znc.conf file
unveil("$zncconfpath", "r") or die "Unable to unveil $!";
- $hostname = $main::conf{hostname};
- $terms = $main::conf{terms};
- $sslport = $main::conf{sslport};
- $plainport = $main::conf{plainport};
- $mailfrom = $main::conf{mailfrom};
- $mailname = $main::conf{mailname};
+ $hostname = $conf{hostname};
+ $terms = $conf{terms};
+ $sslport = $conf{sslport};
+ $plainport = $conf{plainport};
+ $mailfrom = $conf{mailfrom};
+ $mailname = $conf{mailname};
#dependencies for figlet
unveil("/usr/local/bin/figlet", "rx") or die "Unable to unveil $!";
unveil("/usr/lib/libc.so.95.1", "r") or die "Unable to unveil $!";
unveil("/usr/libexec/ld.so", "r") or die "Unable to unveil $!";
+ unveil("/usr/bin/tail", "rx") or die "Unable to unveil $!";
#znc.log file
unveil("$znclog", "r") or die "Unable to unveil $!";
main::cbind("pub", "-", "bnc", \&mbnc);
@@ -64,6 +68,8 @@ sub init {
main::cbind("msg", "-", "regex", \&mregex);
main::cbind("msg", "-", "foreach", \&mforeach);
main::cbind("msgm", "-", "*", \&mcontrolpanel);
+ main::cbind("msg", "-", "taillog", \&mtaillog);
+ main::cbind("msg", "-", "lastseen", \&mlastseen);
my @zncconf = main::readarray($zncconfpath);
$znctree = parseml($znctree, @zncconf);
#print treeget($znctree, "AnonIPLimit")."\n";
@@ -177,7 +183,7 @@ sub mbnc {
}
if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
my $text = $1;
- my $ircid = SQLite::id("irc", "hostmask", $hostmask, $time);
+ my $ircid = SQLite::id("irc", "hostmask", $hostmask, $expires);
my $captcha = SQLite::get("bnc", "ircid", $ircid, "captcha");
if ($text ne $captcha) {
main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !bnc <username> <email>");
@@ -430,6 +436,47 @@ EOF
Mail::mail($mailfrom, $email, $mailname, "Verify IRCNow Account", $body);
}
+sub mtaillog {
+ my ($bot, $nick, $host, $hand, @args) = @_;
+ my ($chan, $text);
+ if (@args == 2) {
+ ($chan, $text) = ($args[0], $args[1]);
+ } else { $text = $args[0]; }
+ my $hostmask = "$nick!$host";
+ open(my $fh, "-|", "/usr/bin/tail", "-f", $znclog) or die "could not start tail: $!";
+ while (my $line = <$fh>) {
+ foreach my $chan (@teamchans) {
+ main::putserv($bot, "PRIVMSG $chan :$line");
+ }
+ }
+}
+
+sub mlastseen {
+ my ($bot, $nick, $host, $hand, @args) = @_;
+ my ($chan, $text);
+ if (@args == 2) {
+ ($chan, $text) = ($args[0], $args[1]);
+ } else { $text = $args[0]; }
+ my $hostmask = "$nick!$host";
+ if (!@logs) { loadlog(); }
+ my @users = treeget($znctree, "User", "Node");
+ foreach my $user (@users) {
+ my @lines = grep(/^\[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\] \[$user\] connected to ZNC from [.0-9a-fA-F:]+/, @logs);
+ if (scalar(@lines) == 0) {
+ foreach my $chan (@teamchans) {
+ main::putserv($bot, "PRIVMSG $chan :$user never logged in");
+ }
+ next;
+ }
+ my $recent = pop(@lines);
+ if ($recent =~ /^\[(\d{4}-\d\d-\d\d) \d\d:\d\d:\d\d\] \[$user\] connected to ZNC from [.0-9a-fA-F:]+/) {
+ my $date = $1;
+ foreach my $chan (@teamchans) {
+ main::putserv($bot, "PRIVMSG $chan :$user $date");
+ }
+ }
+ }
+}
#sub resend {
# my ($bot, $newnick, $email) = @_;
# my $password = newpass();
blob - 4fb614eaa509862f21324fca8ea95f713cbd981d
blob + d7e2450e2724582bb54be4c682350b42126c21be
--- Hash.pm
+++ Hash.pm
@@ -6,16 +6,19 @@ use strict;
use warnings;
use OpenBSD::Pledge;
use OpenBSD::Unveil;
+use Data::Dumper;
+my %conf;
my @words;
my $wordspath = "words";
my $passlength;
sub init {
+ %conf = %main::conf;
+ $passlength = $conf{passlength};
# dictionary words for passwords
unveil($wordspath, "r") or die "Unable to unveil $!";
@words = main::readarray("words");
- $passlength = $main::conf{passlength};
}
sub newpass {
blob - 787df431680b37e12c699719f8197f33ee9a8a62
blob + 9db4dde97ad2d13ad4ee072d8b42db828b1b482c
--- Help.pm
+++ Help.pm
@@ -7,6 +7,7 @@ use warnings;
use OpenBSD::Pledge;
use OpenBSD::Unveil;
+my %conf;
my $chans;
my $teamchans;
my @teamchans;
@@ -15,11 +16,12 @@ my $terms;
my $time = "600";
sub init {
- $chans = $main::conf{chans};
- $teamchans = $main::conf{teamchans};
+ %conf = %main::conf;
+ $chans = $conf{chans};
+ $teamchans = $conf{teamchans};
@teamchans = split /[,\s]+/m, $teamchans;
- $staff = $main::conf{staff};
- $terms = $main::conf{terms};
+ $staff = $conf{staff};
+ $terms = $conf{terms};
main::cbind("pub", "-", "help", \&help);
main::cbind("msg", "-", "help", \&help);
main::cbind("pub", "-", "request", \&help);
blob - 44e7c746404c2f3bfd6ca124450d9b8d790f685b
blob + d54ee5dadb91b9d89b42799efab91e9eb31f23df
--- Mail.pm
+++ Mail.pm
@@ -9,16 +9,18 @@ use OpenBSD::Unveil;
use MIME::Base64;
use Digest::SHA qw(sha256_hex);
+my %conf;
my $staff;
my $hostname;
my $mailfrom;
my $mailname;
sub init {
- $staff = $main::conf{staff};
- $hostname = $main::conf{hostname};
- $mailfrom = $main::conf{mailfrom};
- $mailname = $main::conf{mailname};
+ %conf = %main::conf;
+ $staff = $conf{staff};
+ $hostname = $conf{hostname};
+ $mailfrom = $conf{mailfrom};
+ $mailname = $conf{mailname};
#dependencies for encrypt
unveil("/usr/bin/encrypt", "rx") or die "Unable to unveil $!";
#dependencies for mail
blob - 529ca7f30ad0a76ca696bbdc0179f288b7e09030
blob + 6ea25e42945e5d480da2d1f8ccdca1ab979f3ad4
--- SQLite.pm
+++ SQLite.pm
@@ -15,6 +15,7 @@ use constant {
WARNINGS => 2,
ALL => 3,
};
+my %conf;
my $staff;
my $dbh;
my $verbose;
@@ -22,8 +23,9 @@ my $dbpath = "/var/www/botnow/botnow.db";
my $database = "/var/www/botnow/"; # database path
sub init {
- $staff = $main::conf{staff};
- $verbose = $main::conf{verbose};
+ %conf = %main::conf;
+ $staff = $conf{staff};
+ $verbose = $conf{verbose};
unveil("$dbpath", "rwc") or die "Unable to unveil $!";
unveil("$dbpath-journal", "rwc") or die "Unable to unveil $!";
unveil("$database", "rwxc") or die "Unable to unveil $!";
@@ -292,9 +294,9 @@ sub set {
}
}
-# given a key, val pair in table, return the id that falls within time seconds
+# given a key, val pair in table, return the id that falls within expires seconds
sub id {
- my ($table, $key, $val, $time) = @_;
+ my ($table, $key, $val, $expires) = @_;
my @rows = selectrows($table, $key, $val);
my $maxrow;
foreach my $row (@rows) {
@@ -303,8 +305,8 @@ sub id {
$maxrow = $row;
}
}
- if (abs(time() - $maxrow->{localtime}) <= $time) {
- main::debug(ALL, "id: $maxrow->{id} where $key = $val at $time");
+ if (abs(time() - $maxrow->{localtime}) <= $expires) {
+ main::debug(ALL, "id: $maxrow->{id} where $key = $val at $expires");
return $maxrow->{id};
} else {
main::debug(ERRORS, "no id found");
blob - 53c524758e1e96c1a8aa01a66760bdae51ff98e6
blob + 7ceaffa2a66f7d7b4fa659543990887557470816
--- Shell.pm
+++ Shell.pm
@@ -13,6 +13,7 @@ use lib './';
use SQLite;
use Hash;
+my %conf;
my $chans;
my $teamchans;
my @teamchans;
@@ -20,7 +21,7 @@ my $staff;
my $captchaURL = "https://guava.ircnow.org/captcha.php?vhost=";
my $hostname;
my $terms;
-my $time = "600";
+my $expires;
my $mailfrom;
my $mailname;
my $passpath = "/etc/passwd";
@@ -28,14 +29,16 @@ my $httpdconfpath = "/etc/httpd.conf";
my $acmeconfpath = "/etc/acme-client.conf";
sub init {
- $chans = $main::conf{chans};
- $teamchans = $main::conf{teamchans};
+ %conf = %main::conf;
+ $chans = $conf{chans};
+ $teamchans = $conf{teamchans};
@teamchans = split /[,\s]+/m, $teamchans;
- $staff = $main::conf{staff};
- $hostname = $main::conf{hostname};
- $terms = $main::conf{terms};
- $mailfrom = $main::conf{mailfrom};
- $mailname = $main::conf{mailname};
+ $staff = $conf{staff};
+ $hostname = $conf{hostname};
+ $terms = $conf{terms};
+ $mailfrom = $conf{mailfrom};
+ $mailname = $conf{mailname};
+ $expires = $conf{expires};
#dependencies for figlet
unveil("/usr/local/bin/figlet", "rx") or die "Unable to unveil $!";
unveil("/usr/lib/libc.so.95.1", "r") or die "Unable to unveil $!";
@@ -97,7 +100,7 @@ sub mshell {
}
if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
my $text = $1;
- my $ircid = SQLite::id("irc", "hostmask", $hostmask, $time);
+ my $ircid = SQLite::id("irc", "hostmask", $hostmask, $expires);
if (!defined($ircid)) { die "undefined ircid"; }
my $captcha = SQLite::get("shell", "ircid", $ircid, "captcha");
if ($text ne $captcha) {
blob - e93038460b1c941fbd9a3fbcc6af70ea41e78d32 (mode 644)
blob + /dev/null
--- WWW.pm
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/perl
-
-package WWW;
-
-use strict;
-use warnings;
-use OpenBSD::Pledge;
-use OpenBSD::Unveil;
-my $wwwpath = "/var/www/htdocs/botnow"; # Web folder path
-my $dbpath = "/var/www/botnow/botnow.db";
-my $database = "/var/www/botnow/"; # database path
-my $staff;
-my $verbose;
-
-sub init {
- $staff = $main::conf{staff};
- $verbose = $main::conf{verbose};
-}
-
-sub www {
- my( $username, $email, $password, $service )=@_;
- my $hash = sha256_hex("$username");
- my $filename = "$database/www";
- my $lines = "";
- my $fh;
- if (open($fh, '+<', $filename)) {
- while (my $line = <$fh>) {
- $lines .= $line;
- }
- close $fh;
- }
- open($fh, '>', "$filename") or die "Could not write to '$database/www' $!";
- print $fh $lines;
- print $fh "Hash: $hash, Username: $username, Email: $email, Password: $password\n";
- close $fh;
-}
-
-1; # MUST BE LAST STATEMENT IN FILE
blob - 4b3b776731229d5fd55f6884b1a4c8b6604295ee
blob + 3176c5d375658c4baa5e9debeb957edb4cb87820
--- botnow.conf.example
+++ botnow.conf.example
@@ -60,6 +60,9 @@ die = You did not configure botnow.conf!
#Number of words in password
#passlength = 3
+#Time in seconds before captcha expires
+#expires = 1800
+
#DNS zone directory
#zonedir = /var/nsd/zones/master/
blob - c85d654700ef0e5057cc94a8948f6f89b69ab6cd
blob + 94fe4560c4fc87988416067d1f03b451a614c8c3
--- botnow.pl
+++ botnow.pl
@@ -89,7 +89,7 @@ $conf{terms} = $conf{terms} || "IRCNow: Of the User, B
$conf{ipv6path} = "ipv6s"; # ipv6 file path
$conf{netpath} = "networks"; # networks file path
-$conf{time} = 600; # time difference
+$conf{expires} = $conf{expires} || 1800; # time before captcha expires
if(defined($conf{die})) { die $conf{die}; }
@@ -120,7 +120,7 @@ my $staff = $conf{staff};
my $verbose = $conf{verbose};
my $ipv6path = $conf{ipv6path};
my $netpath = $conf{netpath};
-my $time = $conf{time};
+my $expires = $conf{expires};
unveil("./", "r") or die "Unable to unveil $!";
unveil("$confpath", "r") or die "Unable to unveil $!";
@@ -317,7 +317,7 @@ while(my @ready = $sel->can_read) {
if ($hostmask ne '*status!znc@znc.in') {
if ($text =~ /^(PING|VERSION|TIME|USERINFO) (.*)$/i) {
my ($key, $val) = ($1, $2);
- my $id = SQLite::id("irc", "nick", $nick, $time);
+ my $id = SQLite::id("irc", "nick", $nick, $expires);
SQLite::set("irc", "id", $id, "ctcp".lc($key), $val);
SQLite::set("irc", "id", $id, "localtime", time());
}
@@ -372,29 +372,29 @@ while(my @ready = $sel->can_read) {
} elsif ($code == 307 && $text =~ /^([-_\|`a-zA-Z0-9]+) (.*)/) {
my ($sender, $key) = ($1, "registered");
$val = $2 eq ":is a registered nick" ? "True" : "$2";
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, "identified", $val);
debug(ALL, "$key: $val");
} elsif ($code == 311 && $text =~ /^([-_\|`a-zA-Z0-9]+) ([^:]+)\s+([^:]+) \* :([^:]*)/) {
my ($sender, $key, $val) = ($1, "hostmask", "$1\!$2\@$3");
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, $key, $val);
debug(ALL, "$key: $val");
} elsif ($code == 312 && $text =~ /^([-_\|`a-zA-Z0-9]+) ([^:]+) :([^:]+)/) {
my ($sender, $key, $val) = ($1, "server", $2);
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, $key, $val);
debug(ALL, "$key: $val");
} elsif ($code == 313 && $text =~ /^([-_\|`a-zA-Z0-9]+) :?(.*)/) {
my ($sender, $key, $val) = ($1, "oper", ($2 eq "is an IRC operator" ? "True" : "$2"));
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, $key, $val);
debug(ALL, "$key: $val");
} elsif ($code == 315 && $text =~ /^([-_\|`a-zA-Z0-9]+) :End of \/?WHOIS list/) {
debug(ALL, "End of WHOIS");
} elsif ($code == 317 && $text =~ /^([-_\|`a-zA-Z0-9]+) (\d+) (\d+) :?(.*)/) {
($sender, my $idle, my $epochtime) = ($1, $2, $3);
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, "idle", $idle);
# SQLite::set("irc", "id", $id, "epochtime", time());
debug(ALL, "idle: $idle, epochtime: $epochtime");
@@ -402,28 +402,28 @@ while(my @ready = $sel->can_read) {
debug(ALL, "End of WHOIS");
} elsif ($code == 319 && $text =~ /^([-_\|`a-zA-Z0-9]+) :(.*)/) {
my ($sender, $key, $val) = ($1, "chans", $2);
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, $key, $val);
debug(ALL, "$key: $val");
} elsif ($code == 330 && $text =~ /^([-_\|`a-zA-Z0-9]+) ([-_\|`a-zA-Z0-9]+) :?(.*)/) {
my ($sender, $key, $val) = ($1, "identified", ($3 eq "is logged in as" ? "True" : $2));
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, $key, $val);
debug(ALL, "$key: $val");
} elsif ($code == 338 && $text =~ /^([-_\|`a-zA-Z0-9]+) ([0-9a-fA-F:.]+) :actually using host/) {
my ($sender, $key, $val) = ($1, "ip", $2);
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, $key, $val);
debug(ALL, "$key: $val");
#Unexpected: efnet.port80.se 338 jrmu 206.253.167.44 :actually using host
} elsif ($code == 378 && $text =~ /^([-_\|`a-zA-Z0-9]+) :is connecting from ([^ ]+)\s*([0-9a-fA-F:.]+)?/) {
my ($sender, $key, $val) = ($1, "ip", $3);
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, $key, $val);
debug(ALL, "$key: $val");
} elsif ($code == 671 && $text =~ /^([-_\|`a-zA-Z0-9]+) :is using a secure connection/) {
my ($sender, $key, $val) = ($1, "ssl", "True");
- my $id = SQLite::id("irc", "nick", $sender, $time);
+ my $id = SQLite::id("irc", "nick", $sender, $expires);
SQLite::set("irc", "id", $id, $key, $val);
debug(ALL, "$key: $val");
} elsif ($code =~ /^332$/) { # Topic
blob - 130008e30faaff5537075a20ba8e95f5c2f0f0c5
blob + 6fb52b7a30893f399824b4d1a87a62c9451c3214
--- makefile
+++ makefile
@@ -37,7 +37,7 @@ figlet:
pkg_add figlet-2.2.5
php:
- pkg_add php-7.4.10
+ pkg_add php-7.4.11
# rcctl enable php74_fpm
# rcctl restart php74_fpm
# rcctl enable httpd