added more framework bits,
authorpaulr <me@pjr.cc>
Tue, 1 Nov 2011 04:54:08 +0000 (15:54 +1100)
committerpaulr <me@pjr.cc>
Tue, 1 Nov 2011 04:54:08 +0000 (15:54 +1100)
 - repo admin
 - user admin
 - debug page
 - started setup pages
 - database creation
 - login forms
 - minor css changes

gwvplib/gwvpauth.php [new file with mode: 0644]
gwvplib/gwvpdatabase.php
gwvplib/gwvpdebug.php [new file with mode: 0644]
gwvplib/gwvplib.php
gwvplib/gwvpsetup.php [new file with mode: 0644]
gwvplib/gwvpweb.php
www/css/normal.css
www/index.php

diff --git a/gwvplib/gwvpauth.php b/gwvplib/gwvpauth.php
new file mode 100644 (file)
index 0000000..27afec8
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+
+$CALL_ME_FUNCTIONS["00aaa"] = "gwvp_AuthCallMe";
+
+function gwvp_AuthCallMe()
+{
+       session_start();
+       
+       if(isset($_REQUEST["q"])) {
+               $query = $_REQUEST["q"];
+               if($query == "login") return "gwvp_AuthHandleLogin";
+               if($query == "register") return "gwvp_RegistrationCall";
+               else return false;
+       }
+       
+       return false;
+}
+
+function gwvp_RegistrationCall()
+{
+       if(gwvp_IsRegistrationEnabled()) {
+               gwvp_goMainPage("gwvp_RegistrationPageBody");
+       } else {
+               gwvp_goMainPage("gwvp_RegistrationDisabledBody");
+       }
+}
+
+function gwvp_AuthHandleLogin()
+{
+       global $BASE_URL;
+       $user = "";
+       $pass = "";
+       if(isset($_REQUEST["username"])) $user = $_REQUEST["username"];
+       if(isset($_REQUEST["password"])) $pass = $_REQUEST["password"];
+       
+       // auth the user
+       if($user == "user" && $pass == "pass") {
+               $_SESSION["isloggedin"] = true;
+               $_SESSION["username"] = "user";
+       } else {
+               gwvp_SendMessage("error", "Login Failed");
+       }
+       
+       header("Location: $BASE_URL");
+}
+
+function gwvp_RegistrationPageBody()
+{
+       ?>
+       <form method="post">
+       <table>
+       <tr><td>Name</td><td><input name="name" type="text"></td><td>Your Full Name</td></tr>
+       <tr><td>Email</td><td><input name="email" type="text"></td><td>Your Email Address</td></tr>
+       <tr><td>Nick Name</td><td><input name="nickname" type="text"></td><td>The Name Used to Refer to you on the site</td></tr>
+       <tr><td><input type="submit" name="register" value="Register"></td></tr>
+       </table>
+       </form>
+       <?php
+}
+
+function gwvp_IsLoggedIn()
+{
+       if(isset($_SESSION["isloggedin"])) {
+               if($_SESSION["isloggedin"]) {
+                       return $_SESSION["username"];
+               } else return false;
+       } else return false;
+}
+
+function gwvp_SingleLineLoginForm()
+{
+       global $BASE_URL;
+       
+       echo "<form method=\"post\" action=\"$BASE_URL/login\">Username <input type=\"text\" name=\"username\" class=\"login\">";
+       echo " Passowrd <input type=\"text\" name=\"password\" class=\"login\"><input type=\"submit\" name=\"login\" value=\"Login\" class=\"loginbutton\">";
+       if(gwvp_IsRegistrationEnabled()) echo "<a href=\"$BASE_URL/register\">Register</a></form>";
+       else echo "</form>";
+}
+
+
+function gwvp_IsRegistrationEnabled()
+{
+       return true;
+}
+
+// TODO translate info here
+function gwvp_GetFullName($login)
+{
+       return $login;
+}
+?>
\ No newline at end of file
index d53373e..507fdfc 100644 (file)
@@ -44,5 +44,24 @@ function gwvp_ConnectDB()
        }
 }
 
+/* functions we'll need to access data:
+ * 
+ * getUsers(pattern)
+ * getUserData(username)
+ * getGroups(pattern)
+ * getGroupData(groupname)
+ * modifyGroup(...)
+ * addGroupMember(...)
+ * deleteGroupMember(...)
+ * 
+ * createUser(...)
+ * deleteUser(...)
+ * modifyUser(...)
+ * createRepo(...)
+ * deleteRepo(...)
+ * getRepos()
+ */
+
+
 
 ?>
