Further simplification.

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

ファイルの表示

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