From: paulr Date: Wed, 8 Jun 2011 22:35:34 +0000 (+1000) Subject: generic ssh X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=843363a8f4dca2460800d5c3c72b559cce15c99f;p=configmanager.git generic ssh --- diff --git a/lib/cisco.plugin.php b/lib/cisco.plugin.php index 4b6490c..c1f2032 100644 --- a/lib/cisco.plugin.php +++ b/lib/cisco.plugin.php @@ -4,5 +4,9 @@ $HOST_TYPE["cisco"]["name"] = "Cisco"; $HOST_TYPE["cisco"]["configform"] = "somefuntion"; $HOST_TYPE["cisco"]["postfunction"] = "somefuntion"; +function cisco_getConfig($istest) +{ + genericssh_ssh($host, $username, $password, "show running"); +} ?> \ No newline at end of file diff --git a/lib/db.php b/lib/db.php index f24917f..58f729d 100644 --- a/lib/db.php +++ b/lib/db.php @@ -4,6 +4,12 @@ function db_getDB() { global $DB_URL; + if(!isset($IS_WEB_REQUEST)) { + // only the web requests are allowed to create dbs + return false; + } + + $dbobject = false; global $BASE_DIR, $DB_HANDLE; if($DB_HANDLE != false) return $DB_HANDLE; @@ -29,6 +35,8 @@ function db_createTable($tablename) { $db = db_getDB(); + if(!$db) return false; + if(db_tableExists($tablename)) return true; $sql = "create table \"$tablename\" (\"".$tablename."_id\" INTEGER PRIMARY KEY AUTOINCREMENT"; @@ -47,6 +55,8 @@ function db_insertData($tablename) $db = db_getDB(); + if(!$db) return false; + $sql = "insert into \"$tablename\" values (NULL"; for($i=1; $i < func_num_args(); $i++) { $sql .= ",'".func_get_arg($i)."'"; @@ -60,6 +70,8 @@ function db_selectData($tablename, $column="", $value="") { $db = db_getDB(); + if(!$db) return false; + if($column != "") $extra = " where $column like '%$value%'"; else $extra = ""; $sql = "select * from \"$tablename\"$extra"; @@ -74,6 +86,8 @@ function db_deleteData($tablename, $column, $value) { $db = db_getDB(); + if(!$db) return false; + $sql = "delete from \"$tablename\" where $column like '%$value%'"; //echo "Sql is $sql\n"; return $db->query($sql); @@ -84,6 +98,8 @@ function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $ex { $db = db_getDB(); + if(!$db) return false; + if($exact) $sql = "update \"$tablename\" set $column='$newdata' where $wherecol='$wheredata'"; else $sql = "update \"$tablename\" set $column='$newdata' where $wherecol like '$wheredata'"; return $db->query($sql); @@ -93,6 +109,8 @@ function db_deleteTable($tablename) { $db = db_getDB(); + if(!$db) return false; + $sql = "drop table $tablename"; return $db->query($sql); @@ -102,6 +120,8 @@ function db_tableExists($tablename) { $db = db_getDB(); + if(!$db) return false; + $sql = "select count(*) from sqlite_master where type='table' and name='$tablename'"; $res = $db->query($sql); @@ -115,6 +135,8 @@ function db_getTables() { $db = db_getDB(); + if(!$db) return false; + $sql = "select name from sqlite_master where type='table' and name not like 'sqlite_%'"; $res = $db->query($sql); diff --git a/lib/genericssh.plugin.php b/lib/genericssh.plugin.php new file mode 100644 index 0000000..1842d6d --- /dev/null +++ b/lib/genericssh.plugin.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/lib/lib.php b/lib/lib.php index 0fb5214..49482a9 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -32,5 +32,4 @@ if(is_dir("$basedir")) { echo "No plugins dir ($basedir/plugins), continuing without\n"; } -$db = db_getDB(); ?> \ No newline at end of file diff --git a/lib/screenos.plugin.php b/lib/screenos.plugin.php index 7739cfe..7b1f2db 100644 --- a/lib/screenos.plugin.php +++ b/lib/screenos.plugin.php @@ -22,6 +22,6 @@ function nsos_postFunction() function nsos_getConfig($istest) { - + genericssh_ssh($host, $username, $password, "cli show configuration"); } ?> \ No newline at end of file diff --git a/lib/www.php b/lib/www.php index de4b337..794279b 100644 --- a/lib/www.php +++ b/lib/www.php @@ -1,5 +1,6 @@