\ No newline at end of file
diff --git a/gwvplib/gwvpdebug.php b/gwvplib/gwvpdebug.php
new file mode 100644 (file)
index 0000000..cd3c86f
--- /dev/null
@@ -0,0 +1,74 @@
+<?php 
+$CALL_ME_FUNCTIONS["debug"] = "gwvp_DebugCallMe";
+
+$MENU_ITEMS["999debug"]["text"] = "Debug";
+$MENU_ITEMS["999debug"]["link"] = "$BASE_URL/debug";
+
+function gwvp_DebugEnabled()
+{
+       echo "<pre>";
+       echo "BASEURL: $BASE_URL\n";
+       echo "CUSTOM\n";
+       echo "\n\nserver\n";
+       print_r($_SERVER);
+       echo "\n\n\nrequest\n";
+       print_r($_REQUEST);
+       echo "\n\n\nsession\n";
+       print_r($_SESSION);
+       
+       
+       echo "</pre>";
+}
+
+function gwvp_DebugCallMe()
+{
+       if(isset($_REQUEST["q"])) {
+               $query = $_REQUEST["q"];
+               $myquery = explode("/",$query);
+               if($myquery[0] == "debug") return "gwvp_DebugCall";
+               else return false;
+       }
+       
+       return false;
+       
+}
+
+function gwvp_DebugCall()
+{
+       global $BASE_URL;
+       
+       if(isset($_REQUEST["q"])) {
+               $query = $_REQUEST["q"];
+               $myquery = explode("/",$query);
+               if(isset($myquery[1])) {
+                       switch($myquery[1]) {
+                               case "errormessage":
+                                       error_log("generate error message");
+                                       gwvp_SendMessage("error", "random message");
+                                       header("Location: $BASE_URL/debug");
+                                       break;
+                               case "infomessage":
+                                       error_log("generate info message");
+                                       gwvp_SendMessage("info", "random message");
+                                       header("Location: $BASE_URL/debug");
+                                       break;
+                               default:
+                                       gwvp_goMainPage("gwvp_DebugBody");
+                                       return;
+                       }
+               } else {
+                       gwvp_goMainPage("gwvp_DebugBody");
+               }
+       }
+}
+
+function gwvp_DebugBody()
+{
+       global $BASE_URL;
+       ?>
+       <a href="<?php echo $BASE_URL?>/debug/errormessage">Generate error message</a><br>
+       <a href="<?php echo $BASE_URL?>/debug/infomessage">Generate info message</a><br>
+       <?php
+}
+
+?>
\ No newline at end of file
index 2a70f0c..674e87c 100644 (file)
@@ -4,11 +4,11 @@ require_once("gwvpweb.php");
 require_once("gwvpgitbackend.php");
 require_once("gwvpuseradmin.php");
 require_once("gwvprepoadmin.php");
+require_once("gwvpauth.php");
+require_ocne("gwvpsetup.php");
+
+// only enable this if you need it:
+require_once("gwvpdebug.php");
 
-// TODO: need to do this bit
-function gwvp_issetup()
-{
-       return true;
-}
 
 ?>
\ No newline at end of file
diff --git a/gwvplib/gwvpsetup.php b/gwvplib/gwvpsetup.php
new file mode 100644 (file)
index 0000000..b83e415
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+$CALL_ME_FUNCTIONS["setup"] = "gwvp_SetupCall";
+
+
+function gwvp_SetupCall()
+{
+       if(isset($_REQUEST["q"])) {
+               $query = $_REQUEST["q"];
+               if($query == "postsetup") return "gwvp_PostSetup";
+               else return false;
+       }
+       
+       return false;
+       
+}
+
+function gwvp_PostSetup()
+{
+       gwvp_goMainPage("gwvp_PostSetupPageBody");
+}
+
+function gwvp_PostSetupPageBody()
+{
+       echo "GWVP Is now setup, login at the top of the page and you should in control!";
+}
+
+// TODO: need to do this bit
+function gwvp_issetup()
+{
+       return true;
+}
+
+
+function gwvp_goSetup()
+{
+       
+}
+?>
\ No newline at end of file
index f476161..474cdff 100644 (file)
@@ -20,7 +20,8 @@ function gwvp_goWebBegin()
        
        // next, we go thru the CALL_ME_FUNCTIONS - the purpose of call_me_functions is to determine if a function should be called based on
        // the functions return (i.e. if function returns false, its not it, otherwise it returns a function name we have to call)
