X-Git-Url: http://git.pjr.cc/?p=gwvp.git;a=blobdiff_plain;f=gwvplib%2Fgwvpweb.php;h=01215abe64be3bc6c8a719dcca67f54e4140f2a7;hp=03daa77d51ef310c6e8e5f8581423a48aa95c1f0;hb=047523a5083efd83dcd94b6d2763c9fddb913c90;hpb=1dbfde26ce2b413bed52a7cf7f93f349496951e0 diff --git a/gwvplib/gwvpweb.php b/gwvplib/gwvpweb.php index 03daa77..01215ab 100644 --- a/gwvplib/gwvpweb.php +++ b/gwvplib/gwvpweb.php @@ -1,108 +1,188 @@ $var) { - if($key != "q") { - error_log("adding, $var from $key"); - if($qs == "") $qs.="$key=$var"; - else $qs.="&$key=$var"; - } - } - - //sleep(2); - - $body = ''; - if($rmeth == "POST") { - $body = file_get_contents("php://input"); - } - - - // this is where the fun, it ends. - $myoutput = ""; - unset($myoutput); - - // this be nasty! - - // setup env - if(isset($procenv)) unset($procenv); - $procenv["GATEWAY_INTERFACE"] = "CGI/1.1"; - $procenv["PATH_TRANSLATED"] = "/var/cache/git/test.git$euri"; - $procenv["REQUEST_METHOD"] = "$rmeth"; - $procenv["GIT_HTTP_EXPORT_ALL"] = "1"; - $procenv["QUERY_STRING"] = "$qs"; - $procenv["HTTP_USER_AGENT"] = "git/1.7.1"; - $procenv["REMOTE_USER"] = "paulr"; - $procenv["REMOTE_ADDR"] = "1.2.3.4"; - $procenv["CONTENT_TYPE"] = "application/x-git-upload-pack-request"; - - $pwd = "/var/cache/git"; - - error_log("openproc"); - $proc = proc_open("/usr/lib/git-core/git-http-backend", array(array("pipe","r"),array("pipe","w"),array("file","/dev/null", "w")), $pipes, $pwd, $procenv); - error_log("openproc2, $proc"); - - $stdin = $pipes[0]; - $stdout = $pipes[1]; - - error_log("openproc3"); - - if($body != "") { - fwrite($pipes[0], $body); + global $CALL_ME_FUNCTIONS; + + // first we determine if we have a valid setup and run the installer if not + if(!gwvp_issetup()) { + gwvp_goSetup(); + return; + } + + // 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 - 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(); + if($callme !== false) { + $callme(); + return; } - - error_log("openproc4"); - - $untilblank = false; - while(!$untilblank&&!feof($pipes[1])) { - $lines = rtrim(fgets($pipes[1])); - error_log("got line: $lines"); - if($lines == "") { - $untilblank = true; - error_log("now blank"); - } else header($lines); - if($lines === false) exit(0); - + } + + // we fell-thru to the main web page builder + 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 + global $WEB_ROOT_FS, $BASE_URL; + + // a simple web page layout that loads any css and js files that exist in the css and js directories + echo "GWVP"; + + // 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 ""; + //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 ""; + //echo "required $basedir/$file\n"; + } + } + } + } + + + // start body + echo ""; + + echo "

Git over Web Via PHP

"; + + + echo ""; + + if(isset($_SESSION["message"])) { + echo ""; + } + + echo ""; + + echo ""; + + echo ""; + + echo "
"; + gwvp_MessageBuilder(); + echo "
"; + gwvp_MenuBuilder(); + echo ""; + gwvp_LoginBuilder(); + echo "
"; + if($bodyFunction == null) { + gwvp_BodyBuilder(); + } else { + if(function_exists($bodyFunction)) { + $bodyFunction(); + } else { + error_log("Got called with non-existant body function"); + gwvp_BodyBuilder(); } - - error_log("openproc5"); - - // now the body - while(!feof($pipes[1])) { - echo fread($pipes[1], 1024); + } + echo "
"; + gwvp_TailBuilder(); + echo "
"; + +} + + +// 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 "
$message
"; + break; + case "error": + echo "
$message
"; + break; } - - error_log("openproc6"); - - fclose($stdout); - fclose($stdin); - - - + unset($_SESSION["message"]); + if(isset($_SESSION["messagetype"])) unset($_SESSION["messagetype"]); } } +// builds the menu structure +function gwvp_MenuBuilder() +{ + global $MENU_ITEMS; + + ksort($MENU_ITEMS); + + echo ""; + foreach($MENU_ITEMS as $key => $val) { + $link = $val["link"]; + $text = $val["text"]; + echo ""; + } + echo "
Menu$text
"; + +} + +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() +{ + echo "I AM THE MAIN BODY, FEAR ME!!!!"; +} + +// builds the tail structure +function gwvp_TailBuilder() +{ + echo "Copyright 2011, PJR - licensed under GPL"; +} + ?> \ No newline at end of file