First commit
このコミットが含まれているのは:
コミット
47a9a018f8
6
config.php
ノーマルファイル
6
config.php
ノーマルファイル
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
// Linux = /usr/bin/git, BSD = /usr/local/bin/git
|
||||
define("BIN", "/usr/local/bin/git");
|
||||
define("PDIR", "/home/ryo/dev");
|
||||
define("YOMAMA", "ryo");
|
||||
?>
|
82
index.php
ノーマルファイル
82
index.php
ノーマルファイル
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// Load shit.
|
||||
require_once("config.php");
|
||||
|
||||
// Prevent accessing stuff you're not supposed to access.
|
||||
$path = (isset($_GET["path"]) ? $_GET["path"] : "");
|
||||
if ($path == "/") $path = "";
|
||||
foreach (explode("/", $path) as $e) { if ($e == "." || $e == ".." || $e == ".git") die("fuck off."); }
|
||||
|
||||
// Show URL based on where you're browsing from.
|
||||
$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;
|
||||
}
|
||||
}
|
||||
unset($cgp);
|
||||
|
||||
// Functions
|
||||
function git_branch (string $fp) : string {
|
||||
$res = str_replace("ref: ", "", file_get_contents($fp.".git/HEAD"));
|
||||
$res = explode("/", $res);
|
||||
return trim($res[array_key_last($res)]);
|
||||
}
|
||||
|
||||
function get_commit_msg (string $fp) : string {
|
||||
return date("Y/m/d H:i:s", filemtime($fp.".git/COMMIT_EDITMSG")).": ".trim(file_get_contents($fp.".git/COMMIT_EDITMSG"));
|
||||
}
|
||||
|
||||
function ls (string $fp = "") : array|bool {
|
||||
return array_diff(scandir(PDIR.$fp), ["..", ".", ".git"]);
|
||||
}
|
||||
|
||||
function cat (string $fp) : string {
|
||||
if (!isset($fp)) die("Missing filename.");
|
||||
return str_starts_with(mime_content_type(PDIR."/".$fp), "text/") ? htmlspecialchars(file_get_contents(PDIR."/".$fp)) : "";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
|
||||
<title><?= YOMAMA ?>'s git repo</title>
|
||||
<link rel="stylesheet" type="text/css" href="/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<p>Made by <a href="<?= $url ?>">寮</a>.</p>
|
||||
<h1>
|
||||
<?php
|
||||
$ex = explode("/", $path);
|
||||
$ph = "";
|
||||
foreach ($ex as $i => $pt) {
|
||||
if ($i != 0) $ph .= "/".$pt;
|
||||
else echo "<a href=\"/\">root</a>";
|
||||
echo ($i != array_key_last($ex) ? "<a href=\"/?path=".$ph."\">".$pt."</a>" : $pt);
|
||||
if ($i != array_key_last($ex)) echo "/";
|
||||
}
|
||||
?>
|
||||
</h1>
|
||||
<?php
|
||||
if ($isgit) {
|
||||
echo "<h2>Branch: ".git_branch($proot)."</h2>";
|
||||
echo "<h3>Last commit: ".get_commit_msg($proot)."</h3>";
|
||||
}
|
||||
if (!is_dir(PDIR.$path)) {
|
||||
echo "<pre>".cat($path)."</pre>";
|
||||
}
|
||||
else {
|
||||
echo "<ul>";
|
||||
foreach (ls($path."/") as $p) echo "<li><a href=\"/?path=".$path."/".$p."\">".$p."</a></li>";
|
||||
echo "</ul>";
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
読み込み中…
新しいイシューから参照
ユーザーをブロックする