diff options
Diffstat (limited to 'config/openbgpd')
-rw-r--r-- | config/openbgpd/openbgpd.inc | 290 | ||||
-rw-r--r-- | config/openbgpd/openbgpd.xml | 2 | ||||
-rw-r--r-- | config/openbgpd/openbgpd_neighbors.xml | 4 | ||||
-rw-r--r-- | config/openbgpd/openbgpd_status.php | 270 |
4 files changed, 325 insertions, 241 deletions
diff --git a/config/openbgpd/openbgpd.inc b/config/openbgpd/openbgpd.inc index 573745be..e1619a55 100644 --- a/config/openbgpd/openbgpd.inc +++ b/config/openbgpd/openbgpd.inc @@ -3,7 +3,7 @@ /* $Id$ */ /* openbgpd.inc - Copyright (C) 2007 Scott Ullrich (sullrich@gmail.com) + Copyright (C) 2007 Scott Ullrich (sullrich@gmail.com) part of pfSense All rights reserved. @@ -34,6 +34,12 @@ require_once("service-utils.inc"); define('PKG_BGPD_CONFIG_BASE', '/var/etc/openbgpd'); +$pf_version=substr(trim(file_get_contents("/etc/version")),0,3); +if ($pf_version > 2.0) + define('PKG_BGPD_BIN', '/usr/pbi/openbgpd-' . php_uname("m") . '/sbin'); +else + define('PKG_BGPD_BIN','/usr/local/sbin'); + define('PKG_BGPD_LOGIN', "_bgpd"); define('PKG_BGPD_UID', "130"); define('PKG_BGPD_GROUP', "_bgpd"); @@ -51,132 +57,133 @@ function openbgpd_install_conf() { $pkg_gecos = PKG_BGPD_GECOS; $pkg_homedir = PKG_BGPD_HOMEDIR; $pkg_shell = PKG_BGPD_SHELL; + $pkg_bin = PKG_BGPD_BIN; conf_mount_rw(); // Since we need to embed this in a string, copy to a var. Can't embed constnats. $bgpd_config_base = PKG_BGPD_CONFIG_BASE; - if ($config['installedpackages']['openbgpd']['rawconfig'] && $config['installedpackages']['openbgpd']['rawconfig']['item']) { - // if there is a raw config specified in the 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 package manager. Do not edit!\n\n"; - $setkeycf = ""; - - // Setup AS # - if($openbgpd_conf['asnum']) - $conffile .= "AS {$openbgpd_conf['asnum']}\n"; - - if($openbgpd_conf['fibupdate']) - $conffile .= "fib-update {$openbgpd_conf['fibupdate']}\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"; - $setkeycf .= "delete {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000;\n"; - if($neighbor['md5sigpass']) { - $setkeycf .= "add {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000 -A tcp-md5 \"{$neighbor['md5sigpass']}\";\n"; - $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"; - } - foreach($neighbor['row'] as $row) { - $conffile .= " {$row['parameters']} {$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"; - $setkeycf .= "delete {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000;\n"; - if ($neighbor['md5sigpass']) { - $setkeycf .= "add {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000 -A tcp-md5 \"{$neighbor['md5sigpass']}\";\n"; - $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"; - } - $used_this_item = true; - foreach($neighbor['row'] as $row) { - $conffile .= " {$row['parameters']} {$row['parmvalue']} \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"; - } - } - } - safe_mkdir($bgpd_config_base); - $fd = fopen("{$bgpd_config_base}/bgpd.conf", "w"); + if ($config['installedpackages']['openbgpd']['rawconfig'] && $config['installedpackages']['openbgpd']['rawconfig']['item']) { + // if there is a raw config specified in the 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 package manager. Do not edit!\n\n"; + + // Setup AS # + if($openbgpd_conf['asnum']) + $conffile .= "AS {$openbgpd_conf['asnum']}\n"; + + if($openbgpd_conf['fibupdate']) + $conffile .= "fib-update {$openbgpd_conf['fibupdate']}\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 .= "\tneighbor {$neighbor['neighbor']} {\n"; + $conffile .= "\t\tdescr \"{$neighbor['descr']}\"\n"; + if($neighbor['md5sigpass']) { + $conffile .= "\t\ttcp md5sig password {$neighbor['md5sigpass']}\n"; + } + if($neighbor['md5sigkey']) { + $conffile .= "\t\ttcp md5sig key {$neighbor['md5sigkey']}\n"; + } + $setlocaladdr = true; + 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 .= "\t\tlocal-address {$openbgpd_conf['listenip']}\n"; + $conffile .= "}\n"; + } + } + } + $conffile .= "}\n"; + } + } - // Write out the configuration file - fwrite($fd, $conffile); + // Handle neighbors that do not have a group assigned to them + if(is_array($openbgpd_neighbors)) { + foreach($openbgpd_neighbors as $neighbor) { + if($neighbor['groupname'] == "") { + $conffile .= "neighbor {$neighbor['neighbor']} {\n"; + $conffile .= "\tdescr \"{$neighbor['descr']}\"\n"; + if ($neighbor['md5sigpass']) { + $conffile .= "\ttcp md5sig password {$neighbor['md5sigpass']}\n"; + } + if ($neighbor['md5sigkey']) { + $conffile .= "\ttcp md5sig key {$neighbor['md5sigkey']}\n"; + } + $setlocaladdr = true; + 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"; + $conffile .= "}\n"; + } + } + } - // Close file handle - fclose($fd); + // 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"; + } + } + } + safe_mkdir($bgpd_config_base); + // Write out the configuration file + @file_put_contents("{$bgpd_config_base}/bgpd.conf", $conffile); + @chmod("{$bgpd_config_base}/bgpd.conf", 0600); // Create rc.d file $rc_file_stop = <<<EOF -killall -9 bgpd +killall -TERM bgpd EOF; $rc_file_start = <<<EOF @@ -188,12 +195,14 @@ if [ `pw usershow {$pkg_login} 2>&1 | grep -c "pw: no such user"` -gt 0 ]; then fi /bin/mkdir -p {$bgpd_config_base} -chmod u+rw,go-rw {$bgpd_config_base}/bgpd.conf /usr/sbin/chown -R root:wheel {$bgpd_config_base} +/bin/chmod 0600 {$bgpd_config_base}/bgpd.conf NUMBGPD=`ps auxw | grep -c '[b]gpd.*parent'` if [ \${NUMBGPD} -lt 1 ] ; then - /usr/local/sbin/bgpd -f {$bgpd_config_base}/bgpd.conf + {$pkg_bin}/bgpd -f {$bgpd_config_base}/bgpd.conf +else + {$pkg_bin}/bgpctl reload fi EOF; write_rcfile(array( @@ -203,17 +212,11 @@ EOF; ) ); - // TCP-MD5 support on freebsd. See tcp(5) for more - $fd = fopen("{$g['tmp_path']}/bgpdsetkey.conf", "w"); - fwrite($fd, $setkeycf ); - fclose($fd); - exec("setkey -f {$g['tmp_path']}/bgpdsetkey.conf"); - // bgpd process running? if so reload, else start. if(is_openbgpd_running() == true) { - exec("bgpctl reload"); + exec("{$pkg_bin}/bgpctl reload"); } else { - exec("bgpd"); + exec("{$pkg_bin}/bgpd -f {$bgpd_config_base}/bgpd.conf"); } conf_mount_ro(); @@ -230,34 +233,19 @@ function openbgpd_get_raw_config() { // serialize the raw openbgpd config 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; - } + 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() { global $config, $g; - if($config['installedpackages']['openbgpd']['config']) - $openbgpd_conf = &$config['installedpackages']['openbgpd']['config'][0]; - if($config['installedpackages']['openbgpdneighbors']['config']) - $openbgpd_neighbors = &$config['installedpackages']['openbgpdneighbors']['config']; - $setkeycf = ""; - if(is_array($openbgpd_neighbors)) { - foreach($openbgpd_neighbors as $neighbor) - $setkeycf .= "delete {$openbgpd_conf['listenip']} {$neighbor['neighbor']} tcp 0x1000;\n"; - } - // Clear all SADB entries used. - $fd = fopen("{$g['tmp_path']}/bgpdsetkey.conf", "w"); - fwrite($fd, $setkeycf ); - fclose($fd); - exec("setkey -f {$g['tmp_path']}/bgpdsetkey.conf"); - exec("rm /usr/local/etc/rc.d/bgpd.sh"); exec("rm /usr/local/www/openbgpd_status.php"); exec("killall bgpd"); @@ -362,4 +350,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 2d28de0f..58107d48 100644 --- a/config/openbgpd/openbgpd.xml +++ b/config/openbgpd/openbgpd.xml @@ -151,7 +151,7 @@ <description></description> <rowhelper> <rowhelperfield> - <fielddescr>Announce the specified network as belonging to our AS. If set to connected, routes to directly attached networks will be announced. If set to static, all static routes will be announced.</fielddescr> + <fielddescr>Announce the specified network as belonging to our AS. If set to "(inet|inet6)connected", inet or inet6 routes to directly attached networks will be announced. If set to "(inet|inet6) static", all inet or inet6 static routes will be announced.</fielddescr> <fieldname>networks</fieldname> <description>Network that you would like to advertise</description> <type>input</type> diff --git a/config/openbgpd/openbgpd_neighbors.xml b/config/openbgpd/openbgpd_neighbors.xml index efa82384..5553c022 100644 --- a/config/openbgpd/openbgpd_neighbors.xml +++ b/config/openbgpd/openbgpd_neighbors.xml @@ -100,13 +100,13 @@ <field> <fielddescr>TCP-MD5 key</fielddescr> <fieldname>md5sigkey</fieldname> - <description>The md5 key to communicate with the peer. Does not work with Cisco BGP routers.</description> + <description>The md5 key to communicate with the peer. Does not work with Cisco BGP routers. If the Local Addr option is not set listening ip will be used.</description> <type>input</type> </field> <field> <fielddescr>TCP-MD5 password</fielddescr> <fieldname>md5sigpass</fieldname> - <description>The md5 password to communicate with the peer. Use this when communicating with a Cisco BGP router.</description> + <description>The md5 password to communicate with the peer. Use this when communicating with a Cisco BGP router. If the Local Addr option is not set listenning ip will be used.</description> <type>input</type> </field> <field> diff --git a/config/openbgpd/openbgpd_status.php b/config/openbgpd/openbgpd_status.php index b493236f..99076d12 100644 --- a/config/openbgpd/openbgpd_status.php +++ b/config/openbgpd/openbgpd_status.php @@ -3,7 +3,7 @@ /* openbgpd_status.php part of pfSense (http://www.pfsense.com/) - Copyright (C) 2007 Scott Ullrich (sullrich@gmail.com) + Copyright (C) 2007 Scott Ullrich (sullrich@gmail.com) All rights reserved. Redistribution and use in source and binary forms, with or without @@ -30,6 +30,28 @@ require("guiconfig.inc"); +$commands = array(); + +defCmdT("summary", "OpenBGPD Summary", "/usr/local/sbin/bgpctl show summary"); +defCmdT("interfaces", "OpenBGPD Interfaces", "/usr/local/sbin/bgpctl show interfaces"); +defCmdT("routing", "OpenBGPD Routing", "/usr/local/sbin/bgpctl show rib", true, 4); +defCmdT("forwarding", "OpenBGPD Forwarding", "/usr/local/sbin/bgpctl show fib", true, 5); +defCmdT("network", "OpenBGPD Network", "/usr/local/sbin/bgpctl show network"); +defCmdT("nexthops", "OpenBGPD Nexthops", "/usr/local/sbin/bgpctl show nexthop"); +defCmdT("ip", "OpenBGPD IP", "/usr/local/sbin/bgpctl show ip bgp", true, 4); +defCmdT("neighbors", "OpenBGPD Neighbors", "/usr/local/sbin/bgpctl show neighbor"); + +if (isset($_REQUEST['isAjax'])) { + if (isset($_REQUEST['cmd']) && isset($commands[$_REQUEST['cmd']])) { + echo "{$_REQUEST['cmd']}\n"; + if (isset($_REQUEST['count'])) + echo " of " . countCmdT($commands[$_REQUEST['cmd']]['command']) . " items"; + else + echo htmlspecialchars_decode(doCmdT($commands[$_REQUEST['cmd']]['command'], $_REQUEST['limit'], $_REQUEST['filter'], $_REQUEST['header_size'])); + } + exit; +} + if ($config['version'] >= 6) $pgtitle = array("OpenBGPD", "Status"); else @@ -37,84 +59,178 @@ else include("head.inc"); -function doCmdT($title, $command) { - echo "<p>\n"; - echo "<a name=\"" . $title . "\">\n"; - echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"; - echo "<tr><td class=\"listtopic\">" . $title . "</td></tr>\n"; - echo "<tr><td class=\"listlr\"><pre>"; /* no newline after pre */ - - if ($command == "dumpconfigxml") { - $fd = @fopen("/conf/config.xml", "r"); - if ($fd) { - while (!feof($fd)) { - $line = fgets($fd); - /* remove sensitive contents */ - $line = preg_replace("/<password>.*?<\\/password>/", "<password>xxxxx</password>", $line); - $line = preg_replace("/<pre-shared-key>.*?<\\/pre-shared-key>/", "<pre-shared-key>xxxxx</pre-shared-key>", $line); - $line = preg_replace("/<rocommunity>.*?<\\/rocommunity>/", "<rocommunity>xxxxx</rocommunity>", $line); - $line = str_replace("\t", " ", $line); - echo htmlspecialchars($line,ENT_NOQUOTES); - } - } - fclose($fd); - } else { - $execOutput = ""; - $execStatus = ""; - exec ($command . " 2>&1", $execOutput, $execStatus); - for ($i = 0; isset($execOutput[$i]); $i++) { - if ($i > 0) { - echo "\n"; - } - echo htmlspecialchars($execOutput[$i],ENT_NOQUOTES); +function doCmdT($command, $limit = "all", $filter = "", $header_size = 0) { + $grepline = ""; + if (!empty($filter)) { + $ini = ($header_size > 0 ? $header_size+1 : 1); + $grepline = " | /usr/bin/sed -e '{$ini},\$ { /" . escapeshellarg(htmlspecialchars($filter)) . "/!d; };'"; + } + if (is_numeric($limit) && $limit > 0) { + $limit += $header_size; + $headline = " | /usr/bin/head -n {$limit}"; + } + + $fd = popen("{$command}{$grepline}{$headline} 2>&1", "r"); + $ct = 0; + $result = ""; + while (($line = fgets($fd)) !== FALSE) { + $result .= htmlspecialchars($line, ENT_NOQUOTES); + if ($ct++ > 1000) { + ob_flush(); + $ct = 0; } } - echo "</pre></tr>\n"; - echo "</table>\n"; + pclose($fd); + + return $result; } -/* Execute a command, giving it a title which is the same as the command. */ -function doCmd($command) { - doCmdT($command,$command); +function countCmdT($command) { + $fd = popen("{$command} 2>&1", "r"); + $c = 0; + while (fgets($fd) !== FALSE) + $c++; + + pclose($fd); + + return $c; } -/* Define a command, with a title, to be executed later. */ -function defCmdT($title, $command) { - global $commands; - $title = htmlspecialchars($title,ENT_NOQUOTES); - $commands[] = array($title, $command); +function showCmdT($idx, $data) { + echo "<p>\n"; + echo "<a name=\"" . $data['title'] . "\"> </a>\n"; + echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"; + echo "<tr><td colspan=\"2\" class=\"listtopic\">" . $data['title'] . "</td></tr>\n"; + + $limit_default = "all"; + if ($data['has_filter']) { + $limit_options = array("10", "50", "100", "200", "500", "1000", "all"); + $limit_default = "100"; + + echo "<tr><td class=\"listhdr\" style=\"font-weight:bold;\">\n"; + echo "Display <select onchange=\"update_filter('{$idx}','{$data['header_size']}');\" name=\"{$idx}_limit\" id=\"{$idx}_limit\">\n"; + foreach ($limit_options as $item) + echo "<option value='{$item}' " . ($item == $limit_default ? "selected" : "") . ">{$item}</option>\n"; + echo "</select> <span name=\"{$idx}_count\" id=\"{$idx}_count\">items</span></td>\n"; + echo "<td class=\"listhdr\" align=\"right\" style=\"font-weight:bold;\">Filter expression: \n"; + echo "<input type=\"text\" name=\"{$idx}_filter\" id=\"{$idx}_filter\" class=\"formfld search\" value=\"" . htmlspecialchars($_REQUEST["{$idx}_filter"]) . "\" size=\"30\" />\n"; + echo "<input type=\"button\" class=\"formbtn\" value=\"Filter\" onclick=\"update_filter('{$idx}','{$data['header_size']}');\" />\n"; + echo "</td></tr>\n"; + } + + echo "<tr><td colspan=\"2\" class=\"listlr\"><pre id=\"{$idx}\">"; /* no newline after pre */ + echo "Gathering data, please wait...\n"; + echo "</pre></td></tr>\n"; + echo "</table>\n"; } -/* Define a command, with a title which is the same as the command, - * to be executed later. - */ -function defCmd($command) { - defCmdT($command,$command); +/* Define a command, with a title, to be executed later. */ +function defCmdT($idx, $title, $command, $has_filter = false, $header_size = 0) { + global $commands; + $title = htmlspecialchars($title,ENT_NOQUOTES); + $commands[$idx] = array( + 'title' => $title, + 'command' => $command, + 'has_filter' => $has_filter, + 'header_size' => $header_size); } /* List all of the commands as an index. */ function listCmds() { - global $commands; - echo "<p>This status page includes the following information:\n"; - echo "<ul width=\"700\">\n"; - for ($i = 0; isset($commands[$i]); $i++ ) { - echo "<li><strong><a href=\"#" . $commands[$i][0] . "\">" . $commands[$i][0] . "</a></strong></li>\n"; - } - echo "</ul>\n"; + global $commands; + echo "<p>This status page includes the following information:\n"; + echo "<ul width=\"700\">\n"; + foreach ($commands as $idx => $command) + echo "<li><strong><a href=\"#" . $command['title'] . "\">" . $command['title'] . "</a></strong></li>\n"; + echo "</ul>\n"; } /* Execute all of the commands which were defined by a call to defCmd. */ function execCmds() { - global $commands; - for ($i = 0; isset($commands[$i]); $i++ ) { - doCmdT($commands[$i][0], $commands[$i][1]); - } + global $commands; + foreach ($commands as $idx => $command) + showCmdT($idx, $command); } ?> <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> + +<script type="text/javascript"> +//<![CDATA[ + + function update_count(cmd, header_size) { + var url = "openbgpd_status.php"; + var params = "isAjax=true&count=true&cmd=" + cmd + "&header_size=" + header_size; + var myAjax = new Ajax.Request( + url, + { + method: 'post', + parameters: params, + onComplete: update_count_callback + }); + } + + function update_count_callback(transport) { + // First line contain field id to be updated + var responseTextArr = transport.responseText.split("\n"); + + document.getElementById(responseTextArr[0] + "_count").innerHTML = responseTextArr[1]; + } + + function update_filter(cmd, header_size) { + var url = "openbgpd_status.php"; + var filter = ""; + var limit = "all"; + var limit_field = document.getElementById(cmd + "_limit"); + if (limit_field) { + var index = limit_field.selectedIndex; + limit = limit_field.options[index].value; + filter = document.getElementById(cmd + "_filter").value; + } + var params = "isAjax=true&cmd=" + cmd + "&limit=" + limit + "&filter=" + filter + "&header_size=" + header_size; + var myAjax = new Ajax.Request( + url, + { + method: 'post', + parameters: params, + onComplete: update_filter_callback + }); + } + + function update_filter_callback(transport) { + // First line contain field id to be updated + var responseTextArr = transport.responseText.split("\n"); + var id = responseTextArr.shift(); + + document.getElementById(id).textContent = responseTextArr.join("\n"); + } + +//]]> +</script> + <?php include("fbegin.inc"); ?> +<script type="text/javascript"> +//<![CDATA[ + + function exec_all_cmds() { +<?php + foreach ($commands as $idx => $command) { + if ($command['has_filter']) + echo "\t\tupdate_count('{$idx}', {$command['header_size']});\n"; + echo "\t\tupdate_filter('{$idx}', {$command['header_size']});\n"; + } +?> + } + +if (typeof jQuery == 'undefined') + document.observe('dom:loaded', function(){setTimeout('exec_all_cmds()', 5000);}); +else + jQuery(document).ready(function(){setTimeout('exec_all_cmds()', 5000);}); + +//]]> +</script> + <?php if ($config['version'] < 6) echo '<p class="pgtitle">' . $pgtitle . '</font></p>'; @@ -135,37 +251,17 @@ function execCmds() { ?> </table> <table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td class="tabcont" > - <form action="tinydns_status.php" method="post"> - </form> - </td> - </tr> - <tr> - <td class="tabcont" > - -<?php - -defCmdT("OpenBGPD Summary","bgpctl show summary"); -defCmdT("OpenBGPD Interfaces","bgpctl show interfaces"); -defCmdT("OpenBGPD Routing","bgpctl show rib"); -defCmdT("OpenBGPD Forwarding","bgpctl show fib"); -defCmdT("OpenBGPD Network","bgpctl show network"); -defCmdT("OpenBGPD Network","bgpctl show network"); -defCmdT("OpenBGPD Nexthops","bgpctl show nexthop"); -defCmdT("OpenBGPD IP","bgpctl show ip bgp"); -defCmdT("OpenBGPD Neighbors","bgpctl show neighbor"); + <tr> + <td class="tabcont" > -?> - <div id="cmdspace" style="width:100%"> - <?php listCmds(); ?> - - <?php execCmds(); ?> - </div> - - </table> - </td> - </tr> + <div id="cmdspace" style="width:100%"> + <?php listCmds(); ?> + + <?php execCmds(); ?> + </div> + + </td> + </tr> </table> </div> |