added junos, updated screenos
authorpaulr <me@pjr.cc>
Sat, 11 Jun 2011 20:07:18 +0000 (06:07 +1000)
committerpaulr <me@pjr.cc>
Sat, 11 Jun 2011 20:07:18 +0000 (06:07 +1000)
lib/junos.plugin.php [new file with mode: 0644]
lib/screenos.plugin.php
lib/www.php

diff --git a/lib/junos.plugin.php b/lib/junos.plugin.php
new file mode 100644 (file)
index 0000000..61ec460
--- /dev/null
@@ -0,0 +1,12 @@
+<?php 
+$HOST_TYPE["junos"]["name"] = "Juniper JunOS Devices";
+$HOST_TYPE["junos"]["getconfig"] = "jos_getConfig";
+$HOST_TYPE["junos"]["needsenable"] = false;
+
+
+
+function jos_getConfig($host, $username, $password, $enable)
+{
+       return genericssh_ssh($host, $username, $password, "cli show configuration");
+}
+?>
\ No newline at end of file
index 30da607..20555d3 100644 (file)
@@ -1,60 +1,8 @@
 <?php 
 $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>
-       <?php
-}
-
-function nsos_postFunction()
-{
-       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>";
-}
+$HOST_TYPE["screenos"]["needsenable"] = false;
 
 
 function nsos_getConfigFromDB($hip, $cid)
@@ -64,70 +12,11 @@ function nsos_getConfigFromDB($hip, $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)
+function nsos_getConfig($host, $username, $password, $enable)
 {
        return genericssh_ssh($host, $username, $password, "cli show configuration");
 }
index 3b7c506..91ce2c2 100644 (file)
@@ -4,8 +4,8 @@
 // some global menu stuff
 $MENUS["home"]["url"] = "?action=home";
 $MENUS["home"]["name"] = "Home";
-$MENUS["hosts"]["url"] = "?action=hosts";
-$MENUS["hosts"]["name"] = "Hosts";
+//$MENUS["hosts"]["url"] = "?action=hosts";
+//$MENUS["hosts"]["name"] = "Hosts";
 $MENUS["add"]["url"] = "?action=addhost";
 $MENUS["add"]["name"] = "Add Host";
 $MENUS["config"]["url"] = "?action=config";
@@ -188,10 +188,27 @@ function www_updateHost()
        $hostname = $data[0]["hostname"];
        $htype = $data[0]["hosttype"];
        
-       $func = $HOST_TYPE["$htype"]["updateconfig"];
+       $func = $HOST_TYPE["$htype"]["getconfig"];
+       $logdets = unserialize(base64_decode($hconfig));
+
+       $conf = $func($hip, $logdets["username"], $logdets["password"], $logdets["enable"]);
+
+       // function db_getMaxValue($tablename, $column, $columnsel="", $wheresel="")
+       $oldconf_rid = db_getMaxValue("configs", "configs_id", "hostip", "$hip");
+       $oldconf_id = $oldconf_rid[0][0];
+       error_log("oldconf_id is $oldconf_id");
        
-       error_log("calling $func with $hip, and $hconfig");
-       $func("$hip", $hconfig);
+       // function db_selectData($tablename, $column="", $value="", $orderby = "")
+       $oldconf_r = db_selectData("configs", "configs_id", "$oldconf_id");
+       $oldconf = base64_decode($oldconf_r[0]["configdata"]);
+       
+       if(md5($oldconf) != md5($conf)) {
+               echo "New config found, updating db<br>";
+               db_insertData("configs", "$hip", time(), base64_encode($conf));
+               echo "Config added<br>";
+       } else {
+               echo "New config and old config are the same, not updating<br>";
+       }
        
 }
 
@@ -220,9 +237,6 @@ function www_deleteHost()
        } 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>";
        }
 }
 
@@ -249,12 +263,17 @@ function www_addhost()
        db_createTable("configs", "hostip", "configtime", "configdata");
        ?>
 <form method="post" action="?action=addhostnext">
+<i>Note: if you leave the username/password fields blank, you'll be prompted when
+manually updating on the home page</i>
 <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>Username</td><td><input type="text" name="username"></td></tr>
+<tr><td>Password</td><td><input type="password" name="password"></td></tr>
+<tr><td>Enable Password</td><td><input type="password" name="enable"></td></tr>
 <tr><td>Host Type</td><td><select name="hosttype"><?php www_hostTypesDropDown() ?></select></td></tr>
 <tr><td>Update Schedule</td><td><select name="updatesched"><?php www_updateSchedule() ?></select></td></tr></table>
-<input type="submit" value="Next" name="Next">
+<input type="submit" value="Add" name="Add">
 </form>
        <?php
 }
@@ -272,29 +291,31 @@ function www_addHostStageTwo()
        }
        if(isset($_REQUEST["hosttype"])) {
                $htype = $_REQUEST["hosttype"];
-               $func = $HOST_TYPE["$htype"]["configform"];
                $hip = $_REQUEST["hname"];
+               $user = $_REQUEST["username"];
+               $pass = $_REQUEST["password"];
+               $enable = $_REQUEST["enable"];
                $hname = $_REQUEST["hname"];
                $upsched = $_REQUEST["updatesched"];
-               if(function_exists($func)) {
-                       
-                       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";
-       }
-}
+               
+               $confdetails["username"] = $user;
+               $confdetails["password"] = $pass;
+               $confdetails["enable"] = $enable;
+               
+               $logdata = base64_encode(serialize($confdetails));
+               
+               db_updateData("hosts", "hostconfig", "$logdata", "hostip", "$hip");
+               //function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true)
+               
 
-function www_addHostStageThree()
-{
-       global $HOST_TYPE;
-       if(isset($_REQUEST["hosttype"])) {
-               $htype = $_REQUEST["hosttype"];
-               $func = $HOST_TYPE["$htype"]["postfunction"];
-               if(function_exists($func)) {
-                       $func();
-               } else echo "would call $func for $htype but it doesnt exist\n";
+               echo "Host added successfully, running configuration test<br>";
+               $func = $HOST_TYPE["$htype"]["getconfig"];
+               $conf = $func($hip, $user, $pass, $enable);
+               echo "The config I got is below, hope its correct as it'll be inserted into the DB as config version 1<br><pre>$conf</pre>";
+               
+               //db_createTable("configs", "hostip", "configtime", "configdata");
+               db_insertData("configs", "$hip", time(), base64_encode($conf));
        }
-       
 }
+
 ?>
\ No newline at end of file