kinda stubb'ed the old config out for now and tacked it onto the new
authorpaulr <me@pjr.cc>
Mon, 8 Aug 2011 06:47:03 +0000 (16:47 +1000)
committerpaulr <me@pjr.cc>
Mon, 8 Aug 2011 06:47:03 +0000 (16:47 +1000)
config. its going to be a bitch to deal with later.

libglcas/config.php
libglcas/web.php
plugins/adhoc.php
plugins/admin.php
plugins/repo.php

index 6498046..499c97b 100644 (file)
@@ -15,7 +15,7 @@ class GLCASConfig {
                $this->configPath = $configpath;
                
                try {
-                       $this->dbobject = new PDO("sqlite:".$this->configPath);
+                       $this->dbobject = new PDO("sqlite:$configpath");
                } catch(PDOException $exep) {
                        error_log("execpt on db open");
                        return false;
@@ -36,7 +36,7 @@ class GLCASConfig {
        {
                $sql = "select configvar from config where configname='$configname'";
                $res = $this->dbobject->query($sql);
-               $val = null;
+               $val = false;
                foreach($res as $row) {
                        $val = $row[0];
                        error_log("foreach, $val\n");
@@ -53,27 +53,43 @@ class GLCASConfig {
                return true;
        }
        
-       function addData($configType, $configName, $configVal)
+       function addData($configType, $configCat, $configName, $configVal)
        {
-               $sql = "insert into datatable values (NULL, '$configType', '$configName', '$configVal')";
+               $sql = "insert into datatable values (NULL, '$configType', '$configCat', $configName', '$configVal')";
                $this->dbobject->query($sql);
                
        }
        
-       function getData($configType, $configName="")
+       function saveConfig()
+       {
+               // stub function for old config method reverse compatability
+       }
+       
+       function getData($configType, $configCat="", $configName="")
        {
                $ret = null;
                $nret = 0;
-               if($configName == "") {
-                       $sql = "select data_val,data_name from datatable where data_type='$configType'";
-               } else {
-                       $sql = "select data_val from datatable where data_type='$configType' and data_name='$configName'";
+               $haveWhere = false;
+               if($configCat != "") {
+                       $haveWhere = true;
+                       $wheredata = "where data_category='$configCat'";
                }
+               
+               if($configName != "") {
+                       if($haveWhere) {
+                               $wheredata .= " and data_name='$configName'";
+                       } else {
+                               $wheredata = "where data_name='$configName'";
+                       }
+               }
+               
+               $sql = "select data_val,data_category,data_name from datatable $wheredata";
                $res = $this->dbobject->query($sql);
                
                foreach($res as $row) {
                        $ret[$nret]["val"] = $row[0];
-                       if($configName == "") $ret[$nret]["name"] = $row[1];
+                       $ret[$nret]["cat"] = $row[1];
+                       $ret[$nret]["name"] = $row[2];
                        $nret++;
                }
                
@@ -86,7 +102,7 @@ class GLCASConfig {
                $this->dbobject->query($sql);
        }
        
-       function delAllDAta($configType, $configName)
+       function delAllDAta($configType, $configCat)
        {
                $sql = "delete from datatable where data_type='$configType' and data_name='$configName'";
                //echo "sql is $sql\n";
@@ -100,7 +116,7 @@ class GLCASConfig {
                
                foreach($res as $row) {
                        if($row[0] > 0) {
-                               echo "Tables exist\n";
+                               //echo "Tables exist\n";
                                return;
                        }
                }
@@ -109,7 +125,7 @@ class GLCASConfig {
                $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_name" TEXT,"data_val" TEXT);';
+               $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_category" TEXT,"data_type" TEXT,"data_name" TEXT,"data_val" TEXT);';
                $this->dbobject->query($sql);
 
                $sql = 'CREATE TABLE sqlite_sequence(name,seq);';
index 5dd6f91..96b787e 100644 (file)
@@ -179,6 +179,16 @@ function glcas_startInstaller()
        $gid = $gid_a["name"];
        error_log("user id is $uid, group id is $gid");
        
+       if(isset($_REQUEST["installdir"])) {
+               $c = new GLCASConfig();
+               touch($_REQUEST["installdir"]."/webconfig");
+               $c->loadConfig($_REQUEST["installdir"]."/webconfig");
+               header("Location: index.php");
+               return;
+       }
+       
+       $underroot = realpath($WEB_ROOT_FS."/../");
+       
 ?>
 <html>
 <h1>Welcome to GLCAS</h1>
@@ -190,7 +200,7 @@ now is a place where i can store my config. I search the following directories f
 configuration (webconfig)<br>
 <li> /var/run/glcas/
 <li> /var/lib/glcas/
-<li> <?php echo $WEB_ROOT_FS?>/var/glcas/
+<li> <?php echo $underroot?>/var/glcas/
 <br><br>
 
 As root, you must now create one of these directories and change the ownership of the directory to the web owner.
@@ -201,7 +211,7 @@ Now, tell me where you want me to create the webconfig file:<br>
 <select name="installdir">
 <option value="/var/run/glcas">/var/run/glcas</option>
 <option value="/var/lib/glcas">/var/lib/glcas</option>
-<option value="<?php echo $WEB_ROOT_FS?>/var/glcas/"><?php echo $WEB_ROOT_FS?>/var/glcas/</option>
+<option value="<?php echo $underroot?>/var/glcas/"><?php echo $underroot?>/var/glcas/</option>
 </select>
 <input type="submit" name="Go" value="Go">
 
index 6df9241..9bfbb65 100644 (file)
@@ -15,7 +15,7 @@ class GLCASAdhoc {
                $this->config = $config;
                error_log("constructor for GLCASAdhoc");
                
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
                if(!is_dir("$repostore/adhoc")) {
                        error_log("Creating dir for adhoc component");
                        mkdir("$repostore/adhoc");
@@ -45,15 +45,15 @@ class GLCASAdhoc {
        
        function delPackage($url)
        {       
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
                
                $pkgid = $_REQUEST["pkgid"];
                
-               $pkgs = unserialize($this->config->getConfigVar("adhocpackages"));
+               $pkgs = unserialize($this->config->getConfig("adhocpackages"));
                
                if(isset($pkgs[$pkgid])) {
                        unset($pkgs[$pkgid]);
-                       $this->config->setConfigVar("adhocpackages", serialize($pkgs));
+                       $this->config->setConfig("adhocpackages", serialize($pkgs));
                        $this->config->saveConfig();
                }
                
@@ -64,7 +64,7 @@ class GLCASAdhoc {
        
        function addPackage($url)
        {
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
                
                if(!isset($_REQUEST["pkgname"])) {
                        echo "<font color=\"red\">Error: No package name set</font><br>";
@@ -108,7 +108,7 @@ class GLCASAdhoc {
                        echo "Got a file named $fname, $lname";
                }
                
-               $pkgs = unserialize($this->config->getConfigVar("adhocpackages"));
+               $pkgs = unserialize($this->config->getConfig("adhocpackages"));
                
                $n = -1;
                foreach($pkgs as $key => $var) {
@@ -129,7 +129,7 @@ class GLCASAdhoc {
                        file_put_contents("$repostore/adhoc/$n", $fetfile);
                }
                
-               $this->config->setConfigVar("adhocpackages", serialize($pkgs));
+               $this->config->setConfig("adhocpackages", serialize($pkgs));
                $this->config->saveConfig();
                
                echo "Done";
@@ -148,7 +148,7 @@ class GLCASAdhoc {
        {
                echo "<h2>Packages</h2>";
 
-               $pkgs = unserialize($this->config->getConfigVar("adhocpackages"));
+               $pkgs = unserialize($this->config->getConfig("adhocpackages"));
                echo "<table border=\"1\"><tr><th>Name</th><th>Package Types</th><th>Architecture</th><th>Control</th></tr>";
                
                foreach($pkgs as $key => $var) {
index c10ce86..e7dcd14 100644 (file)
@@ -442,7 +442,7 @@ class GLCASAdmin {
                // repo storage location
                echo "<h3>Storage</h3><br>";
                echo "<form method=\"post\" action=\"?action=setstorage\">";
-               $storloc = $this->config->getConfigVar("storagelocation");
+               $storloc = $this->config->getConfig("storagelocation");
                echo "<input class=\"storage\" type=\"text\" name=\"storageloc\" value=\"$storloc\" size=\"100\">";
                echo "<input type=\"submit\" name=\"Set\" value=\"Set\">";
                echo "</form>";
@@ -450,9 +450,9 @@ class GLCASAdmin {
                echo "<hr>";
                echo "<h3>Proxy Config</h3><br>";
                echo "<form method=\"post\" action=\"?action=setproxy\">";
-               $proxyaddress = $this->config->getConfigVar("proxyaddress");
-               $proxylogin = $this->config->getConfigVar("proxylogin");
-               $proxypass = $this->config->getConfigVar("proxypass");
+               $proxyaddress = $this->config->getConfig("proxyaddress");
+               $proxylogin = $this->config->getConfig("proxylogin");
+               $proxypass = $this->config->getConfig("proxypass");
                echo "Proxy Address <input type=\"text\" name=\"proxyaddress\" value=\"$proxyaddress\" size=\"100\"><br>";
                echo "Proxy Login <input type=\"text\" name=\"proxylogin\" value=\"$proxylogin\" size=\"100\"><br>";
                echo "Proxy Password <input type=\"text\" name=\"proxypassword\" value=\"$proxypass\" size=\"100\"><br>";
index 0f32504..1546e61 100644 (file)
@@ -7,21 +7,22 @@ class GLCASRepo {
        function __construct($config)
        {
                $this->config = $config;
-               if($this->config->getConfigVar("storagelocation") == false) {
+               if($this->config->getConfig("storagelocation") == false) {
                        global $WEB_ROOT_FS;
                        $storloc = "$WEB_ROOT_FS/../var/glcas/cache/";
                        if(!file_exists($storloc)) mkdir($storloc);
-                       $this->config->setConfigVar("storagelocation", realpath($storloc));
-                       $this->config->saveConfig();
+                       $this->config->setConfig("storagelocation", realpath($storloc));
                        error_log("set storage location, $storloc");
                }
        }
        
+       
+       // with the move to the sqlite db, this is going to get painful
        function cron()
        {
                //echo "<pre>";
-               $uconf = unserialize($this->config->getConfigVar("repodata"));
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = unserialize($this->config->getConfig("repodata"));
+               $repostore = $this->config->getConfig("storagelocation");
                //print_r($uconf);
                //echo "</pre>";
                
@@ -38,14 +39,14 @@ class GLCASRepo {
                                echo " - Expire time not set, setting to 2 days by default<br>";
                                $uconf[$rkey]["expiretime"] = 2;
                                $repo["expiretime"] = 2;
-                               $this->config->setConfigVar("repodata", serialize($uconf));
+                               $this->config->setConfig("repodata", serialize($uconf));
                                $this->config->saveConfig();                            
                        }
                        
                        if(!isset($repo["repotype"])) {
                                echo "<font color=\"red\">Repo type not set for repo, setting to yum</font><br>";
                                $uconf[$rkey]["repotype"] = "YUM";
-                               $this->config->setConfigVar("repodata", serialize($uconf));
+                               $this->config->setConfig("repodata", serialize($uconf));
                                $this->config->saveConfig();                            
                        } else if($repo["repotype"] == "YUM") {
                                if($repofrozen) {
@@ -153,8 +154,8 @@ class GLCASRepo {
                $xurl = split("[/,]", $url);
 
                // first get the config
-               $uconf = unserialize($this->config->getConfigVar("repodata"));
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = unserialize($this->config->getConfig("repodata"));
+               $repostore = $this->config->getConfig("storagelocation");
 
                // preset matched to -1
                $matched = -1;
@@ -256,8 +257,8 @@ class GLCASRepo {
 
        function serveUpFile($actualfile, $repoid)
        {
-               $uconf = unserialize($this->config->getConfigVar("repodata"));
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = unserialize($this->config->getConfig("repodata"));
+               $repostore = $this->config->getConfig("storagelocation");
 
                // figure out the range header garbage that centos/redhat send
                if(isset($_SERVER["HTTP_RANGE"])) {
@@ -344,8 +345,8 @@ class GLCASRepo {
                clearstatcache();
 
                // get the configurations we need
-               $uconf = unserialize($this->config->getConfigVar("repodata"));
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = unserialize($this->config->getConfig("repodata"));
+               $repostore = $this->config->getConfig("storagelocation");
 
 
 
@@ -745,8 +746,8 @@ class GLCASRepo {
        function freezeRepo($rkey)
        {
                
-               $uconf = $this->config->getConfigVar("repodata");
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = $this->config->getConfig("repodata");
+               $repostore = $this->config->getConfig("storagelocation");
 
                if($uconf !== false) {
                        $conf = unserialize($uconf);
@@ -765,7 +766,7 @@ class GLCASRepo {
                                        }
                                        $nconf = serialize($conf);
                                        error_log("freeze repo as $rkey");
-                                       $this->config->setConfigVar("repodata", $nconf);
+                                       $this->config->setConfig("repodata", $nconf);
                                        $this->config->saveConfig();
                                }
                        }
@@ -774,8 +775,8 @@ class GLCASRepo {
        
        function deleteRepo($rkey)
        {
-               $uconf = $this->config->getConfigVar("repodata");
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $uconf = $this->config->getConfig("repodata");
+               $repostore = $this->config->getConfig("storagelocation");
 
                if($uconf !== false) {
                        $conf = unserialize($uconf);
@@ -785,7 +786,7 @@ class GLCASRepo {
                                        $nconf = serialize($conf);
                                        system("rm -rf $repostore/$key");
                                        error_log("remove repo as $rkey");
-                                       $this->config->setConfigVar("repodata", $nconf);
+                                       $this->config->setConfig("repodata", $nconf);
                                        $this->config->saveConfig();
                                }
                        }
@@ -794,7 +795,7 @@ class GLCASRepo {
 
        function addRepo($desc, $os, $version, $arch, $other, $shorturl, $prefix, $repurl, $repotype, $init, $expiretime, $blocklist=null)
        {
-               $uconf = $this->config->getConfigVar("repodata");
+               $uconf = $this->config->getConfig("repodata");
 
                $cs["desc"] = $desc;
                $cs["os"] = $os;
@@ -825,11 +826,11 @@ class GLCASRepo {
                $nconf = serialize($conf);
 
                error_log("add repo as $ckey");
-               $this->config->setConfigVar("repodata", $nconf);
+               $this->config->setConfig("repodata", $nconf);
                $this->config->saveConfig();
 
                // now create the base structure in the repo
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
 
 
                // now call update repo
@@ -853,7 +854,7 @@ class GLCASRepo {
        
        function updateRepoApt($repokey)
        {
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
 
                $repod = $this->getRepo($repokey);
 
@@ -882,7 +883,7 @@ class GLCASRepo {
 
        function updateRepoYum($repokey)
        {
-               $repostore = $this->config->getConfigVar("storagelocation");
+               $repostore = $this->config->getConfig("storagelocation");
 
                $repod = $this->getRepo($repokey);
 
@@ -911,7 +912,7 @@ class GLCASRepo {
 
        function getRepo($id)
        {
-               $uconf = $this->config->getConfigVar("repodata");
+               $uconf = $this->config->getConfig("repodata");
                if($uconf !== false) {
                        $lconf = unserialize($uconf);
                        return $lconf[$id];
@@ -921,7 +922,7 @@ class GLCASRepo {
 
        function getRepos()
        {
-               $uconf = $this->config->getConfigVar("repodata");
+               $uconf = $this->config->getConfig("repodata");
                if($uconf !== false) {
                        return unserialize($uconf);
                } else return false;