<?
/* Version 1.0.6
* MRLG for PHP --- multi router looking glass for GNU Zebra and
* Cisco IOS routers, written for PHP-enabled web-server.
* Copyright (C) 2002-2004 Denis Ovsienko
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author can be reached at his homepage: http://pilot.org.ua
*/
// Specify the look you wish lists to have here: ("radio"/"select")
$router_list_style = "radio";
$request_list_style = "radio";
/*
Describe your routers here.
* [title] is what you will see at the web-page, e.g. "border router"
or "core-1-2-net15-gw". If omitted, <address> will be used.
* <address> is IP dotted quad or DNS name, to which this script will telnet.
If omitted, corresonding router will be removed from the page automatically.
Pay attention to be able to resolve DNS name from the web server's side.
* [services] is a list of following words: zebra, ripd, ripngd, ospfd,
bgpd,
ospf6d. It defines availability to execute certain command on the router.
If omitted, no commands will be allowed on the router, although it
will remain on the list.
* [ignore_argc] lets get full routing table, when set to true,
therefore disabled by default
* <username> sets optional username to send before the password for the
router. If not set, username is not sent.
* [password] sets default password for all daemons on the router
* [DAEMON_password] redefines password for DAEMON on the router
* [DAEMON_port] redefines TCP port for the DAEMON. See examples below.
*/
// default values for all routers, used if there is no more specific setting
$router["default"]["zebra_port"] = "2601";
$router["default"]["ripd_port"] = "2602";
$router["default"]["ripngd_port"] = "2603";
$router["default"]["ospfd_port"] = "2604";
$router["default"]["bgpd_port"] = "2605";
$router["default"]["ospf6d_port"] = "2606";
$router["default"]["password"] = "zebra";
$router["default"]["ignore_argc"] = false;
// your routers
// I recommend using of key numbers with step of 10, it allows to insert new
// declarations without reordering the rest of list. As in BASIC or DNS MX.
// an example how to define a CISCO router
$router[40]["title"] = "Cisco 827";
$router[40]["address"] = "ip_address/hostname";
$router[40]["services"] = "zebra";
$router[40]["username"] = "username";
$router[40]["password"] = "password";
$router[40]["zebra_port"] = "23";
$router[40]["ospfd_port"] = "23";
$router[40]["bgpd_port"] = "23";
$request[10]["title"] = "show interface";
$request[10]["command"] = "show int";
$request[10]["handler"] = "zebra";
$request[10]["argc"] = 0;
$request[20]["title"] = "show ip route";
$request[20]["command"] = "show ip route";
$request[20]["handler"] = "zebra";
$request[20]["argc"] = 0;
$request[30]["title"] = "show access-lists";
$request[30]["command"] = "show access-lists";
$request[30]["handler"] = "zebra";
$request[30]["argc"] = 0;
$request[40]["title"] = "show hardware";
$request[40]["command"] = "show hardware";
$request[40]["handler"] = "zebra";
$request[40]["argc"] = 0;
$request[50]["title"] = "show version";
$request[50]["command"] = "show ver";
$request[50]["handler"] = "zebra";
$request[50]["argc"] = 0;
$request[60]["title"] = "show single interface (you must insert the interface
id)";
$request[60]["command"] = "sh int";
$request[60]["handler"] = "zebra";
$request[60]["argc"] = 1;
$request[70]["title"] = "show running-config";
$request[70]["command"] = "show run";
$request[70]["handler"] = "zebra";
$request[70]["argc"] = 0;
$request[80]["title"] = "show dsl interface";
$request[80]["command"] = "show dsl int at0";
$request[80]["handler"] = "zebra";
$request[80]["argc"] = 0;
$request[90]["title"] = "show logging";
$request[90]["command"] = "show logging";
$request[90]["handler"] = "zebra";
$request[90]["argc"] = 0;
$request[100]["title"] = "show processes";
$request[100]["command"] = "show processes";
$request[100]["handler"] = "zebra";
$request[100]["argc"] = 0;
$request[110]["title"] = "show processes cpu";
$request[110]["command"] = "show processes cpu";
$request[110]["handler"] = "zebra";
$request[110]["argc"] = 0;
$request[120]["title"] = "show processes cpu history";
$request[120]["command"] = "show processes cpu history";
$request[120]["handler"] = "zebra";
$request[120]["argc"] = 0;
$request[130]["title"] = "show memory";
$request[130]["command"] = "show mem";
$request[130]["handler"] = "zebra";
$request[130]["argc"] = 0;
$request[140]["title"] = "show controllers";
$request[140]["command"] = "show controllers";
$request[140]["handler"] = "zebra";
$request[140]["argc"] = 0;
$request[150]["title"] = "show cdp";
$request[150]["command"] = "show cdp";
$request[150]["handler"] = "zebra";
$request[150]["argc"] = 0;
$request[160]["title"] = "show ip dhcp (binding, database, pool)";
$request[160]["command"] = "show ip dhcp";
$request[160]["handler"] = "zebra";
$request[160]["argc"] = 1;
$request[170]["title"] = "show ip nat (statistics, translations)";
$request[170]["command"] = "show ip nat";
$request[170]["handler"] = "zebra";
$request[170]["argc"] = 1;
$request[180]["title"] = "show ip traffic";
$request[180]["command"] = "show ip traffic";
$request[180]["handler"] = "zebra";
$request[180]["argc"] = 0;
$request[190]["title"] = "show protocols";
$request[190]["command"] = "show protocols";
$request[190]["handler"] = "zebra";
$request[190]["argc"] = 0;
$request[200]["title"] = "show inventory";
$request[200]["command"] = "show inventory";
$request[200]["handler"] = "zebra";
$request[200]["argc"] = 0;
$request[210]["title"] = "show flash";
$request[210]["command"] = "show flash";
$request[210]["handler"] = "zebra";
$request[210]["argc"] = 0;
$request[220]["title"] = "show users";
$request[220]["command"] = "show users";
$request[220]["handler"] = "zebra";
$request[220]["argc"] = 0;
function printError ($message)
{
echo "<font color=red><code><strong>" . $message .
"</strong></code></font><br>\n";
}
function safeOutput ($string)
{
return htmlentities (substr ($string, 0, 50));
}
function printRouterList ($router, $type)
{
if ($type == "select") echo "<select name=routerid>\n";
while (list ($id, $attribute) = each ($router))
if (strcmp ($id, "default") && !empty($attribute["address"]))
{
if ($type == "select") echo "<option value={$id}";
if ($type == "radio") echo "<input type=radio name=routerid
value={$id}";
if ($_REQUEST["routerid"] == $id)
{
if ($type == "select") echo " selected=on";
if ($type == "radio") echo " checked=on";
}
echo ">";
echo $attribute["title"] ? $attribute["title"] :
$attribute["address"];
if ($type == "select") echo "</option>\n";
if ($type == "radio") echo "</input><br>\n";
}
if ($type == "select") echo "</{$type}>\n";
}
function printRequestList ($request, $type)
{
if ($type == "select") echo "<select name=requestid>";
while (list($id, $attribute) = each ($request))
if (!empty ($attribute["command"]) && !empty ($attribute["handler"])
&& isset ($attribute["argc"]))
{
if ($type == "select") echo "<option value={$id}";
if ($type == "radio") echo "<input type=radio name=requestid
value={$id}";
if ($_REQUEST["requestid"] == $id)
{
if ($type == "select") echo " selected=on";
if ($type == "radio") echo " checked=on";
}
echo ">";
echo $attribute["title"] ? $attribute["title"] :
$attribute["command"];
if ($type == "select") echo "</option>\n";
if ($type == "radio") echo "</input><br>\n";
}
echo "</{$type}>\n";
}
function execPreviousRequest ($router, $request)
{
if (!isset($_REQUEST["routerid"])) return;
$routerid = $_REQUEST["routerid"];
if (!isset ($router[$routerid]["address"])) return;
if (!isset($_REQUEST["requestid"])) return;
$requestid = $_REQUEST["requestid"];
if (!isset ($request[$requestid]["argc"])) return;
$handler = $request[$requestid]["handler"];
if (empty ($handler) || strpos ($router[$routerid]["services"], $handler)
=== false)
{
printError ("This request is not permitted for this router by
administrator.");
return;
}
if ($request[$requestid]["argc"] > 0)
{
if (trim ($_REQUEST["argument"]) == '')
{
$router_defined = isset ($router[$routerid]["ignore_argc"]);
$router_permits = $router[$routerid]["ignore_argc"] == 1;
$default_defined = isset ($router["default"]["ignore_argc"]);
$default_permits = $router["default"]["ignore_argc"] == 1;
$final_permits =
(!$router_defined && $default_defined && $default_permits) ||
($router_defined && $router_permits);
if (!$final_permits)
{
printError ("Full table view is denied on this router");
return;
}
}
else $argument = trim ($_REQUEST["argument"]);
}
// All Ok, do telnet
$address = $router[$routerid]["address"];
if (!empty ($router[$routerid][$handler . "_port"]))
$port = $router[$routerid][$handler . "_port"];
else
$port = $router["default"][$handler . "_port"];
if (!empty ($router[$routerid][$handler . "_password"]))
$password = $router[$routerid][$handler . "_password"];
elseif (!empty ($router[$routerid]["password"]))
$password = $router[$routerid]["password"];
else
$password = $router["default"]["password"];
$command = $request[$requestid]["command"] . (!empty ($argument) ? (" " .
safeOutput ($argument)) : "");
$link = fsockopen ($address, $port, $errno, $errstr, 5);
if (!$link)
{
printError ("Error connecting to router");
return;
}
socket_set_timeout ($link, 5);
$username = $router[$routerid]["username"];
if (!empty ($username)) fputs ($link, "{$username}\n");
fputs ($link, "{$password}\nterminal length 0\n{$command}\n");
// let daemon print bulk of records uninterrupted
if (empty ($argument) && $request[$requestid]["argc"] > 0) sleep (2);
fputs ($link, "quit\n");
echo "<pre>\n";
while (!feof ($link)) $readbuf = $readbuf . fgets ($link, 256);
$start = strpos ($readbuf, $command);
$len = strpos ($readbuf, "quit") - $start;
while ($readbuf[$start + $len] != "\n") $len--;
echo substr($readbuf, $start, $len);
echo "</pre>\n";
fclose ($link);
}
?>
<html>
<head>
<title>Multi-router looking glass</title>
</head>
<body>
<center>
<h1>Multi-router looking glass</h1>
<table border=0>
<form method=post action=<? echo $_SERVER[PHP_SELF]; ?>>
<tr>
<td valign=top><b>Router:</b><br><? printRouterList ($router,
$router_list_style); ?></td>
<td valign=top><b>Comando:</b><br><? printRequestList ($request,
$request_list_style) ?></td>
</tr>
<tr>
<td><b>Opzioni:</b> <input type=text name=argument length=20
maxlength=50<? echo " value='" . safeOutput (trim ($_REQUEST["argument"]) . "'");
?>></td>
<td><input type=submit value="Esegui"></td>
</tr>
</form>
<tr><td colspan=2><hr><b>Output comando:</b><br><?
execPreviousRequest ($router, $request); ?></td></tr>
</table>
</center>
<hr>
<small>
MRLG for PHP version 1.0.6, Copyright © 2002-2004 Denis Ovsienko<br>
MRLG for PHP comes with ABSOLUTELY NO WARRANTY; for details see source
code.<br>
This is free software, and you are welcome to redistribute it
under certain conditions; see source code for details.<br>
Implementazione comandi e traduzione realizzata da <a
href="mailto:
Questo indirizzo e-mail è protetto dallo spam bot. Abilita Javascript per vederlo.
">Alessandro Pensato</a>.
</small>
</body>
</html>