mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
firewall: Cleanup rules reloading.
This has been messed up a lot because there were multiple files which indicated that a reload is needed; shell commands were used to create and remove the indicator file; some functions were duplicated.
This commit is contained in:
@@ -1137,4 +1137,23 @@ sub write_file_utf8 ($) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $FIREWALL_RELOAD_INDICATOR = "${General::swroot}/forward/reread";
|
||||||
|
|
||||||
|
sub firewall_config_changed() {
|
||||||
|
open FILE, ">$FIREWALL_RELOAD_INDICATOR" or die "Could not open $FIREWALL_RELOAD_INDICATOR";
|
||||||
|
close FILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub firewall_needs_reload() {
|
||||||
|
if (-e "$FIREWALL_RELOAD_INDICATOR") {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub firewall_reload() {
|
||||||
|
system("/usr/local/bin/forwardfwctrl");
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ if ($fwdfwsettings{'ACTION'} eq 'saverule')
|
|||||||
&newrule;
|
&newrule;
|
||||||
}else{
|
}else{
|
||||||
if($fwdfwsettings{'nosave2'} ne 'on'){
|
if($fwdfwsettings{'nosave2'} ne 'on'){
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
&base;
|
&base;
|
||||||
}
|
}
|
||||||
@@ -404,7 +404,7 @@ if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw toggle'})
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
&General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
|
&General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
&base;
|
&base;
|
||||||
}
|
}
|
||||||
if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
|
if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
|
||||||
@@ -417,12 +417,12 @@ if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw togglelog'})
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
&General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
|
&General::writehasharray($fwdfwsettings{'config'}, \%togglehash);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
&base;
|
&base;
|
||||||
}
|
}
|
||||||
if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
|
if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
|
||||||
{
|
{
|
||||||
&reread_rules;
|
&General::firewall_reload();
|
||||||
&base;
|
&base;
|
||||||
}
|
}
|
||||||
if ($fwdfwsettings{'ACTION'} eq 'editrule')
|
if ($fwdfwsettings{'ACTION'} eq 'editrule')
|
||||||
@@ -469,7 +469,7 @@ sub addrule
|
|||||||
<td align="right">
|
<td align="right">
|
||||||
END
|
END
|
||||||
|
|
||||||
if (-f "${General::swroot}/forward/reread") {
|
if (&General::firewall_needs_reload()) {
|
||||||
print <<END;
|
print <<END;
|
||||||
<input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-weight: bold; color: green;'>
|
<input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-weight: bold; color: green;'>
|
||||||
END
|
END
|
||||||
@@ -1012,7 +1012,7 @@ sub deleterule
|
|||||||
delete $delhash{$last_key};
|
delete $delhash{$last_key};
|
||||||
|
|
||||||
&General::writehasharray($fwdfwsettings{'config'}, \%delhash);
|
&General::writehasharray($fwdfwsettings{'config'}, \%delhash);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
|
|
||||||
if($fwdfwsettings{'nobase'} ne 'on'){
|
if($fwdfwsettings{'nobase'} ne 'on'){
|
||||||
&base;
|
&base;
|
||||||
@@ -1028,7 +1028,7 @@ sub disable_rule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
&General::writehasharray("$configfwdfw", \%configfwdfw);
|
&General::writehasharray("$configfwdfw", \%configfwdfw);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
sub dec_counter
|
sub dec_counter
|
||||||
{
|
{
|
||||||
@@ -2102,7 +2102,7 @@ sub pos_up
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
&General::writehasharray($fwdfwsettings{'config'}, \%uphash);
|
&General::writehasharray($fwdfwsettings{'config'}, \%uphash);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
sub pos_down
|
sub pos_down
|
||||||
{
|
{
|
||||||
@@ -2129,22 +2129,7 @@ sub pos_down
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
&General::writehasharray($fwdfwsettings{'config'}, \%downhash);
|
&General::writehasharray($fwdfwsettings{'config'}, \%downhash);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
|
||||||
sub rules
|
|
||||||
{
|
|
||||||
if (!-f "${General::swroot}/forward/reread"){
|
|
||||||
system("touch ${General::swroot}/forward/reread");
|
|
||||||
system("touch ${General::swroot}/fwhosts/reread");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub reread_rules
|
|
||||||
{
|
|
||||||
system("/usr/local/bin/forwardfwctrl");
|
|
||||||
if ( -f "${General::swroot}/forward/reread"){
|
|
||||||
system("rm ${General::swroot}/forward/reread");
|
|
||||||
system("rm ${General::swroot}/fwhosts/reread");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sub saverule
|
sub saverule
|
||||||
{
|
{
|
||||||
@@ -2286,7 +2271,7 @@ sub saverule
|
|||||||
$fwdfwsettings{'oldrulenumber'}--;
|
$fwdfwsettings{'oldrulenumber'}--;
|
||||||
}
|
}
|
||||||
&General::writehasharray("$config", $hash);
|
&General::writehasharray("$config", $hash);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
|
}elsif($fwdfwsettings{'rulepos'} > $fwdfwsettings{'oldrulenumber'}){
|
||||||
my %tmp=();
|
my %tmp=();
|
||||||
my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
|
my $val=$fwdfwsettings{'rulepos'}-$fwdfwsettings{'oldrulenumber'};
|
||||||
@@ -2313,7 +2298,7 @@ sub saverule
|
|||||||
$fwdfwsettings{'oldrulenumber'}++;
|
$fwdfwsettings{'oldrulenumber'}++;
|
||||||
}
|
}
|
||||||
&General::writehasharray("$config", $hash);
|
&General::writehasharray("$config", $hash);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,11 +114,6 @@ print<<END;
|
|||||||
END
|
END
|
||||||
|
|
||||||
## ACTION ####
|
## ACTION ####
|
||||||
if ($fwhostsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
|
|
||||||
{
|
|
||||||
&reread_rules;
|
|
||||||
&showmenu;
|
|
||||||
}
|
|
||||||
# Update
|
# Update
|
||||||
if ($fwhostsettings{'ACTION'} eq 'updatenet' )
|
if ($fwhostsettings{'ACTION'} eq 'updatenet' )
|
||||||
{
|
{
|
||||||
@@ -254,7 +249,7 @@ if ($fwhostsettings{'ACTION'} eq 'updateservice')
|
|||||||
}
|
}
|
||||||
$fwhostsettings{'updatesrv'} = '';
|
$fwhostsettings{'updatesrv'} = '';
|
||||||
if($needrules eq 'on'){
|
if($needrules eq 'on'){
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
&addservice;
|
&addservice;
|
||||||
}
|
}
|
||||||
@@ -416,7 +411,7 @@ if ($fwhostsettings{'ACTION'} eq 'savenet' )
|
|||||||
$fwhostsettings{'NETREMARK'}='';
|
$fwhostsettings{'NETREMARK'}='';
|
||||||
#check if an edited net affected groups and need to reload rules
|
#check if an edited net affected groups and need to reload rules
|
||||||
if ($needrules eq 'on'){
|
if ($needrules eq 'on'){
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
&addnet;
|
&addnet;
|
||||||
&viewtablenet;
|
&viewtablenet;
|
||||||
@@ -552,7 +547,7 @@ if ($fwhostsettings{'ACTION'} eq 'savehost')
|
|||||||
$fwhostsettings{'HOSTREMARK'}='';
|
$fwhostsettings{'HOSTREMARK'}='';
|
||||||
#check if we need to update rules while host was edited
|
#check if we need to update rules while host was edited
|
||||||
if($needrules eq 'on'){
|
if($needrules eq 'on'){
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
&addhost;
|
&addhost;
|
||||||
&viewtablehost;
|
&viewtablehost;
|
||||||
@@ -727,7 +722,7 @@ if ($fwhostsettings{'ACTION'} eq 'savegrp')
|
|||||||
#check if ruleupdate is needed
|
#check if ruleupdate is needed
|
||||||
if($count > 0 )
|
if($count > 0 )
|
||||||
{
|
{
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
&addgrp;
|
&addgrp;
|
||||||
&viewtablegrp;
|
&viewtablegrp;
|
||||||
@@ -829,7 +824,7 @@ if ($fwhostsettings{'ACTION'} eq 'saveservicegrp')
|
|||||||
$fwhostsettings{'updatesrvgrp'}='on';
|
$fwhostsettings{'updatesrvgrp'}='on';
|
||||||
}
|
}
|
||||||
if ($count gt 0){
|
if ($count gt 0){
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
}
|
}
|
||||||
&addservicegrp;
|
&addservicegrp;
|
||||||
&viewtableservicegrp;
|
&viewtableservicegrp;
|
||||||
@@ -944,7 +939,9 @@ if ($fwhostsettings{'ACTION'} eq 'deletegrphost')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
&General::writehasharray("$configgrp", \%customgrp);
|
&General::writehasharray("$configgrp", \%customgrp);
|
||||||
if ($fwhostsettings{'grpcnt'} > 0){&rules;}
|
if ($fwhostsettings{'grpcnt'} > 0){
|
||||||
|
&General::firewall_config_changed();
|
||||||
|
}
|
||||||
if ($fwhostsettings{'update'} eq 'on'){
|
if ($fwhostsettings{'update'} eq 'on'){
|
||||||
$fwhostsettings{'remark'}= $grpremark;
|
$fwhostsettings{'remark'}= $grpremark;
|
||||||
$fwhostsettings{'grp_name'}=$grpname;
|
$fwhostsettings{'grp_name'}=$grpname;
|
||||||
@@ -1023,7 +1020,7 @@ if ($fwhostsettings{'ACTION'} eq 'delgrpservice')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
&General::writehasharray("$configsrvgrp", \%customservicegrp);
|
&General::writehasharray("$configsrvgrp", \%customservicegrp);
|
||||||
&rules;
|
&General::firewall_config_changed();
|
||||||
if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
|
if ($fwhostsettings{'updatesrvgrp'} eq 'on'){
|
||||||
$fwhostsettings{'SRVGRP_NAME'}=$grpname;
|
$fwhostsettings{'SRVGRP_NAME'}=$grpname;
|
||||||
$fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
|
$fwhostsettings{'SRVGRP_REMARK'}=$grpremark;
|
||||||
@@ -1112,11 +1109,7 @@ if($fwhostsettings{'ACTION'} eq '')
|
|||||||
&showmenu;
|
&showmenu;
|
||||||
}
|
}
|
||||||
### FUNCTIONS ###
|
### FUNCTIONS ###
|
||||||
sub showmenu
|
sub showmenu {
|
||||||
{
|
|
||||||
if (-f "${General::swroot}/forward/reread"){
|
|
||||||
print "<table border='1' rules='groups' bgcolor='lightgreen' width='100%'><form method='post'><td><div style='font-size:11pt; font-weight: bold;vertical-align: middle; '><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: green; font-weight: bold; font-size: 14pt;'>    $Lang::tr{'fwhost reread'}</td></tr></table></form><br>";
|
|
||||||
}
|
|
||||||
&Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'});
|
&Header::openbox('100%', 'left',$Lang::tr{'fwhost menu'});
|
||||||
print "$Lang::tr{'fwhost welcome'}";
|
print "$Lang::tr{'fwhost welcome'}";
|
||||||
print<<END;
|
print<<END;
|
||||||
@@ -2080,24 +2073,8 @@ sub getipforgroup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sub rules
|
|
||||||
{
|
sub decrease {
|
||||||
if (!-f "${General::swroot}/fwhosts/reread"){
|
|
||||||
system("touch ${General::swroot}/fwhosts/reread");
|
|
||||||
system("touch ${General::swroot}/forward/reread");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub reread_rules
|
|
||||||
{
|
|
||||||
system ("/usr/local/bin/forwardfwctrl");
|
|
||||||
if ( -f "${General::swroot}/fwhosts/reread"){
|
|
||||||
system("rm ${General::swroot}/fwhosts/reread");
|
|
||||||
system("rm ${General::swroot}/forward/reread");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
sub decrease
|
|
||||||
{
|
|
||||||
my $grp=$_[0];
|
my $grp=$_[0];
|
||||||
&General::readhasharray("$confignet", \%customnetwork);
|
&General::readhasharray("$confignet", \%customnetwork);
|
||||||
&General::readhasharray("$confighost", \%customhost);
|
&General::readhasharray("$confighost", \%customhost);
|
||||||
|
|||||||
@@ -43,18 +43,12 @@ my %mainsettings=();
|
|||||||
&General::readhash("${General::swroot}/main/settings", \%mainsettings);
|
&General::readhash("${General::swroot}/main/settings", \%mainsettings);
|
||||||
&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
|
&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
&Header::showhttpheaders();
|
&Header::showhttpheaders();
|
||||||
&Header::getcgihash(\%fwdfwsettings);
|
&Header::getcgihash(\%fwdfwsettings);
|
||||||
&Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
|
&Header::openpage($Lang::tr{'fwdfw menu'}, 1, '');
|
||||||
&Header::openbigbox('100%', 'center',$errormessage);
|
&Header::openbigbox('100%', 'center', $errormessage);
|
||||||
|
|
||||||
if ($fwdfwsettings{'ACTION'} eq ''){
|
if ($fwdfwsettings{'ACTION'} eq 'togglep2p') {
|
||||||
&p2pblock;
|
|
||||||
}
|
|
||||||
if ($fwdfwsettings{'ACTION'} eq 'togglep2p')
|
|
||||||
{
|
|
||||||
open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
|
open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
|
||||||
@p2ps = <FILE>;
|
@p2ps = <FILE>;
|
||||||
close FILE;
|
close FILE;
|
||||||
@@ -72,21 +66,15 @@ if ($fwdfwsettings{'ACTION'} eq 'togglep2p')
|
|||||||
print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
|
print FILE "$p2pline[0];$p2pline[1];$p2pline[2];\n";
|
||||||
}
|
}
|
||||||
close FILE;
|
close FILE;
|
||||||
&rules;
|
|
||||||
&p2pblock;
|
|
||||||
}
|
|
||||||
if ($fwdfwsettings{'ACTION'} eq $Lang::tr{'fwdfw reread'})
|
|
||||||
{
|
|
||||||
&reread_rules;
|
|
||||||
&p2pblock;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
&General::firewall_config_changed();
|
||||||
|
&p2pblock();
|
||||||
|
} else {
|
||||||
|
&p2pblock();
|
||||||
|
}
|
||||||
|
|
||||||
sub p2pblock
|
sub p2pblock
|
||||||
{
|
{
|
||||||
if (-f "${General::swroot}/forward/reread"){
|
|
||||||
print "<table border='1' rules='groups' bgcolor='lightgreen' width='100%'><form method='post'><td><div style='font-size:11pt; font-weight: bold;vertical-align: middle; '><input type='submit' name='ACTION' value='$Lang::tr{'fwdfw reread'}' style='font-face: Comic Sans MS; color: green; font-weight: bold; font-size: 14pt;'>    $Lang::tr{'fwhost reread'}</div></td></tr></table></form><br>";
|
|
||||||
}
|
|
||||||
my $gif;
|
my $gif;
|
||||||
open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
|
open( FILE, "< $p2pfile" ) or die "Unable to read $p2pfile";
|
||||||
@p2ps = <FILE>;
|
@p2ps = <FILE>;
|
||||||
@@ -115,20 +103,6 @@ END
|
|||||||
print"<br><br><br><table width='100%'><tr><td align='left'>$Lang::tr{'fwdfw p2p txt'}</td></tr></table>";
|
print"<br><br><br><table width='100%'><tr><td align='left'>$Lang::tr{'fwdfw p2p txt'}</td></tr></table>";
|
||||||
&Header::closebox();
|
&Header::closebox();
|
||||||
}
|
}
|
||||||
sub rules
|
|
||||||
{
|
|
||||||
if (!-f "${General::swroot}/forward/reread"){
|
|
||||||
system("touch ${General::swroot}/forward/reread");
|
|
||||||
system("touch ${General::swroot}/fwhosts/reread");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sub reread_rules
|
|
||||||
{
|
|
||||||
system("/usr/local/bin/forwardfwctrl");
|
|
||||||
if ( -f "${General::swroot}/forward/reread"){
|
|
||||||
system("rm ${General::swroot}/forward/reread");
|
|
||||||
system("rm ${General::swroot}/fwhosts/reread");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&Header::closebigbox();
|
&Header::closebigbox();
|
||||||
&Header::closepage();
|
&Header::closepage();
|
||||||
|
|||||||
@@ -5,12 +5,21 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "setuid.h"
|
#include "setuid.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (!(initsetuid()))
|
if (!(initsetuid()))
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
safe_system("/var/ipfire/forward/bin/rules.pl");
|
int retval = safe_system("/var/ipfire/forward/bin/rules.pl");
|
||||||
|
|
||||||
|
/* If rules.pl has been successfully executed, the indicator
|
||||||
|
* file is removed. */
|
||||||
|
if (retval == 0) {
|
||||||
|
unlink("/var/ipfire/forward/reread");
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user