adding some framework bits.
authorpaulr <me@pjr.cc>
Thu, 18 Aug 2011 18:19:18 +0000 (04:19 +1000)
committerpaulr <me@pjr.cc>
Thu, 18 Aug 2011 18:19:18 +0000 (04:19 +1000)
agent/agent.php [new file with mode: 0644]
docs/test_method.txt [new file with mode: 0644]
lib/lib.php [deleted file]
libanyhammer/config.php [new file with mode: 0644]
libanyhammer/lib.php [new file with mode: 0644]
libanyhammer/web.php [new file with mode: 0644]
plugins/ah_plugin.php [new file with mode: 0644]
plugins/mysql_hammer.php [new file with mode: 0644]
www/index.php

diff --git a/agent/agent.php b/agent/agent.php
new file mode 100644 (file)
index 0000000..db6a9a6
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+// this is the main agent file that will run on a host, connect to the web controller and do things.
+
+?>
\ No newline at end of file
diff --git a/docs/test_method.txt b/docs/test_method.txt
new file mode 100644 (file)
index 0000000..27b80be
--- /dev/null
@@ -0,0 +1,7 @@
+on the web host, people choose a test and go thru some config
+
+the local web host runs a main controller agent
+
+main controller agent comms with controller agent on all other hosts
+
+controller agent talks to testing agents 
\ No newline at end of file
diff --git a/lib/lib.php b/lib/lib.php
deleted file mode 100644 (file)
index 3c44fb3..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<?php
-
-// i am the main library
-
-?>
\ No newline at end of file
diff --git a/libanyhammer/config.php b/libanyhammer/config.php
new file mode 100644 (file)
index 0000000..330190d
--- /dev/null
@@ -0,0 +1,166 @@
+<?php
+
+class AHConfig {
+       
+       function __construct()
+       {
+               $this->configPath = "";
+               $this->config = "";
+               $this->dbobject = false;
+       }
+       
+       function loadConfig($configpath)
+       {
+               error_log("loadConfig $configpath");
+               $this->configPath = $configpath;
+               
+               try {
+                       $this->dbobject = new PDO("sqlite:$configpath");
+               } catch(PDOException $exep) {
+                       error_log("execpt on db open");
+                       return false;
+               }
+               
+               $this->setupTables();
+       }
+       
+       function setConfig($configname, $configval)
+       {
+               $sql = "delete from config where configname='$configname'";
+               $this->dbobject->query($sql);
+               $sql = "insert into config values ('$configname', '$configval')";
+               $this->dbobject->query($sql);
+       }
+       
+       function getConfig($configname)
+       {
+               $sql = "select configvar from config where configname='$configname'";
+               $res = $this->dbobject->query($sql);
+               $val = false;
+               foreach($res as $row) {
+                       $val = $row[0];
+                       error_log("foreach, $val\n");
+               }
+               
+               return $val;
+       }
+       
+       function delConfig($configname)
+       {
+               $sql = "delete from config where configname='$configname'";
+               $this->dbobject->query($sql);
+               
+               return true;
+       }
+       
+       function addData($configType, $configCat, $configName, $configVal)
+       {
+               $sql = "insert into datatable values (NULL, '$configType', '$configCat', '$configName', '$configVal')";
+               $this->dbobject->query($sql);
+               //error_log("CONFIG: adddata as $sql");
+       }
+       
+       function saveConfig()
+       {
+               // stub function for old config method reverse compatability
+       }
+       
+       function getData($configType, $configCat="", $configName="")
+       {
+               $ret = null;
+               $nret = 0;
+               $haveWhere = false;
+
+               $wheredata = "where data_type='$configType'";
+               if($configCat != "") {
+                       $wheredata .= " and data_category='$configCat'";
+               }
+               
+               if($configName != "") {
+                       $wheredata .= " and data_name='$configName'";
+               }
+               
+               $sql = "select data_category,data_name,data_val from datatable $wheredata";
+               //error_log("CONFIG: get via $sql");
+               
+               $res = $this->dbobject->query($sql);
+               
+               foreach($res as $row) {
+                       $ret[$nret]["val"] = $row[2];
+                       $ret[$nret]["category"] = $row[0];
+                       $ret[$nret]["name"] = $row[1];
+                       $nret++;
+               }
+               if($nret == 0) return false;
+               
+               return $ret;
+       }
+       
+       function delData($configType, $configCat, $configName="", $configVal="")
+       {
+               $extrawhere = "";
+               if($configName != "") {
+                       $extrawhere = " and data_name='$configName'";
+               }
+               if($configVal != "") {
+                       $extrawhere .= " and data_val='$configVal'";
+               }
+               $sql = "delete from datatable where data_type='$configType' and data_category='$configCat' $extrawhere";
+               $this->dbobject->query($sql);
+               
+               //error_log("del all data was $sql");
+       }
+       
+       function delAllDAta($configType, $configCat)
+       {
+               $sql = "delete from datatable where data_type='$configType' and data_category='$configCat'";
+               //echo "sql is $sql\n";
+               $this->dbobject->query($sql);
+               //error_log("del all data was $sql");
+       }
+       
+       function setupTables()
+       {
+               $sql = "SELECT count(name) FROM sqlite_master WHERE type='table' AND name='config';";
+               $res = $this->dbobject->query($sql);
+               
+               foreach($res as $row) {
+                       if($row[0] > 0) {
+                               //echo "Tables exist\n";
+                               return;
+                       }
+               }
+               
+               
+               $sql = 'CREATE TABLE "config" ( "configname" TEXT,"configvar" TEXT);';
+               $this->dbobject->query($sql);
+               
+               $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_type" TEXT,"data_category" TEXT,"data_name" TEXT,"data_val" TEXT);';
+               $this->dbobject->query($sql);
+
+               $sql = 'CREATE TABLE sqlite_sequence(name,seq);';
+               $this->dbobject->query($sql);
+       }
+       
+       private $configPath;
+       private $dbobject;
+       
+}
+               
+function ah_getConfigPath()
+{
+       global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+
+       // if you wish to add more places to find webconfig, add them here.
+       $configpath = false;
+       if(file_exists($WEB_ROOT_FS."/../var/anyhammer/config.db")) return realpath($WEB_ROOT_FS."/../var/anyhammer/config.db");
+       if(file_exists("/var/lib/anyhammer/config.db")) return realpath("/var/lib/anyhammer/config.db");
+       if(file_exists("/var/run/anyhammer/config.db")) return realpath("/var/run/anyhammer/config.db");
+       
+       return $configpath;
+       //return false; 
+}
+
+               
+
+?>
diff --git a/libanyhammer/lib.php b/libanyhammer/lib.php
new file mode 100644 (file)
index 0000000..38b1a0f
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+// i am the main library
+
+/*
+ * 
+ * The Main lib.php file.
+ * 
+ */
+
+//require_once();
+
+// get the lib root, and set include path from it
+$LIB_ROOT_FS = realpath(dirname(__FILE__));
+global $LIB_ROOT_FS;
+
+/*
+ * I shouldnt ever need to do this bit, but its here, just in case
+$adpath = realpath($LIB_ROOT_FS."/../");
+error_log("added libglcas path as $adpath");
+set_include_path(get_include_path().PATH_SEPARATOR.$adpath);
+
+*/
+
+
+require_once("libanyhammer/web.php");
+require_once("libanyhammer/config.php");
+
+function ah_pluginLoader($path="")
+{
+       global $LIB_ROOT_FS;
+       if($path ==  "") {
+               // try and find it
+               $plpath = realpath($LIB_ROOT_FS."/../plugins/");
+               if(file_exists($plpath."/ah_plugin.php")) {
+                       // here it is, load away
+                       error_log("attempting to load plugins from $plpath");
+                       $dh = opendir("$plpath");
+                       if($dh) {
+                               while(($file = readdir($dh))!==false) {
+                                       $mt = preg_match("/.*.php$/", $file);
+                                       if($mt > 0) {
+                                               error_log("loading plugin $file");
+                                               require_once("$plpath/$file");
+                                               //echo "required $basedir/$file\n";
+                                       }
+                               }
+                       }                       
+               }
+       }
+}
+
+
+?>
\ No newline at end of file
diff --git a/libanyhammer/web.php b/libanyhammer/web.php
new file mode 100644 (file)
index 0000000..87f7867
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+
+class AHWeb {
+       function __construct($config)
+       {
+               $this->config = $config;
+       }
+       
+       function go($url)
+       {
+               echo "hello, $url";
+               error_log("called as $url");
+       }
+       
+       
+       
+       private $config;
+}
+
+
+function AHpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="AnyHammer")
+{
+       global $WEB_ROOT_FS, $BASE_URL;
+       
+       // TODO: load css
+       // header
+       echo "<html><head><title>$title</title>";
+       
+       // load css
+       if(file_exists("$WEB_ROOT_FS/css")) {
+               $dh = opendir("$WEB_ROOT_FS/css");
+               if($dh) {
+                       while(($file = readdir($dh))!==false) {
+                               $mt = preg_match("/.*.css$/", $file);
+                               if($mt > 0) {
+                                       error_log("loading css $file");
+                                       echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
+                                       //echo "required $basedir/$file\n";
+                               }
+                       }
+               }               
+       }
+
+       // load js
+       if(file_exists("$WEB_ROOT_FS/js")) {
+               $dh = opendir("$WEB_ROOT_FS/js");
+               if($dh) {
+                       while(($file = readdir($dh))!==false) {
+                               $mt = preg_match("/.*.js$/", $file);
+                               if($mt > 0) {
+                                       error_log("loading js $file");
+                                       echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
+                                       //echo "required $basedir/$file\n";
+                               }
+                       }
+               }               
+       }
+       
+       
+       // start body
+       echo "</head><body>";
+       
+       // page top
+       echo "<h1>$title</h1><br>";
+       echo "<table><tr><td>";
+       AHMessageBuilder();
+       echo "<td></tr><tr><td>";
+       
+       // menu, then body
+       echo "<table><tr><td>";
+       AHMenuBuilder();
+       echo "</td></tr><tr><td>";
+       // body
+       $url = "/";
+       if(isset($_REQUEST["q"])) {
+               $url = $_REQUEST["q"];
+       }
+       
+       if($bodyClass != null) {
+               $bodyClass->$bodyFunction($url);
+       } else if( $bodyFunction != null) {
+               $bodyFunction($url);
+       } else echo $bodycontent;
+       echo "</td></tr></table>";
+       
+       
+       // close the big wrap-around table
+       echo "</td></tr></table>";
+       
+       // footer
+       echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
+       
+}
+?>
\ No newline at end of file
diff --git a/plugins/ah_plugin.php b/plugins/ah_plugin.php
new file mode 100644 (file)
index 0000000..7c7e952
--- /dev/null
@@ -0,0 +1,4 @@
+<?php 
+// just something so we know this is out plugin load path
+
+?>
\ No newline at end of file
diff --git a/plugins/mysql_hammer.php b/plugins/mysql_hammer.php
new file mode 100644 (file)
index 0000000..fbb4f3b
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+// i just need something to put here really
+
+
+?>
\ No newline at end of file
index 4d0c107..e2b7ca1 100644 (file)
@@ -1,5 +1,34 @@
 <?php
 
-// placeholder
+
+$WEB_ROOT_FS = realpath(dirname(__FILE__));
+$BASE_URL = dirname($_SERVER["PHP_SELF"]);
+
+global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+
+// add libglcas as if it were a path in ../libglcas
+if(file_exists("../libanyhammer")) {
+       $path = realpath($WEB_ROOT_FS."/../");
+       error_log("added glcas path as $path");
+       set_include_path(get_include_path().PATH_SEPARATOR.$path);
+}
+
+// include the based library
+require_once("libanyhammer/lib.php");
+
+// load plugins
+ah_pluginLoader();
+
+// need to trigger installer here
+$configpath = ah_getConfigPath();
+if(!$configpath) $configpath = $WEB_ROOT_FS."/../var/anyhammer/config.db";
+$config = new AHConfig($configpath);
+
+$web = new AHWeb();
+
+if(isset($_REQUEST["q"])) {
+       $url = $_REQUEST["q"];
+} else $url = "/";
+$web->go($url);
 
 ?>