Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 14aa2d8fda | |||
| a570a47f5a | |||
|
|
daa56b9cc5 | ||
|
|
39a0598d79 | ||
|
|
3caa8642cb | ||
| 8253bc0805 | |||
| b8731843ed | |||
|
|
02f87475ff | ||
|
|
725b2f5418 | ||
|
|
42ce2cced8 | ||
|
|
a9ebb21641 | ||
| 444e6dbfcf |
@@ -6,7 +6,14 @@ SMEServer Koozali developed git repo for smeserver-xt_geoip smecontribs
|
|||||||
<br />https://wiki.koozali.org/
|
<br />https://wiki.koozali.org/
|
||||||
|
|
||||||
## Bugzilla
|
## Bugzilla
|
||||||
Show list of outstanding bugs: [here](https://bugs.koozali.org/buglist.cgi?component=smeserver-xt_geoip&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-xt_geoip&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-xt_geoip&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-xt_geoip&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-xt_geoip&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-xt_geoip&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-xt_geoip&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-xt_geoip&list_id=105781&order=changeddate+DESC%2Ccomponent%2Cpriority%2Cbug_severity&product=SME+Contribs&query_format=advanced)
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use esmith::Build::CreateLinks qw(:all);
|
|||||||
#--------------------------------------------------
|
#--------------------------------------------------
|
||||||
|
|
||||||
# links to add
|
# links to add
|
||||||
panel_link("xt_geoip","manager");
|
panel_link("xtgeoip","manager");
|
||||||
|
|
||||||
# templates to expand
|
# templates to expand
|
||||||
for my $event (qw(xt_geoip-modify xt_geoip-update xt_geoip-service
|
for my $event (qw(xt_geoip-modify xt_geoip-update xt_geoip-service
|
||||||
@@ -37,8 +37,8 @@ for my $event (qw(xt_geoip-update bootstrap-console-save
|
|||||||
{
|
{
|
||||||
event_link("smeserver-xt_geoip-download-action", $event, "10");
|
event_link("smeserver-xt_geoip-download-action", $event, "10");
|
||||||
}
|
}
|
||||||
for my $event (qw(bootstrap-console-save e-smith-packetfilter-update
|
for my $event (qw(bootstrap-console-save smeserver-packetfilter-update
|
||||||
smeserver-xt_geoip-update remote-access-update))
|
smeserver-xt_geoip-update remoteaccess-update))
|
||||||
{
|
{
|
||||||
event_link("xt_geoip_kmod", $event, "15");
|
event_link("xt_geoip_kmod", $event, "15");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
my $BC = $masq{BadCountries} || '';
|
my $BC = $masq{BadCountries} || '';
|
||||||
my $GP = $masq{GeoIP} || 'disabled';
|
my $GP = $masq{GeoIP} || 'disabled';
|
||||||
my $KERNEL = `/bin/uname -r`;
|
my $KERNEL = `/bin/uname -r`;
|
||||||
chomp($KERNEL);
|
chomp($KERNEL);
|
||||||
my $PATH_MODULE = "/lib/modules/$KERNEL/extra/xt_geoip.ko";
|
my $PATH_MODULE = "/lib/modules/$KERNEL/extra/xt_geoip.ko";
|
||||||
my $PATH2_MODULE = "/lib/modules/$KERNEL/weak-updates/xt_geoip.ko";
|
my $PATH2_MODULE = "/lib/modules/$KERNEL/weak-updates/xt_geoip.ko";
|
||||||
my $PATH3_MODULE = "/lib/modules/$KERNEL/weak-updates/xtables-addons/xt_geoip.ko";
|
my $PATH3_MODULE = "/lib/modules/$KERNEL/weak-updates/xtables-addons/xt_geoip.ko";
|
||||||
my $port;
|
my $port;
|
||||||
@@ -11,8 +11,8 @@
|
|||||||
my $servStatus;
|
my $servStatus;
|
||||||
my $locBC;
|
my $locBC;
|
||||||
|
|
||||||
# to allow reload without locking just after initial install
|
# to allow reload without locking just after initial install
|
||||||
$OUT .=<<'EOF';
|
$OUT .= <<'EOF';
|
||||||
iptables -n --list XTGeoIP >/dev/null 2>&1
|
iptables -n --list XTGeoIP >/dev/null 2>&1
|
||||||
test=$?
|
test=$?
|
||||||
if [[ $test -eq 1 ]] ; then
|
if [[ $test -eq 1 ]] ; then
|
||||||
@@ -26,86 +26,91 @@
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Find the current XTGeoIP_$$ chain, and create a new one.
|
# Find the current XTGeoIP_$$ chain, and create a new one.
|
||||||
$OUT .=<<'EOF';
|
$OUT .= <<'EOF';
|
||||||
OLD_XTGeoIP=$(get_safe_id XTGeoIP filter find)
|
OLD_XTGeoIP=$(get_safe_id XTGeoIP filter find)
|
||||||
NEW_XTGeoIP=$(get_safe_id XTGeoIP filter new)
|
NEW_XTGeoIP=$(get_safe_id XTGeoIP filter new)
|
||||||
/sbin/iptables --new-chain $NEW_XTGeoIP
|
/sbin/iptables --new-chain $NEW_XTGeoIP
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if ( $GP eq 'enabled' )
|
if ($GP eq 'enabled') {
|
||||||
{
|
if (-s $PATH_MODULE || -s $PATH2_MODULE || -s $PATH3_MODULE) {
|
||||||
if (-s $PATH_MODULE || -s $PATH2_MODULE || -s $PATH3_MODULE)
|
|
||||||
{
|
|
||||||
|
|
||||||
# do not block Localhost(s)
|
# do not block Localhost(s)
|
||||||
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -s 127.0.0.0/24 -j RETURN\n";
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -s 127.0.0.0/24 -j RETURN\n";
|
||||||
|
|
||||||
# do not block LAN
|
# do not block LAN
|
||||||
my $locals = "@locals";
|
my $locals = "@locals";
|
||||||
if (@locals)
|
|
||||||
{
|
|
||||||
# Make a new local_chk chain and add any networks found in networks db
|
|
||||||
foreach my $local (@locals)
|
|
||||||
{
|
|
||||||
# If the network is a remote vpn subnet, restrict it to the ipsec0
|
|
||||||
# interface.
|
|
||||||
my ($net, $msk) = split /\//, $local;
|
|
||||||
my $netrec = $nets->get($net);
|
|
||||||
die "Can't find network $net in networks db!\n" unless $netrec;
|
|
||||||
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -s $local";
|
|
||||||
if (($netrec->prop('remoteVPNSubnet') || 'no') eq 'yes')
|
|
||||||
{
|
|
||||||
$OUT .= " --in-interface ipsec0";
|
|
||||||
}
|
|
||||||
$OUT .= " -j RETURN\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
my @services = split(/,/, $masq{'XtServices'});
|
if (@locals) {
|
||||||
|
|
||||||
foreach my $servName (@services)
|
# Make a new local_chk chain and add any networks found in networks db
|
||||||
{
|
foreach my $local (@locals) {
|
||||||
$port = ${$servName}{'TCPPort'} || '';
|
|
||||||
my $servStatus = ${$servName}{'status'} || 'disabled';
|
|
||||||
my $servAccess = ${$servName}{'access'} || 'private';
|
|
||||||
my $locBC = ${$servName}{'BadCountries'} || '';
|
|
||||||
my $reverse = ( ( ${$servName}{'XTGeoipRev'} || 'disabled' ) eq "enabled" )? "!": "";
|
|
||||||
if ($port ne '' and $servStatus eq 'enabled' and $servAccess eq 'public' and $locBC ne '') {
|
|
||||||
push @locPorts, $port;
|
|
||||||
my $multi = ( $port =~ /[,:]/ )? "-m multiport --dports" : "--dport";
|
|
||||||
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -m geoip $reverse --src-cc $locBC -p tcp $multi $port -j ULOG --ulog-prefix \"GeoIP BAN: $servName\"\n";
|
|
||||||
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -m geoip $reverse --src-cc $locBC -p tcp $multi $port -j DROP\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# block for all or other ports should move there
|
# If the network is a remote vpn subnet, restrict it to the ipsec0
|
||||||
if ($BC ne '') {
|
# interface.
|
||||||
my $reverse = ( ( $masq{'XTGeoipRev'} || 'disabled' ) eq "enabled" )? "!": "";
|
my ($net, $msk) = split /\//, $local;
|
||||||
my $others = ( ( $masq{'XTGeoipOther'} || 'disabled') eq "enabled") ? 1 : 0;
|
my $netrec = $nets->get($net);
|
||||||
@locPorts = () unless $others;
|
die "Can't find network $net in networks db!\n" unless $netrec;
|
||||||
if (@locPorts != 0) {
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -s $local";
|
||||||
my $LocPorts = join ',', @locPorts;
|
|
||||||
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -p tcp -m geoip -m multiport ! --dports $LocPorts $reverse --src-cc $BC -j ULOG --ulog-prefix \"GeoIP BAN: OTHER\"\n";
|
if (($netrec->prop('remoteVPNSubnet') || 'no') eq 'yes') {
|
||||||
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -p tcp -m geoip -m multiport ! --dports $LocPorts $reverse --src-cc $BC -j DROP\n";
|
$OUT .= " --in-interface ipsec0";
|
||||||
} else {
|
}
|
||||||
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -p tcp -m geoip $reverse --src-cc $BC -j ULOG --ulog-prefix \"GeoIP BAN: ALL\"\n";
|
$OUT .= " -j RETURN\n";
|
||||||
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -p tcp -m geoip $reverse --src-cc $BC -j DROP\n";
|
} ## end foreach my $local (@locals)
|
||||||
}
|
} ## end if (@locals)
|
||||||
|
|
||||||
|
# [SME: 12445] do not block Remote authorized access
|
||||||
|
# TO DO : allow pin point per service eg this UK ip/network even if UK is filtered
|
||||||
|
if (($masq{XTAcceptValidRemoteHosts} || 'enabled') eq 'enabled') {
|
||||||
|
foreach (split /[,;]/, (${'httpd-admin'}{'ValidFrom'} || '')) {
|
||||||
|
my ($ip, $bits) = Net::IPv4Addr::ipv4_parse("$_");
|
||||||
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -s $ip/$bits -j RETURN\n" unless "$ip" eq '0.0.0.0';
|
||||||
}
|
}
|
||||||
$OUT .= " /sbin/iptables --append \$NEW_XTGeoIP" .
|
} ## end if (($masq{XTAcceptValidRemoteHosts...}))
|
||||||
" -j RETURN\n";
|
|
||||||
|
my @services = split(/,/, $masq{'XtServices'});
|
||||||
|
|
||||||
|
foreach my $servName (@services) {
|
||||||
|
$port = ${$servName}{'TCPPort'} || '';
|
||||||
|
my $servStatus = ${$servName}{'status'} || 'disabled';
|
||||||
|
my $servAccess = ${$servName}{'access'} || 'private';
|
||||||
|
my $locBC = ${$servName}{'BadCountries'} || '';
|
||||||
|
my $reverse = ((${$servName}{'XTGeoipRev'} || 'disabled') eq "enabled") ? "!" : "";
|
||||||
|
|
||||||
|
if ($port ne '' and $servStatus eq 'enabled' and $servAccess eq 'public' and $locBC ne '') {
|
||||||
|
push @locPorts, $port;
|
||||||
|
my $multi = ($port =~ /[,:]/) ? "-m multiport --dports" : "--dport";
|
||||||
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -m geoip $reverse --src-cc $locBC -p tcp $multi $port -j NFLOG --nflog-prefix \"GeoIP BAN: $servName\"\n";
|
||||||
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -m geoip $reverse --src-cc $locBC -p tcp $multi $port -j DROP\n";
|
||||||
|
} ## end if ($port ne '' and $servStatus...)
|
||||||
|
} ## end foreach my $servName (@services)
|
||||||
|
|
||||||
|
# block for all or other ports should move there
|
||||||
|
if ($BC ne '') {
|
||||||
|
my $reverse = (($masq{'XTGeoipRev'} || 'disabled') eq "enabled") ? "!" : "";
|
||||||
|
my $others = (($masq{'XTGeoipOther'} || 'disabled') eq "enabled") ? 1 : 0;
|
||||||
|
@locPorts = () unless $others;
|
||||||
|
|
||||||
|
if (@locPorts != 0) {
|
||||||
|
my $LocPorts = join ',', @locPorts;
|
||||||
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -p tcp -m geoip -m multiport ! --dports $LocPorts $reverse --src-cc $BC -j NFLOG --nflog-prefix \"GeoIP BAN: OTHER\"\n";
|
||||||
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -p tcp -m geoip -m multiport ! --dports $LocPorts $reverse --src-cc $BC -j DROP\n";
|
||||||
|
} else {
|
||||||
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -p tcp -m geoip $reverse --src-cc $BC -j NFLOG --nflog-prefix \"GeoIP BAN: ALL\"\n";
|
||||||
|
$OUT .= " /sbin/iptables -A \$NEW_XTGeoIP -p tcp -m geoip $reverse --src-cc $BC -j DROP\n";
|
||||||
|
}
|
||||||
|
} ## end if ($BC ne '')
|
||||||
|
$OUT .= " /sbin/iptables --append \$NEW_XTGeoIP" . " -j RETURN\n";
|
||||||
## end of add
|
## end of add
|
||||||
|
} ## end if (-s $PATH_MODULE ||...)
|
||||||
}
|
} ## end if ($GP eq 'enabled')
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Having created a new XTGeoIP chain, activate it and destroy the old.
|
# Having created a new XTGeoIP chain, activate it and destroy the old.
|
||||||
$OUT .=<<'EOF';
|
$OUT .= <<'EOF';
|
||||||
/sbin/iptables --replace XTGeoIP 1 \
|
/sbin/iptables --replace XTGeoIP 1 \
|
||||||
--jump $NEW_XTGeoIP
|
--jump $NEW_XTGeoIP
|
||||||
/sbin/iptables --flush $OLD_XTGeoIP
|
/sbin/iptables --flush $OLD_XTGeoIP
|
||||||
/sbin/iptables --delete-chain $OLD_XTGeoIP
|
/sbin/iptables --delete-chain $OLD_XTGeoIP
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
# Copyright (c) Michel Begue 2017
|
# Copyright (c) Michel Begue 2017
|
||||||
# Xt_GeoIP Administration panel
|
# Xt_GeoIP Administration panel
|
||||||
#-------------------------------------------
|
#-------------------------------------------
|
||||||
package esmith::FormMagick::Panel::xt_geoip;
|
package esmith::FormMagick::Panel::xt_geoip;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
#use warnings;
|
#use warnings;
|
||||||
@@ -95,8 +95,8 @@ sub new
|
|||||||
my $self = esmith::FormMagick->new();
|
my $self = esmith::FormMagick->new();
|
||||||
$self->{calling_package} = (caller)[0];
|
$self->{calling_package} = (caller)[0];
|
||||||
bless $self;
|
bless $self;
|
||||||
# $self->debug(1);
|
# $self->debug(1);
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 get_prop
|
=head2 get_prop
|
||||||
@@ -105,17 +105,17 @@ sub new
|
|||||||
|
|
||||||
sub get_prop
|
sub get_prop
|
||||||
{
|
{
|
||||||
my $fm = shift if (ref($_[0]) );
|
my $fm = shift if (ref($_[0]) );
|
||||||
my $item = shift;
|
my $item = shift;
|
||||||
my $prop = shift;
|
my $prop = shift;
|
||||||
|
|
||||||
my $record = $db->get($item);
|
my $record = $db->get($item);
|
||||||
if ($record) {
|
if ($record) {
|
||||||
return $record->prop($prop);
|
return $record->prop($prop);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 get_value
|
=head2 get_value
|
||||||
@@ -124,16 +124,16 @@ sub get_prop
|
|||||||
|
|
||||||
sub get_value
|
sub get_value
|
||||||
{
|
{
|
||||||
my $fm = shift;
|
my $fm = shift;
|
||||||
my $item = shift;
|
my $item = shift;
|
||||||
my $record = $db->get($item);
|
my $record = $db->get($item);
|
||||||
#return ($db->get("masq")->prop($item));
|
#return ($db->get("masq")->prop($item));
|
||||||
if ($record) {
|
if ($record) {
|
||||||
return $record->value();
|
return $record->value();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 get_badcountries
|
=head2 get_badcountries
|
||||||
@@ -171,7 +171,7 @@ sub get_reverse
|
|||||||
my $fm = shift;
|
my $fm = shift;
|
||||||
my $item = shift;
|
my $item = shift;
|
||||||
my $prop = shift;
|
my $prop = shift;
|
||||||
$item = ($item eq 'masq') ? $item : $fm->cgi->param('name');
|
$item = ($item eq 'masq') ? $item : $fm->cgi->param('name');
|
||||||
return $db->get_prop("$item", "$prop") || "disabled";
|
return $db->get_prop("$item", "$prop") || "disabled";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,16 +183,16 @@ method to retrieve the status of geoip (module and filtering) for the form
|
|||||||
|
|
||||||
sub get_stat_geoip
|
sub get_stat_geoip
|
||||||
{
|
{
|
||||||
my $fm = shift;
|
my $fm = shift;
|
||||||
if ( system ( "/bin/test -f /lib/modules/`/bin/uname -r`/weak-updates/xtables-addons/xt_geoip.ko") != 0 ) {
|
if ( system ( "/bin/test -f /lib/modules/`/bin/uname -r`/weak-updates/xtables-addons/xt_geoip.ko") != 0 ) {
|
||||||
return $fm->localise('ERROR_MISSING_MODULE');
|
return $fm->localise('ERROR_MISSING_MODULE');
|
||||||
} elsif ( system ( "/sbin/lsmod | grep 'xt_geoip' > /dev/null") != 0 ) {
|
} elsif ( system ( "/sbin/lsmod | grep 'xt_geoip' > /dev/null") != 0 ) {
|
||||||
return $fm->localise('ERROR_UNLOADED_MODULE');
|
return $fm->localise('ERROR_UNLOADED_MODULE');
|
||||||
} elsif ( get_geoip() eq 'enabled' && system ( "/sbin/iptables -L -n | grep 'XTGeoIP' > /dev/null") != 0 ) {
|
} elsif ( get_geoip() eq 'enabled' && system ( "/sbin/iptables -L -n | grep 'XTGeoIP' > /dev/null") != 0 ) {
|
||||||
return $fm->localise('ERROR_FILTER_CHAIN_MISSING');
|
return $fm->localise('ERROR_FILTER_CHAIN_MISSING');
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -205,9 +205,9 @@ sub get_stat_license_key {
|
|||||||
|
|
||||||
my $fm = shift;
|
my $fm = shift;
|
||||||
if ((get_prop( 'geoip','status' ) || 'disabled') eq 'enabled' ) {
|
if ((get_prop( 'geoip','status' ) || 'disabled') eq 'enabled' ) {
|
||||||
if ( (get_prop( 'geoip','LicenseKey' ) || '') ne '' ) {
|
if ( (get_prop( 'geoip','LicenseKey' ) || '') ne '' ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $fm->localise('ERROR_LICENSE_KEY');
|
return $fm->localise('ERROR_LICENSE_KEY');
|
||||||
|
|
||||||
@@ -231,38 +231,38 @@ Sub to change settings as per user input in the panel
|
|||||||
|
|
||||||
sub change_settings
|
sub change_settings
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $q = $self->{'cgi'};
|
my $q = $self->{'cgi'};
|
||||||
|
|
||||||
my $mq_bc = get_badcountries();
|
my $mq_bc = get_badcountries();
|
||||||
my $mq_gp = get_geoip();
|
my $mq_gp = get_geoip();
|
||||||
my $masq = $db->get('masq') || "disabled";
|
my $masq = $db->get('masq') || "disabled";
|
||||||
my $mq_rv = $masq->prop('XTGeoipRev') || 'disabled';
|
my $mq_rv = $masq->prop('XTGeoipRev') || 'disabled';
|
||||||
my $mq_ot = $masq->prop('XTGeoipOther') || 'disabled';
|
my $mq_ot = $masq->prop('XTGeoipOther') || 'disabled';
|
||||||
|
|
||||||
my $n_mq_bc = $q->param("masq_badcountries");
|
my $n_mq_bc = $q->param("masq_badcountries");
|
||||||
my $n_mq_gp = $q->param("masq_geoip") || $mq_gp;
|
my $n_mq_gp = $q->param("masq_geoip") || $mq_gp;
|
||||||
my $n_upd_gp = $q->param("update_geoip") || '';
|
my $n_upd_gp = $q->param("update_geoip") || '';
|
||||||
my $n_mq_rv = $q->param("masq_reverse") || $mq_rv ;
|
my $n_mq_rv = $q->param("masq_reverse") || $mq_rv ;
|
||||||
my $n_mq_ot = $q->param("masq_others") || $mq_ot ;
|
my $n_mq_ot = $q->param("masq_others") || $mq_ot ;
|
||||||
|
|
||||||
if (($n_mq_bc eq $mq_bc) && ($n_mq_gp eq $mq_gp) && ($n_upd_gp eq 'NO') && ($n_mq_rv eq $mq_rv) && ($n_mq_ot eq $mq_ot)) {
|
if (($n_mq_bc eq $mq_bc) && ($n_mq_gp eq $mq_gp) && ($n_upd_gp eq 'NO') && ($n_mq_rv eq $mq_rv) && ($n_mq_ot eq $mq_ot)) {
|
||||||
return $self->success("NO_CHANGE")
|
return $self->success("NO_CHANGE")
|
||||||
}
|
}
|
||||||
$db->set_prop("masq", "BadCountries", $n_mq_bc);
|
$db->set_prop("masq", "BadCountries", $n_mq_bc);
|
||||||
$db->set_prop("masq", "GeoIP", $n_mq_gp);
|
$db->set_prop("masq", "GeoIP", $n_mq_gp);
|
||||||
$db->set_prop("masq", "XTGeoipRev", $n_mq_rv);
|
$db->set_prop("masq", "XTGeoipRev", $n_mq_rv);
|
||||||
$db->set_prop("masq", "XTGeoipOther", $n_mq_ot);
|
$db->set_prop("masq", "XTGeoipOther", $n_mq_ot);
|
||||||
|
|
||||||
my $eventloc = "xt_geoip-modify";
|
my $eventloc = "xt_geoip-modify";
|
||||||
$eventloc = "xt_geoip-update" if $n_upd_gp eq 'YES';
|
$eventloc = "xt_geoip-update" if $n_upd_gp eq 'YES';
|
||||||
|
|
||||||
unless ( system ( "/sbin/e-smith/signal-event", $eventloc ) == 0 )
|
unless ( system ( "/sbin/e-smith/signal-event", $eventloc ) == 0 )
|
||||||
{
|
{
|
||||||
$self->error("ERROR_UPDATING");
|
$self->error("ERROR_UPDATING");
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
return $self->success("SUCCESS");
|
return $self->success("SUCCESS");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -278,14 +278,14 @@ sub must_exist
|
|||||||
my $listerr = "";
|
my $listerr = "";
|
||||||
my @mq_bcs = split /[,:]/, $q->param("masq_badcountries");
|
my @mq_bcs = split /[,:]/, $q->param("masq_badcountries");
|
||||||
if (@mq_bcs) {
|
if (@mq_bcs) {
|
||||||
my $ctr = @mq_bcs;
|
my $ctr = @mq_bcs;
|
||||||
return $self->localise('ERROR_COUNTRY_MAX: {$ctr}', {ctr=> "$ctr"}) if ($ctr > 50);
|
return $self->localise('ERROR_COUNTRY_MAX: {$ctr}', {ctr=> "$ctr"}) if ($ctr > 50);
|
||||||
|
|
||||||
foreach my $bcs (@mq_bcs) {
|
foreach my $bcs (@mq_bcs) {
|
||||||
my $file = "/usr/share/xt_geoip/LE/" . $bcs . ".iv4";
|
my $file = "/usr/share/xt_geoip/LE/" . $bcs . ".iv4";
|
||||||
if (! -f $file) { $listerr .= $bcs . ","; }
|
if (! -f $file) { $listerr .= $bcs . ","; }
|
||||||
}
|
}
|
||||||
return $self->localise('ERR_COUNTRY_NOT_EXIST: {$listerr}', {listerr=> "$listerr"}) if $listerr;
|
return $self->localise('ERR_COUNTRY_NOT_EXIST: {$listerr}', {listerr=> "$listerr"}) if $listerr;
|
||||||
}
|
}
|
||||||
return 'OK';
|
return 'OK';
|
||||||
}
|
}
|
||||||
@@ -305,41 +305,41 @@ sub print_custom_button
|
|||||||
#Subroutine to list statistics
|
#Subroutine to list statistics
|
||||||
sub generateStats
|
sub generateStats
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $q = $self->{cgi};
|
my $q = $self->{cgi};
|
||||||
|
|
||||||
$self->turn_off_buttons();
|
$self->turn_off_buttons();
|
||||||
|
|
||||||
# Untaint $name before use in system()
|
# Untaint $name before use in system()
|
||||||
my $stats_type = $q->param ('type');
|
my $stats_type = $q->param ('type');
|
||||||
$stats_type =~ /(.+)/; $stats_type = $1;
|
$stats_type =~ /(.+)/; $stats_type = $1;
|
||||||
if ($stats_type ne "ipt" && $stats_type ne "ssh" && $stats_type ne "f2b")
|
if ($stats_type ne "ipt" && $stats_type ne "ssh" && $stats_type ne "f2b")
|
||||||
{
|
{
|
||||||
print $q->p($q->b($self->localise('INVALID_STATS_TYPE')." ".
|
print $q->p($q->b($self->localise('INVALID_STATS_TYPE')." ".
|
||||||
$stats_type));
|
$stats_type));
|
||||||
return '';
|
return '';
|
||||||
} else {
|
} else {
|
||||||
# my $now_string = $self->gen_locale_date_string();
|
# my $now_string = $self->gen_locale_date_string();
|
||||||
my $file = "/var/lib/xt_geoip/extA_" . $stats_type . "_country.lst";
|
my $file = "/var/lib/xt_geoip/extA_" . $stats_type . "_country.lst";
|
||||||
my $filetime = ( -e $file ) ? (stat($file))[9] : 0;
|
my $filetime = ( -e $file ) ? (stat($file))[9] : 0;
|
||||||
my $date_string = strftime("%Y/%m/%d %H:%M", localtime( $filetime )) || '';
|
my $date_string = strftime("%Y/%m/%d %H:%M", localtime( $filetime )) || '';
|
||||||
print $q->h3($self->localise('STATS_GENERATED'), "[", $stats_type, "]", $date_string);
|
print $q->h3($self->localise('STATS_GENERATED'), "[", $stats_type, "]", $date_string);
|
||||||
|
|
||||||
open( XTGEOIPSTATS, $file );
|
open( XTGEOIPSTATS, $file );
|
||||||
print "<pre>\n";
|
print "<pre>\n";
|
||||||
|
|
||||||
while (<XTGEOIPSTATS>)
|
while (<XTGEOIPSTATS>)
|
||||||
{
|
{
|
||||||
print;
|
print;
|
||||||
}
|
}
|
||||||
|
|
||||||
close XTGEOIPSTATS;
|
close XTGEOIPSTATS;
|
||||||
print "</pre>\n";
|
print "</pre>\n";
|
||||||
|
|
||||||
print $q->h3($self->localise('END_OF_STATS'));
|
print $q->h3($self->localise('END_OF_STATS'));
|
||||||
#$self->wherenext('First');
|
#$self->wherenext('First');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_srv_name
|
sub get_srv_name
|
||||||
@@ -363,10 +363,10 @@ sub print_service_table {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $q = $self->{cgi};
|
my $q = $self->{cgi};
|
||||||
my $servname = $self->localise('NAME');
|
my $servname = $self->localise('NAME');
|
||||||
my $port = $self->localise('PORT');
|
my $port = $self->localise('PORT');
|
||||||
my $status = $self->localise('STATUS');
|
my $status = $self->localise('STATUS');
|
||||||
my $access = $self->localise('ACCESS');
|
my $access = $self->localise('ACCESS');
|
||||||
my $servBC = $self->localise('BADCOUNTRIES');
|
my $servBC = $self->localise('BADCOUNTRIES');
|
||||||
my $modify = $self->localise('MODIFY');
|
my $modify = $self->localise('MODIFY');
|
||||||
my $remove = $self->localise('REMOVE');
|
my $remove = $self->localise('REMOVE');
|
||||||
my $action_h = $self->localise('ACTION');
|
my $action_h = $self->localise('ACTION');
|
||||||
@@ -393,30 +393,30 @@ sub print_service_table {
|
|||||||
|
|
||||||
foreach my $servname (@services)
|
foreach my $servname (@services)
|
||||||
{
|
{
|
||||||
my $i = $db->get($servname);
|
my $i = $db->get($servname);
|
||||||
next if not defined $i;
|
next if not defined $i;
|
||||||
|
|
||||||
my $port = $i->prop('TCPPort');
|
my $port = $i->prop('TCPPort');
|
||||||
my $status = $i->prop('status');
|
my $status = $i->prop('status');
|
||||||
my $access = $i->prop('access');
|
my $access = $i->prop('access');
|
||||||
my $servBC = $i->prop('BadCountries') || ' ';
|
my $servBC = $i->prop('BadCountries') || ' ';
|
||||||
my $servRev = (( $i->prop('XTGeoipRev')|| 'disabled') eq 'disabled' )? '==': '!=';
|
my $servRev = (( $i->prop('XTGeoipRev')|| 'disabled') eq 'disabled' )? '==': '!=';
|
||||||
|
|
||||||
my $params = $self->build_serv_cgi_params($servname, $i->props());
|
my $params = $self->build_serv_cgi_params($servname, $i->props());
|
||||||
|
|
||||||
my $href = "$scriptname?$params&action=modify&wherenext=";
|
my $href = "$scriptname?$params&action=modify&wherenext=";
|
||||||
|
|
||||||
my $actionModify = ' ';
|
my $actionModify = ' ';
|
||||||
$actionModify .= $q->a({href => "${href}SrvModify"},$modify)
|
$actionModify .= $q->a({href => "${href}SrvModify"},$modify)
|
||||||
. ' ';
|
. ' ';
|
||||||
|
|
||||||
my $actionRemove = ' ';
|
my $actionRemove = ' ';
|
||||||
$actionRemove .= $q->a({href => "${href}SrvRemove"}, $remove)
|
$actionRemove .= $q->a({href => "${href}SrvRemove"}, $remove)
|
||||||
. ' ';
|
. ' ';
|
||||||
|
|
||||||
my $color = 'red';
|
my $color = 'red';
|
||||||
my $deco= "none";
|
my $deco= "none";
|
||||||
if ($servRev eq '!=' ) { $color = 'green'; }
|
if ($servRev eq '!=' ) { $color = 'green'; }
|
||||||
if ($status eq 'disabled' || $access ne 'public') { $color = 'grey'; $deco= "line-through"; }
|
if ($status eq 'disabled' || $access ne 'public') { $color = 'grey'; $deco= "line-through"; }
|
||||||
print $q->Tr (
|
print $q->Tr (
|
||||||
esmith::cgi::genSmallCell($q, $servname,"normal"),
|
esmith::cgi::genSmallCell($q, $servname,"normal"),
|
||||||
@@ -449,9 +449,9 @@ sub remove_serv {
|
|||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
my $name = $self->cgi->param('name');
|
my $name = $self->cgi->param('name');
|
||||||
if (my $serv = $db->get($name)) {
|
if (my $serv = $db->get($name)) {
|
||||||
my $servBC = $serv->prop('BadCountries') || '';
|
my $servBC = $serv->prop('BadCountries') || '';
|
||||||
if ($servBC ne '') {
|
if ($servBC ne '') {
|
||||||
my $tps = $db->set_prop_and_delete($name, "BadCountries");
|
my $tps = $db->set_prop_and_delete($name, "BadCountries");
|
||||||
$tps = $db->get_prop_and_delete($name, "XTGeoipRev");
|
$tps = $db->get_prop_and_delete($name, "XTGeoipRev");
|
||||||
# Untaint $name before use in system()
|
# Untaint $name before use in system()
|
||||||
# $name =~ /(.+)/; $name = $1;
|
# $name =~ /(.+)/; $name = $1;
|
||||||
@@ -475,24 +475,24 @@ sub modify_serv {
|
|||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
my $name = $self->cgi->param('name');
|
my $name = $self->cgi->param('name');
|
||||||
if (my $serv = $db->get($name)) {
|
if (my $serv = $db->get($name)) {
|
||||||
my $servBC = $serv->prop('BadCountries') || '';
|
my $servBC = $serv->prop('BadCountries') || '';
|
||||||
my $servRev = $serv->prop('XTGeoipRev') || 'disabled';
|
my $servRev = $serv->prop('XTGeoipRev') || 'disabled';
|
||||||
|
|
||||||
my $q = $self->{'cgi'};
|
my $q = $self->{'cgi'};
|
||||||
my $n_servBC = $q->param("masq_srv_badcountries");
|
my $n_servBC = $q->param("masq_srv_badcountries");
|
||||||
my $n_servRev = $q->param("masq_srv_reverse") || $servRev;
|
my $n_servRev = $q->param("masq_srv_reverse") || $servRev;
|
||||||
|
|
||||||
if ($n_servBC eq $servBC && $n_servRev eq $servRev ) {
|
if ($n_servBC eq $servBC && $n_servRev eq $servRev ) {
|
||||||
return $self->success("NO_CHANGE")
|
return $self->success("NO_CHANGE")
|
||||||
}
|
}
|
||||||
$db->set_prop($name, "BadCountries", $n_servBC);
|
$db->set_prop($name, "BadCountries", $n_servBC);
|
||||||
$db->set_prop($name, "XTGeoipRev", $n_servRev);
|
$db->set_prop($name, "XTGeoipRev", $n_servRev);
|
||||||
|
|
||||||
if (system ( "/sbin/e-smith/signal-event", "xt_geoip-service" ) == 0 )
|
if (system ( "/sbin/e-smith/signal-event", "xt_geoip-service" ) == 0 )
|
||||||
{
|
{
|
||||||
return $self->success("SUCCESS");
|
return $self->success("SUCCESS");
|
||||||
} else {
|
} else {
|
||||||
return $self->error("ERROR_UPDATING");
|
return $self->error("ERROR_UPDATING");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$self->error('CANT_FIND_SERV');
|
$self->error('CANT_FIND_SERV');
|
||||||
@@ -507,14 +507,14 @@ sub srv_must_exist
|
|||||||
my $listerr = "";
|
my $listerr = "";
|
||||||
my @mq_bcs = split /[,:]/, $q->param("masq_srv_badcountries");
|
my @mq_bcs = split /[,:]/, $q->param("masq_srv_badcountries");
|
||||||
if (@mq_bcs) {
|
if (@mq_bcs) {
|
||||||
my $ctr = @mq_bcs;
|
my $ctr = @mq_bcs;
|
||||||
return $self->localise('ERROR_COUNTRY_MAX: {$ctr}', {ctr=> "$ctr"}) if ($ctr > 50);
|
return $self->localise('ERROR_COUNTRY_MAX: {$ctr}', {ctr=> "$ctr"}) if ($ctr > 50);
|
||||||
|
|
||||||
foreach my $bcs (@mq_bcs) {
|
foreach my $bcs (@mq_bcs) {
|
||||||
my $file = "/usr/share/xt_geoip/LE/" . $bcs . ".iv4";
|
my $file = "/usr/share/xt_geoip/LE/" . $bcs . ".iv4";
|
||||||
if (! -f $file) { $listerr .= $bcs . ","; }
|
if (! -f $file) { $listerr .= $bcs . ","; }
|
||||||
}
|
}
|
||||||
return $self->localise('ERR_COUNTRY_NOT_EXIST: {$listerr}', {listerr=> "$listerr"}) if $listerr;
|
return $self->localise('ERR_COUNTRY_NOT_EXIST: {$listerr}', {listerr=> "$listerr"}) if $listerr;
|
||||||
}
|
}
|
||||||
return 'OK';
|
return 'OK';
|
||||||
}
|
}
|
||||||
@@ -523,32 +523,32 @@ sub srv_must_exist
|
|||||||
#Subroutine to list counries codes
|
#Subroutine to list counries codes
|
||||||
sub generateCodes
|
sub generateCodes
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $q = $self->{cgi};
|
my $q = $self->{cgi};
|
||||||
|
|
||||||
$self->turn_off_buttons();
|
$self->turn_off_buttons();
|
||||||
|
|
||||||
my $file = "/usr/share/xt_geoip/geoip_countries_list.txt";
|
my $file = "/usr/share/xt_geoip/geoip_countries_list.txt";
|
||||||
unless ( -e $file ) {
|
unless ( -e $file ) {
|
||||||
print $q->p($q->b($self->localise('INVALID_CODES_LIST')));
|
print $q->p($q->b($self->localise('INVALID_CODES_LIST')));
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
print $q->h3($self->localise('COUNTRY_LIST'));
|
print $q->h3($self->localise('COUNTRY_LIST'));
|
||||||
|
|
||||||
open( XTGEOIPCODES, $file );
|
open( XTGEOIPCODES, $file );
|
||||||
print "<pre>\n";
|
print "<pre>\n";
|
||||||
|
|
||||||
while (<XTGEOIPCODES>)
|
while (<XTGEOIPCODES>)
|
||||||
{
|
{
|
||||||
print;
|
print;
|
||||||
}
|
}
|
||||||
|
|
||||||
close XTGEOIPCODES;
|
close XTGEOIPCODES;
|
||||||
print "</pre>\n";
|
print "</pre>\n";
|
||||||
|
|
||||||
print $q->h3($self->localise('END_OF_CODES'));
|
print $q->h3($self->localise('END_OF_CODES'));
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,24 +556,24 @@ sub generateCodes
|
|||||||
#Subroutine to list other services codes
|
#Subroutine to list other services codes
|
||||||
sub otherServices
|
sub otherServices
|
||||||
{
|
{
|
||||||
my ($self, $choice) = @_;
|
my ($self, $choice) = @_;
|
||||||
|
|
||||||
my %serv_ok = map { $_ => 1} split(/,/, $db->get_prop("masq", "XtServices"));
|
my %serv_ok = map { $_ => 1} split(/,/, $db->get_prop("masq", "XtServices"));
|
||||||
# unless $choice eq 'all';
|
# unless $choice eq 'all';
|
||||||
|
|
||||||
my @serv_others = ();
|
my @serv_others = ();
|
||||||
|
|
||||||
for ($db->get_all_by_prop(type => 'service'))
|
for ($db->get_all_by_prop(type => 'service'))
|
||||||
{
|
{
|
||||||
next unless $_->prop('TCPPort');
|
next unless $_->prop('TCPPort');
|
||||||
# if ( $_->prop('TCPPort')) {
|
# if ( $_->prop('TCPPort')) {
|
||||||
|
|
||||||
# push @serv_others, $_->key unless exists( $serv_ok{$_->key});
|
# push @serv_others, $_->key unless exists( $serv_ok{$_->key});
|
||||||
push @serv_others, $_->key unless $choice eq 'sel' and not exists( $serv_ok{$_->key});
|
push @serv_others, $_->key unless $choice eq 'sel' and not exists( $serv_ok{$_->key});
|
||||||
# }
|
# }
|
||||||
}
|
}
|
||||||
|
|
||||||
return \@serv_others;
|
return \@serv_others;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,561 +0,0 @@
|
|||||||
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
|
|
||||||
# name : xt_geoipu, method : post, url : /xt_geoipb, ctlact : Xt_geoip#do_action
|
|
||||||
#
|
|
||||||
# routes : end
|
|
||||||
#----------------------------------------------------------------------
|
|
||||||
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";
|
|
||||||
|
|
||||||
|
|
||||||
sub main {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
$c->app->log->info($c->log_req);
|
|
||||||
|
|
||||||
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->render('xt_geoip');
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
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')));
|
|
||||||
|
|
||||||
my $choice = $c->param('Choice');
|
|
||||||
|
|
||||||
my $result;
|
|
||||||
my %xtg_datas = ();
|
|
||||||
$xtg_datas{'choice'} = $choice;
|
|
||||||
|
|
||||||
if ( $choice eq 'LCOD' ) {
|
|
||||||
|
|
||||||
$result = $c->generateCodes();
|
|
||||||
|
|
||||||
# $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas );
|
|
||||||
# return $c->render('xt_geoip_lst');
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( $choice eq 'LF2B' ) {
|
|
||||||
|
|
||||||
$result = $c->generateStats( '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');
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( $choice eq 'LSSH' ) {
|
|
||||||
|
|
||||||
$result = $c->generateStats( 'ssh' );
|
|
||||||
# $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');
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( $choice eq 'LIPT' ) {
|
|
||||||
|
|
||||||
$result = $c->generateStats( 'ipt' );
|
|
||||||
|
|
||||||
# $c->stash( title => $title, modul => $result, xtg_datas => \%xtg_datas );
|
|
||||||
# return $c->render('xt_geoip_lst');
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( $choice eq 'LSRV' ) {
|
|
||||||
# $c->stash( title => $title, xtg_datas => \%xtg_datas );
|
|
||||||
# return $c->render('xt_geoip_lsrv');
|
|
||||||
}
|
|
||||||
|
|
||||||
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');
|
|
||||||
|
|
||||||
# $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' ] );
|
|
||||||
|
|
||||||
$c->redirect_to('/xt_geoip');
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
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')));
|
|
||||||
my %xtg_datas = ();
|
|
||||||
|
|
||||||
my $choice = $c->param('Choice');
|
|
||||||
$xtg_datas{'choice'} = $choice;
|
|
||||||
|
|
||||||
my ($res, $result) = '';
|
|
||||||
|
|
||||||
|
|
||||||
if ( $choice eq 'LSRV' ) {
|
|
||||||
|
|
||||||
#$result .= 'Blocked for testing ! Avoid updates for now ';
|
|
||||||
|
|
||||||
$res = '';
|
|
||||||
if ( ! $result ) {
|
|
||||||
$res = $c->do_otherServices();
|
|
||||||
$result .= $res unless $res eq 'OK';
|
|
||||||
if ( ! $result ) {
|
|
||||||
$result = $c->l('xtg_SERVICE_SUCCESS');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $choice eq 'UPDT' ) {
|
|
||||||
|
|
||||||
$res = $c->must_exist();
|
|
||||||
$result .= $res unless $res eq 'OK';
|
|
||||||
|
|
||||||
#$result .= 'Blocked for testing ! Avoid updates for now ';
|
|
||||||
|
|
||||||
$res = '';
|
|
||||||
if ( ! $result ) {
|
|
||||||
$res = $c->change_settings();
|
|
||||||
$result .= $res unless $res eq 'OK';
|
|
||||||
if ( ! $result ) {
|
|
||||||
$result = $c->l('xtg_SUCCESS');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ( $choice eq 'REMS' ) {
|
|
||||||
|
|
||||||
#$result .= 'Blocked for testing ! Avoid updates for now ';
|
|
||||||
|
|
||||||
my $name = $c->param('Name');
|
|
||||||
$xtg_datas{name} = $name;
|
|
||||||
|
|
||||||
$res = '';
|
|
||||||
if ( ! $result ) {
|
|
||||||
$res = $c->remove_serv();
|
|
||||||
$result .= $res unless $res eq 'OK';
|
|
||||||
if ( ! $result ) {
|
|
||||||
$result = $c->l('xtg_SUCCESSFULLY_DELETED_SERVICE');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ( $choice eq 'UPDS' ) {
|
|
||||||
|
|
||||||
#$result .= 'Blocked for testing ! Avoid updates for now ';
|
|
||||||
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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) );
|
|
||||||
}
|
|
||||||
|
|
||||||
my $message = "xt_geoip updates $choice DONE";
|
|
||||||
$c->app->log->info($message);
|
|
||||||
$c->flash( success => $result );
|
|
||||||
## $c->flash( error => 'No changes applied !!' );
|
|
||||||
|
|
||||||
#return to 'xt_geoip' route !!!
|
|
||||||
$c->redirect_to('/xt_geoip');
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
sub get_badcountries {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
my $full = shift;
|
|
||||||
|
|
||||||
my $badc = $cdb->get_prop("masq", "BadCountries") || "";
|
|
||||||
return $badc unless $full ;
|
|
||||||
|
|
||||||
my $rev = (($cdb->get_prop("masq", "XTGeoipRev")||"disabled") eq "enabled") ? "!=" : "==";
|
|
||||||
return "$rev $badc ";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub get_geoip {
|
|
||||||
return $cdb->get_prop("masq", "GeoIP") || 'disabled';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub get_reverse {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
my $item = shift;
|
|
||||||
my $prop = shift;
|
|
||||||
|
|
||||||
$item = ($item eq 'masq') ? $item : $c->param('Name');
|
|
||||||
return $cdb->get_prop("$item", "$prop") || "disabled";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub get_stat_geoip {
|
|
||||||
|
|
||||||
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 '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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 )) || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub get_srv_name {
|
|
||||||
my ($c) = @_;
|
|
||||||
return $c->param('Name');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub get_services_table {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
my $choice = shift || 'sel';
|
|
||||||
|
|
||||||
my @services;
|
|
||||||
my @serv_rec;
|
|
||||||
|
|
||||||
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') );
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for ($cdb->get_all_by_prop(type => 'service')) {
|
|
||||||
push @serv_rec, $_ if ( $_->prop('TCPPort') );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return \@serv_rec;
|
|
||||||
}
|
|
||||||
|
|
||||||
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") ? "!=" : "==";
|
|
||||||
return "$rev $badc ";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#Subroutine to list statistics
|
|
||||||
sub generateStats {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
my $stats_type = shift;
|
|
||||||
my $out = '';
|
|
||||||
|
|
||||||
# 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("<h3>%s %s </h3>", $c->l('xtg_INVALID_STATS_TYPE'), $stats_type);
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
# my $now_string = $c->gen_locale_date_string();
|
|
||||||
my $file = "/var/lib/xt_geoip/extA_" . $stats_type . "_country.lst";
|
|
||||||
my $filetime = ( -e $file ) ? (stat($file))[9] : 0;
|
|
||||||
my $date_string = strftime("%Y/%m/%d %H:%M", localtime( $filetime )) || '';
|
|
||||||
|
|
||||||
$out .= sprintf("<h3>%s %s %s</h3>", $c->l('xtg_STATS_GENERATED'), $stats_type, $date_string);
|
|
||||||
|
|
||||||
open( Xt_GEOIPSTATS, $file );
|
|
||||||
$out .= sprintf "<pre>";
|
|
||||||
|
|
||||||
while (<Xt_GEOIPSTATS>)
|
|
||||||
{
|
|
||||||
$out .= sprintf("%s", $_);
|
|
||||||
}
|
|
||||||
|
|
||||||
close Xt_GEOIPSTATS;
|
|
||||||
$out .= sprintf "</pre>";
|
|
||||||
|
|
||||||
$out .= sprintf("<h3>%s</h3>", $c->l('xtg_END_OF_STATS'));
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#Subroutine to list counries codes
|
|
||||||
sub generateCodes {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
|
|
||||||
my $out = '';
|
|
||||||
|
|
||||||
# my $now_string = $c->gen_locale_date_string();
|
|
||||||
my $file = "/usr/share/xt_geoip/geoip_countries_list.txt";
|
|
||||||
unless ( -e $file ) {
|
|
||||||
$out .= "<br>" . $c->l('xtg_INVALID_CODES_LIST');
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $filetime = ( -e $file ) ? (stat($file))[9] : 0;
|
|
||||||
my $date_string = strftime("%Y/%m/%d %H:%M", localtime( $filetime )) || '';
|
|
||||||
|
|
||||||
$out .= sprintf("<h3>%s %s </h3>", $c->l('xtg_COUNTRY_LIST'), $date_string);
|
|
||||||
|
|
||||||
|
|
||||||
open( Xt_GEOIPCODES, $file );
|
|
||||||
|
|
||||||
$out .= sprintf "<pre>";
|
|
||||||
|
|
||||||
while (<Xt_GEOIPCODES>) {
|
|
||||||
$out .= sprintf("%s", $_);
|
|
||||||
}
|
|
||||||
|
|
||||||
close Xt_GEOIPCODES;
|
|
||||||
$out .= sprintf "</pre>";
|
|
||||||
|
|
||||||
$out .= sprintf("<h3>%s</h3>", $c->l('xtg_END_OF_CODES'));
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#Subroutine to list other services codes
|
|
||||||
sub otherServices {
|
|
||||||
|
|
||||||
my ($c, $choice) = @_;
|
|
||||||
|
|
||||||
my %serv_ok = map { $_ => 1} split(/,/, $cdb->get_prop("masq", "XtServices"));
|
|
||||||
# unless $choice eq 'all';
|
|
||||||
|
|
||||||
my @serv_others = ();
|
|
||||||
|
|
||||||
for ($cdb->get_all_by_prop(type => 'service')) {
|
|
||||||
next unless $_->prop('TCPPort');
|
|
||||||
# if ( $_->prop('TCPPort')) {
|
|
||||||
|
|
||||||
# push @serv_others, $_->key unless exists( $serv_ok{$_->key});
|
|
||||||
push @serv_others, $_->key unless $choice eq 'sel' and not exists( $serv_ok{$_->key});
|
|
||||||
# }
|
|
||||||
}
|
|
||||||
|
|
||||||
return \@serv_others;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#Subroutine to update list services codes
|
|
||||||
sub do_otherServices {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
|
|
||||||
my $serv1 = ($cdb->get_prop("masq", "XtServices")) || '';
|
|
||||||
my $serv2 = join( ',', @{$c->every_param('Selectedservices')} );
|
|
||||||
|
|
||||||
$cdb->set_prop("masq", "XtServices", $serv2) if ( $serv1 ne $serv2);
|
|
||||||
|
|
||||||
return 'OK';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub change_settings {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
|
|
||||||
my $mq_bc = get_badcountries();
|
|
||||||
my $mq_gp = get_geoip();
|
|
||||||
my $masq = $cdb->get('masq') || "disabled";
|
|
||||||
my $mq_rv = $masq->prop('XTGeoipRev') || 'disabled';
|
|
||||||
my $mq_ot = $masq->prop('XTGeoipOther') || 'disabled';
|
|
||||||
|
|
||||||
my $n_mq_bc = $c->param("Masq_badcountries");
|
|
||||||
my $n_mq_gp = $c->param("Masq_geoip") || $mq_gp;
|
|
||||||
my $n_upd_gp = $c->param("Update_geoip") || '';
|
|
||||||
my $n_mq_rv = $c->param("Masq_reverse") || $mq_rv ;
|
|
||||||
my $n_mq_ot = $c->param("Masq_others") || $mq_ot ;
|
|
||||||
|
|
||||||
if (($n_mq_bc eq $mq_bc) && ($n_mq_gp eq $mq_gp) && ($n_upd_gp eq 'NO') && ($n_mq_rv eq $mq_rv) && ($n_mq_ot eq $mq_ot)) {
|
|
||||||
return 'OK'
|
|
||||||
}
|
|
||||||
|
|
||||||
$cdb->set_prop("masq", "BadCountries", $n_mq_bc);
|
|
||||||
$cdb->set_prop("masq", "GeoIP", $n_mq_gp);
|
|
||||||
$cdb->set_prop("masq", "XTGeoipRev", $n_mq_rv);
|
|
||||||
$cdb->set_prop("masq", "XTGeoipOther", $n_mq_ot);
|
|
||||||
|
|
||||||
my $eventloc = "xt_geoip-modify";
|
|
||||||
$eventloc = "xt_geoip-update" if $n_upd_gp eq 'YES';
|
|
||||||
|
|
||||||
unless ( system ( "/sbin/e-smith/signal-event", $eventloc ) == 0 ) {
|
|
||||||
return $c->l("xtg_ERROR_UPDATING");
|
|
||||||
}
|
|
||||||
return 'OK';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
=head2 valid_badcountries
|
|
||||||
|
|
||||||
subroutine to validate countries.
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub must_exist {
|
|
||||||
|
|
||||||
my $c = shift;
|
|
||||||
|
|
||||||
my $listerr = "";
|
|
||||||
my @mq_bcs = split /[,:]/, $c->param("Masq_badcountries");
|
|
||||||
if (@mq_bcs) {
|
|
||||||
my $ctr = @mq_bcs;
|
|
||||||
|
|
||||||
return $c->l('xtg_ERROR_COUNTRY_MAX', $ctr) if ($ctr > 50);
|
|
||||||
|
|
||||||
foreach my $bcs (@mq_bcs) {
|
|
||||||
my $file = "/usr/share/xt_geoip/LE/" . $bcs . ".iv4";
|
|
||||||
if (! -f $file) { $listerr .= $bcs . ","; }
|
|
||||||
}
|
|
||||||
|
|
||||||
return $c->l('xtg_ERROR_COUNTRY_NOT_EXIST', $listerr) if $listerr;
|
|
||||||
}
|
|
||||||
return 'OK';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub remove_serv {
|
|
||||||
|
|
||||||
my ( $c ) = @_;
|
|
||||||
my $name = $c->param('Name');
|
|
||||||
|
|
||||||
# Untaint $name before use in system()
|
|
||||||
$name =~ /(.+)/; $name = $1;
|
|
||||||
|
|
||||||
if (my $serv = $cdb->get($name)) {
|
|
||||||
my $servBC = $serv->prop('BadCountries') || '';
|
|
||||||
if ($servBC ne '') {
|
|
||||||
my $tps = $cdb->get_prop_and_delete($name, "BadCountries");
|
|
||||||
$tps = $cdb->get_prop_and_delete($name, "XTGeoipRev");
|
|
||||||
|
|
||||||
unless (system ("/sbin/e-smith/signal-event", "xt_geoip-service") == 0) {
|
|
||||||
return $c->l("xtg_ERROR_WHILE_DELETING_SERVICE").' '.$name;
|
|
||||||
}
|
|
||||||
return 'OK';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $c->l('xtg_CANT_FIND_SERV');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub modify_serv {
|
|
||||||
|
|
||||||
my ($c) = @_;
|
|
||||||
my $name = $c->param('Name');
|
|
||||||
|
|
||||||
# Untaint $name before use in system()
|
|
||||||
$name =~ /(.+)/; $name = $1;
|
|
||||||
|
|
||||||
if (my $serv = $cdb->get($name)) {
|
|
||||||
my $servBC = $serv->prop('BadCountries') || '';
|
|
||||||
my $servRev = $serv->prop('XTGeoipRev') || 'disabled';
|
|
||||||
|
|
||||||
my $n_servBC = $c->param("Masq_srv_badcountries");
|
|
||||||
my $n_servRev = $c->param("Masq_srv_reverse") || $servRev;
|
|
||||||
|
|
||||||
if ($n_servBC eq $servBC && $n_servRev eq $servRev ) {
|
|
||||||
return 'OK';
|
|
||||||
}
|
|
||||||
|
|
||||||
$cdb->set_prop($name, "BadCountries", $n_servBC);
|
|
||||||
$cdb->set_prop($name, "XTGeoipRev", $n_servRev);
|
|
||||||
|
|
||||||
unless (system ( "/sbin/e-smith/signal-event", "xt_geoip-service" ) == 0 ) {
|
|
||||||
return $c->l("xtg_ERROR_UPDATING").' '.$name;
|
|
||||||
}
|
|
||||||
return 'OK';
|
|
||||||
} else {
|
|
||||||
return $c->l('xtg_CANT_FIND_SERV');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
|
||||||
1026
root/usr/share/smanager/lib/SrvMngr/Controller/Xtgeoip.pm
Normal file
1026
root/usr/share/smanager/lib/SrvMngr/Controller/Xtgeoip.pm
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<HR class='sme-copyrightbar'>
|
<HR class='sme-copyrightbar'>
|
||||||
|
|
||||||
%= form_for '/xt_geoip' => (method => 'POST') => begin
|
%= form_for '/xtgeoip' => (method => 'POST') => begin
|
||||||
|
|
||||||
%= $c->render_to_string(inline => l('xtg_COUNTRY_LIST_DESCRIPTION'));
|
%= $c->render_to_string(inline => l('xtg_COUNTRY_LIST_DESCRIPTION'));
|
||||||
%= submit_button l 'xtg_CNTRY_LIST', class => 'action'
|
%= submit_button l 'xtg_CNTRY_LIST', class => 'action'
|
||||||
@@ -11,4 +11,4 @@
|
|||||||
% end
|
% end
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- button_to l('xtg_CNTRY_LIST') => "/xt_geoip" => (class => 'action') -->
|
<!-- button_to l('xtg_CNTRY_LIST') => "/xgteoip" => (class => 'action') -->
|
||||||
|
|||||||
@@ -2,41 +2,41 @@
|
|||||||
|
|
||||||
<HR class='sme-copyrightbar'>
|
<HR class='sme-copyrightbar'>
|
||||||
|
|
||||||
%= form_for '/xt_geoip' => (method => 'POST') => begin
|
%= form_for '/xtgeoip' => (method => 'POST') => begin
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
%= l('xtg_SERVICE_DESCRIPTION')
|
%= l('xtg_SERVICE_DESCRIPTION')
|
||||||
</h2>
|
</h2>
|
||||||
%= $c->render_to_string(inline => l('xtg_SERVICE_DESCRIPTION2'));
|
%= $c->render_to_string(inline => l('xtg_SERVICE_DESCRIPTION2'));
|
||||||
|
|
||||||
% my @services = @{$c->get_services_table('sel')};
|
% my @services = @{$c->get_services_table('sel')};
|
||||||
% if (scalar @services == 0) {
|
% if (scalar @services == 0) {
|
||||||
%=l 'xtg_NO_SERVICES'
|
%=l 'xtg_NO_SERVICES'
|
||||||
% } else {
|
% } else {
|
||||||
<table class="sme-border"><tbody>
|
<table class="sme-border"><tbody>
|
||||||
<tr><th class='sme-border'>
|
<tr><th class='sme-border'>
|
||||||
%=l 'NAME'
|
%=l 'NAME'
|
||||||
</th><th class='sme-border'>
|
</th><th class='sme-border'>
|
||||||
%=l 'PORT'
|
%=l 'PORT'
|
||||||
</th><th class='sme-border'>
|
</th><th class='sme-border'>
|
||||||
%=l 'STATUS'
|
%=l 'STATUS'
|
||||||
</th><th class='sme-border'>
|
</th><th class='sme-border'>
|
||||||
%=l 'ACCESS'
|
%=l 'ACCESS'
|
||||||
</th><th class='sme-border'>
|
</th><th class='sme-border'>
|
||||||
%=l 'xtg_BADCOUNTRIES'
|
%=l 'xtg_BADCOUNTRIES'
|
||||||
</th><th class='sme-border' colspan='2'>
|
</th><th class='sme-border' colspan='2'>
|
||||||
%=l 'ACTION'
|
%=l 'ACTION'
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
% foreach my $sv (@services) {
|
% foreach my $sv (@services) {
|
||||||
% my $svBC = $sv->prop('BadCountries') || ' ';
|
% my $svBC = $sv->prop('BadCountries') || ' ';
|
||||||
% my $svRev = (( $sv->prop('Xt_geoipRev')|| 'disabled') eq 'disabled' )? '==': '!=';
|
% my $svRev = (( $sv->prop('XTGeoipRev')|| 'disabled') eq 'disabled' )? '==': '!=';
|
||||||
% my $color = 'red';
|
% my $color = 'red';
|
||||||
% my $deco= "none";
|
% my $deco= "none";
|
||||||
% if ($svRev eq '!=' ) { $color = 'green'; }
|
% if ($svRev eq '!=' ) { $color = 'green'; }
|
||||||
% if ($sv->prop('status') eq 'disabled' || $sv->prop('access') ne 'public') { $color = 'grey'; $deco= "line-through"; }
|
% if ($sv->prop('status') eq 'disabled' || $sv->prop('access') ne 'public') { $color = 'grey'; $deco= "line-through"; }
|
||||||
% my $BC = "<font color='$color' style='text-decoration: $deco'>"."$svRev $svBC"."</font>";
|
% my $BC = "<font color='$color' style='text-decoration: $deco'>"."$svRev $svBC"."</font>";
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
%= t td => (class => 'sme-border') => $sv->key
|
%= t td => (class => 'sme-border') => $sv->key
|
||||||
@@ -45,15 +45,15 @@
|
|||||||
%= t td => (class => 'sme-border') => $sv->prop('access')
|
%= t td => (class => 'sme-border') => $sv->prop('access')
|
||||||
%= t td => (class => 'sme-border') => $c->render_to_string(inline => $BC)
|
%= t td => (class => 'sme-border') => $c->render_to_string(inline => $BC)
|
||||||
|
|
||||||
% my $actionModify = "<a href='xt_geoipb?Choice=UPDS&Name=" . $sv->key . "'>" . l('MODIFY') . "</a>";
|
% my $actionModify = "<a href='xtgeoipb?Choice=UPDS&Name=" . $sv->key . "'>" . l('MODIFY') . "</a>";
|
||||||
% my $actionRemove = "<a href='xt_geoipb?Choice=REMS&Name=" . $sv->key . "'>" . l('REMOVE') . "</a>";
|
% my $actionRemove = "<a href='xtgeoipb?Choice=REMS&Name=" . $sv->key . "'>" . l('REMOVE') . "</a>";
|
||||||
|
|
||||||
<td class='sme-border'><%= $c->render_to_string(inline => $actionModify) %></td>
|
<td class='sme-border'><%= $c->render_to_string(inline => $actionModify) %></td>
|
||||||
<td class='sme-border'><%= $c->render_to_string(inline => $actionRemove) %></td>
|
<td class='sme-border'><%= $c->render_to_string(inline => $actionRemove) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
% }
|
% }
|
||||||
</tbody></table>
|
</tbody></table>
|
||||||
% }
|
% }
|
||||||
|
|
||||||
%= $c->render_to_string(inline => l('xtg_SERVICE_LIST_DESCRIPTION'));
|
%= $c->render_to_string(inline => l('xtg_SERVICE_LIST_DESCRIPTION'));
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
%= $c->render_to_string(inline => l('xtg_STATS_DESCRIPTION'));
|
%= $c->render_to_string(inline => l('xtg_STATS_DESCRIPTION'));
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
%= form_for '/xt_geoip' => (method => 'POST') => begin
|
%= form_for '/xtgeoip' => (method => 'POST') => begin
|
||||||
|
|
||||||
%= $c->render_to_string(inline => l('xtg_IPT_LIST_DESCRIPTION'));
|
%= $c->render_to_string(inline => l('xtg_IPT_LIST_DESCRIPTION'));
|
||||||
%= submit_button l 'xtg_IPT_LIST', class => 'action'
|
%= submit_button l 'xtg_IPT_LIST', class => 'action'
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
% end
|
% end
|
||||||
|
|
||||||
%= form_for '/xt_geoip' => (method => 'POST') => begin
|
%= form_for '/xtgeoip' => (method => 'POST') => begin
|
||||||
|
|
||||||
%= $c->render_to_string(inline => l('xtg_SSH_LIST_DESCRIPTION'));
|
%= $c->render_to_string(inline => l('xtg_SSH_LIST_DESCRIPTION'));
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
% end
|
% end
|
||||||
|
|
||||||
%= form_for '/xt_geoip' => (method => 'POST') => begin
|
%= form_for '/xtgeoip' => (method => 'POST') => begin
|
||||||
|
|
||||||
%= $c->render_to_string(inline => l('xtg_F2B_LIST_DESCRIPTION'));
|
%= $c->render_to_string(inline => l('xtg_F2B_LIST_DESCRIPTION'));
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
% layout 'default', title => "Smanager - xt_geoip";
|
% layout 'default', title => "Smanager - xtgeoip";
|
||||||
|
|
||||||
% content_for 'module' => begin
|
% content_for 'module' => begin
|
||||||
|
|
||||||
<div id="module" class="module xt_geoip-panel">
|
<div id="module" class="module xt_geoip-panel">
|
||||||
|
|
||||||
%if ($config->{debug} == 1) {
|
%if (config->{debug} == 1) {
|
||||||
<p>
|
<p>
|
||||||
%= dumper $c->current_route
|
%= dumper $c->current_route
|
||||||
%= dumper $xtg_datas
|
%= dumper $xtg_datas
|
||||||
</p>
|
</p>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
% if ( stash 'error' ) {
|
% if ( stash 'error' ) {
|
||||||
<br><div class=sme-error>
|
<br><div class=sme-error>
|
||||||
%= $c->render_to_string(inline => stash 'error')
|
%= $c->render_to_string(inline => stash 'error')
|
||||||
</div>
|
</div>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
<h1><%= $title %></h1>
|
<h1><%= $title %></h1>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
%= $c->render_to_string(inline => l('xtg_XT_GEOIP_STATUS_DESCRIPTION'));
|
%= $c->render_to_string(inline => l('xtg_XT_GEOIP_STATUS_DESCRIPTION'));
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
%= form_for '/xt_geoip' => (method => 'POST') => begin
|
%= form_for '/xtgeoip' => (method => 'POST') => begin
|
||||||
|
|
||||||
<p><span class=label>
|
<p><span class=label>
|
||||||
%=l 'xtg_LABEL_GEOIP_STATUS'
|
%=l 'xtg_LABEL_GEOIP_STATUS'
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
% layout 'default', title => "Smanager - xt_geoip";
|
% layout 'default', title => "Smanager - xtgeoip";
|
||||||
|
|
||||||
% content_for 'module' => begin
|
% content_for 'module' => begin
|
||||||
|
|
||||||
<div id="module" class="module xt_geoip-panel">
|
<div id="module" class="module xt_geoip-panel">
|
||||||
|
|
||||||
%if ($config->{debug} == 1) {
|
%if (config->{debug} == 1) {
|
||||||
<p>
|
<p>
|
||||||
%= dumper $c->current_route
|
%= dumper $c->current_route
|
||||||
%= dumper $xtg_datas
|
%= dumper $xtg_datas
|
||||||
</p>
|
</p>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
% if ( stash 'error' ) {
|
% if ( stash 'error' ) {
|
||||||
<br><div class=sme-error>
|
<br><div class=sme-error>
|
||||||
%= $c->render_to_string(inline => stash 'error')
|
%= $c->render_to_string(inline => stash 'error')
|
||||||
</div>
|
</div>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
<h1><%= $title %></h1>
|
<h1><%= $title %></h1>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
%= $c->render_to_string(inline => l('xtg_DESC_AVAILABLE_SERVICES'));
|
%= $c->render_to_string(inline => l('xtg_DESC_AVAILABLE_SERVICES'));
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
%= form_for '/xt_geoipb' => (method => 'POST') => begin
|
%= form_for '/xtgeoipb' => (method => 'POST') => begin
|
||||||
|
|
||||||
<p><span class=label>
|
<p><span class=label>
|
||||||
%=l 'xtg_LABEL_AVAILABLE_SERVICES'
|
%=l 'xtg_LABEL_AVAILABLE_SERVICES'
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
% layout 'default', title => "Smanager - xt_geoip - List";
|
% layout 'default', title => "Smanager - xtgeoip - List";
|
||||||
|
|
||||||
% content_for 'module' => begin
|
% content_for 'module' => begin
|
||||||
|
|
||||||
<div id="module" class="module xt_geoip-panel">
|
<div id="module" class="module xt_geoip-panel">
|
||||||
|
|
||||||
%if ($config->{debug} == 1) {
|
%if (config->{debug} == 1) {
|
||||||
<p>
|
<p>
|
||||||
%= dumper $c->current_route
|
%= dumper $c->current_route
|
||||||
%= dumper $xtg_datas
|
%= dumper $xtg_datas
|
||||||
</p>
|
</p>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
% if ( stash 'error' ) {
|
% if ( stash 'error' ) {
|
||||||
<br><div class=sme-error>
|
<br><div class=sme-error>
|
||||||
%= $c->render_to_string(inline => stash 'error')
|
%= $c->render_to_string(inline => stash 'error')
|
||||||
</div>
|
</div>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
<h1><%= $title %></h1>
|
<h1><%= $title %></h1>
|
||||||
|
|
||||||
%= form_for '/xt_geoip' => (method => 'GET') => begin
|
%= form_for '/xtgeoip' => (method => 'GET') => begin
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
%= $c->render_to_string(inline => stash 'modul');
|
%= $c->render_to_string(inline => stash 'modul');
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
% layout 'default', title => "Smanager - xt_geoip";
|
% layout 'default', title => "Smanager - xtgeoip";
|
||||||
|
|
||||||
% content_for 'module' => begin
|
% content_for 'module' => begin
|
||||||
|
|
||||||
<div id="module" class="module xt_geoip-panel">
|
<div id="module" class="module xt_geoip-panel">
|
||||||
|
|
||||||
%if ($config->{debug} == 1) {
|
%if (config->{debug} == 1) {
|
||||||
<p>
|
<p>
|
||||||
%= dumper $c->current_route
|
%= dumper $c->current_route
|
||||||
%= dumper $xtg_datas
|
%= dumper $xtg_datas
|
||||||
</p>
|
</p>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
% if ( stash 'error' ) {
|
% if ( stash 'error' ) {
|
||||||
<br><div class=sme-error>
|
<br><div class=sme-error>
|
||||||
%= $c->render_to_string(inline => stash 'error')
|
%= $c->render_to_string(inline => stash 'error')
|
||||||
</div>
|
</div>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
<h1><%= $title %></h1>
|
<h1><%= $title %></h1>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
%= $c->render_to_string(inline => l('xtg_REMOVE_DESC'));
|
%= $c->render_to_string(inline => l('xtg_REMOVE_DESC'));
|
||||||
|
|
||||||
%= form_for '/xt_geoipb' => (method => 'POST') => begin
|
%= form_for '/xtgeoipb' => (method => 'POST') => begin
|
||||||
|
|
||||||
<p><span class=label>
|
<p><span class=label>
|
||||||
%=l 'xtg_LABEL_SERVICE'
|
%=l 'xtg_LABEL_SERVICE'
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
% layout 'default', title => "Smanager - xt_geoip";
|
% layout 'default', title => "Smanager - xtgeoip";
|
||||||
|
|
||||||
% content_for 'module' => begin
|
% content_for 'module' => begin
|
||||||
|
|
||||||
<div id="module" class="module xt_geoip-panel">
|
<div id="module" class="module xt_geoip-panel">
|
||||||
|
|
||||||
%if ($config->{debug} == 1) {
|
%if (config->{debug} == 1) {
|
||||||
<p>
|
<p>
|
||||||
%= dumper $c->current_route
|
%= dumper $c->current_route
|
||||||
%= dumper $xtg_datas
|
%= dumper $xtg_datas
|
||||||
</p>
|
</p>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
% if ( stash 'error' ) {
|
% if ( stash 'error' ) {
|
||||||
<br><div class=sme-error>
|
<br><div class=sme-error>
|
||||||
%= $c->render_to_string(inline => stash 'error')
|
%= $c->render_to_string(inline => stash 'error')
|
||||||
</div>
|
</div>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
<h1><%= $title %></h1>
|
<h1><%= $title %></h1>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
%= $c->render_to_string(inline => l('xtg_ADD_DESC'));
|
%= $c->render_to_string(inline => l('xtg_ADD_DESC'));
|
||||||
|
|
||||||
%= form_for '/xt_geoipb' => (method => 'POST') => begin
|
%= form_for '/xtgeoipb' => (method => 'POST') => begin
|
||||||
|
|
||||||
<p><span class=label>
|
<p><span class=label>
|
||||||
%=l 'xtg_LABEL_SERVICE'
|
%=l 'xtg_LABEL_SERVICE'
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
<br><span class=label>
|
<br><span class=label>
|
||||||
%=l 'xtg_LABEL_REVERSE_MATCH'
|
%=l 'xtg_LABEL_REVERSE_MATCH'
|
||||||
</span><span class=data>
|
</span><span class=data>
|
||||||
% param 'Masq_srv_reverse' => $c->get_reverse('','Xt_geoipRev') unless param 'Masq_srv_reverse';
|
% param 'Masq_srv_reverse' => $c->get_reverse('masq','XTGeoipRev') unless param 'Masq_srv_reverse';
|
||||||
%= select_field 'Masq_srv_reverse' => [['!=' => 'enabled'], ['==' => 'disabled']], class => 'input'
|
%= select_field 'Masq_srv_reverse' => [['!=' => 'enabled'], ['==' => 'disabled']], class => 'input'
|
||||||
</span></p>
|
</span></p>
|
||||||
|
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
% layout 'default', title => "Smanager - xt_geoip";
|
% layout 'default', title => "Smanager - xtgeoip";
|
||||||
|
|
||||||
% content_for 'module' => begin
|
% content_for 'module' => begin
|
||||||
|
|
||||||
<div id="module" class="module xt_geoip-panel">
|
<div id="module" class="module xt_geoip-panel">
|
||||||
|
|
||||||
%if ($config->{debug} == 1) {
|
%if (config->{debug} == 1) {
|
||||||
<p>
|
<p>
|
||||||
%= dumper $c->current_route
|
%= dumper $c->current_route
|
||||||
%= dumper $xtg_datas
|
%= dumper $xtg_datas
|
||||||
</p>
|
</p>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
% if ( stash 'error' ) {
|
% if ( stash 'error' ) {
|
||||||
<br><div class=sme-error>
|
<br><div class=sme-error>
|
||||||
%= $c->render_to_string(inline => stash 'error')
|
%= $c->render_to_string(inline => stash 'error')
|
||||||
</div>
|
</div>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
<h1><%= $title %></h1>
|
<h1><%= $title %></h1>
|
||||||
|
|
||||||
%= form_for '/xt_geoipb' => (method => 'POST') => begin
|
%= form_for '/xtgeoipb' => (method => 'POST') => begin
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
%=l 'xtg_DESC_GEOIP'
|
%=l 'xtg_DESC_GEOIP'
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<br><span class=label>
|
<br><span class=label>
|
||||||
%=l 'xtg_LABEL_REVERSE_MATCH'
|
%=l 'xtg_LABEL_REVERSE_MATCH'
|
||||||
</span><span class=data>
|
</span><span class=data>
|
||||||
% param 'Masq_reverse' => $c->get_reverse('masq','Xt_geoipRev') unless param 'Masq_reverse';
|
% param 'Masq_reverse' => $c->get_reverse('masq','XTGeoipRev') unless param 'Masq_reverse';
|
||||||
%= select_field 'Masq_reverse' => [[ '!=' => 'enabled'], [ '==' => 'disabled']], class => 'input'
|
%= select_field 'Masq_reverse' => [[ '!=' => 'enabled'], [ '==' => 'disabled']], class => 'input'
|
||||||
</span></p>
|
</span></p>
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<br><span class=label>
|
<br><span class=label>
|
||||||
%=l 'xtg_LABEL_OTHERS'
|
%=l 'xtg_LABEL_OTHERS'
|
||||||
</span><span class=data>
|
</span><span class=data>
|
||||||
% param 'Masq_others' => $c->get_reverse('masq','Xt_geoipOther') unless param 'Masq_others';
|
% param 'Masq_others' => $c->get_reverse('masq','XT_GeoipOther') unless param 'Masq_others';
|
||||||
%= select_field 'Masq_others' => [[(l 'DISABLED') => 'disabled'], [(l 'ENABLED') => 'enabled']], class => 'input'
|
%= select_field 'Masq_others' => [[(l 'DISABLED') => 'disabled'], [(l 'ENABLED') => 'enabled']], class => 'input'
|
||||||
</span></p>
|
</span></p>
|
||||||
|
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
|
# Run the builder - this leaves all the file in /usr.share/xt_geoip
|
||||||
|
# It's messy but I don't know how to get iptables to read a sub dir
|
||||||
|
|
||||||
cd /usr/share/xt_geoip
|
cd /usr/share/xt_geoip
|
||||||
if ( ./xt_geoip_dl )
|
if ( ./xt_geoip_dl )
|
||||||
then
|
then
|
||||||
/usr/libexec/xtables-addons/xt_geoip_build GeoIPCountryWhois.csv
|
/usr/share/xt_geoip/xt_geoip_build_maxmind
|
||||||
fi
|
fi
|
||||||
257
root/usr/share/xt_geoip/xt_geoip_build_maxmind
Normal file
257
root/usr/share/xt_geoip/xt_geoip_build_maxmind
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
#
|
||||||
|
# Converter for MaxMind (GeoLite2) CSV database to binary, for xt_geoip
|
||||||
|
# Copyright Jan Engelhardt, 2008-2011
|
||||||
|
# Copyright Philip Prindeville, 2018
|
||||||
|
# copied from /usr/libexec/xtables-addons to work on Koozali SME v11
|
||||||
|
# cannot work out to get iptables to read from a sub directory from a here
|
||||||
|
#
|
||||||
|
use Getopt::Long;
|
||||||
|
use Net::CIDR::Lite;
|
||||||
|
use Socket qw(AF_INET AF_INET6 inet_pton);
|
||||||
|
use warnings;
|
||||||
|
use Text::CSV_XS; # or trade for Text::CSV
|
||||||
|
use strict;
|
||||||
|
$| = 1;
|
||||||
|
my $csv = Text::CSV_XS->new(
|
||||||
|
{ allow_whitespace => 1,
|
||||||
|
binary => 1,
|
||||||
|
eol => $/,
|
||||||
|
}
|
||||||
|
); # or Text::CSV
|
||||||
|
|
||||||
|
#my $source_dir = ".";
|
||||||
|
my $source_dir = "./GeoLite2-Country-CSV";
|
||||||
|
my $quiet = 0;
|
||||||
|
my $target_dir = ".";
|
||||||
|
&Getopt::Long::Configure(qw(bundling));
|
||||||
|
&GetOptions(
|
||||||
|
"D=s" => \$target_dir,
|
||||||
|
"S=s" => \$source_dir,
|
||||||
|
"q" => \$quiet,
|
||||||
|
"s" => sub { $target_dir = "/usr/share/xt_geoip"; },
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!-d $source_dir) {
|
||||||
|
print STDERR "Source directory \"$source_dir\" does not exist.\n";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!-d $target_dir) {
|
||||||
|
print STDERR "Target directory \"$target_dir\" does not exist.\n";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
my %countryId;
|
||||||
|
my %countryName;
|
||||||
|
&loadCountries();
|
||||||
|
&dump(&collect());
|
||||||
|
|
||||||
|
sub loadCountries {
|
||||||
|
sub id;
|
||||||
|
sub cc;
|
||||||
|
sub long;
|
||||||
|
sub ct;
|
||||||
|
sub cn;
|
||||||
|
%countryId = ();
|
||||||
|
%countryName = ();
|
||||||
|
my $file = "$source_dir/GeoLite2-Country-Locations-en.csv";
|
||||||
|
open(my $fh, '<', $file) || die "Couldn't open list country names\n";
|
||||||
|
|
||||||
|
# first line is headers
|
||||||
|
my $row = $csv->getline($fh);
|
||||||
|
my %header = map { ($row->[$_], $_); } (0 .. $#{$row});
|
||||||
|
my %pairs = (
|
||||||
|
country_iso_code => 'ISO Country Code',
|
||||||
|
geoname_id => 'ID',
|
||||||
|
country_name => 'Country Name',
|
||||||
|
continent_code => 'Continent Code',
|
||||||
|
continent_name => 'Continent Name',
|
||||||
|
);
|
||||||
|
|
||||||
|
# verify that the columns we need are present
|
||||||
|
map { die "Table has no $pairs{$_} column\n" unless (exists $header{$_}); } keys %pairs;
|
||||||
|
my %remapping = (
|
||||||
|
id => 'geoname_id',
|
||||||
|
cc => 'country_iso_code',
|
||||||
|
long => 'country_name',
|
||||||
|
ct => 'continent_code',
|
||||||
|
cn => 'continent_name',
|
||||||
|
);
|
||||||
|
|
||||||
|
# now create a function which returns the value of that column #
|
||||||
|
map { eval "sub $_ () { \$header{\$remapping{$_}}; }"; } keys %remapping;
|
||||||
|
|
||||||
|
while (my $row = $csv->getline($fh)) {
|
||||||
|
if ($row->[cc] eq '' && $row->[long] eq '') {
|
||||||
|
$countryId{ $row->[id] } = $row->[ct];
|
||||||
|
$countryName{ $row->[ct] } = $row->[cn];
|
||||||
|
} else {
|
||||||
|
$countryId{ $row->[id] } = $row->[cc];
|
||||||
|
$countryName{ $row->[cc] } = $row->[long];
|
||||||
|
}
|
||||||
|
} ## end while (my $row = $csv->getline...)
|
||||||
|
$countryName{A1} = 'Anonymous Proxy';
|
||||||
|
$countryName{A2} = 'Satellite Provider';
|
||||||
|
$countryName{O1} = 'Other Country';
|
||||||
|
close($fh);
|
||||||
|
|
||||||
|
# clean up the namespace
|
||||||
|
undef &id;
|
||||||
|
undef &cc;
|
||||||
|
undef &long;
|
||||||
|
undef &ct;
|
||||||
|
undef &cn;
|
||||||
|
} ## end sub loadCountries
|
||||||
|
|
||||||
|
sub lookupCountry {
|
||||||
|
my ($id, $rid, $proxy, $sat) = @_;
|
||||||
|
|
||||||
|
if ($proxy) {
|
||||||
|
return 'A1';
|
||||||
|
} elsif ($sat) {
|
||||||
|
return 'A2';
|
||||||
|
}
|
||||||
|
$id ||= $rid;
|
||||||
|
|
||||||
|
if ($id eq '') {
|
||||||
|
return 'O1';
|
||||||
|
}
|
||||||
|
die "Unknown id: $id line $.\n" unless (exists $countryId{$id});
|
||||||
|
return $countryId{$id};
|
||||||
|
} ## end sub lookupCountry
|
||||||
|
|
||||||
|
sub collect {
|
||||||
|
my ($file, $fh, $row);
|
||||||
|
my (%country, %header);
|
||||||
|
sub net;
|
||||||
|
sub id;
|
||||||
|
sub rid;
|
||||||
|
sub proxy;
|
||||||
|
sub sat;
|
||||||
|
my %pairs = (
|
||||||
|
network => 'Network',
|
||||||
|
registered_country_geoname_id => 'Registered Country ID',
|
||||||
|
geoname_id => 'Country ID',
|
||||||
|
is_anonymous_proxy => 'Anonymous Proxy',
|
||||||
|
is_satellite_provider => 'Satellite',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (sort keys %countryName) {
|
||||||
|
$country{$_} = {
|
||||||
|
name => $countryName{$_},
|
||||||
|
pool_v4 => Net::CIDR::Lite->new(),
|
||||||
|
pool_v6 => Net::CIDR::Lite->new(),
|
||||||
|
};
|
||||||
|
} ## end foreach (sort keys %countryName)
|
||||||
|
$file = "$source_dir/GeoLite2-Country-Blocks-IPv4.csv";
|
||||||
|
open($fh, '<', $file) || die "Can't open IPv4 database\n";
|
||||||
|
|
||||||
|
# first line is headers
|
||||||
|
$row = $csv->getline($fh);
|
||||||
|
%header = map { ($row->[$_], $_); } (0 .. $#{$row});
|
||||||
|
|
||||||
|
# verify that the columns we need are present
|
||||||
|
map { die "Table has no %pairs{$_} column\n" unless (exists $header{$_}); } keys %pairs;
|
||||||
|
my %remapping = (
|
||||||
|
net => 'network',
|
||||||
|
id => 'geoname_id',
|
||||||
|
rid => 'registered_country_geoname_id',
|
||||||
|
proxy => 'is_anonymous_proxy',
|
||||||
|
sat => 'is_satellite_provider',
|
||||||
|
);
|
||||||
|
|
||||||
|
# now create a function which returns the value of that column #
|
||||||
|
map { eval "sub $_ () { \$header{\$remapping{$_}}; }"; } keys %remapping;
|
||||||
|
|
||||||
|
while ($row = $csv->getline($fh)) {
|
||||||
|
my ($cc, $cidr);
|
||||||
|
$cc = lookupCountry($row->[id], $row->[rid], $row->[proxy], $row->[sat]);
|
||||||
|
$cidr = $row->[net];
|
||||||
|
$country{$cc}->{pool_v4}->add($cidr);
|
||||||
|
|
||||||
|
if (!$quiet && $. % 4096 == 0) {
|
||||||
|
print STDOUT "\r\e[2K$. entries";
|
||||||
|
}
|
||||||
|
} ## end while ($row = $csv->getline...)
|
||||||
|
print STDOUT "\r\e[2K$. entries total\n" unless ($quiet);
|
||||||
|
close($fh);
|
||||||
|
|
||||||
|
# clean up the namespace
|
||||||
|
undef &net;
|
||||||
|
undef &id;
|
||||||
|
undef &rid;
|
||||||
|
undef &proxy;
|
||||||
|
undef &sat;
|
||||||
|
$file = "$source_dir/GeoLite2-Country-Blocks-IPv6.csv";
|
||||||
|
open($fh, '<', $file) || die "Can't open IPv6 database\n";
|
||||||
|
|
||||||
|
# first line is headers
|
||||||
|
$row = $csv->getline($fh);
|
||||||
|
%header = map { ($row->[$_], $_); } (0 .. $#{$row});
|
||||||
|
|
||||||
|
# verify that the columns we need are present
|
||||||
|
map { die "Table has no %pairs{$_} column\n" unless (exists $header{$_}); } keys %pairs;
|
||||||
|
|
||||||
|
# unlikely the IPv6 table has different columns, but just to be sure
|
||||||
|
# create a function which returns the value of that column #
|
||||||
|
map { eval "sub $_ () { \$header{\$remapping{$_}}; }"; } keys %remapping;
|
||||||
|
|
||||||
|
while ($row = $csv->getline($fh)) {
|
||||||
|
my ($cc, $cidr);
|
||||||
|
$cc = lookupCountry($row->[id], $row->[rid], $row->[proxy], $row->[sat]);
|
||||||
|
$cidr = $row->[net];
|
||||||
|
$country{$cc}->{pool_v6}->add($cidr);
|
||||||
|
|
||||||
|
if (!$quiet && $. % 4096 == 0) {
|
||||||
|
print STDOUT "\r\e[2K$. entries";
|
||||||
|
}
|
||||||
|
} ## end while ($row = $csv->getline...)
|
||||||
|
print STDOUT "\r\e[2K$. entries total\n" unless ($quiet);
|
||||||
|
close($fh);
|
||||||
|
|
||||||
|
# clean up the namespace
|
||||||
|
undef &net;
|
||||||
|
undef &id;
|
||||||
|
undef &rid;
|
||||||
|
undef &proxy;
|
||||||
|
undef &sat;
|
||||||
|
return \%country;
|
||||||
|
} ## end sub collect
|
||||||
|
|
||||||
|
sub dump {
|
||||||
|
my $country = shift @_;
|
||||||
|
|
||||||
|
foreach my $iso_code (sort keys %{$country}) {
|
||||||
|
&dump_one($iso_code, $country->{$iso_code});
|
||||||
|
}
|
||||||
|
} ## end sub dump
|
||||||
|
|
||||||
|
sub dump_one {
|
||||||
|
my ($iso_code, $country) = @_;
|
||||||
|
my @ranges;
|
||||||
|
@ranges = $country->{pool_v4}->list_range();
|
||||||
|
writeCountry($iso_code, $country->{name}, AF_INET, @ranges);
|
||||||
|
@ranges = $country->{pool_v6}->list_range();
|
||||||
|
writeCountry($iso_code, $country->{name}, AF_INET6, @ranges);
|
||||||
|
} ## end sub dump_one
|
||||||
|
|
||||||
|
sub writeCountry {
|
||||||
|
my ($iso_code, $name, $family, @ranges) = @_;
|
||||||
|
my $fh;
|
||||||
|
printf "%5u IPv%s ranges for %s %s\n", scalar(@ranges), ($family == AF_INET ? '4' : '6'), $iso_code, $name unless ($quiet);
|
||||||
|
my $file = "$target_dir/" . uc($iso_code) . ".iv" . ($family == AF_INET ? '4' : '6');
|
||||||
|
|
||||||
|
if (!open($fh, '>', $file)) {
|
||||||
|
print STDERR "Error opening $file: $!\n";
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
binmode($fh);
|
||||||
|
|
||||||
|
foreach my $range (@ranges) {
|
||||||
|
my ($start, $end) = split('-', $range);
|
||||||
|
$start = inet_pton($family, $start);
|
||||||
|
$end = inet_pton($family, $end);
|
||||||
|
print $fh $start, $end;
|
||||||
|
} ## end foreach my $range (@ranges)
|
||||||
|
close $fh;
|
||||||
|
} ## end sub writeCountry
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
# Original script from xtables-addons
|
# Original script from xtables-addons
|
||||||
# SME specific use of ConfigDB
|
# SME specific use of ConfigDB
|
||||||
# replace /usr/libexec/xtables-addons/xt_geoip_dl in /usr/share/xt_geoip/update_base
|
# replace /usr/libexec/xtables-addons/xt_geoip_dl in /usr/share/xt_geoip/update_base
|
||||||
|
# Koozali SME v11
|
||||||
|
# Now migrated to using files in /usr/share/xt_geoip
|
||||||
|
|
||||||
|
|
||||||
status=$(/sbin/e-smith/config getprop geoip status)
|
status=$(/sbin/e-smith/config getprop geoip status)
|
||||||
if [[ "$status" != "enabled" ]]
|
if [[ "$status" != "enabled" ]]
|
||||||
@@ -26,5 +29,9 @@ then
|
|||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unzip -q GeoLite2-Country-CSV.zip
|
# unzip -q GeoLite2-Country-CSV.zip
|
||||||
|
if [ ! -d "/usr/share/xt_geoip/GeoLite2-Country-CSV" ]; then
|
||||||
|
mkdir -p "/usr/share/xt_geoip/GeoLite2-Country-CSV";
|
||||||
|
fi
|
||||||
|
unzip -o -q -j GeoLite2-Country-CSV.zip -d /usr/share/xt_geoip/GeoLite2-Country-CSV
|
||||||
rm -f GeoLite2-Country-CSV.zip
|
rm -f GeoLite2-Country-CSV.zip
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
%define name smeserver-xt_geoip
|
%define name smeserver-xt_geoip
|
||||||
%define version 1.3.1
|
%define version 1.3.1
|
||||||
%define release 22
|
%define release 31
|
||||||
|
|
||||||
Summary: smserver rpm to setup database, update and configuration for xt_geoip module with a panel.
|
Summary: smserver rpm to setup database, update and configuration for xt_geoip module with a panel.
|
||||||
Name: %{name}
|
Name: %{name}
|
||||||
@@ -14,14 +14,17 @@ Source: %{name}-%{version}.tar.xz
|
|||||||
BuildArchitectures: noarch
|
BuildArchitectures: noarch
|
||||||
BuildRoot: /var/tmp/%{name}-%{version}
|
BuildRoot: /var/tmp/%{name}-%{version}
|
||||||
BuildRequires: e-smith-devtools
|
BuildRequires: e-smith-devtools
|
||||||
Requires: e-smith-release >= 10.0
|
Requires: e-smith-release >= 11.0
|
||||||
Requires: server-manager >= 0.1.0-23
|
Requires: server-manager >= 11
|
||||||
Requires: xtables-addons = 2.14
|
Requires: xtables-addons >= 3.25
|
||||||
Requires: GeoIP >= 1.5.0
|
# Is this required now?
|
||||||
|
Requires: GeoIP >= 1.6.0
|
||||||
Requires: libmaxminddb >= 1.1.1
|
Requires: libmaxminddb >= 1.1.1
|
||||||
|
# Is this required now?
|
||||||
Requires: libmaxminddb-devel >= 1.1.1
|
Requires: libmaxminddb-devel >= 1.1.1
|
||||||
Requires: geolite2-country
|
Requires: geolite2-country
|
||||||
Requires: geolite2-city
|
Requires: geolite2-city
|
||||||
|
Requires: perl-Text-CSV_XS
|
||||||
AutoReqProv: no
|
AutoReqProv: no
|
||||||
|
|
||||||
%description
|
%description
|
||||||
@@ -53,6 +56,7 @@ rm -f %{name}-%{version}-filelist
|
|||||||
--file /usr/share/xt_geoip/geoip_stats 'attr(0755, root, root)'\
|
--file /usr/share/xt_geoip/geoip_stats 'attr(0755, root, root)'\
|
||||||
--file /usr/share/xt_geoip/xt_geoip_dl 'attr(0750, root, root)'\
|
--file /usr/share/xt_geoip/xt_geoip_dl 'attr(0750, root, root)'\
|
||||||
--file /usr/share/xt_geoip/update_base 'attr(0750, root, root)'\
|
--file /usr/share/xt_geoip/update_base 'attr(0750, root, root)'\
|
||||||
|
--file /usr/share/xt_geoip/xt_geoip_build_maxmind 'attr(0750, root, root)'\
|
||||||
> %{name}-%{version}-filelist
|
> %{name}-%{version}-filelist
|
||||||
echo "%doc COPYING" >> %{name}-%{version}-filelist
|
echo "%doc COPYING" >> %{name}-%{version}-filelist
|
||||||
|
|
||||||
@@ -65,10 +69,6 @@ rm -rf %{name}-%{version}
|
|||||||
|
|
||||||
%post
|
%post
|
||||||
|
|
||||||
if (systemctl list-unit-files |grep smanager) then
|
|
||||||
echo "Smanager restart in spec file"
|
|
||||||
/sbin/e-smith/signal-event smanager-refresh;
|
|
||||||
fi
|
|
||||||
|
|
||||||
%postun
|
%postun
|
||||||
|
|
||||||
@@ -78,6 +78,41 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Oct 28 2025 Jean-Philippe Pialasse <jpp@koozali.org> 1.3.1-31.sme
|
||||||
|
- Update the references in Createlinks to smeserver-*-update [SME: 13249]
|
||||||
|
thanks to Zsolt Vasarhelyi
|
||||||
|
|
||||||
|
* Wed Oct 22 2025 John Crisp <jcrisp@safeandsoundit.co.uk> 1.3.1-30.sme
|
||||||
|
- Fix error in patch for [SME: 12445]
|
||||||
|
- Tidy template
|
||||||
|
|
||||||
|
* Tue Oct 21 2025 John Crisp <jcrisp@safeandsoundit.co.uk> 1.3.1-29.sme
|
||||||
|
- Fix SmartMatch errors [SME: 13240]
|
||||||
|
- Fix panel errors [SME: 13173]
|
||||||
|
- Do not block remote access authorized [SME: 12445]
|
||||||
|
|
||||||
|
* Tue Oct 07 2025 Brian Read <brianr@koozali.org> 1.3.1-28.sme
|
||||||
|
- Add UTF8 and avoid potential DB caching problems [SME: 13209]
|
||||||
|
|
||||||
|
* Sat Oct 04 2025 Brian Read <brianr@koozali.org> 1.3.1-27.sme
|
||||||
|
- Remove smanager-refresh from spec file [SME: 13212]
|
||||||
|
|
||||||
|
* Thu Mar 20 2025 John Crisp <jcrisp@safeandsoundit.co.uk> 1.3.1-26.sme
|
||||||
|
- Fix createlink typo remote-access-update [SME: 12438]
|
||||||
|
|
||||||
|
* Thu Feb 13 2025 John Crisp <jcrisp@safeandsoundit.co.uk> 1.3.1-25.sme
|
||||||
|
- Fix various typos as per bug but more to find [SME: 12472]
|
||||||
|
|
||||||
|
* Thu Feb 13 2025 John Crisp <jcrisp@safeandsoundit.co.uk> 1.3.1-24.sme
|
||||||
|
- move scripting back to /usr/share/geoip
|
||||||
|
- Lose the LE/BE (Little/Big Endian) parts as iptables can't seem to read the file in subdirs
|
||||||
|
- Update ULOG to NFLOG in rules but restricts the number of countries
|
||||||
|
|
||||||
|
* Wed Feb 12 2025 John Crisp <jcrisp@safeandsoundit.co.uk> 1.3.1-23.sme
|
||||||
|
- Update dependencies for xtables addons
|
||||||
|
- Remove $ from config in templates
|
||||||
|
- Add db open entries to subs
|
||||||
|
|
||||||
* Sat Sep 07 2024 cvs2git.sh aka Brian Read <brianr@koozali.org> 1.3.1-22.sme
|
* Sat Sep 07 2024 cvs2git.sh aka Brian Read <brianr@koozali.org> 1.3.1-22.sme
|
||||||
- Roll up patches and move to git repo [SME: 12338]
|
- Roll up patches and move to git repo [SME: 12338]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user