From a6c1e18207e119655aa0a6b3fc759b16c296dd31 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Tue, 30 Jun 2009 15:31:37 -0400 Subject: Adding "RAW Configuration" support which bypasses the GUI and uses the raw file. Submitted-by: Aarno Aukia (aarnoaukia_AT_gmail.com) --- config/openbgpd/openbgpd.inc | 205 ++++++++++++++++++--------------- config/openbgpd/openbgpd.xml | 9 ++ config/openbgpd/openbgpd_groups.xml | 6 +- config/openbgpd/openbgpd_neighbors.xml | 6 +- config/openbgpd/openbgpd_status.php | 1 + 5 files changed, 134 insertions(+), 93 deletions(-) (limited to 'config') diff --git a/config/openbgpd/openbgpd.inc b/config/openbgpd/openbgpd.inc index c786f0d9..3b622d66 100644 --- a/config/openbgpd/openbgpd.inc +++ b/config/openbgpd/openbgpd.inc @@ -34,97 +34,103 @@ function openbgpd_install_conf() { conf_mount_rw(); - if($config['installedpackages']['openbgpd']['config']) - $openbgpd_conf = &$config['installedpackages']['openbgpd']['config'][0]; - if($config['installedpackages']['openbgpd']['config'][0]['row']) - $openbgpd_rows = &$config['installedpackages']['openbgpd']['config'][0]['row']; - if($config['installedpackages']['openbgpdgroups']['config']) - $openbgpd_groups = &$config['installedpackages']['openbgpdgroups']['config']; - if($config['installedpackages']['openbgpdneighbors']['config']) - $openbgpd_neighbors = &$config['installedpackages']['openbgpdneighbors']['config']; - - $fd = fopen("/usr/local/etc/bgpd.conf", "w"); - - $conffile = ""; - - // Setup AS # - if($openbgpd_conf['asnum']) - $conffile .= "AS {$openbgpd_conf['asnum']}\n"; - - // Setup holdtime if defined. Default is 90. - if($openbgpd_conf['holdtime']) - $conffile .= "holdtime {$openbgpd_conf['holdtime']}\n"; - - // Specify listen ip - if($openbgpd_conf['listenip']) - $conffile .= "listen on {$openbgpd_conf['listenip']}\n"; - - // Specify router id - if($openbgpd_conf['routerid']) - $conffile .= "router-id {$openbgpd_conf['routerid']}\n"; - - // Handle advertised networks - if($config['installedpackages']['openbgpd']['config'][0]['row']) - if(is_array($openbgpd_rows)) - foreach($openbgpd_rows as $row) - $conffile .= "network {$row['networks']}\n"; - - // Attach neighbors to their respective group owner - if(is_array($openbgpd_groups)) { - foreach($openbgpd_groups as $group) { - $conffile .= "group \"{$group['name']}\" {\n"; - $conffile .= " remote-as {$group['remoteas']}\n"; - 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"; - if($neighbor['md5sigpass']) - $conffile .= " tcp md5sig password {$neighbor['md5sigpass']}\n"; - if($neighbor['md5sigkey']) - $conffile .= " tcp md5sig key {$neighbor['md5sigkey']}\n"; - foreach($neighbor['row'] as $row) { - $conffile .= " {$row['paramaters']} {$row['parmvalue']} \n"; - } - $conffile .= " }\n"; - } - } - } - $conffile .= "}\n"; - } - } - - // Handle neighbors that do not have a group assigned to them - if(is_array($openbgpd_neighbors)) { - foreach($openbgpd_neighbors as $neighbor) { - $used_this_item = false; - if($neighbor['groupname'] == "") { - $conffile .= " neighbor {$neighbor['neighbor']} {\n"; - $conffile .= " descr \"{$neighbor['descr']}\"\n"; - $used_this_item = true; - foreach($neighbor['row'] as $row) { - $conffile .= " {$row['paramaters']} {$row['parmvalue']} \n"; - } - if($used_this_item) - $conffile .= " }\n"; - } - } - if($used_this_item) - $conffile .= "}\n"; - } + if ($config['installedpackages']['openbgpd']['rawconfig'] && $config['installedpackages']['openbgpd']['rawconfig']['item']) { + // if there is a raw config specifyed in tthe config.xml use that instead of the assisted config + $conffile = implode("\n",$config['installedpackages']['openbgpd']['rawconfig']['item']); + //$conffile = $config['installedpackages']['openbgpd']['rawconfig']; + } else { + // generate bgpd.conf based on the assistant + if($config['installedpackages']['openbgpd']['config']) + $openbgpd_conf = &$config['installedpackages']['openbgpd']['config'][0]; + if($config['installedpackages']['openbgpd']['config'][0]['row']) + $openbgpd_rows = &$config['installedpackages']['openbgpd']['config'][0]['row']; + if($config['installedpackages']['openbgpdgroups']['config']) + $openbgpd_groups = &$config['installedpackages']['openbgpdgroups']['config']; + if($config['installedpackages']['openbgpdneighbors']['config']) + $openbgpd_neighbors = &$config['installedpackages']['openbgpdneighbors']['config']; + + $conffile = "# This file was created by the pfSense package manager. Do not edit!\n\n"; + + // Setup AS # + if($openbgpd_conf['asnum']) + $conffile .= "AS {$openbgpd_conf['asnum']}\n"; + + // Setup holdtime if defined. Default is 90. + if($openbgpd_conf['holdtime']) + $conffile .= "holdtime {$openbgpd_conf['holdtime']}\n"; + + // Specify listen ip + if($openbgpd_conf['listenip']) + $conffile .= "listen on {$openbgpd_conf['listenip']}\n"; + + // Specify router id + if($openbgpd_conf['routerid']) + $conffile .= "router-id {$openbgpd_conf['routerid']}\n"; + + // Handle advertised networks + if($config['installedpackages']['openbgpd']['config'][0]['row']) + if(is_array($openbgpd_rows)) + foreach($openbgpd_rows as $row) + $conffile .= "network {$row['networks']}\n"; + + // Attach neighbors to their respective group owner + if(is_array($openbgpd_groups)) { + foreach($openbgpd_groups as $group) { + $conffile .= "group \"{$group['name']}\" {\n"; + $conffile .= " remote-as {$group['remoteas']}\n"; + 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"; + if($neighbor['md5sigpass']) + $conffile .= " tcp md5sig password {$neighbor['md5sigpass']}\n"; + if($neighbor['md5sigkey']) + $conffile .= " tcp md5sig key {$neighbor['md5sigkey']}\n"; + foreach($neighbor['row'] as $row) { + $conffile .= " {$row['paramaters']} {$row['parmvalue']} \n"; + } + $conffile .= " }\n"; + } + } + } + $conffile .= "}\n"; + } + } + + // Handle neighbors that do not have a group assigned to them + if(is_array($openbgpd_neighbors)) { + foreach($openbgpd_neighbors as $neighbor) { + $used_this_item = false; + if($neighbor['groupname'] == "") { + $conffile .= " neighbor {$neighbor['neighbor']} {\n"; + $conffile .= " descr \"{$neighbor['descr']}\"\n"; + $used_this_item = true; + foreach($neighbor['row'] as $row) { + $conffile .= " {$row['paramaters']} {$row['parmvalue']} \n"; + } + if($used_this_item) + $conffile .= " }\n"; + } + } + if($used_this_item) + $conffile .= "}\n"; + } + + // OpenBGPD filters + $conffile .= "deny from any\n"; + $conffile .= "deny to any\n"; + if(is_array($openbgpd_neighbors)) { + foreach($openbgpd_neighbors as $neighbor) { + $conffile .= "allow from {$neighbor['neighbor']}\n"; + $conffile .= "allow to {$neighbor['neighbor']}\n"; + } + } + } + + $fd = fopen("/usr/local/etc/bgpd.conf", "w"); - // OpenBGPD filters - $conffile .= "deny from any\n"; - $conffile .= "deny to any\n"; - if(is_array($openbgpd_neighbors)) { - foreach($openbgpd_neighbors as $neighbor) { - $conffile .= "allow from {$neighbor['neighbor']}\n"; - $conffile .= "allow to {$neighbor['neighbor']}\n"; - } - } - - // Write out the configuration file - fwrite($fd, "# This file was created by the pfSense package manager. Do not edit!\n\n"); + // Write out the configuration file fwrite($fd, $conffile); // Close file handle @@ -150,6 +156,23 @@ function openbgpd_install_conf() { conf_mount_ro(); } +// get the raw openbgpd confi file for manual inspection/editing +function openbgpd_get_raw_config() { + return file_get_contents("/usr/local/etc/bgpd.conf"); +} + +// serialize the raw openbgpd confi file to config.xml +function openbgpd_put_raw_config($conffile) { + global $config; + if ($conffile == "") + unset($config['installedpackages']['openbgpd']['rawconfig']); + else { + $config['installedpackages']['openbgpd']['rawconfig'] = array(); + $config['installedpackages']['openbgpd']['rawconfig']['item'] = explode("\n",$_POST['openbgpd_raw']); + //$config['installedpackages']['openbgpd']['rawconfig'] = $conffile; + } +} + function deinstall_openbgpd() { exec("rm /usr/local/etc/rc.d/bgpd.sh"); exec("rm /usr/local/www/openbgpd_status.php"); @@ -220,4 +243,4 @@ function is_openbgpd_running() { return false; } -?> \ No newline at end of file +?> diff --git a/config/openbgpd/openbgpd.xml b/config/openbgpd/openbgpd.xml index 3bb37f7d..f1130720 100644 --- a/config/openbgpd/openbgpd.xml +++ b/config/openbgpd/openbgpd.xml @@ -55,6 +55,11 @@ 077 http://www.pfsense.com/packages/config/openbgpd/openbgpd_status.php + + /usr/local/www/ + 077 + http://www.pfsense.com/packages/config/openbgpd/openbgpd_raw.php + /usr/local/pkg/ 077 @@ -90,6 +95,10 @@ Groups /pkg.php?xml=openbgpd_groups.xml&id=0 + + Raw config + /openbgpd_raw.php + Status /openbgpd_status.php diff --git a/config/openbgpd/openbgpd_groups.xml b/config/openbgpd/openbgpd_groups.xml index 248a97df..7f479427 100644 --- a/config/openbgpd/openbgpd_groups.xml +++ b/config/openbgpd/openbgpd_groups.xml @@ -59,7 +59,11 @@ /pkg.php?xml=openbgpd_groups.xml - + + Raw config + /openbgpd_raw.php + + Status /openbgpd_status.php diff --git a/config/openbgpd/openbgpd_neighbors.xml b/config/openbgpd/openbgpd_neighbors.xml index cc170c0b..b938e6fb 100644 --- a/config/openbgpd/openbgpd_neighbors.xml +++ b/config/openbgpd/openbgpd_neighbors.xml @@ -59,6 +59,10 @@ Groups /pkg.php?xml=openbgpd_groups.xml + + Raw config + /openbgpd_raw.php + Status /openbgpd_status.php @@ -176,4 +180,4 @@ grey_out_value_boxes(); - \ No newline at end of file + diff --git a/config/openbgpd/openbgpd_status.php b/config/openbgpd/openbgpd_status.php index 5660734f..414c56e0 100644 --- a/config/openbgpd/openbgpd_status.php +++ b/config/openbgpd/openbgpd_status.php @@ -120,6 +120,7 @@ function execCmds() { $tab_array[] = array(gettext("Settings"), false, "/pkg_edit.php?xml=openbgpd.xml&id=0"); $tab_array[] = array(gettext("Neighbors"), false, "/pkg.php?xml=openbgpd_neighbors.xml"); $tab_array[] = array(gettext("Groups"), false, "/pkg.php?xml=openbgpd_groups.xml"); + $tab_array[] = array(gettext("Raw config"), true, "/openbgpd_raw.php"); $tab_array[] = array(gettext("Status"), true, "/openbgpd_status.php"); display_top_tabs($tab_array); ?> -- cgit v1.2.3