Blame
Date:
Fri Dec 17 13:35:57 2021 UTC
Message:
Imported sources
001
2021-12-17
jrmu
#!/usr/bin/perl
002
2021-12-17
jrmu
003
2021-12-17
jrmu
package Shell;
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
2021-12-17
jrmu
use MIME::Base64;
010
2021-12-17
jrmu
use Data::Dumper;
011
2021-12-17
jrmu
use Digest::SHA qw(sha256_hex);
012
2021-12-17
jrmu
use lib './';
013
2021-12-17
jrmu
require "SQLite.pm";
014
2021-12-17
jrmu
require "Hash.pm";
015
2021-12-17
jrmu
016
2021-12-17
jrmu
my %conf = %main::conf;
017
2021-12-17
jrmu
my $chans = $conf{chans};
018
2021-12-17
jrmu
my $teamchans = $conf{teamchans};
019
2021-12-17
jrmu
my @teamchans = split /[,\s]+/m, $teamchans;
020
2021-12-17
jrmu
my $staff = $conf{staff};
021
2021-12-17
jrmu
my $captchaURL = "https://example.com/captcha.php?vhost=";
022
2021-12-17
jrmu
my $hostname = $conf{hostname};
023
2021-12-17
jrmu
my $terms = $conf{terms};
024
2021-12-17
jrmu
my $expires = $conf{expires};
025
2021-12-17
jrmu
my $mailfrom = $conf{mailfrom};
026
2021-12-17
jrmu
my $mailname = $conf{mailname};
027
2021-12-17
jrmu
my $passpath = "/etc/passwd";
028
2021-12-17
jrmu
my $httpdconfpath = "/etc/httpd.conf";
029
2021-12-17
jrmu
my $acmeconfpath = "/etc/acme-client.conf";
030
2021-12-17
jrmu
my $pfconfpath = "/etc/pf.conf";
031
2021-12-17
jrmu
my $relaydconfpath = "/etc/relayd.conf";
032
2021-12-17
jrmu
my $startPort;
033
2021-12-17
jrmu
my $endPort;
034
2021-12-17
jrmu
main::cbind("pub", "-", "shell", \&mshell);
035
2021-12-17
jrmu
main::cbind("msg", "-", "shell", \&mshell);
036
2021-12-17
jrmu
037
2021-12-17
jrmu
sub init {
038
2021-12-17
jrmu
#dependencies for figlet
039
2021-12-17
jrmu
unveil("/usr/local/bin/figlet", "rx") or die "Unable to unveil $!";
040
2021-12-17
jrmu
unveil("/usr/lib/libc.so.95.1", "r") or die "Unable to unveil $!";
041
2021-12-17
jrmu
unveil("/usr/libexec/ld.so", "r") or die "Unable to unveil $!";
042
2021-12-17
jrmu
#dependencies for shell account
043
2021-12-17
jrmu
unveil($passpath, "r") or die "Unable to unveil $!";
044
2021-12-17
jrmu
unveil($httpdconfpath, "rwxc") or die "Unable to unveil $!";
045
2021-12-17
jrmu
unveil($acmeconfpath, "rwxc") or die "Unable to unveil $!";
046
2021-12-17
jrmu
unveil($pfconfpath, "rwxc") or die "Unable to unveil $!";
047
2021-12-17
jrmu
unveil($relaydconfpath, "rwxc") or die "Unable to unveil $!";
048
2021-12-17
jrmu
unveil("/usr/sbin/chown", "rx") or die "Unable to unveil $!";
049
2021-12-17
jrmu
unveil("/bin/chmod", "rx") or die "Unable to unveil $!";
050
2021-12-17
jrmu
unveil("/usr/sbin/groupadd", "rx") or die "Unable to unveil $!";
051
2021-12-17
jrmu
unveil("/usr/sbin/useradd", "rx") or die "Unable to unveil $!";
052
2021-12-17
jrmu
unveil("/usr/sbin/groupdel", "rx") or die "Unable to unveil $!";
053
2021-12-17
jrmu
unveil("/usr/sbin/userdel", "rx") or die "Unable to unveil $!";
054
2021-12-17
jrmu
unveil("/bin/mkdir", "rx") or die "Unable to unveil $!";
055
2021-12-17
jrmu
unveil("/bin/ln", "rx") or die "Unable to unveil $!";
056
2021-12-17
jrmu
unveil("/usr/sbin/acme-client", "rx") or die "Unable to unveil $!";
057
2021-12-17
jrmu
unveil("/bin/rm", "rx") or die "Unable to unveil $!";
058
2021-12-17
jrmu
unveil("/bin/mv", "rx") or die "Unable to unveil $!";
059
2021-12-17
jrmu
unveil("/home/", "rwxc") or die "Unable to unveil $!";
060
2021-12-17
jrmu
}
061
2021-12-17
jrmu
062
2021-12-17
jrmu
# !shell <username> <email>
063
2021-12-17
jrmu
# !shell captcha <captcha>
064
2021-12-17
jrmu
sub mshell {
065
2021-12-17
jrmu
my ($bot, $nick, $host, $hand, @args) = @_;
066
2021-12-17
jrmu
my ($chan, $text);
067
2021-12-17
jrmu
if (@args == 2) {
068
2021-12-17
jrmu
($chan, $text) = ($args[0], $args[1]);
069
2021-12-17
jrmu
} else { $text = $args[0]; }
070
2021-12-17
jrmu
my $hostmask = "$nick!$host";
071
2021-12-17
jrmu
if (defined($chan) && $chans =~ /$chan/) {
072
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $chan :$nick: Please check private message");
073
2021-12-17
jrmu
}
074
2021-12-17
jrmu
if ($text =~ /^$/) {
075
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :Type !help for new instructions");
076
2021-12-17
jrmu
foreach my $chan (@teamchans) {
077
2021-12-17
jrmu
main::putservlocalnet($bot, "PRIVMSG $chan :Help shell *$nick* on ".$bot->{name});
078
2021-12-17
jrmu
}
079
2021-12-17
jrmu
return;
080
2021-12-17
jrmu
} elsif (main::isstaff($bot, $nick) && $text =~ /^delete\s+([[:ascii:]]+)/) {
081
2021-12-17
jrmu
my $username = $1;
082
2021-12-17
jrmu
if (SQLite::deleterows("shell", "username", $username)) {
083
2021-12-17
jrmu
# TODO delete shell
084
2021-12-17
jrmu
deleteshell($username);
085
2021-12-17
jrmu
foreach my $chan (@teamchans) {
086
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $chan :$username deleted");
087
2021-12-17
jrmu
}
088
2021-12-17
jrmu
}
089
2021-12-17
jrmu
return;
090
2021-12-17
jrmu
}
091
2021-12-17
jrmu
### TODO: Check duplicate emails ###
092
2021-12-17
jrmu
my @rows = SQLite::selectrows("irc", "nick", $nick);
093
2021-12-17
jrmu
foreach my $row (@rows) {
094
2021-12-17
jrmu
my $password = SQLite::get("shell", "ircid", $row->{id}, "password");
095
2021-12-17
jrmu
if (defined($password)) {
096
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
097
2021-12-17
jrmu
return;
098
2021-12-17
jrmu
}
099
2021-12-17
jrmu
}
100
2021-12-17
jrmu
if ($text =~ /^lastseen\s+([[:alnum:]]+)/) {
101
2021-12-17
jrmu
}
102
2021-12-17
jrmu
if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
103
2021-12-17
jrmu
my $text = $1;
104
2021-12-17
jrmu
my $ircid = SQLite::id("irc", "nick", $nick, $expires);
105
2021-12-17
jrmu
if (!defined($ircid)) { die "undefined ircid"; }
106
2021-12-17
jrmu
my $captcha = SQLite::get("shell", "ircid", $ircid, "captcha");
107
2021-12-17
jrmu
if ($text ne $captcha) {
108
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !shell <username> <email>");
109
2021-12-17
jrmu
return;
110
2021-12-17
jrmu
}
111
2021-12-17
jrmu
my $pass = Hash::newpass();
112
2021-12-17
jrmu
chomp(my $encrypted = `encrypt $pass`);
113
2021-12-17
jrmu
my $username = SQLite::get("shell", "ircid", $ircid, "username");
114
2021-12-17
jrmu
my $email = SQLite::get("shell", "ircid", $ircid, "email");
115
2021-12-17
jrmu
my $version = SQLite::get("shell", "ircid", $ircid, "version");
116
2021-12-17
jrmu
my $bindhost = "$username.$hostname";
117
2021-12-17
jrmu
SQLite::set("shell", "ircid", $ircid, "password", $encrypted);
118
2021-12-17
jrmu
if (DNS::nextdns($username)) {
119
2021-12-17
jrmu
sleep(2);
120
2021-12-17
jrmu
createshell($username, $pass, $bindhost);
121
2021-12-17
jrmu
mailshell($username, $email, $pass, "shell", $version);
122
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :Check your email!");
123
2021-12-17
jrmu
124
2021-12-17
jrmu
#www($newnick, $reply, $password, "bouncer");
125
2021-12-17
jrmu
} else {
126
2021-12-17
jrmu
foreach my $chan (@teamchans) {
127
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $chan :Assigning bindhost $bindhost failed");
128
2021-12-17
jrmu
}
129
2021-12-17
jrmu
}
130
2021-12-17
jrmu
return;
131
2021-12-17
jrmu
} elsif ($text =~ /^([[:alnum:]]+)\s+([[:ascii:]]+)/) {
132
2021-12-17
jrmu
my ($username, $email) = ($1, $2);
133
2021-12-17
jrmu
my @users = col($passpath, 1, ":");
134
2021-12-17
jrmu
my @matches = grep(/^$username$/i, @users);
135
2021-12-17
jrmu
if (scalar(@matches) > 0) {
136
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :Sorry, username taken. Please choose another username, or contact staff for help.");
137
2021-12-17
jrmu
return;
138
2021-12-17
jrmu
}
139
2021-12-17
jrmu
# my $captcha = join'', map +(0..9,'a'..'z','A'..'Z')[rand(10+26*2)], 1..4;
140
2021-12-17
jrmu
my $captcha = int(rand(999));
141
2021-12-17
jrmu
my $ircid = int(rand(2147483647));
142
2021-12-17
jrmu
SQLite::set("irc", "id", $ircid, "localtime", time());
143
2021-12-17
jrmu
SQLite::set("irc", "id", $ircid, "date", main::date());
144
2021-12-17
jrmu
SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
145
2021-12-17
jrmu
SQLite::set("irc", "id", $ircid, "nick", $nick);
146
2021-12-17
jrmu
SQLite::set("shell", "ircid", $ircid, "username", $username);
147
2021-12-17
jrmu
SQLite::set("shell", "ircid", $ircid, "email", $email);
148
2021-12-17
jrmu
SQLite::set("shell", "ircid", $ircid, "captcha", $captcha);
149
2021-12-17
jrmu
main::whois($bot->{sock}, $nick);
150
2021-12-17
jrmu
main::ctcp($bot->{sock}, $nick);
151
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`);
152
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :$captchaURL".encode_base64($captcha));
153
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :Type !shell captcha <text>");
154
2021-12-17
jrmu
foreach my $chan (@teamchans) {
155
2021-12-17
jrmu
main::putservlocalnet($bot, "PRIVMSG $chan :$nick\'s captcha on $bot->{name} is $captcha");
156
2021-12-17
jrmu
}
157
2021-12-17
jrmu
} else {
158
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $nick :Invalid username or email. Type !shell <username> <email> to try again.");
159
2021-12-17
jrmu
foreach my $chan (@teamchans) {
160
2021-12-17
jrmu
main::putserv($bot, "PRIVMSG $chan :Help *$nick* on ".$bot->{name});
161
2021-12-17
jrmu
}
162
2021-12-17
jrmu
}
163
2021-12-17
jrmu
}
164
2021-12-17
jrmu
sub mailshell {
165
2021-12-17
jrmu
my( $username, $email, $password, $service, $version )=@_;
166
2021-12-17
jrmu
my $passhash = sha256_hex("$username");
167
2021-12-17
jrmu
my $versionhash = encode_base64($version);
168
2021-12-17
jrmu
my $body = <<"EOF";
169
2021-12-17
jrmu
You created a shell account!
170
2021-12-17
jrmu
171
2021-12-17
jrmu
Username: $username
172
2021-12-17
jrmu
Password: $password
173
2021-12-17
jrmu
Server: $hostname
174
2021-12-17
jrmu
SSH Port: 22
175
2021-12-17
jrmu
Your Ports: $startPort to $endPort
176
2021-12-17
jrmu
177
2021-12-17
jrmu
To customize your vhost, connect to ask in #ircnow
178
2021-12-17
jrmu
179
2021-12-17
jrmu
*IMPORTANT*: Verify your email address:
180
2021-12-17
jrmu
181
2021-12-17
jrmu
https://www.$hostname/register.php?id=$passhash&version=$versionhash
182
2021-12-17
jrmu
183
2021-12-17
jrmu
You *MUST* click on the link within 24 hours or your account will be deleted.
184
2021-12-17
jrmu
185
2021-12-17
jrmu
IRCNow
186
2021-12-17
jrmu
EOF
187
2021-12-17
jrmu
Mail::mail($mailfrom, $email, $mailname, "Verify IRCNow Account", $body);
188
2021-12-17
jrmu
}
189
2021-12-17
jrmu
190
2021-12-17
jrmu
191
2021-12-17
jrmu
#sub mregex {
192
2021-12-17
jrmu
# my ($bot, $nick, $host, $hand, $text) = @_;
193
2021-12-17
jrmu
# if ($staff !~ /$nick/) { return; }
194
2021-12-17
jrmu
# if ($text =~ /^ips?\s+([-_()|0-9A-Za-z:\.?*\s]{3,})$/) {
195
2021-12-17
jrmu
# my $ips = $1; # space-separated list of IPs
196
2021-12-17
jrmu
# main::putserv($bot, "PRIVMSG $nick :".regexlist($ips));
197
2021-12-17
jrmu
# } elsif ($text =~ /^users?\s+([-_()|0-9A-Za-z:\.?*\s]{3,})$/) {
198
2021-12-17
jrmu
# my $users = $1; # space-separated list of usernames
199
2021-12-17
jrmu
# main::putserv($bot, "PRIVMSG $nick :".regexlist($users));
200
2021-12-17
jrmu
# } elsif ($text =~ /^[-_()|0-9A-Za-z:,\.?*\s]{3,}$/) {
201
2021-12-17
jrmu
# my @lines = regex($text);
202
2021-12-17
jrmu
# foreach my $l (@lines) { print "$l\n"; }
203
2021-12-17
jrmu
# }
204
2021-12-17
jrmu
#}
205
2021-12-17
jrmu
#sub mforeach {
206
2021-12-17
jrmu
# my ($bot, $nick, $host, $hand, $text) = @_;
207
2021-12-17
jrmu
# if ($staff !~ /$nick/) { return; }
208
2021-12-17
jrmu
# if ($text =~ /^network\s+del\s+([[:graph:]]+)\s+(#[[:graph:]]+)$/) {
209
2021-12-17
jrmu
# my ($user, $chan) = ($1, $2);
210
2021-12-17
jrmu
# foreach my $n (@main::networks) {
211
2021-12-17
jrmu
# main::putserv($bot, "PRIVMSG *controlpanel :delchan $user $n->{name} $chan");
212
2021-12-17
jrmu
# }
213
2021-12-17
jrmu
# }
214
2021-12-17
jrmu
#}
215
2021-12-17
jrmu
216
2021-12-17
jrmu
#sub loadlog {
217
2021-12-17
jrmu
# open(my $fh, '<', "$authlog") or die "Could not read file 'authlog' $!";
218
2021-12-17
jrmu
# chomp(@logs = <$fh>);
219
2021-12-17
jrmu
# close $fh;
220
2021-12-17
jrmu
#}
221
2021-12-17
jrmu
222
2021-12-17
jrmu
# return all lines matching a pattern
223
2021-12-17
jrmu
#sub regex {
224
2021-12-17
jrmu
# my ($pattern) = @_;
225
2021-12-17
jrmu
# if (!@logs) { loadlog(); }
226
2021-12-17
jrmu
# return grep(/$pattern/, @logs);
227
2021-12-17
jrmu
#}
228
2021-12-17
jrmu
229
2021-12-17
jrmu
# given a list of IPs, return matching users
230
2021-12-17
jrmu
# or given a list of users, return matching IPs
231
2021-12-17
jrmu
#sub regexlist {
232
2021-12-17
jrmu
# my ($items) = @_;
233
2021-12-17
jrmu
# my @items = split /[,\s]+/m, $items;
234
2021-12-17
jrmu
# my $pattern = "(".join('|', @items).")";
235
2021-12-17
jrmu
# if (!@logs) { loadlog(); }
236
2021-12-17
jrmu
# my @matches = grep(/$pattern/, @logs);
237
2021-12-17
jrmu
# my @results;
238
2021-12-17
jrmu
# foreach my $match (@matches) {
239
2021-12-17
jrmu
# if ($match =~ /^\[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\] \[([^]\/]+)(\/[^]]+)?\] connected to ZNC from (.*)/) {
240
2021-12-17
jrmu
# my ($user, $ip) = ($1, $3);
241
2021-12-17
jrmu
# if ($items =~ /[.:]/) { # items are IP addresses
242
2021-12-17
jrmu
# push(@results, $user);
243
2021-12-17
jrmu
# } else { # items are users
244
2021-12-17
jrmu
# push(@results, $ip);
245
2021-12-17
jrmu
# }
246
2021-12-17
jrmu
# }
247
2021-12-17
jrmu
# }
248
2021-12-17
jrmu
# my @sorted = sort @results;
249
2021-12-17
jrmu
# @results = do { my %seen; grep { !$seen{$_}++ } @sorted }; # uniq
250
2021-12-17
jrmu
# return join(' ', @results);
251
2021-12-17
jrmu
#}
252
2021-12-17
jrmu
253
2021-12-17
jrmu
sub createshell {
254
2021-12-17
jrmu
my ($username, $password, $bindhost) = @_;
255
2021-12-17
jrmu
system "doas groupadd $username";
256
2021-12-17
jrmu
system "doas adduser -batch $username $username $username `encrypt $password`";
257
2021-12-17
jrmu
system "doas chmod 700 /home/$username /home/$username/.ssh";
258
2021-12-17
jrmu
system "doas chmod 600 /home/$username/{.Xdefaults,.cshrc,.cvsrc,.login,.mailrc,.profile}";
259
2021-12-17
jrmu
system "doas mkdir /var/www/htdocs/$username";
260
2021-12-17
jrmu
system "doas ln -s /var/www/htdocs/$username /home/$username/htdocs";
261
2021-12-17
jrmu
system "doas chown -R $username:www /var/www/htdocs/$username /home/$username/htdocs";
262
2021-12-17
jrmu
system "doas chmod -R o-rx /var/www/htdocs/$username /home/$username/htdocs";
263
2021-12-17
jrmu
system "doas chmod -R g+rwx /var/www/htdocs/$username /home/$username/htdocs";
264
2021-12-17
jrmu
my $lusername = lc $username;
265
2021-12-17
jrmu
my $block = <<"EOF";
266
2021-12-17
jrmu
server "$lusername.$hostname" {
267
2021-12-17
jrmu
listen on * port 80
268
2021-12-17
jrmu
location "/.well-known/acme-challenge/*" {
269
2021-12-17
jrmu
root "/acme"
270
2021-12-17
jrmu
request strip 2
271
2021-12-17
jrmu
}
272
2021-12-17
jrmu
location "*.php" {
273
2021-12-17
jrmu
fastcgi socket "/run/php-fpm.sock"
274
2021-12-17
jrmu
}
275
2021-12-17
jrmu
root "/htdocs/$username"
276
2021-12-17
jrmu
}
277
2021-12-17
jrmu
EOF
278
2021-12-17
jrmu
main::appendfile($httpdconfpath, $block);
279
2021-12-17
jrmu
$block = <<"EOF";
280
2021-12-17
jrmu
domain "$lusername.$hostname" {
281
2021-12-17
jrmu
domain key "/etc/ssl/private/$lusername.$hostname.key"
282
2021-12-17
jrmu
domain full chain certificate "/etc/ssl/$lusername.$hostname.crt"
283
2021-12-17
jrmu
sign with letsencrypt
284
2021-12-17
jrmu
}
285
2021-12-17
jrmu
EOF
286
2021-12-17
jrmu
main::appendfile($acmeconfpath, $block);
287
2021-12-17
jrmu
configurepf($username);
288
2021-12-17
jrmu
system "doas rcctl reload httpd";
289
2021-12-17
jrmu
system "doas acme-client -F $lusername.$hostname";
290
2021-12-17
jrmu
system "doas ln -s /etc/ssl/$lusername.$hostname.crt /etc/ssl/$lusername.$hostname.fullchain.pem";
291
2021-12-17
jrmu
system "doas pfctl -f /etc/pf.conf";
292
2021-12-17
jrmu
configurerelayd($username);
293
2021-12-17
jrmu
$block = <<"EOF";
294
2021-12-17
jrmu
~ * * * * acme-client $lusername.$hostname && rcctl reload relayd
295
2021-12-17
jrmu
EOF
296
2021-12-17
jrmu
system "echo $block | doas crontab -";
297
2021-12-17
jrmu
#edquota $username
298
2021-12-17
jrmu
return 1;
299
2021-12-17
jrmu
}
300
2021-12-17
jrmu
301
2021-12-17
jrmu
sub deleteshell {
302
2021-12-17
jrmu
my ($username, $bindhost) = @_;
303
2021-12-17
jrmu
my $lusername = lc $username;
304
2021-12-17
jrmu
system "doas groupdel $username";
305
2021-12-17
jrmu
system "doas userdel $username";
306
2021-12-17
jrmu
system "doas rm -f /etc/ssl/$lusername.$hostname.crt /etc/ssl/$lusername.$hostname.fullchain.pem /etc/ssl/private/$lusername.$hostname.key";
307
2021-12-17
jrmu
my $httpdconf = main::readstr($httpdconfpath);
308
2021-12-17
jrmu
my $block = <<"EOF";
309
2021-12-17
jrmu
server "$lusername.$hostname" {
310
2021-12-17
jrmu
listen on * port 80
311
2021-12-17
jrmu
location "/.well-known/acme-challenge/*" {
312
2021-12-17
jrmu
root "/acme"
313
2021-12-17
jrmu
request strip 2
314
2021-12-17
jrmu
}
315
2021-12-17
jrmu
location "*.php" {
316
2021-12-17
jrmu
fastcgi socket "/run/php-fpm.sock"
317
2021-12-17
jrmu
}
318
2021-12-17
jrmu
root "/htdocs/$username"
319
2021-12-17
jrmu
}
320
2021-12-17
jrmu
EOF
321
2021-12-17
jrmu
$block =~ s/{/\\{/gm;
322
2021-12-17
jrmu
$block =~ s/}/\\}/gm;
323
2021-12-17
jrmu
$block =~ s/\./\\./gm;
324
2021-12-17
jrmu
$block =~ s/\*/\\*/gm;
325
2021-12-17
jrmu
$httpdconf =~ s{$block}{}gm;
326
2021-12-17
jrmu
print $httpdconf;
327
2021-12-17
jrmu
main::writefile($httpdconfpath, $httpdconf);
328
2021-12-17
jrmu
329
2021-12-17
jrmu
my $acmeconf = main::readstr($acmeconfpath);
330
2021-12-17
jrmu
$block = <<"EOF";
331
2021-12-17
jrmu
domain "$lusername.$hostname" {
332
2021-12-17
jrmu
domain key "/etc/ssl/private/$lusername.$hostname.key"
333
2021-12-17
jrmu
domain full chain certificate "/etc/ssl/$lusername.$hostname.fullchain.pem"
334
2021-12-17
jrmu
sign with letsencrypt
335
2021-12-17
jrmu
}
336
2021-12-17
jrmu
EOF
337
2021-12-17
jrmu
$block =~ s/{/\\{/gm;
338
2021-12-17
jrmu
$block =~ s/}/\\}/gm;
339
2021-12-17
jrmu
$block =~ s/\./\\./gm;
340
2021-12-17
jrmu
$block =~ s/\*/\\*/gm;
341
2021-12-17
jrmu
$acmeconf =~ s{$block}{}gm;
342
2021-12-17
jrmu
main::writefile($acmeconfpath, $acmeconf);
343
2021-12-17
jrmu
return 1;
344
2021-12-17
jrmu
}
345
2021-12-17
jrmu
346
2021-12-17
jrmu
#TODO Fix for $i
347
2021-12-17
jrmu
# Return column $i from $filename as an array with file separator $FS
348
2021-12-17
jrmu
sub col {
349
2021-12-17
jrmu
my ($filename, $i, $FS) = @_;
350
2021-12-17
jrmu
my @rows = main::readarray($filename);
351
2021-12-17
jrmu
my @results;
352
2021-12-17
jrmu
foreach my $row (@rows) {
353
2021-12-17
jrmu
if ($row =~ /^(.*?)$FS/) {
354
2021-12-17
jrmu
push(@results, $1);
355
2021-12-17
jrmu
}
356
2021-12-17
jrmu
}
357
2021-12-17
jrmu
return @results;
358
2021-12-17
jrmu
}
359
2021-12-17
jrmu
360
2021-12-17
jrmu
sub configurepf {
361
2021-12-17
jrmu
my $username = shift;
362
2021-12-17
jrmu
my @read = split('\n', main::readstr($pfconfpath) );
363
2021-12-17
jrmu
364
2021-12-17
jrmu
my $previousline = "";
365
2021-12-17
jrmu
my @pfcontent;
366
2021-12-17
jrmu
foreach my $line(@read)
367
2021-12-17
jrmu
{
368
2021-12-17
jrmu
my $currline = $line;
369
2021-12-17
jrmu
if( $currline ne "# end user ports") {
370
2021-12-17
jrmu
$previousline = $currline;
371
2021-12-17
jrmu
} else {
372
2021-12-17
jrmu
#pass in proto {tcp udp} to port {31361:31370} user {JL}
373
2021-12-17
jrmu
if( $previousline =~ /(\d*):(\d*)/ ) {
374
2021-12-17
jrmu
my $startport = ( $1 + 10 );
375
2021-12-17
jrmu
my $endport = ( $2 + 10 );
376
2021-12-17
jrmu
my $insert = "pass in proto {tcp udp} to port {$startport:$endport} user {$username}";
377
2021-12-17
jrmu
push(@pfcontent, $insert);
378
2021-12-17
jrmu
$startPort = $startport;
379
2021-12-17
jrmu
$endPort = $endport;
380
2021-12-17
jrmu
}
381
2021-12-17
jrmu
}
382
2021-12-17
jrmu
push(@pfcontent, $currline)
383
2021-12-17
jrmu
}
384
2021-12-17
jrmu
main::writefile("$pfconfpath", join("\n",@pfcontent))
385
2021-12-17
jrmu
}
386
2021-12-17
jrmu
387
2021-12-17
jrmu
sub configurerelayd {
388
2021-12-17
jrmu
my ($username) = @_;
389
2021-12-17
jrmu
my $block = "tls { keypair $username.$hostname }";
390
2021-12-17
jrmu
my $relaydconf = main::readstr($relaydconfpath);
391
2021-12-17
jrmu
my $newconf;
392
2021-12-17
jrmu
if ($relaydconf =~ /^.*tls\s+{\s+keypair\s+[.0-9a-zA-Z]+\s*}/m) {
393
2021-12-17
jrmu
$newconf = "$`$&\n\t$block$'";
394
2021-12-17
jrmu
}
395
2021-12-17
jrmu
main::writefile($relaydconfpath, $newconf);
396
2021-12-17
jrmu
}
397
2021-12-17
jrmu
398
2021-12-17
jrmu
#unveil("./newacct", "rx") or die "Unable to unveil $!";
399
2021-12-17
jrmu
1; # MUST BE LAST STATEMENT IN FILE
IRCNow