. */ /* TITLE: Title of the site */ $TITLE = "BarryServer : Git"; /* ROOT: The location of this script in your document root * e.g. "example.com/abc/git.php" = "/abc", * "example.com/git.php" = "" */ $ROOT = ""; /* SCRIPT: Name of the script after alias by server * e.g. "example.com/git" -> "example.com/git.php" = "/git" */ $SCRIPT = ""; /* ORIGINAL: The location of all the git repositories */ $ORIGINAL = "/home/git"; /* BRANCH: The default branch to use */ $BRANCH = "master"; /* DESCRIPTION: Description of the site */ $DESCRIPTION = "A BarryServer Git Browser"; /* FOOTER: Text displayed at the bottom of each page */ $FOOTER = "BarryServer Git Browser"; ?> <?php echo $TITLE; ?>

".$TITLE.""; $full = $ROOT.$SCRIPT; foreach (explode("/", substr($path,1)) as $part) { $full .= "/".$part; echo "/".$part.""; } echo "

\n"; if ($path === "/") { echo " git clone git://".$_SERVER["SERVER_NAME"]."/<repo>.git

\n"; $repos = preg_grep("/(.git)$/", scandir($ORIGINAL)); foreach ($repos as $repo) { $desc = file_get_contents($ORIGINAL."/".$repo."/description"); echo "".substr($repo,0,-4)." :: ".$desc."
"; } } else { $repo = explode("/", substr($path,1))[0]; if (!is_dir($ORIGINAL."/".$repo.".git")) { echo " \n 404! Repository not found!
\n"; echo " [RETURN]\n
\n"; } else { $branch = explode("/", substr($path,1))[1]; echo " git clone "; if ($branch !== $BRANCH) {echo "-b ".$branch." ";} echo "git://".$_SERVER["SERVER_NAME"]."/".$repo.".git

\n"; $rest = implode("/",array_slice(explode("/", substr($path,1)),2)); chdir($ORIGINAL."/".$repo.".git"); if (!isset($branch)) {header("Location: ".$ROOT.$SCRIPT."/".$repo."/");} if (substr($path,-1) !== "/" && $rest === "" && $branch !== "" && isset($branch)) {header("Location: ".$ROOT.$SCRIPT."/".$repo."/".$branch."/");} if ($branch === "") { $branches = shell_exec("git show-branch"); foreach (explode("\n",$branches) as $cbranch) { echo preg_replace("/\[(.+)\] (.+)/","$1",$cbranch)."
"; } } else { $files = shell_exec("git ls-tree --full-name ".$branch." ".$rest); if (substr($rest,-1) !== "/" && $rest !== "") { if (explode(" ",explode("\n",$files)[0])[1] === "tree") {header("Location: ".$ROOT.$SCRIPT."/".$repo."/".$branch."/".$rest."/");} } if (substr($rest,-1) === "/" && $rest !== "") { if (explode(" ",explode("\n",shell_exec("git ls-tree --full-name ".$branch." ".substr($rest,0,-1)))[0])[1] === "blob") {header("Location: ".$ROOT.$SCRIPT."/".$repo."/".$branch."/".substr($rest,0,-1));} } if ($rest === "") {$ctype = "tree";} else { if (substr($rest,-1) === "/") { $ctype = "tree"; } else { $ctyle = "blob"; } } if ($ctype === "tree") { $folderstxt = ""; if ($rest !== "") {$folderstxt .= " ../
\n";} $filestxt = ""; foreach (explode("\n",$files) as $file) { $name = explode(" ",$file); if ($name[1] == "tree") { $folderstxt .= " ".end(explode("/",explode("\t",$name[2])[1]))."
\n"; } if ($name[1] == "blob") { $filestxt .= " ".end(explode("/",explode("\t",$name[2])[1]))."
\n"; } } echo $folderstxt; echo $filestxt; if ($readmefile = shell_exec("git ls-tree --full-name ".$branch." ".$rest."README")) { $readme = shell_exec("git cat-file -p ".explode("\t",explode(" ",explode("\n",$readmefile)[0])[2])[0]); $readme = preg_replace("/>/",">",$readme); $readme = preg_replace("/$2",$readme); $readme = preg_replace("/(^|\n)## (.+)/","

$2

",$readme); $readme = preg_replace("/(^|\n)### (.+)/","

$2

",$readme); $readme = preg_replace("/(^|\n)#### (.+)/","

$2

",$readme); $readme = preg_replace("/(^|\n)##### (.+)/","
$2
",$readme); $readme = preg_replace("/(^|\n)###### (.+)/","
$2
",$readme); $readme = preg_replace("/```([^`]+)```/","
$1
",$readme); $readme = preg_replace("/`([^`]+)`/","$1",$readme); $readme = preg_replace("/(^|\n)---($|\n)/","

",$readme); $readme = preg_replace("/\n\n/","
",$readme); $readme = preg_replace("/(^|\n) - (.*)/","
  • $2
  • ",$readme); $readme = preg_replace("/\[img src=\"([^\"]+)\"\]/","",$readme); $readme = preg_replace("/\[link src=\"([^\"]+)\"\]/","$1",$readme); echo "
    \n ".$readme; } } else { if (shell_exec("git ls-tree --full-name ".$branch." ".$rest)) { $content = shell_exec("git cat-file -p ".explode("\t",explode(" ",explode("\n",$files)[0])[2])[0]); echo "
    \n".htmlspecialchars($content)."
    \n"; } else { echo " \n 404! File not found!
    \n"; echo " [RETURN]\n
    \n"; } } } } } if ($DESCRIPTION !== "" && $path === "/") { echo "

    \n"; echo " ".$DESCRIPTION."\n"; } if ($FOOTER !== "") { echo "

    \n"; echo " ".$FOOTER."\n"; } ?>