Further simplification.

このコミットが含まれているのは:
2023-01-22 11:31:49 +09:00
コミット ed347b7392
1個のファイルの変更4行の追加11行の削除

ファイルの表示

@ -4,8 +4,7 @@
define("PDIR", "/home/".YOMAMA."/dev");
// Prevent accessing stuff you're not supposed to access.
$path = (isset($_GET["path"]) ? $_GET["path"] : "");
$path = htmlentities($path);
$path = htmlentities((isset($_GET["path"]) ? $_GET["path"] : ""));
if ($path == "/") $path = "";
foreach (explode("/", $path) as $e) { if ($e == "." || $e == ".." || $e == ".git") die("fuck off."); }
@ -13,22 +12,17 @@
$url = (str_contains($_SERVER['HTTP_HOST'], ".i2p") ? "http://ryocafe.i2p" : (str_contains($_SERVER["HTTP_HOST"], ".onion") ? "http://asc7ewkcvat2wsoi5yuwkej5ukyrqqnpnzpj4u34r2jxnoxhnbx6yqad.onion" : "https://ryocafe.site"));
// Get the Git info and whether it's a Git repo at all.
$isgit = false;
$cgp = PDIR;
$proot = "";
foreach (explode("/", $path) as $cg) {
$cgp .= $cg."/";
if (file_exists($cgp.".git")) {
$proot = $cgp;
$isgit = true;
}
if (file_exists($cgp.".git")) $proot = $cgp;
}
unset($cgp);
// Functions
function git_branch (string $fp) : string {
$res = str_replace("ref: ", "", file_get_contents($fp.".git/HEAD"));
$res = explode("/", $res);
$res = explode("/", str_replace("ref: ", "", file_get_contents($fp.".git/HEAD")));
return trim($res[array_key_last($res)]);
}
@ -66,8 +60,7 @@
?>
</h1>
<?php
if ($isgit) echo "<h2>Branch: ".git_branch($proot)."</h2>";
unset($isgit);
if ($proot != "") echo "<h2>Branch: ".git_branch($proot)."</h2>";
unset($proot);
if (!is_dir(PDIR.$path)) {
echo "<pre>".cat($path)."</pre>";