diff options
-rw-r--r-- | packages/carp_sync_client.php | 59 | ||||
-rw-r--r-- | packages/carp_sync_server.php | 23 |
2 files changed, 54 insertions, 28 deletions
diff --git a/packages/carp_sync_client.php b/packages/carp_sync_client.php index cfe59d4b..2d27501b 100644 --- a/packages/carp_sync_client.php +++ b/packages/carp_sync_client.php @@ -29,32 +29,47 @@ if($config['installedpackages']['carpsettings']['config'] != "") { foreach($config['installedpackages']['carpsettings']['config'] as $carp) { - if($carp['synchronizerules'] <> "" and $carp['synchronizetoip'] <> "" ) { + if($carp['synchronizetoip'] <> "" ) { /* lets sync! */ $synchronizetoip = $carp['synchronizetoip']; - $current_rules_section = backup_config_section("filter"); - $current_nat_section = backup_config_section("nat"); - $current_aliases_section = backup_config_section("aliases"); - /* generate firewall rules xml */ - $fout = fopen("{$g['tmp_path']}/rules_section.txt","w"); - fwrite($fout, $current_rules_section); - fclose($fout); - /* generate nat rules xml */ - $fout = fopen("{$g['tmp_path']}/nat_section.txt","w"); - fwrite($fout, $current_nat_section); - fclose($fout); - /* generate aliases xml */ - $fout = fopen("{$g['tmp_path']}/aliases_section.txt","w"); - fwrite($fout, $current_aliases_section); - fclose($fout); + if($carp['synchronizerules'] <> "") { + $current_rules_section = backup_config_section("filter"); + /* generate firewall rules xml */ + $fout = fopen("{$g['tmp_path']}/rules_section.txt","w"); + fwrite($fout, $current_rules_section); + fclose($fout); + mwexec("/usr/bin/scp {$g['tmp_path']}/rules_section.txt root@{$synchronizetoip}:/tmp/"); + unlink("{$g['tmp_path']}/rules_section.txt"); + } + if($carp['synchronizenat'] <> "") { + $current_nat_section = backup_config_section("nat"); + /* generate nat rules xml */ + $fout = fopen("{$g['tmp_path']}/nat_section.txt","w"); + fwrite($fout, $current_nat_section); + fclose($fout); + mwexec("/usr/bin/scp {$g['tmp_path']}/nat_section.txt root@{$synchronizetoip}:/tmp/"); + unlink("{$g['tmp_path']}/nat_section.txt"); + } + if($carp['synchronizealiases'] <> "") { + $current_aliases_section = backup_config_section("aliases"); + /* generate aliases xml */ + $fout = fopen("{$g['tmp_path']}/aliases_section.txt","w"); + fwrite($fout, $current_aliases_section); + fclose($fout); + mwexec("/usr/bin/scp {$g['tmp_path']}/aliases_section.txt root@{$synchronizetoip}:/tmp/"); + unlink("{$g['tmp_path']}/aliases_section.txt"); + } + if($carp['synchronizetrafficshaper'] <> "") { + $current_trafficshaper_section = backup_config_section("shaper"); + /* generate aliases xml */ + $fout = fopen("{$g['tmp_path']}/trafficshaper_section.txt","w"); + fwrite($fout, $current_trafficshaper_section); + fclose($fout); + mwexec("/usr/bin/scp {$g['tmp_path']}/trafficshaper_section.txt root@{$synchronizetoip}:/tmp/"); + unlink("{$g['tmp_path']}/trafficshaper_section.txt"); + } /* copy configuration to remote host */ - mwexec("/usr/bin/scp {$g['tmp_path']}/rules_section.txt root@{$synchronizetoip}:/tmp/"); - mwexec("/usr/bin/scp {$g['tmp_path']}/aliases_section.txt root@{$synchronizetoip}:/tmp/"); - mwexec("/usr/bin/scp {$g['tmp_path']}/nat_section.txt root@{$synchronizetoip}:/tmp/"); mwexec("/usr/bin/ssh {$synchronizetoip} /usr/local/pkg/carp_sync_server.php"); - unlink("{$g['tmp_path']}/rules_section.txt"); - unlink("{$g['tmp_path']}/aliases_section.txt"); - unlink("{$g['tmp_path']}/nat_section.txt"); } } } diff --git a/packages/carp_sync_server.php b/packages/carp_sync_server.php index cb292488..417a59f6 100644 --- a/packages/carp_sync_server.php +++ b/packages/carp_sync_server.php @@ -40,13 +40,24 @@ if($config['installedpackages']['carpsettings']['config'] != "") $rules = return_filename_as_string("{$g['tmp_path']}/rules_section.txt"); $aliases = return_filename_as_string("{$g['tmp_path']}/aliases_section.txt"); $nat = return_filename_as_string("{$g['tmp_path']}/nat_section.txt"); - restore_config_section("filter", $rules); - restore_config_section("aliases", $aliases); - restore_config_section("nat", $nat); + $trafficshaper = return_filename_as_string("{$g['tmp_path']}/trafficshaper_section.txt"); + if($rules <> "") { + restore_config_section("filter", $rules); + unlink("{$g['tmp_path']}/rules_section.txt"); + } + if($aliases <> "") { + restore_config_section("aliases", $aliases); + unlink("{$g['tmp_path']}/aliases_section.txt"); + } + if($nat <> "") { + restore_config_section("nat", $nat); + unlink("{$g['tmp_path']}/nat_section.txt"); + } + if($trafficshaper <> "") { + restore_config_section("shaper", $trafficshaper); + unlink("{$g['tmp_path']}/nat_section.txt"); + } filter_configure(); - unlink("{$g['tmp_path']}/rules_section.txt"); - unlink("{$g['tmp_path']}/aliases_section.txt"); - unlink("{$g['tmp_path']}/nat_section.txt"); } ?>
\ No newline at end of file |