[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

VPN Patch for botnow


Dear reader,

Here is my VPN Patch for botnow.

I have copied the original email and pasted it on my ircnow.org email
account since my mailserver doesn't want to send it.

Greets Miniontoby

---------------------------- Original Message ----------------------------

Hey,

 Here's the patch for botnow for the VPN module!

 Greets Miniontoby


 diff --git a/VPN.pm b/VPN.pm
 index 1d5af6d..14db578 100644
 --- a/VPN.pm
 +++ b/VPN.pm
 @@ -6,28 +6,126 @@ use strict;
 use warnings;
 use OpenBSD::Pledge;
 use OpenBSD::Unveil;
 +require "DNS.pm";
 +require "SQLite.pm";
 +
 +my %conf = %main::conf;
 +my $chans = $conf{chans};
 +my $teamchans = $conf{teamchans};
 +my @teamchans = split /[,\s]+/m, $teamchans;
 +my $staff = $conf{staff};
 +my $expires = $conf{expires};
 +my $ikedconf = $conf{ikedconf};
 +# File containing IRC networks
 +my $netpath = "networks";
 +my @networks;
 +
 +main::cbind("pub", "-", "vpn", \&vpn);
 +main::cbind("msg", "-", "vpn", \&vpn);
 sub init {
 + unveil("/usr/bin/rcctl", "rx") or die "Unable to unveil $!";
 + unveil($ikedconf, "crx") or die "Unable to unveil $!";
 +}
 +
 +sub vpn {
 + 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 (defined($chan) && $chans =~ /$chan/) {
 + main::putserv($bot, "PRIVMSG $chan :$nick: Please check private message");
 + }
 + if ($text =~ /^$/) {
 + main::putserv($bot, "PRIVMSG $nick :Type !help for new instructions");
 + foreach my $chan (@teamchans) {
 + main::putservlocalnet($bot, "PRIVMSG $chan :$staff: Help *$nick* on
network ".$bot->{name});
 + }
 + return;
 + }
 + my @rows = SQLite::selectrows("irc", "nick", $nick);
 + foreach my $row (@rows) {
 + my $password = SQLite::get("vpn", "ircid", $row->{id}, "password");
 + if (defined($password)) {
 + main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person.
Please contact staff if you need help.");
 + return;
 + }
 + }
 + if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
 + my $text = $1;
 + my $ircid = SQLite::id("irc", "nick", $nick, $expires);
 + if (!defined($ircid)) { die "undefined ircid"; }
 + my $captcha = SQLite::get("vpn", "ircid", $ircid, "captcha");
 + if ($text ne $captcha) {
 + main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new
captcha, type !vpn  ");
 + return;
 + }
 +
 + my $pass = Hash::newpass();
 + chomp(my $encrypted = `encrypt $pass`);
 + my $username = SQLite::get("vpn", "ircid", $ircid, "username");
 + my $email = SQLite::get("vpn", "ircid", $ircid, "email");
 + my $version = SQLite::get("vpn", "ircid", $ircid, "version");
 + SQLite::set("vpn", "ircid", $ircid, "password", $encrypted);
 +
 + createvpn($username, $pass);
 + foreach my $chan (@teamchans) {
 + main::putservlocalnet($bot, "PRIVMSG $chan :$staff: vpn created for
$username");
 + }
 + my $msg =  0) {
 + main::putserv($bot, "PRIVMSG $nick :Sorry, username taken. Please
choose another username, or contact staff for help.");
 + return;
 + }
 +
 + my $captcha = int(rand(999));
 + my $ircid = int(rand(2147483647));
 + SQLite::set("irc", "id", $ircid, "localtime", time());
 + SQLite::set("irc", "id", $ircid, "date", main::date());
 + SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
 + SQLite::set("irc", "id", $ircid, "nick", $nick);
 + SQLite::set("vpn", "ircid", $ircid, "username", $username);
 + SQLite::set("vpn", "ircid", $ircid, "email", $email);
 + SQLite::set("vpn", "ircid", $ircid, "captcha", $captcha);
 + main::whois($bot->{sock}, $nick);
 + main::ctcp($bot->{sock}, $nick);
 + main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`);
 + # main::putserv($bot, "PRIVMSG $nick
:$captchaURL".encode_base64($captcha));
 + main::putserv($bot, "PRIVMSG $nick :Type !vpn captcha ");
 + foreach my $chan (@teamchans) {
 + main::putservlocalnet($bot, "PRIVMSG $chan :$nick\'s captcha on
$bot->{name} is $captcha");
 + }
 + }
 +}
 +sub createvpn {
 + my ($username, $password) = @_;
 + `doas sh -c 'echo "user $username $password" >> /etc/iked.conf'`;
 + `doas rcctl reload iked`;
 +}
 +
 +sub col {
 + my ($filename) = @_;
 + my @rows = main::readarray($filename);
 + my @results;
 + foreach my $row (@rows) {
 + if ($row =~ /^user (.*?) /) {
 + push(@results, $1);
 + }
 + }
 + return @results;
 }
 -# if ($reply =~ /^!vpn (.*) ([-_0-9a-zA-Z]+)$/i) {
 -# my $ircnick = $1;
 -# my $newnick = $2;
 -# if ($staff !~ /$sender/) {
 -# return;
 -# }
 -# my $password = newpass();
 -# createvpn($password, $newnick);
 -# sendmsg($bot, $sender, "vpn created for $newnick");
 -#my $msg = > /etc/doas.conf
  usermod -G _dovecot botnow
  chmod g+rw ${HOSTNAMEIF}
  cp captcha.png register.php ${HTDOCS}/
 -cp LICENSE README botnow botnow.conf.example BNC.pm DNS.pm Mail.pm
SQLite.pm Shell.pm table.sql Hash.pm Help.pm install networks captcha.png
register.php words report ${HOMEDIR}/
 +cp LICENSE README botnow botnow.conf.example BNC.pm DNS.pm Mail.pm
SQLite.pm Shell.pm table.sql Hash.pm Help.pm VPN.pm install networks
captcha.png register.php words report ${HOMEDIR}/
  mkdir ${HOMEDIR}/backups/
  chown -R ${USERNAME}:${USERNAME} ${HOMEDIR}
  chmod -R go-rx ${HOMEDIR}
 diff --git a/table.sql b/table.sql
 index 1b71f51..b9d4874 100644
 --- a/table.sql
 +++ b/table.sql
 @@ -95,3 +95,15 @@ CREATE TABLE smtp (
  mime VARCHAR(100),
  subject VARCHAR(100)
  );
 +CREATE TABLE vpn (
 + id INTEGER PRIMARY KEY,
 + hashid VARCHAR(100),
 + ircid INTEGER,
 + wwwid INTEGER,
 + smtpid INTEGER,
 + username VARCHAR(32),
 + email VARCHAR(100),
 + password VARCHAR(100),
 + localtime VARCHAR(100),
 + captcha INTEGER
 +);