fixing up the "is setup" check in the installer
[gwvp.git] / gwvplib / gwvpsetup.php
index b83e415..a9e7a06 100644 (file)
@@ -21,18 +21,131 @@ function gwvp_PostSetup()
 
 function gwvp_PostSetupPageBody()
 {
-       echo "GWVP Is now setup, login at the top of the page and you should in control!";
+       echo "GWVP Is now setup, login at the top of the page and you should be in control!";
 }
 
 // TODO: need to do this bit
 function gwvp_issetup()
 {
-       return true;
+       // check for the config file
+       if(!file_exists("config.php")) return false;
+        
+       return gwvp_isDBSetup();
 }
 
 
 function gwvp_goSetup()
 {
+       global $BASE_URL;
        
+       if(isset($_REQUEST["install"])) {
+               switch($_REQUEST["install"]) {
+                       case "tryinstall":
+                               gwvp_goSetupDoInstall();
+                               break;
+                       default:
+                               gwvp_goSetupGoMain();
+                               break;
+                               
+               }
+       } else {
+               header("Location: $BASE_URL/?install=begin");
+       }
+}
+
+function gwvp_goSetupGoMain()
+{
+       
+       // interesting, TODO: need a non-unix dependant way of doing this
+       $webusername = exec("whoami");
+       
+       $defrepoloc = "/var/lib/gwvp/gitrepos";
+       $defdataloc = "/var/lib/gwvp/data";
+       
+       $repodata = "$defrepoloc";
+       if(file_exists("$defrepoloc")) {
+               $repodata .= " exists";
+               if(is_writable("$defrepoloc")) {
+                       $repodata .= " and is wriable - this is ok as it is";
+               } else {
+                       $repodata .= " but is not writable - needs permissions for the web user";
+               }
+       } else $repodata .= " does not exist (needs to be created)";
+
+       $datadata = "$defdataloc";
+       if(file_exists("$defdataloc")) {
+               $datadata .= " exists";
+               if(is_writable("$defdataloc")) {
+                       $datadata .= " and is wriable - this is ok as it is";
+               } else {
+                       $datadata .= " but is not writable - needs permissions for the web user";
+               }
+       } else $datadata .= " does not exist (needs to be created)";
+       
+       echo "<html><body><h1>Welcome to the GWVP setup Page</h1>";
+       echo "Fill out the form below and lets get started<br>";
+       
+       echo "<form method=\"post\"><table>";
+       echo "<input type=\"hidden\" name=\"install\" value=\"tryinstall\">";
+       echo "<tr><td>Site Name</td><td><input type=\"text\" name=\"sitename\"></td><td>Some Name for your site</td></tr>";
+       echo "<tr><td>First User Full Name</td><td><input type=\"text\" name=\"firstuserfullname\"></td><td>The name of the admin of your site</td></tr>";
+       echo "<tr><td>First User email address</td><td><input type=\"text\" name=\"firstuseremail\"></td><td>The email address of the admin of your site (login)</td></tr>";
+       echo "<tr><td>First User Username</td><td><input type=\"text\" name=\"firstuserusername\"></td><td>The name used to idenity the user on the site</td></tr>";
+       echo "<tr><td>First User Password</td><td><input type=\"text\" name=\"pass1\"></td><td>Password for the user</td></tr>";
+       echo "<tr><td>First User Password (confirm)</td><td><input type=\"text\" name=\"pass2\"></td><td>and confirm it...</td></tr>";
+       echo "<tr><td>Database Type</td><td><select name=\"dbtype\"><option value=\"sqlite\">SQLite</option></select></td><td>SQLite only at this point</td></tr>";
+       echo "<tr><td>Database name</td><td><input type=\"text\" name=\"dbname\" value=\"gvwp\"></td><td>For SQLite, this is simple the file on disk</td></tr>";
+       echo "<tr><td>GIT repository storage Location</td><td><input type=\"text\" name=\"repoloc\" value=\"$defrepoloc\"></td><td>The location (on disk) of the repos - you need to create this (see below)</td><td><i><b>Note: $repodata</b></i></td></tr>";
+       echo "<tr><td>Data storage Location</td><td><input type=\"text\" name=\"dataloc\" value=\"$defdataloc\"></td><td>The location (on disk) where the database for this site is stored - you need to create this (see below)</td><td><i><b>Note: $datadata</b></i></td></tr>";
+       echo "<tr><td><input type=\"submit\" value=\"Install\" name=\"Install\"></td></tr>";
+       echo "</table></form>";
+       
+       echo "<hr><h2>GIT Repo Storage Location Creation</h2>";
+       echo "<b>GIT Repo Storage Location</b> - A location (accessible by the web user, $webusername) must be created on disk for this application to store git repositories (and only repositories) in.";
+       echo "To do this, do the following (as root or via sudo):<br>";
+       echo "<li>Create a directory - sudo mkdir -p $defrepoloc<br>";
+       echo "<li>Change ownership of the directory to the web user - sudo chown $webusername $defrepoloc<br>";
+       echo "And, your done<br>";
+       
+       
+       echo "<hr><h2>Data Storage Location Creation</h2>";
+       echo "<b>Data Storage Location</b> - A location (accessible by the web user, $webusername) must be created on disk for this application to store data (such as database information) in.";
+       echo "To do this, do the following (as root or via sudo):<br>";
+       echo "<li>Create a directory - sudo mkdir -p $defdataloc<br>";
+       echo "<li>Change ownership of the directory to the web user - sudo chown $webusername $defdataloc<br>";
+       echo "And, your done<br>";
+       echo "</body></html>";
+}
+
+function gwvp_goSetupDoInstall()
+{
+       $sitename = $_REQUEST["sitename"];
+       $fufn = $_REQUEST["firstuserfullname"];
+       $fwem = $_REQUEST["firstuseremail"];
+       $fwusername = $_REQUEST["firstuserusername"];
+       $fwpass = $_REQUEST["pass1"];
+       $fwpassconf = $_REQUEST["pass2"];
+       $dbtype = $_REQUEST["dbtype"];
+       $dbname = $_REQUEST["dbname"];
+       $repoloc = $_REQUEST["repoloc"];
+       $dataloc = $_REQUEST["dataloc"];
+       
+       echo "<html><body>";
+       echo "<table>";
+       echo "<tr><td>Sitename</td><td>$sitename</td></tr>";
+       echo "<tr><td>fullname</td><td>$fufn</td></tr>";
+       echo "<tr><td>email</td><td>$fwem</td></tr>";
+       echo "<tr><td>username</td><td>$fwusername</td></tr>";
+       echo "<tr><td>pass</td><td>$fwpass</td></tr>";
+       echo "<tr><td>passconfirm</td><td>$fwpassconf</td></tr>";
+       echo "<tr><td>dbtype</td><td>$dbtype</td></tr>";
+       echo "<tr><td>dbname</td><td>$dbname</td></tr>";
+       echo "<tr><td>repoloc</td><td>$repoloc</td></tr>";
+       echo "<tr><td>dataloc</td><td>$dataloc</td></tr>";
+       echo "</table>";
+       echo "</body></html>";
+
 }
+
+
 ?>
\ No newline at end of file