<?php
+$DB_URL="sqlite:$BASE_DIR/var/ds_store.db";
+
+global $DB_URL;
+
?>
\ No newline at end of file
--- /dev/null
+<?php
+
+$HOST_TYPE["cisco"]["name"] = "Cisco";
+$HOST_TYPE["cisco"]["configform"] = "somefuntion";
+$HOST_TYPE["cisco"]["postfunction"] = "somefuntion";
+
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+function db_getDB()
+{
+ global $DB_URL;
+
+ $dbobject = false;
+ global $BASE_DIR, $DB_HANDLE;
+ if($DB_HANDLE != false) return $DB_HANDLE;
+ try {
+ $dbobject = new PDO("$DB_URL");
+ } catch(PDOException $exep) {
+ error_log("execpt on db open");
+ return false;
+ }
+
+ $DB_HANDLE = $dbobject;
+
+ return $dbobject;
+}
+
+function db_createDB()
+{
+ // theres not much to do yet with only sqlite support
+}
+
+// all columns end up as text
+function db_createTable($tablename)
+{
+ $db = db_getDB();
+
+ if(db_tableExists($tablename)) return true;
+
+ $sql = "create table \"$tablename\" (\"".$tablename."_id\" INTEGER PRIMARY KEY AUTOINCREMENT";
+ for($i=1; $i < func_num_args(); $i++) {
+ $colname = func_get_arg($i);
+ $sql .= ", $colname text";
+ }
+ $sql .= ")";
+
+ //echo "sql: $sql\n";
+ $db->query($sql);
+}
+
+function db_insertData($tablename)
+{
+
+ $db = db_getDB();
+
+ $sql = "insert into \"$tablename\" values (NULL";
+ for($i=1; $i < func_num_args(); $i++) {
+ $sql .= ",'".func_get_arg($i)."'";
+ }
+ $sql .=")";
+
+ $db->query($sql);
+}
+
+function db_selectData($tablename, $column="", $value="")
+{
+ $db = db_getDB();
+
+ if($column != "") $extra = " where $column like '%$value%'";
+ else $extra = "";
+ $sql = "select * from \"$tablename\"$extra";
+ $res = $db->query($sql);
+ if(!$res) return false;
+ $data = $res->fetchAll();
+
+ return $data;
+}
+
+function db_deleteData($tablename, $column, $value)
+{
+ $db = db_getDB();
+
+ $sql = "delete from \"$tablename\" where $column like '%$value%'";
+ //echo "Sql is $sql\n";
+ return $db->query($sql);
+
+}
+
+function db_updateData($tablename, $column, $newdata, $wherecol, $wheredata, $exact=true)
+{
+ $db = db_getDB();
+
+ 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);
+}
+
+function db_deleteTable($tablename)
+{
+ $db = db_getDB();
+
+ $sql = "drop table $tablename";
+
+ return $db->query($sql);
+}
+
+function db_tableExists($tablename)
+{
+ $db = db_getDB();
+
+ $sql = "select count(*) from sqlite_master where type='table' and name='$tablename'";
+ $res = $db->query($sql);
+
+ $value = $res->fetchColumn();
+
+ if($value == 1) return true;
+ else return false;
+}
+
+function db_getTables()
+{
+ $db = db_getDB();
+
+ $sql = "select name from sqlite_master where type='table' and name not like 'sqlite_%'";
+ $res = $db->query($sql);
+
+ return $res->fetchAll();
+}
+?>
\ No newline at end of file
<?php
+$BASE_DIR = realpath(dirname(__FILE__)."/../");
+
+$DB_HANDLE = false;
+global $BASE_DIR, $HOST_TYPES, $DB_HANDLE;
+
+// require some files
+require_once("www.php");
+require_once("db.php");
+require_once("xmlrpc.php");
+
+// get the config
+if(file_exists("../etc/config.php")) require_once("../etc/config.php");
+
+// first and foremost, load the plugins
+$basedir = dirname(__FILE__);
+
+// we load this first
+if(is_dir("$basedir")) {
+ $dh = opendir("$basedir");
+ if($dh) {
+ while(($file = readdir($dh))!==false) {
+ $mt = preg_match("/.*\.plugin\.php$/", $file);
+ if($mt > 0) {
+ require_once("$basedir/$file");
+ //echo "required $basedir/$file\n";
+ }
+ }
+ }
+} else {
+ echo "No plugins dir ($basedir/plugins), continuing without\n";
+}
+
+$db = db_getDB();
?>
\ No newline at end of file
--- /dev/null
+<?php
+$HOST_TYPE["screenos"]["name"] = "Netscreen Screen OS";
+$HOST_TYPE["screenos"]["configform"] = "nsos_formFunction";
+$HOST_TYPE["screenos"]["postfunction"] = "nsos_postFunction";
+
+function nsos_formFunction()
+{
+ ?>
+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()
+{
+ echo "i am post function, your awesome<br>";
+ echo "<pre>";
+ print_r($_REQUEST);
+ echo "</pre>";
+}
+
+function nsos_getConfig($istest)
+{
+
+}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+$HOST_TYPE["unix"]["name"] = "Unix (ssh)";
+$HOST_TYPE["unix"]["configform"] = "somefuntion";
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+// some global menu stuff
+$MENUS["home"]["url"] = "?action=home";
+$MENUS["home"]["name"] = "Home";
+$MENUS["hosts"]["url"] = "?action=hosts";
+$MENUS["hosts"]["name"] = "Hosts";
+$MENUS["add"]["url"] = "?action=addhost";
+$MENUS["add"]["name"] = "Add Host";
+$MENUS["config"]["url"] = "?action=config";
+$MENUS["config"]["name"] = "Configure";
+
+$FUNCTIONS["config"] = "www_configure";
+$FUNCTIONS["addhost"] = "www_addhost";
+$FUNCTIONS["addhostnext"] = "www_addHostStageTwo";
+$FUNCTIONS["addhostthree"] = "www_addHostStageThree";
+
+
+function www_header()
+{
+ ?>
+<html>
+<title>Network Config Manager</title>
+<body>
+ <?php
+}
+
+function www_pageLayout()
+{
+ ?>
+<table>
+<tr><td colspan="2"><h1>Network Config Manager</h1></td></tr>
+<tr valign="top"><td><?php www_menu() ?></td><td><?php www_body() ?></td></tr>
+</table>
+
+ <?php
+}
+
+function www_footer()
+{
+ ?>
+<br><font size="-1"><i>Copyright 2003-2011, Paul J Robinson</i></font><br>
+</body>
+</html>
+ <?php
+}
+
+function www_menu()
+{
+ global $MENUS;
+ foreach($MENUS as $menuitems) {
+ $url = $menuitems["url"];
+ $name = $menuitems["name"];
+ echo "<a href=\"$url\">$name</a><br>";
+ }
+}
+
+function www_body()
+{
+ global $FUNCTIONS;
+
+ $called = false;
+ if(isset($_REQUEST["action"])) {
+ $req = $_REQUEST["action"];
+ if(isset($FUNCTIONS["$req"])) {
+ $func = $FUNCTIONS["$req"];
+ if(function_exists($func)) {
+ $func();
+ return true;
+ }
+ }
+ }
+
+ $db = db_getDB();
+
+ // here we do the normal body, whatever that
+ // we'll list the hosts, the size of the current config and
+ // the last time it was updated, plus the number of versions
+
+}
+
+function www_hostTypesDropDown()
+{
+ global $HOST_TYPE;
+
+ foreach($HOST_TYPE as $tloop => $types) {
+ $typename = $types["name"];
+ $typever = $tloop;
+ echo "<option value=\"$typever\">$typename</option>";
+ }
+}
+
+function www_addhost()
+{
+ ?>
+<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>
+<input type="submit" value="Next" name="Next">
+</form>
+ <?php
+}
+
+function www_addHostStageTwo()
+{
+ global $HOST_TYPE;
+ if(isset($_REQUEST["hosttype"])) {
+ $htype = $_REQUEST["hosttype"];
+ $func = $HOST_TYPE["$htype"]["configform"];
+ if(function_exists($func)) {
+ echo "<form method=\"post\" action=\"?action=addhostthree&hosttype=$htype\">";
+ $func();
+ echo "<input type=\"submit\" value=\"Add\" name=\"Add\">";
+ } else echo "would call $func for $htype but it doesnt exist\n";
+ }
+}
+
+function www_addHostStageThree()
+{
+ global $HOST_TYPE;
+ if(isset($_REQUEST["hosttype"])) {
+ $htype = $_REQUEST["htype"];
+ $func = $HOST_TYPE["$htype"]["postfunction"];
+ if(function_exists($func)) {
+ $func();
+ } else echo "would call $func for $htype but it doesnt exist\n";
+ }
+
+}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+function rpc_handler()
+{
+ echo "rpc handler goes here\n";
+}
+
+?>
\ No newline at end of file
<?php
require_once("../lib/lib.php");
+
+if(isset($_REQUEST["xmlrpc"])) {
+ rpc_handler();
+ return;
+}
+www_header();
+www_pageLayout();
+www_footer();
?>
\ No newline at end of file