function execCmds()
{
    global $commands;
    for ($i = 0; isset($commands[$i]); $i++) {
        doCmdT($commands[$i][0], $commands[$i][1]);
    }
}
$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;
}
$pgtitle = array("OpenBGPD", "Status");
include "head.inc";
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;