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> / inc / ssh.inc.php (e9b2393a061e04bfb1290db46344f11bb85b8c2b) (2,326B) (mode 100644) [raw]
<?php
//
// Description: This file deals with commands accepted by ssh
//
require_once($INC . "/sql.inc.php");
require_once($INC . "/state.inc.php");
require_once($INC . "/prof.inc.php");
require_once($INC . "/repo.inc.php");

function rg_ssh_status($db, $uid)
{
	rg_log("ssh_status");

	echo "Here will be the status.\n";

	// also details about payments: warn if disk space is low etc.

	exit(0);
}

function rg_ssh_repos($db, $uid)
{
	rg_log("ssh_repos");

	echo "Repositories (name, creation, disk used/quota):\n";
	$sql = "SELECT * FROM repos"
		. " WHERE uid = $uid"
		. " AND deleted = 0"
		. " ORDER BY name, itime";
	$pad = "                                              ";
	$res = rg_sql_query($db, $sql);
	while (($row = rg_sql_fetch_array($res))) {
		echo substr(substr($row['name'], 0, 40) . $pad, 0, 32)
			. "\t" . gmdate("Y-m-d", $row['itime'])
			. "\t" . rg_1024($row['disk_used_mb']) . "/" . rg_1024($row['disk_quota_mb'])
			. "\n";
	}
	rg_sql_free_result($res);

	exit(0);
}

function rg_ssh_repo($db, $uid, $paras)
{
	rg_log("ssh_repo: " . rg_array2string($paras));

	if (empty($paras)) {
		echo "Please specify repo name.\n";
		exit(0);
	}

	$repo_name = trim($paras[0]);

	$ri = rg_repo_info($db, 0, $uid, $repo_name);
	if ($ri === FALSE) {
		echo "Unknown repo!\n";
		exit(0);
	}

	echo "Repo:		" . $ri['name'] . "\n";
	echo "Description:\n";
	$_d = explode("\n", $ri['description']);
	if (!empty($_d)) {
		foreach ($_d as $_line)
			echo "  " . $_line . "\n";
	}
	echo "Creation time:	" . gmdate("Y-m-d", $ri['itime']) . " UTC\n";
	echo "Disk used:	" . rg_1024($ri['disk_used_mb']) . " MiB\n";
	echo "Disk quota:	" . rg_1024($ri['disk_quota_mb']) . " MiB\n";
	$rights = implode(", ", rg_rights_text("repo", $ri['default_rights']));
	echo "Default rights:	" . $rights . "\n";

	if ($ri['master'] > 0) {
		$mri = rg_repo_info($db, $ri['master'], 0, "");
		if ($mri !== FALSE) {
			echo "Master:		" . $mri['name'] . "\n";
		}
	}

	exit(0);
}

function rg_ssh_dispatch($db, $uid, $cmd)
{
	$paras = explode(" ", $cmd);
	$cmd = array_shift($paras);

	switch ($cmd) {
		case 'status': rg_ssh_status($db, $uid); break;
		case 'repos': rg_ssh_repos($db, $uid); break;
		case 'repo': rg_ssh_repo($db, $uid, $paras); break;
		case '':
			echo "Available commmands: status, repos, repo.\n";
			exit(0);
	}
}

?>
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