diff --git a/root/usr/share/smanager/lib/SrvMngr/Controller/Xt_geoip.pm b/root/usr/share/smanager/lib/SrvMngr/Controller/Xt_geoip.pm index 3dc1154..1237745 100644 --- a/root/usr/share/smanager/lib/SrvMngr/Controller/Xt_geoip.pm +++ b/root/usr/share/smanager/lib/SrvMngr/Controller/Xt_geoip.pm @@ -4,7 +4,6 @@ package SrvMngr::Controller::Xt_geoip; # heading : Network # description : GeoIP IP filtering # navigation : 6000 610 - # name : xt_geoip, method : get, url : /xt_geoip, ctlact : Xt_geoip#main # name : xt_geoipd, method : post, url : /xt_geoip, ctlact : Xt_geoip#do_display # name : xt_geoipc, method : get, url : /xt_geoipb, ctlact : Xt_geoip#do_display @@ -15,464 +14,402 @@ package SrvMngr::Controller::Xt_geoip; use strict; use warnings; use Mojo::Base 'Mojolicious::Controller'; - use POSIX qw(strftime); - use Locale::gettext; use SrvMngr::I18N; - use SrvMngr qw( theme_list init_session ); -our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; - +# our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; +my ($cdb); sub main { - my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->render_to_string(inline =>($c->l('xtg_FORM_TITLE'))); - + our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; + my $title = $c->render_to_string(inline => ($c->l('xtg_FORM_TITLE'))); my %xtg_datas = (); $xtg_datas{'choice'} = ''; - - $c->stash( title => $title, xtg_datas => \%xtg_datas); + $c->stash(title => $title, xtg_datas => \%xtg_datas); $c->render('xt_geoip'); -}; - +} ## end sub main sub do_display { - my $c = shift; $c->app->log->info($c->log_req); - - my $title = $c->render_to_string(inline =>($c->l('xtg_FORM_TITLE'))); - + our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; + my $title = $c->render_to_string(inline => ($c->l('xtg_FORM_TITLE'))); my $choice = $c->param('Choice'); - my $result; my %xtg_datas = (); $xtg_datas{'choice'} = $choice; - if ( $choice eq 'LCOD' ) { - + if ($choice eq 'LCOD') { $result = $c->generateCodes(); -# $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); -# return $c->render('xt_geoip_lst'); - }; + # $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); + # return $c->render('xt_geoip_lst'); + } ## end if ($choice eq 'LCOD') - if ( $choice eq 'LF2B' ) { + if ($choice eq 'LF2B') { + $result = $c->generateStats('f2b'); - $result = $c->generateStats( 'f2b' ); -# $result = $c->render_to_string(inline => generateStats($c, 'f2b')); + # $result = $c->render_to_string(inline => generateStats($c, 'f2b')); + # $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); + # return $c->render('xt_geoip_lst'); + } ## end if ($choice eq 'LF2B') -# $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); -# return $c->render('xt_geoip_lst'); - }; + if ($choice eq 'LSSH') { + $result = $c->generateStats('ssh'); - if ( $choice eq 'LSSH' ) { + # $result = $c->render_to_string(inline => generateStats($c, 'ssh')); + # $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); + # return $c->render('xt_geoip_lst'); + } ## end if ($choice eq 'LSSH') - $result = $c->generateStats( 'ssh' ); -# $result = $c->render_to_string(inline => generateStats($c, 'ssh')); + if ($choice eq 'LIPT') { + $result = $c->generateStats('ipt'); -# $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); -# return $c->render('xt_geoip_lst'); - }; + # $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); + # return $c->render('xt_geoip_lst'); + } ## end if ($choice eq 'LIPT') - if ( $choice eq 'LIPT' ) { + if ($choice eq 'LSRV') { - $result = $c->generateStats( 'ipt' ); + # $c->stash( title => $title, xtg_datas => \%xtg_datas ); + # return $c->render('xt_geoip_lsrv'); + } ## end if ($choice eq 'LSRV') -# $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); -# return $c->render('xt_geoip_lst'); - }; + if ($choice eq 'UPDT') { - if ( $choice eq 'LSRV' ) { -# $c->stash( title => $title, xtg_datas => \%xtg_datas ); -# return $c->render('xt_geoip_lsrv'); - } + # $c->stash( title => $title, xtg_datas => \%xtg_datas ); + # return $c->render('xt_geoip_updt'); + } ## end if ($choice eq 'UPDT') - if ( $choice eq 'UPDT' ) { -# $c->stash( title => $title, xtg_datas => \%xtg_datas ); -# return $c->render('xt_geoip_updt'); - } + if ($choice eq 'UPDS') { + $xtg_datas{name} = $c->param('Name'); - if ( $choice eq 'UPDS' ) { + # $c->stash( title => $title, xtg_datas => \%xtg_datas ); + # return $c->render('xt_geoip_upds'); + } ## end if ($choice eq 'UPDS') - $xtg_datas{name} = $c->param('Name'); - -# $c->stash( title => $title, xtg_datas => \%xtg_datas ); -# return $c->render('xt_geoip_upds'); - } - - if ( $choice eq 'REMS' ) { - - $xtg_datas{name} = $c->param('Name'); - -# $c->stash( title => $title, xtg_datas => \%xtg_datas ); -# return $c->render('xt_geoip_rems'); - } - - $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas ); - - return $c->render( 'xt_geoip_lst' ) if ( $choice ~~ [ 'LCOD', 'LF2B', 'LSSH', 'LIPT' ] ); - - return $c->render( 'xt_geoip'.'_'.lc($choice) ) if ( $choice ~~ [ 'UPDT', 'UPDS', 'REMS', 'LSRV' ] ); + if ($choice eq 'REMS') { + $xtg_datas{name} = $c->param('Name'); + # $c->stash( title => $title, xtg_datas => \%xtg_datas ); + # return $c->render('xt_geoip_rems'); + } ## end if ($choice eq 'REMS') + $c->stash(title => $title, modul => $result, xtg_datas => \%xtg_datas); + return $c->render('xt_geoip_lst') if ($choice ~~ [ 'LCOD', 'LF2B', 'LSSH', 'LIPT' ]); + return $c->render('xt_geoip' . '_' . lc($choice)) if ($choice ~~ [ 'UPDT', 'UPDS', 'REMS', 'LSRV' ]); $c->redirect_to('/xt_geoip'); - -}; - +} ## end sub do_display sub do_action { - my $c = shift; $c->app->log->info($c->log_req); - - my $rt = $c->current_route; - - my $title = $c->render_to_string(inline =>($c->l('xtg_FORM_TITLE'))); + our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; + my $rt = $c->current_route; + my $title = $c->render_to_string(inline => ($c->l('xtg_FORM_TITLE'))); my %xtg_datas = (); - - my $choice = $c->param('Choice'); + my $choice = $c->param('Choice'); $xtg_datas{'choice'} = $choice; - my ($res, $result) = ''; + if ($choice eq 'LSRV') { - if ( $choice eq 'LSRV' ) { + #$result .= 'Blocked for testing ! Avoid updates for now '; + $res = ''; - #$result .= 'Blocked for testing ! Avoid updates for now '; + if (!$result) { + $res = $c->do_otherServices(); + $result .= $res unless $res eq 'OK'; - $res = ''; - if ( ! $result ) { - $res = $c->do_otherServices(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('xtg_SERVICE_SUCCESS'); - } - } - } + if (!$result) { + $result = $c->l('xtg_SERVICE_SUCCESS'); + } + } ## end if (!$result) + } ## end if ($choice eq 'LSRV') - if ( $choice eq 'UPDT' ) { + if ($choice eq 'UPDT') { + $res = $c->must_exist(); + $result .= $res unless $res eq 'OK'; - $res = $c->must_exist(); - $result .= $res unless $res eq 'OK'; - - #$result .= 'Blocked for testing ! Avoid updates for now '; + #$result .= 'Blocked for testing ! Avoid updates for now '; + $res = ''; - $res = ''; - if ( ! $result ) { - $res = $c->change_settings(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('xtg_SUCCESS'); - } - } - } + if (!$result) { + $res = $c->change_settings(); + $result .= $res unless $res eq 'OK'; + if (!$result) { + $result = $c->l('xtg_SUCCESS'); + } + } ## end if (!$result) + } ## end if ($choice eq 'UPDT') - if ( $choice eq 'REMS' ) { + if ($choice eq 'REMS') { - #$result .= 'Blocked for testing ! Avoid updates for now '; + #$result .= 'Blocked for testing ! Avoid updates for now '; + my $name = $c->param('Name'); + $xtg_datas{name} = $name; + $res = ''; - my $name = $c->param('Name'); - $xtg_datas{name} = $name; + if (!$result) { + $res = $c->remove_serv(); + $result .= $res unless $res eq 'OK'; - $res = ''; - if ( ! $result ) { - $res = $c->remove_serv(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('xtg_SUCCESSFULLY_DELETED_SERVICE'); - } - } - } + if (!$result) { + $result = $c->l('xtg_SUCCESSFULLY_DELETED_SERVICE'); + } + } ## end if (!$result) + } ## end if ($choice eq 'REMS') + if ($choice eq 'UPDS') { - if ( $choice eq 'UPDS' ) { + #$result .= 'Blocked for testing ! Avoid updates for now '; + my $name = $c->param('Name'); + $xtg_datas{name} = $name; + $res = ''; - #$result .= 'Blocked for testing ! Avoid updates for now '; + if (!$result) { + $res = $c->modify_serv(); + $result .= $res unless $res eq 'OK'; - my $name = $c->param('Name'); - $xtg_datas{name} = $name; - - $res = ''; - if ( ! $result ) { - $res = $c->modify_serv(); - $result .= $res unless $res eq 'OK'; - if ( ! $result ) { - $result = $c->l('xtg_SERVICE_SUCCESS'); - } - } - } + if (!$result) { + $result = $c->l('xtg_SERVICE_SUCCESS'); + } + } ## end if (!$result) + } ## end if ($choice eq 'UPDS') # common parts if ($res ne 'OK') { - $c->stash( error => $result ); - $c->stash( title => $title, xtg_datas => \%xtg_datas ); - return $c->render( 'xt_geoip'.'_'.lc($choice) ); + $c->stash(error => $result); + $c->stash(title => $title, xtg_datas => \%xtg_datas); + return $c->render('xt_geoip' . '_' . lc($choice)); } - my $message = "xt_geoip updates $choice DONE"; $c->app->log->info($message); - $c->flash( success => $result ); + $c->flash(success => $result); ## $c->flash( error => 'No changes applied !!' ); - #return to 'xt_geoip' route !!! $c->redirect_to('/xt_geoip'); - -}; - +} ## end sub do_action sub get_badcountries { - - my $c = shift; + my $c = shift; my $full = shift; - + our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; my $badc = $cdb->get_prop("masq", "BadCountries") || ""; - return $badc unless $full ; - - my $rev = (($cdb->get_prop("masq", "XTGeoipRev")||"disabled") eq "enabled") ? "!=" : "=="; + return $badc unless $full; + my $rev = (($cdb->get_prop("masq", "XTGeoipRev") || "disabled") eq "enabled") ? "!=" : "=="; return "$rev $badc "; -} - +} ## end sub get_badcountries sub get_geoip { - return $cdb->get_prop("masq", "GeoIP") || 'disabled'; + return $cdb->get_prop("masq", "GeoIP") || 'disabled'; } - sub get_reverse { - - my $c = shift; + my $c = shift; my $item = shift; my $prop = shift; - $item = ($item eq 'masq') ? $item : $c->param('Name'); return $cdb->get_prop("$item", "$prop") || "disabled"; -} - +} ## end sub get_reverse sub get_stat_geoip { + my $c = shift; - my $c = shift; - if ( system ( "/bin/test -f /lib/modules/`/bin/uname -r`/weak-updates/xtables-addons/xt_geoip.ko") != 0 ) { - return $c->l('xtg_ERROR_MISSING_MODULE'); - } elsif ( system ( "/sbin/lsmod | grep 'xt_geoip' > /dev/null") != 0 ) { - return $c->l('xtg_ERROR_UNLOADED_MODULE'); - } elsif ( get_geoip() eq 'enabled' && system ( "/sbin/iptables -L -n | grep 'XTGeoIP' > /dev/null") != 0 ) { - return $c->l('xtg_ERROR_FILTER_CHAIN_MISSING'); - } else { - return ''; - } -} - + if (system("/bin/test -f /lib/modules/`/bin/uname -r`/weak-updates/xtables-addons/xt_geoip.ko") != 0) { + return $c->l('xtg_ERROR_MISSING_MODULE'); + } elsif (system("/sbin/lsmod | grep 'xt_geoip' > /dev/null") != 0) { + return $c->l('xtg_ERROR_UNLOADED_MODULE'); + } elsif (get_geoip() eq 'enabled' && system("/sbin/iptables -L -n | grep 'XTGeoIP' > /dev/null") != 0) { + return $c->l('xtg_ERROR_FILTER_CHAIN_MISSING'); + } else { + return ''; + } +} ## end sub get_stat_geoip sub get_stat_license_key { - my $c = shift; - if (($cdb->get_prop( 'geoip','status' ) || 'disabled') eq 'enabled' ) { - if ( ($cdb->get_prop( 'geoip','LicenseKey' ) || '') ne '' ) { - return ''; - } - } - return $c->l('xtg_ERROR_LICENSE_KEY'); -} + our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; + if (($cdb->get_prop('geoip', 'status') || 'disabled') eq 'enabled') { + if (($cdb->get_prop('geoip', 'LicenseKey') || '') ne '') { + return ''; + } + } ## end if (($cdb->get_prop('geoip'...))) + return $c->l('xtg_ERROR_LICENSE_KEY'); +} ## end sub get_stat_license_key sub get_date_update { my $file = "/usr/share/xt_geoip/LE/A1.iv4"; - my $filetime = ( -e $file ) ? (stat($file))[9] : 0; - return strftime("%Y/%m/%d %H:%M", localtime( $filetime )) || ''; -} - + my $filetime = (-e $file) ? (stat($file))[9] : 0; + return strftime("%Y/%m/%d %H:%M", localtime($filetime)) || ''; +} ## end sub get_date_update sub get_srv_name { my ($c) = @_; return $c->param('Name'); } - sub get_services_table { - my $c = shift; + our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; my $choice = shift || 'sel'; - my @services; my @serv_rec; - if ( $choice ne 'all' ) { + if ($choice ne 'all') { @services = split(/,/, $cdb->get_prop("masq", "XtServices")); - for ( @services ) { - my $rec = $cdb->get( $_ ); - push @serv_rec, $rec if ( $rec && $rec->prop('TCPPort') ); - } + + for (@services) { + my $rec = $cdb->get($_); + push @serv_rec, $rec if ($rec && $rec->prop('TCPPort')); + } } else { - for ($cdb->get_all_by_prop(type => 'service')) { - push @serv_rec, $_ if ( $_->prop('TCPPort') ); - } - } + + for ($cdb->get_all_by_prop(type => 'service')) { + push @serv_rec, $_ if ($_->prop('TCPPort')); + } + } ## end else [ if ($choice ne 'all') ] return \@serv_rec; -} +} ## end sub get_services_table sub get_srv_badcountries { - my ( $c, $name, $full ) = @_; - - my $badc = $cdb->get_prop($name, "BadCountries")||""; - return $badc unless $full ; - - my $rev = (($cdb->get_prop($name, "XTGeoipRev")||"disabled") eq "enabled") ? "!=" : "=="; + my ($c, $name, $full) = @_; + our $cdb = esmith::ConfigDB->open() or die "Couldn't open ConfigDB\n"; + my $badc = $cdb->get_prop($name, "BadCountries") || ""; + return $badc unless $full; + my $rev = (($cdb->get_prop($name, "XTGeoipRev") || "disabled") eq "enabled") ? "!=" : "=="; return "$rev $badc "; -} - +} ## end sub get_srv_badcountries #Subroutine to list statistics sub generateStats { + my $c = shift; + my $stats_type = shift; + my $out = ''; - my $c = shift; - my $stats_type = shift; - my $out = ''; + # Untaint $name before use in system() + $stats_type =~ /(.+)/; + $stats_type = $1; - # Untaint $name before use in system() - $stats_type =~ /(.+)/; $stats_type = $1; - if ($stats_type ne "ipt" and $stats_type ne "ssh" and $stats_type ne "f2b") { - $out .= sprintf("
"; - - while ("; - - $out .= sprintf(") - { - $out .= sprintf("%s", $_); - } - - close Xt_GEOIPSTATS; - $out .= sprintf "
"; + while ("; + $out .= sprintf(") { + $out .= sprintf("%s", $_); + } + close Xt_GEOIPSTATS; + $out .= sprintf "
"; - - while ("; - - $out .= sprintf(") { - $out .= sprintf("%s", $_); - } - - close Xt_GEOIPCODES; - $out .= sprintf "
"; + while ("; + $out .= sprintf(") { + $out .= sprintf("%s", $_); + } + close Xt_GEOIPCODES; + $out .= sprintf "
%= dumper $c->current_route %= dumper $xtg_datas diff --git a/root/usr/share/smanager/themes/default/templates/xt_geoip_lsrv.html.ep b/root/usr/share/smanager/themes/default/templates/xt_geoip_lsrv.html.ep index 8b33453..2fb4573 100644 --- a/root/usr/share/smanager/themes/default/templates/xt_geoip_lsrv.html.ep +++ b/root/usr/share/smanager/themes/default/templates/xt_geoip_lsrv.html.ep @@ -4,7 +4,7 @@
%= dumper $c->current_route %= dumper $xtg_datas diff --git a/root/usr/share/smanager/themes/default/templates/xt_geoip_lst.html.ep b/root/usr/share/smanager/themes/default/templates/xt_geoip_lst.html.ep index feee69a..02ec9c6 100644 --- a/root/usr/share/smanager/themes/default/templates/xt_geoip_lst.html.ep +++ b/root/usr/share/smanager/themes/default/templates/xt_geoip_lst.html.ep @@ -4,7 +4,7 @@
%= dumper $c->current_route %= dumper $xtg_datas diff --git a/root/usr/share/smanager/themes/default/templates/xt_geoip_rems.html.ep b/root/usr/share/smanager/themes/default/templates/xt_geoip_rems.html.ep index 7e54c60..5e65d3e 100644 --- a/root/usr/share/smanager/themes/default/templates/xt_geoip_rems.html.ep +++ b/root/usr/share/smanager/themes/default/templates/xt_geoip_rems.html.ep @@ -4,7 +4,7 @@
%= dumper $c->current_route %= dumper $xtg_datas diff --git a/root/usr/share/smanager/themes/default/templates/xt_geoip_upds.html.ep b/root/usr/share/smanager/themes/default/templates/xt_geoip_upds.html.ep index 8e96141..77c0ab4 100644 --- a/root/usr/share/smanager/themes/default/templates/xt_geoip_upds.html.ep +++ b/root/usr/share/smanager/themes/default/templates/xt_geoip_upds.html.ep @@ -4,7 +4,7 @@
%= dumper $c->current_route %= dumper $xtg_datas diff --git a/root/usr/share/smanager/themes/default/templates/xt_geoip_updt.html.ep b/root/usr/share/smanager/themes/default/templates/xt_geoip_updt.html.ep index f45cb99..3e6b649 100644 --- a/root/usr/share/smanager/themes/default/templates/xt_geoip_updt.html.ep +++ b/root/usr/share/smanager/themes/default/templates/xt_geoip_updt.html.ep @@ -4,7 +4,7 @@
%= dumper $c->current_route
%= dumper $xtg_datas
diff --git a/smeserver-xt_geoip.spec b/smeserver-xt_geoip.spec
index 506f2e4..c60d042 100644
--- a/smeserver-xt_geoip.spec
+++ b/smeserver-xt_geoip.spec
@@ -1,6 +1,6 @@
%define name smeserver-xt_geoip
%define version 1.3.1
-%define release 22
+%define release 23
Summary: smserver rpm to setup database, update and configuration for xt_geoip module with a panel.
Name: %{name}
@@ -14,14 +14,17 @@ Source: %{name}-%{version}.tar.xz
BuildArchitectures: noarch
BuildRoot: /var/tmp/%{name}-%{version}
BuildRequires: e-smith-devtools
-Requires: e-smith-release >= 10.0
-Requires: server-manager >= 0.1.0-23
-Requires: xtables-addons = 2.14
-Requires: GeoIP >= 1.5.0
+Requires: e-smith-release >= 11.0
+Requires: server-manager >= 11
+Requires: xtables-addons >= 3.25
+# Is this required now?
+Requires: GeoIP >= 1.6.0
Requires: libmaxminddb >= 1.1.1
+# Is this required now?
Requires: libmaxminddb-devel >= 1.1.1
Requires: geolite2-country
Requires: geolite2-city
+Requires: perl-Text-CSV_XS
AutoReqProv: no
%description
@@ -78,6 +81,11 @@ fi
%changelog
+* Wed Feb 12 2025 John Crisp