From 6ec163b98180eb8bacbf515ca9c9f079424da376 Mon Sep 17 00:00:00 2001 From: Ermal Date: Wed, 27 Mar 2013 16:07:34 +0100 Subject: Correctly generate the hex value needed for md5sigkey value. Use correct permissions for configuration file when generating --- config/openbgpd/openbgpd.inc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'config/openbgpd') diff --git a/config/openbgpd/openbgpd.inc b/config/openbgpd/openbgpd.inc index 2d1f47fd..f099e44d 100644 --- a/config/openbgpd/openbgpd.inc +++ b/config/openbgpd/openbgpd.inc @@ -122,8 +122,11 @@ function openbgpd_install_conf() { $conffile .= " tcp md5sig password {$neighbor['md5sigpass']}\n"; } if($neighbor['md5sigkey']) { - $setkeycf .= "add {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000 -A tcp-md5 0x{$neighbor['md5sigkey']};\n"; - $conffile .= " tcp md5sig key {$neighbor['md5sigkey']}\n"; + $hex = ""; + for ($i = 0; $i < strlen($neighbor['md5sigkey']); $i++) + $hex .= dechex(ord($neighbor['md5sigkey'][$i])); + $setkeycf .= "add {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000 -A tcp-md5 0x{$hex};\n"; + $conffile .= " tcp md5sig key {$hex}\n"; } foreach($neighbor['row'] as $row) { $conffile .= " {$row['parameters']} {$row['parmvalue']} \n"; @@ -149,8 +152,11 @@ function openbgpd_install_conf() { $conffile .= " tcp md5sig password {$neighbor['md5sigpass']}\n"; } if ($neighbor['md5sigkey']) { - $setkeycf .= "add {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000 -A tcp-md5 0x{$neighbor['md5sigkey']};\n"; - $conffile .= " tcp md5sig key {$neighbor['md5sigkey']}\n"; + $hex = ""; + for ($i = 0; $i < strlen($neighbor['md5sigkey']); $i++) + $hex .= dechex(ord($neighbor['md5sigkey'][$i])); + $setkeycf .= "add {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000 -A tcp-md5 0x{$hex};\n"; + $conffile .= " tcp md5sig key {$hex}\n"; } $used_this_item = true; foreach($neighbor['row'] as $row) { @@ -173,13 +179,9 @@ function openbgpd_install_conf() { } } safe_mkdir($bgpd_config_base); - $fd = fopen("{$bgpd_config_base}/bgpd.conf", "w"); - - // Write out the configuration file - fwrite($fd, $conffile); - - // Close file handle - fclose($fd); + // Write out the configuration file + @file_put_contents("{$bgpd_config_base}/bgpd.conf", "w"); + @chmod("{$bgpd_config_base}/bgpd.conf", 0666); // Create rc.d file $rc_file_stop = <<