commit 508e42881039eebebd6f2b001a42579950242266 from: Izzy Blacklock date: Sun Aug 13 19:18:58 2023 UTC code cleanup, pod document, debug messages commit - d15f745e78985e5677b797fd69c5275bd5c5ed61 commit + 508e42881039eebebd6f2b001a42579950242266 blob - 51099211f36246a4e0ae6e89e847f95783b93ddf blob + 46aa09213e699f27dd1c7b0e7ecb8b3e00f5b660 --- bin/dnsTest.pl +++ bin/dnsTest.pl @@ -10,7 +10,7 @@ use lib qw(./lib); use IRCNOW::Database; use IRCNOW::IO::IRC; -use IRCNOW::Acct::DNS; +use IRCNOW::Acct::DNS qw(randip6); # Load debug modules and set path for auto backups. @@ -18,21 +18,18 @@ use IRCNOW::IO qw(:DEBUG); $verbosity=ALL; # verbosity is exported via :DEBUG sets the debug level $IRCNOW::IO::backupspath = 'zones/'; -#my $dbase='/var/www/botnow/botnow.db'; -#debug(INFO, "Loading Database $dbase"); -#my $botnowDB = IRCNOW::Database->new(dbpath=>$dbase); - -use Data::Dumper; - #my $acct=new IRCNOW::Acct(); #print $acct->newpass() . "\n"; my $dnsAcct=new IRCNOW::Acct::DNS(); -$dnsAcct->init(); +#$dnsAcct->init(); #unveil() or die "Unable to lock unveil $!"; -$dnsAcct->nextdns('izzyb'); +my $ipv6 = $dnsAcct->nextdns('resuwen'); +print "Your new ipv6 address: $ipv6\n"; +my $random_ipv6 = randip6(); +print "$random_ipv6\n"; =pod @@ -54,6 +51,9 @@ $IRCNOW::IO::backupspath = 'zones/'; # DNS commands related to IRCNOW accounts. use IRCNOW::Acct::DNS; +my $ipv6 = $dnsAcct->nextdns('resuwen'); +print "Your new ipv6 address: $ipv6\n"; + =head1 DESCRIPTION This script provides example usage of the IRCNOW::Acct::DNS module. blob - 91dae8a4dc2e7e0e1a5166a7b9fad5b50a203b41 blob + 01d768d15d31db714b0e6441d16ce945bc96c6f4 --- lib/IRCNOW/Acct/DNS.pm +++ lib/IRCNOW/Acct/DNS.pm @@ -3,6 +3,24 @@ package IRCNOW::Acct::DNS; use strict; use warnings; use Carp; + +use Exporter 'import'; + +our @EXPORT_OK = qw( + randip6 +); +#our %EXPORT_TAGS = ( +#); +#Exporter::export_ok_tags(qw{ +# +#}); + + + + + + + #use OpenBSD::Pledge; #use OpenBSD::Unveil; use lib qw(./lib); @@ -115,7 +133,7 @@ sub setdns { } my ($name, $origin, $type, $value) = @_; - debug(ALL,"SUB: setdns($name, $origin, $type, $value)"); + debug(ALL,"SUB: setdns(".($name||'').", ".($origin||'').", ".($type||'').", ".($value||'').")"); my $filename = $self->{zonedir} ."/$origin"; my @lines = readarray($filename); foreach my $line (@lines) { @@ -134,8 +152,8 @@ sub setdns { } # trailing newline necessary writefile("$filename", join("\n", @lines)."\n"); - debug(ALL, 'Running: doas -u _nsd nsd-control reload'); - if (system("doas -u _nsd nsd-control reload")) { + debug(ALL, 'SYSTEM: doas -u _nsd nsd-control reload'); + if (system("doas -u _nsd nsd-control reload >/dev/null")) { return 0; } else { return 1; @@ -230,3 +248,131 @@ sub nextdns { } 1; # MUST BE LAST STATEMENT IN FILE + +=pod + +=head1 NAME + +IRCNOW::Acct::DNS + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +This library provides functions for creating and managing dns records for users. + +=head1 PACKAGE VARIABLES + +This library can be called in either OOP mode or standard function calls. The functions descriptions below provide a list of package variables that are used by the function. The veriable descriptions below indicate if they have default values. You can set these variables via options passed to new() or by setting hash keys in the $IRCNOW::Acct::DNS::conf hash like this: + +=head2 OOP Method + + use IRCNOW::Acct::DNS; + my $acctDNS = new IRCNOW::Acct::DNS( + ip6subnet => 64, + hostname => system('hostname'), + ); + my $ipv6 = $acctDNS->nextdns('resuwen'); + +=head2 Package Variables + + use IRCNOW::Acct::DNS qw(nextdns); + my $dnsConf=$IRCNOW::Acct::DNS::conf; + $dnsConf->{ip6subnet} = 64; + $dnsConf->{hostname} = system('hostname'); + my $ipv6 = nextdns('resuwen'); + +or + + use IRCNOW::Acct::DNS qw(nextdns); + my $conf = { + ip6subnet => 64, + hostname => system('hostname'), + }; + $IRCNOW::Acct::DNS::conf = $conf; + my $ipv6 = nextdns('resuwen'); + +=head3 Variable Descriptions + +=head4 ip4 (defaults to hosts ipv4 address) + + ipv4 address of the host + +=head4 ip6 (defaults to hosts ipv6 address) + + ipv6 address of the host + +=head4 ip6subnet (default 64) + + ip6 subnet length in bits. + +=head4 hostname (defaults to hostname of the system.) + + hostname of the system. Root domain used for the created dns entries. + +=head1 FUNCTIONS + +=head2 readip6s($filename) + +Return list of ipv6 addresses from filename + +=head3 Package Variables + +=head2 setrdns($ip6, $subnet, $hostname) + +set rdns of $ip6 to $hostname given $subnet +return true on success; false on failure + +=head3 Package Variables + +=head2 delrdns($ip6, $subnet) + +delete rdns of $ip6 given $subnet +return true on success; false on failure + +=head3 Package Variables + +=head2 setdns($name, $origin, $type, $value) + +given $origin. create $name RR of $type and set to $value if provided; +if $value is missing, delete $domain +returns true upon success, false upon failure + +=head3 Package Variables + + zonedir + +=head2 host($host) + +given hostname, return IP addresses; or given IP address, return hostname + +=head3 Package Variables + +=head2 ip6full($ip6) + +Return an ipv6 address with all zeroes filled in + +=head3 Package Variables + +=head2 ip6mask($ip6net, $subnet, $ip6host) + +Returns the network part of the first IPv6 address (indicated by subnet) +with the host part of the second IPv6 address + +=head3 Package Variables + +=head2 randip6() + +This function returns a random ipv6 address. + +=head3 Package Variables + +=head2 nextdns($subdomain) + +This function creates an A and AAAA records for subdomain provided. + +=head3 Package Variables + + ip6subnet, hostname, ip6, hostnameif + +=cut