From 1209bb2b2c42b6f18233a54df684cc27cadfc581 Mon Sep 17 00:00:00 2001 From: paulr Date: Mon, 13 Jun 2011 05:55:07 +1000 Subject: [PATCH] god hates me --- lib/junos.plugin.php | 1 + lib/screenos.plugin.php | 39 ++++++++++++++++++++ lib/www.php | 92 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 104 insertions(+), 28 deletions(-) diff --git a/lib/junos.plugin.php b/lib/junos.plugin.php index 61ec460..6f70932 100644 --- a/lib/junos.plugin.php +++ b/lib/junos.plugin.php @@ -7,6 +7,7 @@ $HOST_TYPE["junos"]["needsenable"] = false; function jos_getConfig($host, $username, $password, $enable) { + error_log("junos: attempting login with $username, $password to $host"); return genericssh_ssh($host, $username, $password, "cli show configuration"); } ?> \ No newline at end of file diff --git a/lib/screenos.plugin.php b/lib/screenos.plugin.php index 20555d3..1cf4914 100644 --- a/lib/screenos.plugin.php +++ b/lib/screenos.plugin.php @@ -20,4 +20,43 @@ function nsos_getConfig($host, $username, $password, $enable) { return genericssh_ssh($host, $username, $password, "cli show configuration"); } + +// remembver this: +function screenosisgay($host, $username, $password, $command) +{ + $connector = ssh2_connect("$host"); + error_log("attempting connect to $host with $username"); + if($connector) { + error_log("connector true"); + } else { + error_log("connector false"); + } + ssh2_auth_password($connector, "$username", "$password"); + $stream = ssh2_shell($connector, 'ansi'); + fwrite($stream, PHP_EOL); + fwrite($stream, "set console page 0".PHP_EOL); + fwrite($stream, "get config".PHP_EOL); + fwrite($stream, PHP_EOL); + sleep(1); + stream_set_blocking($stream, true); + //fwrite($stream, "exit".PHP_EOL); + //fwrite($stream, "n".PHP_EOL); + + + $config = ""; + $initline = ""; + $haveinit = false; + while($buf = fgets($stream, 4096)) { + flush(); + echo "got buf\n\"$buf\"\n"; + $initline = $buf; + $config .= $buf; + } + fclose($stream); + + return $config; +} + + + ?> \ No newline at end of file diff --git a/lib/www.php b/lib/www.php index dc3a105..21a6d03 100644 --- a/lib/www.php +++ b/lib/www.php @@ -197,37 +197,69 @@ function www_updateHost() $need_enable = false; // this aint the right way. - if($logdets["username"] == "" && $_REQUEST["username"] == "") { - // we need a user - $need_user = true; + if($logdets["username"] == "") { + if(!isset($_REQUEST["username"])) { + // we need a user + $need_user = true; + } else { + $act_user = $_REQUEST["username"]; + } + } else { + $act_user = $logdets["username"]; } - if($logdets["password"] == "" && $_REQUEST["password"] == "") { - // we need a user - $need_pass = true; + if($logdets["password"] == "") { + if(!isset($_REQUEST["password"])) { + // we need a user + $need_pass = true; + } else { + $act_pass = $_REQUEST["password"]; + } + } else { + $act_pass = $logdets["password"]; } - if($logdets["enable"] == "" && $_REQUEST["enable"] == "" && $HOST_TYPE["$htype"]["needsenable"]) { - $need_enable = true; + if($HOST_TYPE["$htype"]["needsenable"]) { + if($logdets["enable"] == "") { + if(!isset($_REQUEST["enable"])) { + $need_enable = true; + } else { + $act_enable = $_REQUEST["enable"]; + } + } else { + $act_enable = $logdets["enable"]; + } } - $conf = $func($hip, $act_user, $act_pass, $act_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"); + if($need_user || $need_pass || $need_enable) { + echo "No Username/Password information stored, please enter them now (they will not be saved)
"; + echo "
"; + if($need_user) { + echo "User
"; + } + if($need_pass) echo "Password
"; + if($need_enable) echo "Enable Password
"; + echo ""; + echo ""; + } else { - // function db_selectData($tablename, $column="", $value="", $orderby = "") - $oldconf_r = db_selectData("configs", "configs_id", "$oldconf_id"); - $oldconf = base64_decode($oldconf_r[0]["configdata"]); + $conf = $func($hip, $act_user, $act_pass, $act_enable); - if(md5($oldconf) != md5($conf)) { - echo "New config found, updating db
"; - db_insertData("configs", "$hip", time(), base64_encode($conf)); - echo "Config added
"; - } else { - echo "New config and old config are the same, not updating
"; + // 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"); + + // 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
"; + db_insertData("configs", "$hip", time(), base64_encode($conf)); + echo "Config added
"; + } else { + echo "New config and old config are the same, not updating
"; + } } - } function www_hostTypesDropDown() @@ -326,10 +358,14 @@ function www_addHostStageTwo() //function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true) - echo "Host added successfully, running configuration test
"; - $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
$conf
"; + if($user != "" && $pass != "") { + echo "Host added successfully, running configuration test
"; + $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
$conf
"; + } else { + echo "Host added. but cant run config test until you manually update
"; + } //db_createTable("configs", "hostip", "configtime", "configdata"); db_insertData("configs", "$hip", time(), base64_encode($conf)); -- 1.7.0.4