-       // this is important for our plugin structure later on
+       // this is important for our plugin structure later on - the key on the array serves an an ordering method
+       ksort($CALL_ME_FUNCTIONS);
        foreach($CALL_ME_FUNCTIONS as $key => $val) {
                error_log("checking callmefunction $key as $val");
                $callme = $val();
@@ -34,6 +35,12 @@ function gwvp_goWebBegin()
        gwvp_goMainPage();
 }
 
+function gwvp_SendMessage($messagetype, $message)
+{
+       $_SESSION["messagetype"] = $messagetype;
+       $_SESSION["message"] = $message;
+}
+
 function gwvp_goMainPage($bodyFunction = null)
 {
        // the main page will look pretty simple, a title, a menu then a body
@@ -79,9 +86,21 @@ function gwvp_goMainPage($bodyFunction = null)
        echo "<h1>Git over Web Via PHP</h2>";
        
        
-       echo "<table width=\"100%\"><tr width=\"100%\"><td>";
+       echo "<table width=\"100%\">";
+
+       if(isset($_SESSION["message"])) {
+               echo "<tr width=\"100%\"><td>";
+               gwvp_MessageBuilder();
+               echo "</td></tr>";
+       }
+       
+       echo "<tr width=\"100%\"><td>";
        gwvp_MenuBuilder();
-       echo "</td></tr>";
+       echo "</td><td align=\"right\">";
+       gwvp_LoginBuilder();
+       echo "</td>";
+       
+       echo "</tr>";
        
        echo "<tr><td>";
        if($bodyFunction == null) {
@@ -102,6 +121,29 @@ function gwvp_goMainPage($bodyFunction = null)
        
 }
 
+
+// builds the message builder if its needed
+function gwvp_MessageBuilder()
+{
+       $message = "";
+       $messagetype = "info";
+       if(isset($_SESSION["message"])) $message = $_SESSION["message"];
+       if(isset($_SESSION["messagetype"])) $messagetype = $_SESSION["messagetype"];
+       
+       if($message != "") {
+               switch($messagetype) {
+                       case "info":
+                               echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#AAFFAA\">$message</td></tr></table>";
+                               break;
+                       case "error":
+                               echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#FFAAAA\">$message</td></tr></table>";
+                               break;
+               }
+               unset($_SESSION["message"]);
+               if(isset($_SESSION["messagetype"])) unset($_SESSION["messagetype"]);
+       }
+}
+
 // builds the menu structure
 function gwvp_MenuBuilder()
 {
@@ -119,6 +161,18 @@ function gwvp_MenuBuilder()
        
 }
 
+function gwvp_LoginBuilder()
+{
+       global $WEB_ROOT_FS, $BASE_URL;
+       
+       $login = gwvp_IsLoggedIn();
+       if($login === false) {
+               gwvp_SingleLineLoginForm();
+       } else {
+               echo "Hello, ".gwvp_GetFullName($login);
+       }
+}
+
 // builds the body structure
 function gwvp_BodyBuilder()
 {
index bf63908..78f157d 100644 (file)
@@ -130,9 +130,18 @@ div.wrapper {
 
 input[type=text] {
        width: 200px;
-       
+       border: 1px solid
 }
 
-input.storage {
+input.login {
+       width: 100px;
+       border: 1px solid
+}
+
+.loginbutton {
+       border: 1px solid
+}
+
+input.long {
        width: 400px;   
 }
\ No newline at end of file
index aef8e3d..1bc6bc7 100644 (file)
@@ -30,15 +30,8 @@ require_once("gwvplib.php");
 gwvp_goWebBegin();
 //goWebGitBackEnd();
 
-
-echo "<pre>";
-echo "BASEURL: $BASE_URL\n";
-echo "CUSTOM\n";
-print_r($_SERVER);
-print_r($_REQUEST);
-
-
-echo "</pre>";
-
+if(function_exists("gwvp_DebugEnabled")) {
+       gwvp_DebugEnabled();
+}
 
 ?>