Compare commits
8 Commits
1.0-21
...
1_0-28_el8
| Author | SHA1 | Date | |
|---|---|---|---|
| a2c3f3cdb4 | |||
| 367e4da9e8 | |||
| 5858500b80 | |||
| 2e7e5047d8 | |||
| bd88797db8 | |||
| 03a5304866 | |||
| 12516e2505 | |||
| f053c60040 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
*.log
|
||||
*spec-20*
|
||||
*.0.tgz
|
||||
*.0.tar.xz
|
||||
|
||||
@@ -6,7 +6,14 @@ SMEServer Koozali developed git repo for smeserver-wireguard smecontribs
|
||||
<br />https://wiki.koozali.org/Wireguard
|
||||
|
||||
## Bugzilla
|
||||
Show list of outstanding bugs: [here](https://bugs.koozali.org/buglist.cgi?component=smeserver-wireguard&product=SME%20Contribs&query_format=advanced&limit=0&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=CONFIRMED)
|
||||
Show list of outstanding bugs:
|
||||
[All](https://bugs.koozali.org/buglist.cgi?action=wrap&bug_status=UNCONFIRMED&bug_status=CONFIRMED&bug_status=NEEDINFO&bug_status=IN_PROGRESS&bug_status=RESOLVED&bug_status=VERIFIED&classification=Contribs&component=smeserver-wireguard&list_id=105781&order=changeddate+DESC%2Ccomponent%2Cpriority%2Cbug_severity&product=SME+Contribs&query_format=advanced)
|
||||
[Confirmed](https://bugs.koozali.org/buglist.cgi?action=wrap&bug_status=CONFIRMED&classification=Contribs&component=smeserver-wireguard&list_id=105781&order=changeddate+DESC%2Ccomponent%2Cpriority%2Cbug_severity&product=SME+Contribs&query_format=advanced)
|
||||
[Unconfirmed](https://bugs.koozali.org/buglist.cgi?action=wrap&bug_status=UNCONFIRMED&classification=Contribs&component=smeserver-wireguard&list_id=105781&order=changeddate+DESC%2Ccomponent%2Cpriority%2Cbug_severity&product=SME+Contribs&query_format=advanced)
|
||||
[Need Info](https://bugs.koozali.org/buglist.cgi?action=wrap&bug_status=NEEDINFO&classification=Contribs&component=smeserver-wireguard&list_id=105781&order=changeddate+DESC%2Ccomponent%2Cpriority%2Cbug_severity&product=SME+Contribs&query_format=advanced)
|
||||
[In Progress](https://bugs.koozali.org/buglist.cgi?action=wrap&bug_status=IN_PROGRESS&classification=Contribs&component=smeserver-wireguard&list_id=105781&order=changeddate+DESC%2Ccomponent%2Cpriority%2Cbug_severity&product=SME+Contribs&query_format=advanced)
|
||||
[Verified](https://bugs.koozali.org/buglist.cgi?action=wrap&bug_status=VERIFIED&classification=Contribs&component=smeserver-wireguard&list_id=105781&order=changeddate+DESC%2Ccomponent%2Cpriority%2Cbug_severity&product=SME+Contribs&query_format=advanced)
|
||||
[Resolved](https://bugs.koozali.org/buglist.cgi?action=wrap&bug_status=RESOLVED&classification=Contribs&component=smeserver-wireguard&list_id=105781&order=changeddate+DESC%2Ccomponent%2Cpriority%2Cbug_severity&product=SME+Contribs&query_format=advanced)
|
||||
|
||||
## Description
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use esmith::Build::CreateLinks qw(:all);
|
||||
|
||||
panel_link("webhosting", "manager");
|
||||
|
||||
for my $event (qw(
|
||||
webhosting-modify smeserver-webhosting-update
|
||||
))
|
||||
{
|
||||
#we can avoid those 2 as we are tricking ourself as ibay-modify and it will do those and php
|
||||
#templates2events("/etc/httpd/conf/httpd.conf", $event);
|
||||
#safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/httpd-e-smith");
|
||||
event_link("webhosting-php-expand", $event, "05");
|
||||
event_link("webhosting-php-adjust", $event, "90");
|
||||
}
|
||||
$event="smeserver-webhosting-update";
|
||||
event_link("navigation-conf", $event, "70");
|
||||
# for smeserver-manager
|
||||
safe_symlink('restart', "root/etc/e-smith/events/$event/services2adjust/smanager");
|
||||
event_link('navigation2-conf', "$event", '80');
|
||||
event_link('routes2-conf', "$event", '80');
|
||||
event_link('locales2-conf', "$event", '80');
|
||||
@@ -15,65 +15,56 @@ package SrvMngr::Controller::Wireguard;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
use Locale::gettext;
|
||||
use SrvMngr::I18N;
|
||||
use SrvMngr qw( theme_list init_session is_normal_password );
|
||||
|
||||
use esmith::ConfigDB;
|
||||
use esmith::ConfigDB::UTF8;
|
||||
use Net::IP;
|
||||
|
||||
our $adb = esmith::AccountsDB->open() || die "Couldn't open accounts DB\ndb";
|
||||
our $cdb = esmith::ConfigDB->open() || die "Couldn't open config DB\n";
|
||||
our $wdb = esmith::ConfigDB->open('wireguard') || esmith::ConfigDB->create('wireguard');
|
||||
our $ndb = esmith::NetworksDB->open_ro || die "Error opening networks DB\n";
|
||||
|
||||
my $adb;
|
||||
my $cdb;
|
||||
my $wdb;
|
||||
my $ndb;
|
||||
|
||||
sub main {
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info($c->log_req);
|
||||
|
||||
my %wrg_datas = ();
|
||||
$wdb = esmith::ConfigDB::UTF8->open('wireguard') || esmith::ConfigDB::UTF8->create('wireguard');
|
||||
my $title = $c->l('wrg_FORM_TITLE');
|
||||
|
||||
$wrg_datas{'trt'} = 'LST';
|
||||
|
||||
$cdb = esmith::ConfigDB->open() || die "Couldn't open config DB\n";
|
||||
$cdb = esmith::ConfigDB::UTF8->open() || die "Couldn't open config DB\n";
|
||||
my $wg = $cdb->get('wg-quick@wg0');
|
||||
|
||||
$wrg_datas{'wgpub'} = $wg->prop('public');
|
||||
$wrg_datas{'wgip'} = $wg->prop('ip');
|
||||
$wrg_datas{'wgmask'} = $wg->prop('mask');
|
||||
$wrg_datas{'wgport'} = $wg->prop('UDPPort');
|
||||
$wrg_datas{'sstatus'} = $wg->prop('status');
|
||||
|
||||
my @wgstatus = `/usr/bin/wg show wg0 dump`;
|
||||
|
||||
my $type = 'wg0';
|
||||
my @wgconf = $wdb->get_all_by_prop(type => $type);
|
||||
|
||||
$c->stash( title => $title, wrg_datas => \%wrg_datas,
|
||||
wgstatus => \@wgstatus, wgconf => \@wgconf );
|
||||
|
||||
$c->stash(
|
||||
title => $title,
|
||||
wrg_datas => \%wrg_datas,
|
||||
wgstatus => \@wgstatus,
|
||||
wgconf => \@wgconf
|
||||
);
|
||||
$c->render(template => 'wireguard');
|
||||
|
||||
};
|
||||
|
||||
} ## end sub main
|
||||
|
||||
sub do_display {
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info($c->log_req);
|
||||
|
||||
my $rt = $c->current_route;
|
||||
my $trt = ($c->param('trt') || '');
|
||||
my $wgconf = $c->param('Wgconf') || '';
|
||||
|
||||
my %wrg_datas = ();
|
||||
my $title = $c->l('wrg_FORM_TITLE');
|
||||
my $modul = '';
|
||||
$adb = esmith::AccountsDB->open() || die "Couldn't open accounts DB\ndb";
|
||||
$cdb = esmith::ConfigDB::UTF8->open() || die "Couldn't open config DB\n";
|
||||
$wdb = esmith::ConfigDB::UTF8->open('wireguard') || esmith::ConfigDB::UTF8->create('wireguard');
|
||||
|
||||
#$ndb = esmith::NetworksDB->open_ro || die "Error opening networks DB\n";
|
||||
$wrg_datas{'trt'} = $trt;
|
||||
|
||||
if ($trt eq 'QRC') {
|
||||
@@ -83,6 +74,7 @@ sub do_display {
|
||||
if ($trt eq 'MOD') {
|
||||
$wrg_datas{'wgconf'} = $wgconf;
|
||||
my $rec = $wdb->get($wgconf);
|
||||
|
||||
if ($rec) {
|
||||
$wrg_datas{'info'} = $rec->prop('info') || '';
|
||||
$wrg_datas{'allowedips'} = $rec->prop('allowedips') || '';
|
||||
@@ -91,8 +83,8 @@ sub do_display {
|
||||
$wrg_datas{'account'} = $rec->prop('user') || '';
|
||||
$wrg_datas{'status'} = $rec->prop('status') || '';
|
||||
$wrg_datas{'dns'} = $rec->prop('dns') || '';
|
||||
}
|
||||
}
|
||||
} ## end if ($rec)
|
||||
} ## end if ($trt eq 'MOD')
|
||||
|
||||
if ($trt eq 'REM') {
|
||||
$wrg_datas{'wgconf'} = $wgconf;
|
||||
@@ -101,6 +93,7 @@ sub do_display {
|
||||
}
|
||||
|
||||
if ($trt eq 'NEW') {
|
||||
|
||||
# nothing for a new client
|
||||
}
|
||||
|
||||
@@ -111,105 +104,111 @@ sub do_display {
|
||||
$wrg_datas{'private'} = $wg->prop('private');
|
||||
$wrg_datas{'public'} = $wg->prop('public');
|
||||
$wrg_datas{'status'} = $wg->prop('status');
|
||||
}
|
||||
} ## end if ($trt eq 'UPD')
|
||||
|
||||
if ($trt eq 'LST') {
|
||||
my @wgss = $adb->wgss();
|
||||
$c->stash(wgss => \@wgss);
|
||||
}
|
||||
|
||||
$c->stash(title => $title, modul => $modul, wrg_datas => \%wrg_datas);
|
||||
$c->render(template => 'wireguard');
|
||||
|
||||
};
|
||||
|
||||
} ## end sub do_display
|
||||
|
||||
sub do_action {
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info($c->log_req);
|
||||
|
||||
my $rt = $c->current_route;
|
||||
my $trt = ($c->param('trt') || '');
|
||||
|
||||
my %wrg_datas = ();
|
||||
my $title = $c->l('wrg_FORM_TITLE');
|
||||
|
||||
$wrg_datas{'trt'} = $trt;
|
||||
|
||||
my $result = '';
|
||||
my $res = '';
|
||||
$adb = esmith::AccountsDB->open() || die "Couldn't open accounts DB\ndb";
|
||||
$cdb = esmith::ConfigDB::UTF8->open() || die "Couldn't open config DB\n";
|
||||
$wdb = esmith::ConfigDB::UTF8->open('wireguard') || esmith::ConfigDB::UTF8->create('wireguard');
|
||||
$ndb = esmith::NetworksDB->open_ro || die "Error opening networks DB\n";
|
||||
|
||||
if ($trt eq 'QRC') {
|
||||
|
||||
# NEVER
|
||||
}
|
||||
|
||||
if ($trt eq 'LST') {
|
||||
|
||||
# NEVER
|
||||
}
|
||||
|
||||
if ($trt eq 'MOD') {
|
||||
$wrg_datas{'wgconf'} = $c->param('Wgconf');
|
||||
|
||||
# controls
|
||||
$res = 'OK'; # no controls here...
|
||||
$result .= $res unless $res eq 'OK';
|
||||
|
||||
if (!$result) {
|
||||
$res = performModifyClient($c);
|
||||
$result .= $res unless $res eq 'OK';
|
||||
|
||||
if (!$result) {
|
||||
$result = $c->l('wrg_SUCCESSFULLY_MODIFIED_CONF');
|
||||
}
|
||||
}
|
||||
}
|
||||
} ## end if (!$result)
|
||||
} ## end if ($trt eq 'MOD')
|
||||
|
||||
if ($trt eq 'REM') {
|
||||
if ($c->param("cancel")) {
|
||||
$c->stash(error => $c->l('wrg_CANCELLED'));
|
||||
$c->redirect_to('/wireguard');
|
||||
}
|
||||
|
||||
# controls
|
||||
$res = 'OK'; # no controls here...
|
||||
$result .= $res unless $res eq 'OK';
|
||||
|
||||
if (!$result) {
|
||||
$res = performRemoveClient($c);
|
||||
$result .= $res unless $res eq 'OK';
|
||||
|
||||
if (!$result) {
|
||||
$result = $c->l('wrg_SUCCESSFULLY_REMOVED_CONF');
|
||||
}
|
||||
}
|
||||
}
|
||||
} ## end if (!$result)
|
||||
} ## end if ($trt eq 'REM')
|
||||
|
||||
if ($trt eq 'NEW') {
|
||||
|
||||
# controls
|
||||
$res = 'OK'; # no controls here...
|
||||
$result .= $res unless $res eq 'OK';
|
||||
|
||||
if (!$result) {
|
||||
$res = performCreateClient($c);
|
||||
$result .= $res unless $res eq 'OK';
|
||||
|
||||
if (!$result) {
|
||||
$result = $c->l('wrg_SUCCESSFULLY_ADDED_CONF');
|
||||
}
|
||||
}
|
||||
}
|
||||
} ## end if (!$result)
|
||||
} ## end if ($trt eq 'NEW')
|
||||
|
||||
if ($trt eq 'UPD') {
|
||||
|
||||
# controls
|
||||
$res = 'OK'; # no controls here...
|
||||
$result .= $res unless $res eq 'OK';
|
||||
|
||||
if (!$result) {
|
||||
$res = performUpdateConfig($c);
|
||||
$result .= $res unless $res eq 'OK';
|
||||
|
||||
if (!$result) {
|
||||
$result = $c->l('wrg_SUCCESSFULLY_UPDATED_CONF');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} ## end if (!$result)
|
||||
} ## end if ($trt eq 'UPD')
|
||||
|
||||
# common parts
|
||||
|
||||
if ($res ne 'OK') {
|
||||
$c->stash(error => $result);
|
||||
$c->stash(title => $title, wrg_datas => \%wrg_datas);
|
||||
@@ -217,22 +216,17 @@ sub do_action {
|
||||
}
|
||||
|
||||
#force reload as successfull (for Main)
|
||||
$wdb = esmith::ConfigDB->open('wireguard');
|
||||
|
||||
$wdb = esmith::ConfigDB::UTF8->open('wireguard');
|
||||
my $message = "'Wireguard' update ($trt) DONE";
|
||||
$c->app->log->info($message);
|
||||
$c->flash(success => $result);
|
||||
|
||||
$c->redirect_to('/wireguard');
|
||||
}
|
||||
|
||||
} ## end sub do_action
|
||||
|
||||
# action for 'MOD'
|
||||
sub performModifyClient {
|
||||
|
||||
my $c = shift;
|
||||
my $msg = "OK";
|
||||
|
||||
my $wgacc = $c->param('Wgconf');
|
||||
my $account = $c->param('Account');
|
||||
my $private = $c->param('Private') || '';
|
||||
@@ -242,52 +236,44 @@ sub performModifyClient{
|
||||
my $allowedips = $c->param('Allowedips') || '';
|
||||
|
||||
#todo validate fields
|
||||
|
||||
# Untaint info and account before use in system()
|
||||
($info) = $info =~ /([A-Za-z0-9_\-. ]+)/;
|
||||
|
||||
# trim both ends
|
||||
$info =~ s/^ +| +$//g;
|
||||
($account) = $account =~ /([A-Za-z0-9_-]+)/;
|
||||
|
||||
return $c->l('wrg_ERROR_FIELD_CONTENT') unless ($account and $info);
|
||||
|
||||
my %props = ('user' => $account
|
||||
,'private' => $private
|
||||
,'public' => $public
|
||||
,'info' => $info
|
||||
,'status' => $status
|
||||
,'allowedips' => $allowedips
|
||||
my %props = (
|
||||
'user' => $account,
|
||||
'private' => $private,
|
||||
'public' => $public,
|
||||
'info' => $info,
|
||||
'status' => $status,
|
||||
'allowedips' => $allowedips
|
||||
);
|
||||
|
||||
$wdb->get($wgacc)->merge_props(%props)
|
||||
or $msg = "Error occurred while modifying pseudonym in database.";
|
||||
|
||||
# Untaint before use in system()
|
||||
($wgacc) = ($wgacc =~ /(\d+\.+\d+\.+\d+\.+\d+\.+\/\d+\.+)/);
|
||||
system( "/sbin/e-smith/signal-event", "wireguard-user-modify", "$wgacc",)
|
||||
== 0 or $msg = "Error occurred while modifying wirequard account.";
|
||||
|
||||
return "$msg"
|
||||
|
||||
}
|
||||
|
||||
system("/sbin/e-smith/signal-event", "wireguard-user-modify", "$wgacc",) == 0
|
||||
or $msg = "Error occurred while modifying wirequard account.";
|
||||
return "$msg";
|
||||
} ## end sub performModifyClient
|
||||
|
||||
# action for 'NEW'
|
||||
sub performCreateClient {
|
||||
|
||||
my $c = shift;
|
||||
my $type = shift;
|
||||
|
||||
my $username = $c->param('Account');
|
||||
my $info = $c->param('Info');
|
||||
|
||||
# Untaint info and account before use in system()
|
||||
($info) = $info =~ /([A-Za-z0-9_\-. ]+)/;
|
||||
|
||||
# trim both ends
|
||||
$info =~ s/^ +| +$//g;
|
||||
|
||||
($username) = $username =~ /([A-Za-z0-9_-]+)/;
|
||||
|
||||
return $c->l('wrg_ERROR_FIELD_CONTENT') unless ($username and $info);
|
||||
|
||||
#get username
|
||||
@@ -299,17 +285,13 @@ sub performCreateClient {
|
||||
unless (system("/sbin/e-smith/signal-event", "wireguard-user-create", "$username", "$info") == 0) {
|
||||
return $c->error('wrg_ERROR_OCCURED');
|
||||
}
|
||||
|
||||
return 'OK';
|
||||
}
|
||||
|
||||
} ## end sub performCreateClient
|
||||
|
||||
# action for 'UPD'
|
||||
sub performUpdateConfig {
|
||||
|
||||
my $c = shift;
|
||||
my $msg = "OK";
|
||||
|
||||
my $ip = $c->param('Ip');
|
||||
my $mask = $c->param('Mask');
|
||||
my $private = $c->param('Private');
|
||||
@@ -324,72 +306,69 @@ sub performUpdateConfig {
|
||||
|
||||
# we get number of entries in wireguard db
|
||||
my @num = $wdb->get_all_by_prop(type => "wg0");
|
||||
|
||||
if (scalar @num > 0) {
|
||||
|
||||
# we get current values
|
||||
my $pprivate = $cdb->get('wg-quick@wg0')->prop('private');
|
||||
my $ppublic = $cdb->get('wg-quick@wg0')->prop('public');
|
||||
my $pip = $cdb->get('wg-quick@wg0')->prop('ip');
|
||||
my $pmask = $cdb->get('wg-quick@wg0')->prop('mask');
|
||||
|
||||
# if # entries >0 and private |public | ip is chnaged then we push an error and stop
|
||||
if ($pprivate ne $private || $ppublic ne $public || $pip ne $ip || $mask ne $pmask) {
|
||||
return $c->l('wrg_CLIENTS_ALREADY_CONFIGURED');
|
||||
}
|
||||
}
|
||||
} ## end if (scalar @num > 0)
|
||||
|
||||
#todo validate fields
|
||||
|
||||
my %props = ('ip' => $ip
|
||||
,'mask' => $mask
|
||||
,'private' => $private
|
||||
,'public' => $public
|
||||
,'status' => $status
|
||||
my %props = (
|
||||
'ip' => $ip,
|
||||
'mask' => $mask,
|
||||
'private' => $private,
|
||||
'public' => $public,
|
||||
'status' => $status
|
||||
);
|
||||
|
||||
# Test Ip is inside CIDR
|
||||
if (!test_for_private_ip($ip, $mask)) {
|
||||
$msg = "IP must be in private range";
|
||||
|
||||
#$fm->error($msg);return;
|
||||
}
|
||||
|
||||
$cdb->get('wg-quick@wg0')->merge_props(%props)
|
||||
or $msg = "Error occurred while modifying server details.";
|
||||
|
||||
|
||||
if ($msg eq "OK") {
|
||||
|
||||
# Untaint before use in system()
|
||||
($ip) = ($ip =~ /(\d+\.+\d+\.+\d+\.+\d+\.+\/\d+\.+)/);
|
||||
system( "/sbin/e-smith/signal-event", "wireguard-conf-modify", "$ip",)
|
||||
== 0 or $msg = "Error occurred while modifying wireguard conf.";
|
||||
}
|
||||
|
||||
system("/sbin/e-smith/signal-event", "wireguard-conf-modify", "$ip",) == 0
|
||||
or $msg = "Error occurred while modifying wireguard conf.";
|
||||
} ## end if ($msg eq "OK")
|
||||
return "$msg";
|
||||
|
||||
}
|
||||
|
||||
} ## end sub performUpdateConfig
|
||||
|
||||
# action for 'REM'
|
||||
sub performRemoveClient {
|
||||
|
||||
my ($c) = @_;
|
||||
|
||||
my $conf = $c->param('Wgconf');
|
||||
|
||||
if ($c->param("remove")) {
|
||||
unless ($wdb->get($conf)->delete()) {
|
||||
return $c->l('wrg_ERROR_OCCURED');
|
||||
}
|
||||
|
||||
unless (system("/sbin/e-smith/signal-event", "wireguard-user-delete") == 0) {
|
||||
return $c->l('wrg_ERROR_OCCURED');
|
||||
}
|
||||
return 'OK';
|
||||
}
|
||||
} ## end if ($c->param("remove"...))
|
||||
return $c->l('wrg_CANCELLED');
|
||||
|
||||
}
|
||||
|
||||
} ## end sub performRemoveClient
|
||||
|
||||
# called from templates
|
||||
sub get_existing_accounts {
|
||||
|
||||
my $c = shift;
|
||||
my @existingAccounts = ('Administrator');
|
||||
|
||||
@@ -397,42 +376,31 @@ sub get_existing_accounts {
|
||||
push @existingAccounts, $account->key;
|
||||
}
|
||||
return \@existingAccounts;
|
||||
|
||||
}
|
||||
|
||||
} ## end sub get_existing_accounts
|
||||
|
||||
# called from templates
|
||||
sub get_wgs_info {
|
||||
|
||||
my ($c, $attr, $data) = @_;
|
||||
|
||||
return undef if (not defined $attr or not defined $data);
|
||||
|
||||
my $value;
|
||||
$value = $wdb->get("$data")->prop('info') if ($attr eq 'info' and $wdb->get("$data"));
|
||||
$value = $wdb->get("$data")->prop('user') if ($attr eq 'user' and $wdb->get("$data"));
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
|
||||
} ## end sub get_wgs_info
|
||||
|
||||
# called from templates
|
||||
sub get_conf_info {
|
||||
|
||||
my ($c, $ipacc) = @_;
|
||||
##my $ipacc = $c->param('Wgconf');
|
||||
|
||||
#untaint
|
||||
($ipacc) = $ipacc =~ /(\d+\.\d+\.\d+\.\d+\/\d+)/;
|
||||
#get from db
|
||||
|
||||
#get from db
|
||||
# return if does not exist
|
||||
my $acc = $wdb->get($ipacc) or return undef;
|
||||
|
||||
# return if current user is not admin or the user
|
||||
return undef unless $c->is_admin;
|
||||
|
||||
my $key = $acc->key;
|
||||
my $info = $acc->prop('info');
|
||||
my $private = $acc->prop('private');
|
||||
@@ -450,7 +418,6 @@ sub get_conf_info {
|
||||
#DNS
|
||||
my $IPAddress = $cdb->get('InternalInterface')->prop('IPAddress');
|
||||
my $dns = ($allowedips =~ /0.0.0.0\/0/) ? "DNS = $IPAddress" : "";
|
||||
|
||||
my $fulltext = "#configuration for $key $info
|
||||
[Interface]
|
||||
PrivateKey = $private
|
||||
@@ -463,24 +430,16 @@ AllowedIPs = $allowedips
|
||||
Endpoint = $ExternalIP:$Port
|
||||
";
|
||||
my @fulltext = split("\n", $fulltext);
|
||||
|
||||
return \@fulltext;
|
||||
|
||||
}
|
||||
|
||||
} ## end sub get_conf_info
|
||||
|
||||
# called from templates
|
||||
sub get_conf_qr {
|
||||
|
||||
my ($c, $fulltext, $type) = @_;
|
||||
|
||||
my $qr = `echo "$fulltext" |qrencode -t PNG -o - |base64`;
|
||||
|
||||
return $qr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
sub get_internet_ip_address {
|
||||
|
||||
#we could use DNS to do this faster but some provider will block DNS
|
||||
@@ -490,7 +449,6 @@ sub get_internet_ip_address {
|
||||
use Net::DNS;
|
||||
use LWP::Simple;
|
||||
my $timeout = 1;
|
||||
|
||||
my @httpslist = qw(
|
||||
checkip.amazonaws.com
|
||||
myexternalip.com/raw
|
||||
@@ -512,9 +470,7 @@ eth0.me/ );
|
||||
[ '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) {
|
||||
@@ -525,40 +481,40 @@ eth0.me/ );
|
||||
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");
|
||||
|
||||
# untaint, dns output is tainted
|
||||
($ip) = $ip =~ /(\d+\.\d+\.\d+\.\d+)/;
|
||||
return $ip if $ip =~ /(\d+\.\d+\.\d+\.\d+)/;
|
||||
}
|
||||
} ## end foreach my $rr ($reply->answer)
|
||||
} 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+)/;
|
||||
}
|
||||
} ## end while ($ii < 5)
|
||||
|
||||
# not needed but in case, untaint
|
||||
($ip) = $ip =~ /(\d+\.\d+\.\d+\.\d+)/;
|
||||
return $ip;
|
||||
|
||||
}
|
||||
|
||||
} ## end sub get_internet_ip_address
|
||||
|
||||
sub test_for_private_ip {
|
||||
|
||||
use NetAddr::IP;
|
||||
$_ = shift;
|
||||
my $mask = shift;
|
||||
@@ -566,10 +522,6 @@ sub test_for_private_ip {
|
||||
my $iprange = NetAddr::IP->new($1, "$mask");
|
||||
return unless $iprange;
|
||||
return ($iprange->first()->is_rfc1918() and $iprange->last()->is_rfc1918());
|
||||
|
||||
}
|
||||
|
||||
|
||||
} ## end sub test_for_private_ip
|
||||
1
|
||||
|
||||
__END__
|
||||
@@ -46,7 +46,7 @@
|
||||
'wrg_ERROR_WRONG_ACCT_TYPE' => 'The associated account shoult be a user or admin account.',
|
||||
'wrg_ERROR_OCCURED' => 'An error occured',
|
||||
'wrg_CLIENTS_ALREADY_CONFIGURED' => 'You can not alter the server ip, mask, private and public key as there are already some clients configured.',
|
||||
'wrg_NO_CONF' => 'No configured client',
|
||||
'wrg_NO_CONF' => 'No configured clients',
|
||||
'wrg_INTERFACE' => 'Interface',
|
||||
'wrg_CANCELLED' => 'Operation cancelled',
|
||||
'wrg_SUCCESSFULLY_MODIFIED_CONF' => 'Client configuration successfully modified',
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
</span>
|
||||
%= $wrg_datas->{wgport}
|
||||
<br></p>
|
||||
<br />
|
||||
|
||||
<table class="sme-border"><tbody>
|
||||
<tr>
|
||||
@@ -91,6 +92,7 @@
|
||||
% if ( scalar @$wgconf == 0 ) {
|
||||
%= l 'wrg_NO_CONF'
|
||||
% } else {
|
||||
<br />
|
||||
<table class="sme-border"><tbody>
|
||||
<tr>
|
||||
<th class='sme-border'>
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
|
||||
Mojolicious Template Code Formatter vmojofmt 0.1.9
|
||||
Input data:
|
||||
Upload a file:
|
||||
(none)
|
||||
Remove empty lines from output
|
||||
Formatted Output:
|
||||
Output Syntax:
|
||||
|
||||
<div id='wrg_mod'>
|
||||
|
||||
%= form_for '/wireguard2' => (method => 'POST') => begin
|
||||
|
||||
@@ -5,21 +5,29 @@
|
||||
%= l 'wrg_DESC_REMOVE_CLIENT'
|
||||
</p>
|
||||
|
||||
<p><br><span class=label>
|
||||
<p><span class=label>
|
||||
%= l 'wrg_USER'
|
||||
</span><span class=data>
|
||||
%= $wrg_datas->{account}
|
||||
</p>
|
||||
|
||||
<p><span class=label>
|
||||
%= l 'wrg_CONF_NAME'
|
||||
</span>
|
||||
</span><span class=data>
|
||||
%= $wrg_datas->{wgconf}
|
||||
<br></p>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<p><span class=label>
|
||||
%= l 'COMMENT'
|
||||
</span>
|
||||
</span><span class=data>
|
||||
%= $wrg_datas->{wgcomment}
|
||||
<br></p>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<div class='center'>
|
||||
%= submit_button l('CANCEL'), name => 'cancel', class => 'action'
|
||||
%= submit_button l('REMOVE'), name => 'remove', class => 'action'
|
||||
<div class="center">
|
||||
%= submit_button l('REMOVE'), name => 'remove', class => 'action left-btn'
|
||||
%= submit_button l('CANCEL'), name => 'cancel', class => 'action center-btn'
|
||||
</div>
|
||||
|
||||
%= hidden_field 'trt' => $wrg_datas->{trt}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
% content_for 'module' => begin
|
||||
<div id='module' class='module wireguard-panel'>
|
||||
|
||||
% if ($config->{debug} == 1) {
|
||||
% if (config->{debug} == 1) {
|
||||
<p>
|
||||
%= dumper $c->current_route
|
||||
%= dumper $wrg_datas
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
%define release 21
|
||||
%define release 28
|
||||
%define version 1.0
|
||||
%define debug_package %{nil}
|
||||
|
||||
Name: smeserver-wireguard
|
||||
Version: %{version}
|
||||
@@ -11,14 +12,14 @@ License: GPL
|
||||
URL: https://wiki.koozali.org/Wireguard
|
||||
Source0: smeserver-wireguard-1.0.tar.xz
|
||||
|
||||
BuildRequires: e-smith-devtools
|
||||
BuildRequires: smeserver-devtools
|
||||
Requires: wireguard-tools
|
||||
Requires: kmod-wireguard
|
||||
Requires: smeserver-release >= 10
|
||||
Requires: qrencode
|
||||
Requires: perl-Net-Netmask
|
||||
Requires: e-smith-base >= 5.8.1-2
|
||||
Requires: e-smith-lib >= 2.6.0-15
|
||||
Requires: smeserver-base >= 5.8.1-2
|
||||
Requires: smeserver-lib >= 2.6.0-15
|
||||
|
||||
AutoReqProv: no
|
||||
|
||||
@@ -36,7 +37,7 @@ This package provides the Koozali SME SERVER configuration for controlling WireG
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
perl createlink
|
||||
perl createlinks
|
||||
|
||||
|
||||
%install
|
||||
@@ -53,13 +54,31 @@ cat %{name}-%{version}-filelist
|
||||
#%doc COPYING
|
||||
|
||||
%post
|
||||
if (systemctl list-unit-files |grep smanager) then
|
||||
echo "Smanager restart in spec file"
|
||||
/sbin/e-smith/signal-event smanager-refresh;
|
||||
fi
|
||||
|
||||
|
||||
%changelog
|
||||
* Fri Oct 03 2025 Brian Read <brianr@koozali.org> 1.0-28.sme
|
||||
- Add in UTF8 to ConfigDB open [SME: 13209]
|
||||
|
||||
* Fri Oct 03 2025 Brian Read <brianr@koozali.org> 1.0-27.sme
|
||||
- Remove smanager-refresh from spec file [SME: 13212]
|
||||
|
||||
* Fri Sep 26 2025 Brian Read <brianr@koozali.org> 1.0-26.sme
|
||||
- Fix remove logic, add in user name to rem panel re-format templates, add space to list panel [SME: 13168]
|
||||
|
||||
* Thu Sep 25 2025 Brian Read <brianr@koozali.org> 1.0-25.sme
|
||||
- Sort outy Remove panel placement and operation of buttons [SME: 13168]
|
||||
|
||||
* Wed Sep 24 2025 Brian Read <brianr@koozali.org> 1.0-24.sme
|
||||
- Sort out access to DB vis a vis caching [SME: 13168]
|
||||
|
||||
* Mon Sep 22 2025 Brian Read <brianr@koozali.org> 1.0-23.sme
|
||||
- add debuginfo define to suppress it [SME: 13168]
|
||||
- Fix config call in layout [SME: 13168]
|
||||
|
||||
* Sun Sep 08 2024 Brian Read <brianr@koozali.org> 1.0-22.sme
|
||||
- Map e-smith package names to smeserver
|
||||
|
||||
* Sat Sep 07 2024 cvs2git.sh aka Brian Read <brianr@koozali.org> 1.0-21.sme
|
||||
- Roll up patches and move to git repo [SME: 12338]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user