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.
Commit fe5d01344b9131edeb2812f72549bf74d8242653

Do not allow random input as reference
Author: Catalin(ux) M. BOIE
Author date (UTC): 2016-03-14 16:31
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2016-03-14 16:31
Parent(s): 485f0f8bae787bfbd7c52c9b934af977d8a2b871
Signing key:
Tree: 60d132274fe3fcfcf75e00f40072914ff195eccf
File Lines added Lines deleted
inc/git.inc.php 30 12
inc/user/repo-page.php 13 1
File inc/git.inc.php changed (mode: 100644) (index 528eaae..55761de)
... ... function rg_git_log($path, $max, $from, $to, $also_patch)
807 807 $from_to = ''; $from_to = '';
808 808 } else if (empty($from)) { } else if (empty($from)) {
809 809 rg_log('from empty'); rg_log('from empty');
810 $from_to = ' ' . $to;
810 $from_to = $to;
811 811 } else if (strcmp($from, $rg_git_zero) == 0) { } else if (strcmp($from, $rg_git_zero) == 0) {
812 812 rg_log('from zero'); rg_log('from zero');
813 $from_to = ' ' . $rg_git_empty . '..' . $to;
813 $from_to = $rg_git_empty . '..' . $to;
814 814 $test_for_master = FALSE; $test_for_master = FALSE;
815 815 } else { } else {
816 $from_to = ' ' . $from . '..' . $to;
816 $from_to = $from . '..' . $to;
817 817 } }
818 818
819 819 if ($test_for_master) { if ($test_for_master) {
 
... ... function rg_git_log($path, $max, $from, $to, $also_patch)
858 858 . "body:%b%x00\"\"" . "body:%b%x00\"\""
859 859 . "notes:%N%x00\"\"" . "notes:%N%x00\"\""
860 860 . "%x00ROCKETGIT_END_OF_VARS%x00\"" . "%x00ROCKETGIT_END_OF_VARS%x00\""
861 . $from_to;
861 . ' ' . escapeshellarg($from_to);
862 862 $a = rg_exec($cmd); $a = rg_exec($cmd);
863 863 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
864 864 rg_internal_error("error on log (" . $a['errmsg'] . ")"); rg_internal_error("error on log (" . $a['errmsg'] . ")");
 
... ... function rg_git_refs($repo_path)
1517 1517 return $ret; return $ret;
1518 1518 } }
1519 1519
1520 /*
1521 * Returns true if a ref is valid
1522 * @refs - the output of rg_git_refs
1523 * @type - 'tag' or 'branch'
1524 */
1525 function rg_git_ref_valid($refs, $type, $ref)
1526 {
1527 if (!isset($refs[$type]))
1528 return FALSE;
1529
1530 foreach ($refs[$type] as $name) {
1531 if (strcmp($name, $ref) == 0)
1532 return TRUE;
1533 }
1534
1535 return FALSE;
1536 }
1537
1520 1538 /* /*
1521 1539 * Returns an array with links to branches and tags * Returns an array with links to branches and tags
1540 * @refs is the output of rg_git_refs function
1522 1541 */ */
1523 function rg_git_branches_and_tags($repo_dir, $base_url, $current_ref)
1542 function rg_git_branches_and_tags($refs, $base_url, $current_ref)
1524 1543 { {
1525 rg_log_enter("git_branches_and_tags: repo_dir=$repo_dir base_url=$base_url"
1544 rg_log_enter("git_branches_and_tags: base_url=$base_url"
1526 1545 . " current_ref=$current_ref"); . " current_ref=$current_ref");
1527 1546
1528 1547 $ret = array(); $ret = array();
1529 $ret['HTML:branches_and_tags'] = "";
1548 $ret['HTML:branches_and_tags'] = '';
1530 1549
1531 $current = ltrim($current_ref, "/");
1550 $current = ltrim($current_ref, '/');
1532 1551 if (empty($current)) if (empty($current))
1533 $current = "branch/master";
1552 $current = 'branch/master';
1534 1553 //rg_log("DEBUG: current=[$current]"); //rg_log("DEBUG: current=[$current]");
1535 1554
1536 $refs = rg_git_refs($repo_dir);
1537 1555 $_l = array(); $_l = array();
1538 1556 foreach ($refs as $o => $list) { foreach ($refs as $o => $list) {
1539 1557 if (empty($list)) if (empty($list))
 
... ... function rg_git_branches_and_tags($repo_dir, $base_url, $current_ref)
1564 1582 $ret['HTML:branches_and_tags'] .= "</div>\n"; $ret['HTML:branches_and_tags'] .= "</div>\n";
1565 1583 } }
1566 1584
1567 rg_log("rg_git_branches_and_tags: ret:" . rg_array2string($ret));
1585 //rg_log("DEBUG: rg_git_branches_and_tags: ret:" . rg_array2string($ret));
1568 1586
1569 1587 rg_log_exit(); rg_log_exit();
1570 1588 return $ret; return $ret;
 
... ... function rg_git_parse_ref(&$paras)
1597 1615 } }
1598 1616
1599 1617 array_shift($paras); array_shift($paras);
1600 $val = array_shift($paras);
1618 $val = trim(array_shift($paras));
1601 1619 $ret['ref_url'] = "/" . $ret['ref_type'] . "/" . $val; $ret['ref_url'] = "/" . $ret['ref_type'] . "/" . $val;
1602 1620
1603 1621 $val = str_replace(',', '/', $val); $val = str_replace(',', '/', $val);
File inc/user/repo-page.php changed (mode: 100644) (index e8bc46c..b82135e)
... ... if (strcmp($_subop, "history") == 0) {
138 138 $_subsubop = empty($paras) ? "" : array_shift($paras); $_subsubop = empty($paras) ? "" : array_shift($paras);
139 139 $rg['source_menu'][$_subsubop] = 1; $rg['source_menu'][$_subsubop] = 1;
140 140
141 $refs = rg_git_refs($rg['repo_path']);
142 //rg_log_ml('DEBUG: refs: ' . print_r($refs, TRUE));
143
141 144 $type_ref = rg_git_parse_ref($paras); $type_ref = rg_git_parse_ref($paras);
142 145 $ref = $type_ref['ref_path']; $ref = $type_ref['ref_path'];
146 if (rg_git_ref_valid($refs, $type_ref['ref_type'], $type_ref['ref_val']) !== TRUE) {
147 $_a = array('branch', 'master');
148 $type_ref = rg_git_parse_ref($_a);
149 $ref = $type_ref['ref_path'];
150 }
151
152 //rg_log_ml('DEBUG: type_ref: ' . print_r($type_ref, TRUE));
143 153 $rg = array_merge($rg, $type_ref); $rg = array_merge($rg, $type_ref);
154 rg_log('DEBUG: ref=[' . $ref . ']');
155
144 156
145 $bt = rg_git_branches_and_tags($rg['repo_path'], $rg['ri']['url_repo'],
157 $bt = rg_git_branches_and_tags($refs, $rg['ri']['url_repo'],
146 158 $type_ref['ref_url']); $type_ref['ref_url']);
147 159 $rg = array_merge($rg, $bt); $rg = array_merge($rg, $bt);
148 160
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