<?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);
}
/*
* List repos
*/
function rg_ssh_repos($db, $uid)
{
rg_log("ssh_repos");
$sql = "SELECT * FROM repos"
. " WHERE uid = $uid"
. " AND deleted = 0"
. " ORDER BY name, itime";
$pad = " ";
$res = rg_sql_query($db, $sql);
$rows = rg_sql_num_rows($res);
if ($rows > 0) {
echo "Repositories (name, creation, disk used):\n";
while (($row = rg_sql_fetch_array($res))) {
echo substr(substr($row['name'], 0, 40) . $pad, 0, 32)
. " " . gmdate("Y-m-d", $row['itime'])
. " " . rg_1024($row['disk_used_mb'] * 1024 * 1024)
. "\n";
}
} else {
echo "You have no repository.\n";
}
rg_sql_free_result($res);
exit(0);
}
/*
* Info about a repo
*/
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['exists'] != 1) {
echo "Error: unknown repo.\n";
exit(0);
}
echo "Repo: " . $ri['name'] . "\n";
echo "Repo type: " . ($ri['public'] == 1 ? "public" : "private") . "\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'] * 1024 * 1024) . "\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);
}
}
?>
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