260 |
# add private and public key if not present |
# add private and public key if not present |
261 |
unless (defined ${'wg-quick@wg0'}{'private'}) { |
unless (defined ${'wg-quick@wg0'}{'private'}) { |
262 |
$value= `/usr/bin/wg genkey`; |
$value= `/usr/bin/wg genkey`; |
263 |
|
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 |
264 |
|
--- 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 |
265 |
|
+++ 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 |
266 |
|
@@ -244,5 +244,10 @@ |
267 |
|
<trans>No configured client</trans> |
268 |
|
</entry> |
269 |
|
|
270 |
|
+ <entry> |
271 |
|
+ <base>INTERFACE</base> |
272 |
|
+ <trans>Interface</trans> |
273 |
|
+ </entry> |
274 |
|
+ |
275 |
|
|
276 |
|
</lexicon> |
277 |
|
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 |
278 |
|
--- smeserver-wireguard-1.0.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm 2021-11-03 00:04:00.691000000 -0400 |
279 |
|
+++ smeserver-wireguard-1.0/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm 2021-11-03 00:06:45.195000000 -0400 |
280 |
|
@@ -82,7 +82,7 @@ |
281 |
|
esmith::cgi::genSmallCell($q, $fm->localise('CONF_NAME'),"header"), |
282 |
|
esmith::cgi::genSmallCell($q, $fm->localise('USER'),"header"), |
283 |
|
esmith::cgi::genSmallCell($q, $fm->localise('INFO'),"header"), |
284 |
|
- esmith::cgi::genSmallCell($q, $fm->localise('STATUS'),"header"), |
285 |
|
+ esmith::cgi::genSmallCell($q, $fm->localise('LABEL_STATUS'),"header"), |
286 |
|
esmith::cgi::genSmallCell($q, $fm->localise('ACTION'),"header", 3), |
287 |
|
), |
288 |
|
"\n"; |
289 |
|
@@ -131,7 +131,12 @@ |
290 |
|
my $wgip = $wg->prop('ip'); |
291 |
|
my $wgmask = $wg->prop('mask'); |
292 |
|
my $wgport = $wg->prop('UDPPort'); |
293 |
|
+ my $sstatus = $wg->prop('status'); |
294 |
|
|
295 |
|
+ print $q->Tr (esmith::cgi::genSmallCell($q,$fm->localise('INTERFACE'),"header"), |
296 |
|
+ esmith::cgi::genSmallCell($q, "wg0"),); |
297 |
|
+ print $q->Tr (esmith::cgi::genSmallCell($q,$fm->localise('LABEL_STATUS'),"header"), |
298 |
|
+ esmith::cgi::genSmallCell($q, $sstatus),); |
299 |
|
print $q->Tr (esmith::cgi::genSmallCell($q,$fm->localise('PUBLIC_KEY'),"header"), |
300 |
|
esmith::cgi::genSmallCell($q, $wgpub),); |
301 |
|
print $q->Tr (esmith::cgi::genSmallCell($q,$fm->localise('IP'),"header"), |
302 |
|
@@ -228,11 +233,10 @@ |
303 |
|
|
304 |
|
#here we guess wan IP |
305 |
|
# are we server-gateway mode ? so external lan, should do |
306 |
|
-my $ExternalIP = $cdb->get('ExternalInterface')->prop('IPAddress'); |
307 |
|
# else we should guess from an external service |
308 |
|
-# dig @resolver4.opendns.com myip.opendns.com +short |
309 |
|
-# dig @resolver4.opendns.com myip.opendns.com +short -4 |
310 |
|
-# dig @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6 |
311 |
|
+#my $internet_ip_address = get_internet_ip_address(); |
312 |
|
+my $ExternalIP = $cdb->get('ExternalInterface')->prop('IPAddress'); |
313 |
|
+$ExternalIP=get_internet_ip_address() unless defined $ExternalIP; |
314 |
|
|
315 |
|
#DNS |
316 |
|
my $IPAddress = $cdb->get('InternalInterface')->prop('IPAddress'); |
317 |
|
@@ -250,8 +254,6 @@ |
318 |
|
AllowedIPs = $allowedips |
319 |
|
Endpoint = $ExternalIP:$Port |
320 |
|
"; |
321 |
|
-# we could add a DNS field in [Interface] |
322 |
|
-# DNS = 1.1.1.1, 1.0.0.1 |
323 |
|
|
324 |
|
print "<br><textarea cols='70' rows='10'>$fulltext </textarea>"; |
325 |
|
|
326 |
|
@@ -476,7 +478,7 @@ |
327 |
|
$fm->error('ERROR_OCCURED','FIRST_PAGE'); |
328 |
|
return undef; |
329 |
|
} |
330 |
|
- unless (system ("/sbin/e-smith/signal-event", "wireguard-client-remove") == 0 ){ |
331 |
|
+ unless (system ("/sbin/e-smith/signal-event", "wireguard-user-delete") == 0 ){ |
332 |
|
$fm->error('ERROR_OCCURED','FIRST_PAGE'); |
333 |
|
return undef; |
334 |
|
} |
335 |
|
@@ -539,4 +541,73 @@ |
336 |
|
} |
337 |
|
|
338 |
|
|
339 |
|
+ |
340 |
|
+sub get_internet_ip_address { |
341 |
|
+ #we could use DNS to do this faster but some provider will block DNS |
342 |
|
+ #dig +short myip.opendns.com @resolver1.opendns.com |
343 |
|
+ #also resolver1.opendns.com resolver2.opendns.com resolver3.opendns.com |
344 |
|
+ #here a list of available site with https |
345 |
|
+ use Net::DNS; |
346 |
|
+ use LWP::Simple; |
347 |
|
+ my $timeout=1; |
348 |
|
+ |
349 |
|
+ my @httpslist=qw( |
350 |
|
+checkip.amazonaws.com |
351 |
|
+myexternalip.com/raw |
352 |
|
+ifconfig.me/ |
353 |
|
+icanhazip.com/ |
354 |
|
+ident.me/ |
355 |
|
+tnx.nl/ip |
356 |
|
+ipecho.net/plain |
357 |
|
+wgetip.com/ |
358 |
|
+ip.tyk.nu/ |
359 |
|
+bot.whatismyipaddress.com/ |
360 |
|
+ipof.in/txt |
361 |
|
+l2.io/ip |
362 |
|
+eth0.me/ ); |
363 |
|
+ my @dns = ( |
364 |
|
+ ['myip.opendns.com', 'resolver1.opendns.com', 'A'], |
365 |
|
+ ['myip.opendns.com', 'resolver2.opendns.com', 'A'], |
366 |
|
+ ['myip.opendns.com', 'resolver3.opendns.com', 'A'], |
367 |
|
+ ['myip.opendns.com', 'resolver4.opendns.com', 'A'], |
368 |
|
+ ['whoami.akamai.net', 'ns1-1.akamaitech.net', 'A'], |
369 |
|
+ ['o-o.myaddr.l.google.com', 'ns1.google.com', 'TXT'] |
370 |
|
+ |
371 |
|
+ ); |
372 |
|
+ my $ip; |
373 |
|
+ |
374 |
|
+ #foreach my $i ( 0 .. $#dns) { |
375 |
|
+ # dns calls; test only one random... |
376 |
|
+ my $i = rand(@httpslist); |
377 |
|
+ my $res = Net::DNS::Resolver->new( |
378 |
|
+ nameservers => [ $dns[$i][1] ], |
379 |
|
+ udp_timeout => $timeout, |
380 |
|
+ tcp_timeout => $timeout |
381 |
|
+ ); |
382 |
|
+ my $reply = $res->search($dns[$i][0], $dns[$i][2]); |
383 |
|
+ if ($reply) { |
384 |
|
+ foreach my $rr ($reply->answer) { |
385 |
|
+ $ip= $rr->txtdata if $rr->can("txtdata"); |
386 |
|
+ $ip= $rr->address if $rr->can("address"); |
387 |
|
+ return $ip if $ip =~ /(\d+\.\d+\.\d+\.\d+)/; |
388 |
|
+ } |
389 |
|
+ } else { |
390 |
|
+ warn "query failed: ", $res->errorstring, "\n"; |
391 |
|
+ } |
392 |
|
+ #} |
393 |
|
+ |
394 |
|
+ # https calls |
395 |
|
+ my $ii=0; |
396 |
|
+ my $service; |
397 |
|
+ while ( $ii <5 ) { |
398 |
|
+ $service=$httpslist[rand(@httpslist)]; |
399 |
|
+ $ip = (get "https://$service" ); |
400 |
|
+ chomp $ip; |
401 |
|
+ $ii++; |
402 |
|
+ last if $ip =~ /(\d+\.\d+\.\d+\.\d+)/; |
403 |
|
+ } |
404 |
|
+ return $ip; |
405 |
|
+} |
406 |
|
+ |
407 |
|
+ |
408 |
|
1; |