$HOST_TYPE["screenos"]["name"] = "Netscreen Screen OS";
$HOST_TYPE["screenos"]["configform"] = "nsos_formFunction";
$HOST_TYPE["screenos"]["postfunction"] = "nsos_postFunction";
+$HOST_TYPE["screenos"]["updateconfig"] = "nsos_updateConfig";
+$HOST_TYPE["screenos"]["detail"] = "nsos_detail";
+$HOST_TYPE["screenos"]["getconfig"] = "nsos_getConfigFromDB";
function nsos_formFunction()
{
?>
+Note: If your router/firewall/device uses a one-time password, leave these blank and manually update from the
+home page<br>
Name <input type="text" name="username"><br>
Password <input type="password" name="password"><br>
Method <select name="methodtype"><option value="ssh">SSH</option><option value="telnet">Telnet</option></select>
function nsos_postFunction()
{
- echo "i am post function, your awesome<br>";
+ if($_REQUEST["password"] != "" && $_REQUEST["username"] != "") {
+
+ $hip = $_REQUEST["hostip"];
+ $user = $_REQUEST["username"];
+ $pass = $_REQUEST["password"];
+ $config = nsos_getConfig($hip, $user, $pass);
+ $hconfig["username"] = $user;
+ $hconfig["password"] = $pass;
+ $lastupdate = time();
+ $upsched = $_REQUEST["upsched"];
+ db_updateData("hosts", "hostconfig", base64_encode(serialize($hconfig)), "hostip", "$hip");
+ db_updateData("hosts", "lastupdate", "$lastupdate", "hostip", "$hip");
+ db_updateData("hosts", "updateschedule", "$upsched", "hostip", "$hip");
+ db_insertData("configs", "$hip", "$lastupdate", base64_encode($config));
+ //db_createTable("configs", "hostip", "configtime", "configdata");
+ //db_createTable("hosts", "hostname", "hostip", "hosttype", "hostconfig", "lastupdate", "updateschedule");
+ //function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true)
+
+ echo "if the below is accurate, this has worked<br>";
+
+ echo "Attempting first config grab, i see<br>";
+ echo "<pre>";
+ echo $config;
+ echo "</pre>";
+ } else {
+ echo "No username and password set, you can update manually from the home page\n";
+ $hconfig["username"] = "";
+ $hconfig["password"] = "";
+ db_updateData("hosts", "hostconfig", base64_encode(serialize($hconfig)), "hostip", "$hip");
+ }
+
+
echo "<pre>";
print_r($_REQUEST);
echo "</pre>";
}
-function nsos_getConfig($istest)
+
+function nsos_getConfigFromDB($hip, $cid)
+{
+ $data = db_selectData("configs", "configs_id", "$cid");
+
+ return base64_decode($data[0]["configdata"]);
+}
+
+function nsos_detail($hip)
+{
+ $data = db_selectData("configs", "hostip", "$hip", "configtime desc");
+
+ echo "<table border=\"1\">";
+ echo "<tr><th>Config Data</th><th>Compare</th></tr>";
+ foreach($data as $dstruct) {
+ //echo "<pre>";
+ //print_r($dstruct);
+ //echo "</pre>";
+ $dold = round((time()-$dstruct["configtime"])/86400);
+
+ $lupdate = strftime("%T %e %b %G", $dstruct["configtime"])." ($dold days old)";
+ $cid = $dstruct["configs_id"];
+ echo "<tr><td>$lupdate <a href=\"?action=getconfig&cid=$cid&hip=$hip\">Get</a> <a href=\"?action=downloadconfig&cid=$cid&hip=$hip\">Download</a></td><td>Tick</td></tr>";
+ }
+ echo "</table>";
+
+}
+
+function nsos_updateConfig($hip, $hostconfig)
+{
+ $hconf = unserialize(base64_decode($hostconfig));
+ if($hconf["username"] == "" && !isset($_REQUEST["username"])) {
+ echo "No username/password data<br>";
+?>
+<form method="post" action="?action=update&hip=<?php echo $hip ?>">
+Name <input type="text" name="username"><br>
+Password <input type="password" name="password"><br>
+<input type="submit" name="Go" value="Go"><br>
+</form>
+<?php
+ return 0;
+ }
+
+ if(isset($_REQUEST["username"])) {
+ $hconf["username"] = $_REQUEST["username"];
+ $hconf["password"] = $_REQUEST["password"];
+ }
+
+ $lastconfig_n_d = db_getMaxValue("configs", "configs_id", "hostip", $hip);
+ $lastconfig_n = $lastconfig_n_d[0][0];
+ $lastconfig_d = db_selectData("configs", "configs_id", "$lastconfig_n");
+ $lastconfig = base64_decode($lastconfig_d[0]["configdata"]);
+
+ $config = nsos_getConfig($hip, $hconf["username"], $hconf["password"]);
+
+ if(md5($config) == md5($lastconfig)) {
+ echo "Retrieved config is same as previous one, ignoring<br>";
+ return 0;
+ }
+
+ //error_log("getting config with ".$hconf["username"]." and ".$conf["password"]);
+ echo "Got config, saving it to db<br>";
+ $lastupdate = time();
+ db_updateData("hosts", "lastupdate", "$lastupdate", "hostip", "$hip");
+ db_insertData("configs", "$hip", "$lastupdate", base64_encode($config));
+
+ echo "Config is:<br><pre>";
+ echo $config;
+ echo "</pre>";
+}
+
+function nsos_getConfig($host, $username, $password)
{
- genericssh_ssh($host, $username, $password, "cli show configuration");
+ return genericssh_ssh($host, $username, $password, "cli show configuration");
}
?>
\ No newline at end of file
$FUNCTIONS["addhost"] = "www_addhost";
$FUNCTIONS["addhostnext"] = "www_addHostStageTwo";
$FUNCTIONS["addhostthree"] = "www_addHostStageThree";
-
+$FUNCTIONS["delete"] = "www_deleteHost";
+$FUNCTIONS["update"] = "www_updateHost";
+$FUNCTIONS["detail"] = "www_hostDetail";
+$FUNCTIONS["getconfig"] = "www_getConfig";
+$FUNCTIONS["downloadconfig"] = "www_downloadConfig";
function www_header()
{
$db = db_getDB();
- // here we do the normal body, whatever that
+ // here we do the normal body
// we'll list the hosts, the size of the current config and
// the last time it was updated, plus the number of versions
+ $data = db_selectData("hosts");
+ if(!$data) {
+ echo "No hosts currently exist, add them from the right<br>";
+ } else {
+ echo "<table border=\"1\">";
+ echo "<tr><th>Name</th><th>Address</th><th>Last Update</th><th>Schedule</th><th>Versions</th><th>Controls</th></tr>";
+ foreach($data as $dstruct) {
+ //print_r($dstruct);
+ $name = $dstruct["hostname"];
+ $addr = $dstruct["hostip"];
+ if($dstruct["lastupdate"] != 0) {
+ $dold = round((time()-$dstruct["lastupdate"])/86400);
+
+ $lupdate = strftime("%T %e %b %G", $dstruct["lastupdate"])." ($dold days old)";
+ } else {
+ $lupdate = "Never";
+ }
+ $sched = $dstruct["updateschedule"];
+ $vd = count(db_selectData("configs", "hostip", "$addr"));
+ echo "<tr><td><a href=\"?action=detail&hip=$addr\">$name</a></td><td>$addr</td><td>$lupdate</td><td>$sched</td><td>$vd</td><td>";
+ echo "<a href=\"?action=delete&hip=$addr\">Delete</a> <a href=\"?action=edit&hip=$addr\">Edit</a> <a href=\"?action=update&hip=$addr\">Update</a>";
+ echo "</td></tr>";
+
+ }
+ echo "</table>";
+ }
+
+}
+
+function www_getConfig()
+{
+ global $HOST_TYPE;
+
+ $cid = $_REQUEST["cid"];
+ $hip = $_REQUEST["hip"];
+ $data = db_selectData("hosts", "hostip", "$hip");
+
+ $hostname = $data[0]["hostname"];
+ $htype = $data[0]["hosttype"];
+
+ $func = $HOST_TYPE["$htype"]["getconfig"];
+
+ error_log("calling $func with $hip, and $cid");
+ $rdata = $func("$hip", "$cid");
+
+ echo "Config:<br>";
+ echo "<pre>";
+ echo $rdata;
+ echo "</pre>";
+}
+
+function www_downloadConfig()
+{
+ global $HOST_TYPE;
+
+ $cid = $_REQUEST["cid"];
+ $hip = $_REQUEST["hip"];
+ $data = db_selectData("hosts", "hostip", "$hip");
+
+ $hostname = $data[0]["hostname"];
+ $htype = $data[0]["hosttype"];
+
+ $func = $HOST_TYPE["$htype"]["getconfig"];
+
+ error_log("calling $func with $hip, and $cid");
+ $rdata = $func("$hip", "$cid");
+
+ echo "Config:<br>";
+ echo "<pre>";
+ echo $rdata;
+ echo "</pre>";
+}
+
+function www_hostDetail()
+{
+ global $HOST_TYPE;
+
+ //db_createTable("configs", "hostip", "configtime", "configdata");
+ //db_createTable("hosts", "hostname", "hostip", "hosttype", "hostconfig", "lastupdate", "updateschedule");
+ //function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true)
+ $hip = $_REQUEST["hip"];
+ $data = db_selectData("hosts", "hostip", "$hip");
+
+ $hconfig = $data[0]["hostconfig"];
+ $hostname = $data[0]["hostname"];
+ $htype = $data[0]["hosttype"];
+
+ $func = $HOST_TYPE["$htype"]["detail"];
+
+ error_log("calling $func with $hip, and $hconfig");
+ $func("$hip");
+}
+
+function www_updateHost()
+{
+ global $HOST_TYPE;
+
+ //db_createTable("configs", "hostip", "configtime", "configdata");
+ //db_createTable("hosts", "hostname", "hostip", "hosttype", "hostconfig", "lastupdate", "updateschedule");
+ //function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true)
+ $hip = $_REQUEST["hip"];
+ $data = db_selectData("hosts", "hostip", "$hip");
+
+ $hconfig = $data[0]["hostconfig"];
+ $hostname = $data[0]["hostname"];
+ $htype = $data[0]["hosttype"];
+
+ $func = $HOST_TYPE["$htype"]["updateconfig"];
+
+ error_log("calling $func with $hip, and $hconfig");
+ $func("$hip", $hconfig);
}
}
}
+function www_deleteHost()
+{
+ $hip = $_REQUEST["hip"];
+ $data = db_selectData("hosts", "hostip", "$hip");
+
+ $hostname = $data[0]["hostname"];
+
+ if(isset($_REQUEST["confirmed"])) {
+ db_deleteData("hosts", "hostip", "$hip");
+ db_deleteData("configs", "hostip", "$hip");
+ echo "Done!";
+ } else {
+ echo "Are you use you wish to delete the host, $hostname with IP address $hip? (and all associated config info)<br>";
+ echo "<a href=\"?action=delete&hip=$hip&confirmed=yes\">Yes</a>";
+ echo "<pre>";
+ print_r($data);
+ echo "</pre>";
+ }
+}
+
+function www_updateSchedule()
+{
+?>
+<option value="0">Manual Only</option>
+<option value="900">Every 15 Minutes</option>
+<option value="3600">Every Hour</option>
+<option value="14400">Every 4 Hours</option>
+<option value="86400">Once a Day</option>
+<option value="604800">Once a Week</option>
+<option value="2592000">Once a Month (30 Days)</option>
+<option value="7776000">Every 3 Months (90 days)</option>
+<option value="10368000">Every 6 Months (180 Days)</option>
+<?php
+}
+
function www_addhost()
{
+ $db = db_getDB();
+
+ db_createTable("hosts", "hostname", "hostip", "hosttype", "hostconfig", "lastupdate", "updateschedule");
+ db_createTable("configs", "hostip", "configtime", "configdata");
?>
<form method="post" action="?action=addhostnext">
<table>
<tr><td>Name</td><td><input type="text" name="cname"></td></tr>
<tr><td>Hostname/IP Address</td><td><input type="text" name="hname"></td></tr>
<tr><td>Host Type</td><td><select name="hosttype"><?php www_hostTypesDropDown() ?></select></td></tr>
-</table>
+<tr><td>Update Schedule</td><td><select name="updatesched"><?php www_updateSchedule() ?></select></td></tr></table>
<input type="submit" value="Next" name="Next">
</form>
<?php
function www_addHostStageTwo()
{
global $HOST_TYPE;
+
+ $data = db_selectData("hosts", "hostip", $_REQUEST["hname"]);
+ if($data) {
+ echo "Host already exists in database\n";
+ return false;
+ } else {
+ db_insertData("hosts", $_REQUEST["cname"], $_REQUEST["hname"], $_REQUEST["hosttype"], "", "", $_REQUEST["updatesched"]);
+ }
if(isset($_REQUEST["hosttype"])) {
$htype = $_REQUEST["hosttype"];
$func = $HOST_TYPE["$htype"]["configform"];
+ $hip = $_REQUEST["hname"];
+ $hname = $_REQUEST["hname"];
+ $upsched = $_REQUEST["updatesched"];
if(function_exists($func)) {
- echo "<form method=\"post\" action=\"?action=addhostthree&hosttype=$htype\">";
+
+ echo "<form method=\"post\" action=\"?action=addhostthree&hosttype=$htype&hostname=$hname&hostip=$hip&upsched=$upsched\">";
$func();
echo "<input type=\"submit\" value=\"Add\" name=\"Add\">";
} else echo "would call $func for $htype but it doesnt exist\n";
{
global $HOST_TYPE;
if(isset($_REQUEST["hosttype"])) {
- $htype = $_REQUEST["htype"];
+ $htype = $_REQUEST["hosttype"];
$func = $HOST_TYPE["$htype"]["postfunction"];
if(function_exists($func)) {
$func();