--- rpms/smeserver-wireguard/contribs10/smeserver-wireguard-1.0-bz11721-init.patch 2021/11/01 02:41:08 1.7 +++ rpms/smeserver-wireguard/contribs10/smeserver-wireguard-1.0-bz11721-init.patch 2021/11/03 18:19:58 1.10 @@ -250,3 +250,193 @@ diff -Nur --no-dereference smeserver-wir Endpoint = $ExternalIP:$Port "; # we could add a DNS field in [Interface] +diff -Nur --no-dereference smeserver-wireguard-1.0.old/root/etc/e-smith/db/configuration/migrate/wireguard smeserver-wireguard-1.0/root/etc/e-smith/db/configuration/migrate/wireguard +--- smeserver-wireguard-1.0.old/root/etc/e-smith/db/configuration/migrate/wireguard 2021-11-01 21:46:45.647000000 -0400 ++++ smeserver-wireguard-1.0/root/etc/e-smith/db/configuration/migrate/wireguard 2021-11-01 21:50:17.661000000 -0400 +@@ -1,4 +1,6 @@ + { ++my $wireguard = $DB->get('wg-quick@wg0') || $DB->new_record('wg-quick@wg0', {type => 'service'}); ++ + # add private and public key if not present + unless (defined ${'wg-quick@wg0'}{'private'}) { + $value= `/usr/bin/wg genkey`; +diff -Nur --no-dereference smeserver-wireguard-1.0.old/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/wireguard smeserver-wireguard-1.0/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/wireguard +--- smeserver-wireguard-1.0.old/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/wireguard 2021-11-03 00:04:00.688000000 -0400 ++++ smeserver-wireguard-1.0/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/wireguard 2021-11-03 00:24:10.217000000 -0400 +@@ -244,5 +244,10 @@ + No configured client + + ++ ++ INTERFACE ++ Interface ++ ++ + + +diff -Nur --no-dereference smeserver-wireguard-1.0.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm smeserver-wireguard-1.0/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm +--- smeserver-wireguard-1.0.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm 2021-11-03 00:04:00.691000000 -0400 ++++ smeserver-wireguard-1.0/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm 2021-11-03 00:06:45.195000000 -0400 +@@ -82,7 +82,7 @@ + esmith::cgi::genSmallCell($q, $fm->localise('CONF_NAME'),"header"), + esmith::cgi::genSmallCell($q, $fm->localise('USER'),"header"), + esmith::cgi::genSmallCell($q, $fm->localise('INFO'),"header"), +- esmith::cgi::genSmallCell($q, $fm->localise('STATUS'),"header"), ++ esmith::cgi::genSmallCell($q, $fm->localise('LABEL_STATUS'),"header"), + esmith::cgi::genSmallCell($q, $fm->localise('ACTION'),"header", 3), + ), + "\n"; +@@ -131,7 +131,12 @@ + my $wgip = $wg->prop('ip'); + my $wgmask = $wg->prop('mask'); + my $wgport = $wg->prop('UDPPort'); ++ my $sstatus = $wg->prop('status'); + ++ print $q->Tr (esmith::cgi::genSmallCell($q,$fm->localise('INTERFACE'),"header"), ++ esmith::cgi::genSmallCell($q, "wg0"),); ++ print $q->Tr (esmith::cgi::genSmallCell($q,$fm->localise('LABEL_STATUS'),"header"), ++ esmith::cgi::genSmallCell($q, $sstatus),); + print $q->Tr (esmith::cgi::genSmallCell($q,$fm->localise('PUBLIC_KEY'),"header"), + esmith::cgi::genSmallCell($q, $wgpub),); + print $q->Tr (esmith::cgi::genSmallCell($q,$fm->localise('IP'),"header"), +@@ -228,11 +233,10 @@ + + #here we guess wan IP + # are we server-gateway mode ? so external lan, should do +-my $ExternalIP = $cdb->get('ExternalInterface')->prop('IPAddress'); + # else we should guess from an external service +-# dig @resolver4.opendns.com myip.opendns.com +short +-# dig @resolver4.opendns.com myip.opendns.com +short -4 +-# dig @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6 ++#my $internet_ip_address = get_internet_ip_address(); ++my $ExternalIP = $cdb->get('ExternalInterface')->prop('IPAddress'); ++$ExternalIP=get_internet_ip_address() unless defined $ExternalIP; + + #DNS + my $IPAddress = $cdb->get('InternalInterface')->prop('IPAddress'); +@@ -250,8 +254,6 @@ + AllowedIPs = $allowedips + Endpoint = $ExternalIP:$Port + "; +-# we could add a DNS field in [Interface] +-# DNS = 1.1.1.1, 1.0.0.1 + + print "
"; + +@@ -476,7 +478,7 @@ + $fm->error('ERROR_OCCURED','FIRST_PAGE'); + return undef; + } +- unless (system ("/sbin/e-smith/signal-event", "wireguard-client-remove") == 0 ){ ++ unless (system ("/sbin/e-smith/signal-event", "wireguard-user-delete") == 0 ){ + $fm->error('ERROR_OCCURED','FIRST_PAGE'); + return undef; + } +@@ -539,4 +541,73 @@ + } + + ++ ++sub get_internet_ip_address { ++ #we could use DNS to do this faster but some provider will block DNS ++ #dig +short myip.opendns.com @resolver1.opendns.com ++ #also resolver1.opendns.com resolver2.opendns.com resolver3.opendns.com ++ #here a list of available site with https ++ use Net::DNS; ++ use LWP::Simple; ++ my $timeout=1; ++ ++ my @httpslist=qw( ++checkip.amazonaws.com ++myexternalip.com/raw ++ifconfig.me/ ++icanhazip.com/ ++ident.me/ ++tnx.nl/ip ++ipecho.net/plain ++wgetip.com/ ++ip.tyk.nu/ ++bot.whatismyipaddress.com/ ++ipof.in/txt ++l2.io/ip ++eth0.me/ ); ++ my @dns = ( ++ ['myip.opendns.com', 'resolver1.opendns.com', 'A'], ++ ['myip.opendns.com', 'resolver2.opendns.com', 'A'], ++ ['myip.opendns.com', 'resolver3.opendns.com', 'A'], ++ ['myip.opendns.com', 'resolver4.opendns.com', 'A'], ++ ['whoami.akamai.net', 'ns1-1.akamaitech.net', 'A'], ++ ['o-o.myaddr.l.google.com', 'ns1.google.com', 'TXT'] ++ ++ ); ++ my $ip; ++ ++ #foreach my $i ( 0 .. $#dns) { ++ # dns calls; test only one random... ++ my $i = rand(@httpslist); ++ my $res = Net::DNS::Resolver->new( ++ nameservers => [ $dns[$i][1] ], ++ udp_timeout => $timeout, ++ tcp_timeout => $timeout ++ ); ++ my $reply = $res->search($dns[$i][0], $dns[$i][2]); ++ if ($reply) { ++ foreach my $rr ($reply->answer) { ++ $ip= $rr->txtdata if $rr->can("txtdata"); ++ $ip= $rr->address if $rr->can("address"); ++ return $ip if $ip =~ /(\d+\.\d+\.\d+\.\d+)/; ++ } ++ } else { ++ warn "query failed: ", $res->errorstring, "\n"; ++ } ++ #} ++ ++ # https calls ++ my $ii=0; ++ my $service; ++ while ( $ii <5 ) { ++ $service=$httpslist[rand(@httpslist)]; ++ $ip = (get "https://$service" ); ++ chomp $ip; ++ $ii++; ++ last if $ip =~ /(\d+\.\d+\.\d+\.\d+)/; ++ } ++ return $ip; ++} ++ ++ + 1; +diff -Nur --no-dereference smeserver-wireguard-1.0.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm smeserver-wireguard-1.0/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm +--- smeserver-wireguard-1.0.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm 2021-11-03 14:18:15.780000000 -0400 ++++ smeserver-wireguard-1.0/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm 2021-11-03 14:18:39.640000000 -0400 +@@ -234,9 +234,8 @@ + #here we guess wan IP + # are we server-gateway mode ? so external lan, should do + # else we should guess from an external service +-#my $internet_ip_address = get_internet_ip_address(); + my $ExternalIP = $cdb->get('ExternalInterface')->prop('IPAddress'); +-$ExternalIP=get_internet_ip_address() unless defined $ExternalIP; ++$ExternalIP = get_internet_ip_address() unless defined $ExternalIP; + + #DNS + my $IPAddress = $cdb->get('InternalInterface')->prop('IPAddress'); +@@ -589,6 +588,8 @@ + foreach my $rr ($reply->answer) { + $ip= $rr->txtdata if $rr->can("txtdata"); + $ip= $rr->address if $rr->can("address"); ++ # untaint, dns output is tainted ++ ($ip) = $ip =~ /(\d+\.\d+\.\d+\.\d+)/; + return $ip if $ip =~ /(\d+\.\d+\.\d+\.\d+)/; + } + } else { +@@ -606,8 +607,9 @@ + $ii++; + last if $ip =~ /(\d+\.\d+\.\d+\.\d+)/; + } ++ # not needed but in case, untaint ++ ($ip) = $ip =~ /(\d+\.\d+\.\d+\.\d+)/; + return $ip; + } + +- + 1;