diff options
author | Ermal <eri@pfsense.org> | 2013-03-28 12:43:13 +0100 |
---|---|---|
committer | Ermal <eri@pfsense.org> | 2013-03-28 12:43:13 +0100 |
commit | 8a93e1031e88f255788778f26c6acccdcccd333b (patch) | |
tree | 255a44c46024148f37bc63e269da0e9259a2fb84 | |
parent | 7c702b5a98c27526c780af46dfc8494c9a6cabbc (diff) | |
download | pfsense-packages-8a93e1031e88f255788778f26c6acccdcccd333b.tar.gz pfsense-packages-8a93e1031e88f255788778f26c6acccdcccd333b.tar.bz2 pfsense-packages-8a93e1031e88f255788778f26c6acccdcccd333b.zip |
Correctly write config file and also properly avoid php errors with some extra safety belts
-rw-r--r-- | config/openbgpd/openbgpd.inc | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/config/openbgpd/openbgpd.inc b/config/openbgpd/openbgpd.inc index 297cbe13..e5dd8069 100644 --- a/config/openbgpd/openbgpd.inc +++ b/config/openbgpd/openbgpd.inc @@ -113,22 +113,24 @@ function openbgpd_install_conf() { if(is_array($openbgpd_neighbors)) { foreach($openbgpd_neighbors as $neighbor) { if($neighbor['groupname'] == $group['name']) { - $conffile .= " neighbor {$neighbor['neighbor']} {\n"; - $conffile .= " descr \"{$neighbor['descr']}\"\n"; + $conffile .= "\tneighbor {$neighbor['neighbor']} {\n"; + $conffile .= "\t\tdescr \"{$neighbor['descr']}\"\n"; if($neighbor['md5sigpass']) { - $conffile .= " tcp md5sig password {$neighbor['md5sigpass']}\n"; + $conffile .= "\t\ttcp md5sig password {$neighbor['md5sigpass']}\n"; } if($neighbor['md5sigkey']) { - $conffile .= " tcp md5sig key {$neighbor['md5sigkey']}\n"; + $conffile .= "\t\ttcp md5sig key {$neighbor['md5sigkey']}\n"; } $setlocaladdr = true; - foreach($neighbor['row'] as $row) { - if ($row['parameters'] == "local-address") - $setlocaladdr = false; - $conffile .= " {$row['parameters']} {$row['parmvalue']} \n"; - } + if (is_array($neighbor['row'])) { + foreach($neighbor['row'] as $row) { + if ($row['parameters'] == "local-address") + $setlocaladdr = false; + $conffile .= "\t\t{$row['parameters']} {$row['parmvalue']} \n"; + } + } if ($setlocaladdr == true) - $conffile .= "\tlocal-address {$openbgpd_conf['listenip']}\n"; + $conffile .= "\t\tlocal-address {$openbgpd_conf['listenip']}\n"; $conffile .= "}\n"; } } @@ -143,25 +145,25 @@ function openbgpd_install_conf() { $used_this_item = false; if($neighbor['groupname'] == "") { $conffile .= "neighbor {$neighbor['neighbor']} {\n"; - $conffile .= " descr \"{$neighbor['descr']}\"\n"; + $conffile .= "\tdescr \"{$neighbor['descr']}\"\n"; if ($neighbor['md5sigpass']) { - $conffile .= " tcp md5sig password {$neighbor['md5sigpass']}\n"; + $conffile .= "\ttcp md5sig password {$neighbor['md5sigpass']}\n"; } if ($neighbor['md5sigkey']) { - $conffile .= " tcp md5sig key {$neighbor['md5sigkey']}\n"; + $conffile .= "\ttcp md5sig key {$neighbor['md5sigkey']}\n"; } - $used_this_item = true; $setlocaladdr = true; - foreach($neighbor['row'] as $row) { - if ($row['parameters'] == "local-address") - $setlocaladdr = false; - $conffile .= " {$row['parameters']} {$row['parmvalue']} \n"; - } + if (is_array($neighbor['row'])) { + foreach($neighbor['row'] as $row) { + if ($row['parameters'] == "local-address") + $setlocaladdr = false; + $conffile .= "\t{$row['parameters']} {$row['parmvalue']} \n"; + } + } if ($setlocaladdr == true) $conffile .= "\tlocal-address {$openbgpd_conf['listenip']}\n"; } - if($used_this_item) - $conffile .= "}\n"; + $conffile .= "}\n"; } } @@ -177,7 +179,7 @@ function openbgpd_install_conf() { } safe_mkdir($bgpd_config_base); // Write out the configuration file - @file_put_contents("{$bgpd_config_base}/bgpd.conf", "w"); + @file_put_contents("{$bgpd_config_base}/bgpd.conf", $conffile); @chmod("{$bgpd_config_base}/bgpd.conf", 0666); // Create rc.d file |