Blame
Date:
Sun Oct 8 22:28:02 2023 UTC
Message:
Now prevents creating accounts that exist in database with a password
001
2021-12-17
jrmu
#!/usr/bin/perl
002
2021-12-17
jrmu
003
2021-12-17
jrmu
package VPN;
004
2021-12-17
jrmu
005
2021-12-17
jrmu
use strict;
006
2021-12-17
jrmu
use warnings;
007
2021-12-17
jrmu
use OpenBSD::Pledge;
008
2021-12-17
jrmu
use OpenBSD::Unveil;
009
2023-07-29
jrmu
require "DNS.pm";
010
2023-07-29
jrmu
require "SQLite.pm";
011
2021-12-17
jrmu
012
2023-07-29
jrmu
my %conf = %main::conf;
013
2023-07-29
jrmu
my $chans = $conf{chans};
014
2023-07-29
jrmu
my $teamchans = $conf{teamchans};
015
2023-07-29
jrmu
my @teamchans = split /[,\s]+/m, $teamchans;
016
2023-07-29
jrmu
my $staff = $conf{staff};
017
2023-07-29
jrmu
my $expires = $conf{expires};
018
2023-07-29
jrmu
my $ikedconf = $conf{ikedconf} || "/etc/iked.conf";
019
2023-07-29
jrmu
# File containing IRC networks
020
2023-07-29
jrmu
my $netpath = "networks";
021
2023-07-29
jrmu
my @networks;
022
2023-07-29
jrmu
023
2023-07-29
jrmu
main::cbind("pub", "-", "vpn", \&vpn);
024
2023-07-29
jrmu
main::cbind("msg", "-", "vpn", \&vpn);
025
2023-07-29
jrmu
026
2021-12-17
jrmu
sub init {
027
2023-07-29
jrmu
# unveil("/usr/bin/rcctl", "rx") or die "Unable to unveil $!";
028
2023-07-29
jrmu
unveil($ikedconf, "crx") or die "Unable to unveil $!";
029
2021-12-17
jrmu
}
030
2023-07-29
jrmu
031
2023-07-29
jrmu
sub vpn {
032
2023-07-29
jrmu
my ($bot, $nick, $host, $hand, @args) = @_;
033
2023-07-29
jrmu
my ($chan, $text);
034
2023-07-29
jrmu
if (@args == 2) {
035
2023-07-29
jrmu
($chan, $text) = ($args[0], $args[1]);
036
2023-07-29
jrmu
} else { $text = $args[0]; }
037
2023-07-29
jrmu
my $hostmask = "$nick!$host";
038
2023-07-29
jrmu
if (defined($chan) && $chans =~ /$chan/) {
039
2023-07-29
jrmu
main::putserv($bot, "PRIVMSG $chan :$nick: Please check private message");
040
2023-07-29
jrmu
}
041
2023-07-29
jrmu
if ($text =~ /^$/) {
042
2023-07-29
jrmu
main::putserv($bot, "PRIVMSG $nick :Type !help for new instructions");
043
2023-07-29
jrmu
foreach my $chan (@teamchans) {
044
2023-07-29
jrmu
main::putservlocalnet($bot, "PRIVMSG $chan :$staff: Help *$nick* on network".$bot->{name});
045
2023-07-29
jrmu
}
046
2023-07-29
jrmu
return;
047
2023-07-29
jrmu
}
048
2023-07-29
jrmu
my @rows = SQLite::selectrows("irc", "nick", $nick);
049
2023-07-29
jrmu
foreach my $row (@rows) {
050
2023-07-29
jrmu
my $password = SQLite::get("vpn", "ircid", $row->{id}, "password");
051
2023-07-29
jrmu
if (defined($password)) {
052
2023-07-29
jrmu
main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
053
2023-07-29
jrmu
return;
054
2023-07-29
jrmu
}
055
2023-07-29
jrmu
}
056
2023-07-29
jrmu
if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
057
2023-07-29
jrmu
my $text = $1;
058
2023-07-29
jrmu
my $ircid = SQLite::id("irc", "nick", $nick, $expires);
059
2023-07-29
jrmu
if (!defined($ircid)) { die "undefined ircid"; }
060
2023-07-29
jrmu
my $captcha = SQLite::get("vpn", "ircid", $ircid, "captcha");
061
2023-07-29
jrmu
if ($text ne $captcha) {
062
2023-07-29
jrmu
main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !vpn <username> <email>");
063
2023-07-29
jrmu
return;
064
2023-07-29
jrmu
}
065
2023-07-29
jrmu
my $pass = Hash::newpass();
066
2023-07-29
jrmu
chomp(my $encrypted = `encrypt $pass`);
067
2023-07-29
jrmu
my $username = SQLite::get("vpn", "ircid", $ircid, "username");
068
2023-07-29
jrmu
my $email = SQLite::get("vpn", "ircid", $ircid, "email");
069
2023-07-29
jrmu
my $version = SQLite::get("vpn", "ircid", $ircid, "version");
070
2023-07-29
jrmu
SQLite::set("vpn", "ircid", $ircid, "password", $encrypted);
071
2023-07-29
jrmu
072
2023-07-29
jrmu
createvpn($username, $pass);
073
2023-07-29
jrmu
foreach my $chan (@teamchans) {
074
2023-07-29
jrmu
main::putservlocalnet($bot, "PRIVMSG $chan :$staff: vpn created for $username");
075
2023-07-29
jrmu
}
076
2023-07-29
jrmu
my $msg = <<"EOF";
077
2023-07-29
jrmu
Your vpn account has been created! Username: $username with password: $pass
078
2023-07-29
jrmu
Our official support channel is #vpn. To connect, please follow these instructions:
079
2023-07-29
jrmu
https://wiki.ircnow.org/Vpn/Vpn
080
2023-07-29
jrmu
EOF
081
2023-07-29
jrmu
main::putserv($bot, "PRIVMSG $nick :$msg");
082
2023-07-29
jrmu
} elsif ($text =~ /^([[:alnum:]]+)\s+([[:ascii:]]+)/) {
083
2023-07-29
jrmu
my ($username, $email) = ($1, $2);
084
2023-07-29
jrmu
if ($staff !~ /$nick/) {
085
2023-07-29
jrmu
return;
086
2023-07-29
jrmu
}
087
2023-07-29
jrmu
my @users = col($ikedconf);
088
2023-07-29
jrmu
my @matches = grep(/^$username$/i, @users);
089
2023-07-29
jrmu
if (scalar(@matches) > 0) {
090
2023-07-29
jrmu
main::putserv($bot, "PRIVMSG $nick :Sorry, username taken. Please choose another username, or contact staff for help.");
091
2023-07-29
jrmu
return;
092
2023-07-29
jrmu
}
093
2023-07-29
jrmu
094
2023-07-29
jrmu
my $captcha = int(rand(999));
095
2023-07-29
jrmu
my $ircid = int(rand(2147483647));
096
2023-07-29
jrmu
SQLite::set("irc", "id", $ircid, "localtime", time());
097
2023-07-29
jrmu
SQLite::set("irc", "id", $ircid, "date", main::date());
098
2023-07-29
jrmu
SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
099
2023-07-29
jrmu
SQLite::set("irc", "id", $ircid, "nick", $nick);
100
2023-07-29
jrmu
SQLite::set("vpn", "ircid", $ircid, "username", $username);
101
2023-07-29
jrmu
SQLite::set("vpn", "ircid", $ircid, "email", $email);
102
2023-07-29
jrmu
SQLite::set("vpn", "ircid", $ircid, "captcha", $captcha);
103
2023-08-01
jrmu
main::whois($bot, $nick);
104
2023-08-01
jrmu
main::ctcp($bot, $nick);
105
2023-07-29
jrmu
main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`);
106
2023-07-29
jrmu
# main::putserv($bot, "PRIVMSG $nick :$captchaURL".encode_base64($captcha));
107
2023-07-29
jrmu
main::putserv($bot, "PRIVMSG $nick :Type !vpn captcha <text>");
108
2023-07-29
jrmu
foreach my $chan (@teamchans) {
109
2023-07-29
jrmu
main::putservlocalnet($bot, "PRIVMSG $chan :$nick\'s captcha on $bot->{name} is $captcha");
110
2023-07-29
jrmu
}
111
2023-07-29
jrmu
}
112
2023-07-29
jrmu
}
113
2023-07-29
jrmu
sub createvpn {
114
2023-07-29
jrmu
my ($username, $password) = @_;
115
2023-07-29
jrmu
`doas sh -c 'echo "user $username $password" >> /etc/iked.conf'`;
116
2023-07-29
jrmu
`doas rcctl reload iked`;
117
2023-07-29
jrmu
}
118
2023-07-29
jrmu
sub col {
119
2023-07-29
jrmu
my ($filename) = @_;
120
2023-07-29
jrmu
my @rows = main::readarray($filename);
121
2023-07-29
jrmu
my @results;
122
2023-07-29
jrmu
foreach my $row (@rows) {
123
2023-07-29
jrmu
if ($row =~ /^user (.*?) /) {
124
2023-07-29
jrmu
push(@results, $1);
125
2023-07-29
jrmu
}
126
2023-07-29
jrmu
}
127
2023-07-29
jrmu
return @results;
128
2023-07-29
jrmu
}
129
2023-07-29
jrmu
130
2023-07-29
jrmu
#sub init {
131
2023-07-29
jrmu
#}
132
2021-12-17
jrmu
# if ($reply =~ /^!vpn (.*) ([-_0-9a-zA-Z]+)$/i) {
133
2021-12-17
jrmu
# my $ircnick = $1;
134
2021-12-17
jrmu
# my $newnick = $2;
135
2021-12-17
jrmu
# if ($staff !~ /$sender/) {
136
2021-12-17
jrmu
# return;
137
2021-12-17
jrmu
# }
138
2021-12-17
jrmu
# my $password = newpass();
139
2021-12-17
jrmu
# createvpn($password, $newnick);
140
2021-12-17
jrmu
# sendmsg($bot, $sender, "vpn created for $newnick");
141
2021-12-17
jrmu
#my $msg = <<"EOF";
142
2021-12-17
jrmu
#Your vpn account has been created! Username: $newnick with password: $password
143
2021-12-17
jrmu
#Our official support channel is #vpn. To connect, please follow these instructions: https://ircnow.org/kb/doku.php?id=vpn:vpn .
144
2021-12-17
jrmu
#EOF
145
2021-12-17
jrmu
# sendmsg($bot, $ircnick, $msg);
146
2021-12-17
jrmu
# }
147
2021-12-17
jrmu
#sub createvpn {
148
2021-12-17
jrmu
# my ($password, $username) = @_;
149
2021-12-17
jrmu
# `doas sh -c 'echo "user '$username' '$password'" >> /etc/iked.conf'`;
150
2021-12-17
jrmu
# `doas rcctl reload iked`;
151
2021-12-17
jrmu
#}
152
2021-12-17
jrmu
153
2021-12-17
jrmu
1; # MUST BE LAST STATEMENT IN FILE
IRCNow