xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / root / index.php (69e711647048eb98061fb3727cbe3782ccf616b3) (3,760B) (mode 100644) [raw]
<?php
error_reporting(E_ALL);
ini_set("track_errors", "On");

$INC = dirname(__FILE__) . "/../inc";
require_once("/etc/rocketgit/config.php");
require_once($INC . "/init.inc.php");
require_once($INC . "/log.inc.php");
include_once($INC . "/sql.inc.php");
include_once($INC . "/struct.inc.php");
include_once($INC . "/user.inc.php");
include_once($INC . "/repo.inc.php");
include_once($INC . "/keys.inc.php");
include_once($INC . "/token.inc.php");
include_once($INC . "/prof.inc.php");
include_once($INC . "/mr.inc.php");
include_once($INC . "/bug.inc.php");

rg_prof_start("MAIN");

rg_log_set_file($rg_web_log_dir . "/main.log");

// Init variables
$THEME_URL = "/themes/" . $rg_theme;
$op = ""; $subop = ""; $subsubop = ""; $cop = "";
$rr = array("user" => "", "repo" => "", "prefix" => "");
$paras = array();
$rg_ui = array();

// We have variable 'vv' passed from webserver - build 'op' and rest of paras
$vv = rg_var_str("vv");
rg_log("DEBUG: vv=$vv.");
if (strcmp($vv, "/") == 0) { // main page for site (not for user)
	$op = "main";
} else if (strncmp($vv, "/op/", 4) == 0) { // command
	$_t = substr($vv, 4);
	$_t = explode("/", $_t);
	$op = $_t[0];
	if (isset($_t[1])) {
		$subop = $_t[1];
		if (isset($_t[2]))
			$subsubop = $_t[2];
	}
	$cop = rtrim("/op/" . $op . "/" . $subop . "/" . $subsubop, "/");
} else { // user or organization
	if (strncmp($vv, "/user/", 6) == 0) {
		$vv6 = substr($vv, 6);
		$rr['prefix'] = "/user";
	} else {
		$vv6 = $vv;
		$rr['prefix'] = "";
	}
	$_t = explode("/", $vv6);
	$rr['user'] = $_t[0];
	$op = "home-page";
	if (isset($_t[1])) {
		$rr['repo'] = $_t[1];
		$op = "repo-page";

		if (isset($_t[2])) {
			$subop = $_t[2];

			// pass rest of vv to lower layers
			$i = 3;
			while (isset($_t[$i])) {
				$paras[] = $_t[$i];
				$i++;
			}
		}
	}
	$cop = $vv;
}


$doit = rg_var_uint("doit");
$sid = rg_var_re("sid", "/[^A-Za-z0-9]/");
$token = rg_var_re("token", "/[^A-Za-z0-9]/");

rg_log("IP: " . @$_SERVER['REMOTE_ADDR']);
rg_log("_REQUEST: " . rg_array2string($_REQUEST));
rg_log("_COOKIE: " . rg_array2string($_COOKIE));
rg_log("Start! cop=[$cop] op=$op subop=$subop subsubop=$subsubop"
	. " doit=$doit sid=$sid rr: " . rg_array2string($rr));
rg_log("paras: " . implode("|", $paras));


// database connection
$db = rg_sql_open($rg_sql);
if ($db === FALSE) {
	// TODO: Retry?
	die("Cannot open database!");
}

while (1) {
	$r = rg_sql_struct_update_needed($db);
	if ($r === FALSE)
		break;

	echo "Schema is not up-to-date! Sleep 1 second...";
	sleep(1);
}

rg_user_login_by_sid($db, $sid, $rg_ui);
rg_log("After login_by_sid, rg_ui=" . rg_array2string($rg_ui));


$body = "";
$second_menu = array();
rg_log("Dispatching to [$op]");
include($INC . "/dispatch/dispatch.php");


// menu
$first_menu = array(
	"login" => array(
		"text" => "Login",
		"uid0" => 1,
		"op" => "/op/login"),
	"home-page" => array(
		"text" => "Home",
		"op" => $rr['prefix'] . "/" . $rr['user']),
	"personal" => array(
		"text" => "Personal",
		"op" => "/op/personal"),
	"repo" => array(
		"text" => "Repositories",
		"op" => "/op/repo"),
	"admin" => array(
		"text" => "Admin",
		"needs_admin" => 1,
		"op" => "/op/admin"),
	"suggestion"=> array(
		"text" => "Suggestion",
		"op" => "/op/suggestion"),
	"logout" => array(
		"text" => "Logout",
		"op" => "/op/logout")
);
$first_menu[$op]['sub'] = $second_menu;
$more['HTML:rg_menu'] = implode("", rg_menu($first_menu, $rg_ui, $op, $subop));

if ($rg_ui['uid'] > 0)
	$more['rg_username'] = $rg_ui['username'];
else
	$more['rg_username'] = "Not logged in";

rg_prof_end("MAIN");

// TODO: Do something with the profiling, here

$more['HTML:rg_theme_url'] = $THEME_URL;
$more['HTML:rg_body'] = $body;
echo rg_template("index.html", $more);

rg_log("DONE!");
rg_prof_log("rg_log");
?>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master