File inc/user.inc.php changed (mode: 100644) (index 041c8cd..cbb14f1) |
... |
... |
function rg_user_list_to_full_info($db, $list) |
1849 |
1849 |
} |
} |
1850 |
1850 |
|
|
1851 |
1851 |
/* |
/* |
1852 |
|
* This function deals with incoming compressed input. |
|
|
1852 |
|
* This function deals with incoming (compressed) input. |
1853 |
1853 |
* Please note that if the webserver was configured without an input filter |
* Please note that if the webserver was configured without an input filter |
1854 |
1854 |
* (like apache's SetInputFilter DEFLATE), this function will |
* (like apache's SetInputFilter DEFLATE), this function will |
1855 |
1855 |
* take care of it. |
* take care of it. |
1856 |
1856 |
* Returns the uncompressed stream. |
* Returns the uncompressed stream. |
1857 |
1857 |
*/ |
*/ |
1858 |
|
function rg_process_gzip($content_length, $content_encoding) |
|
|
1858 |
|
function rg_process_input($content_length, $content_encoding) |
1859 |
1859 |
{ |
{ |
1860 |
|
rg_log('DEBUG: process_gzip: cl=' . $content_length |
|
|
1860 |
|
rg_log_enter('DEBUG: process_input: cl=' . $content_length |
1861 |
1861 |
. ' content_encoding=' . $content_encoding); |
. ' content_encoding=' . $content_encoding); |
1862 |
1862 |
|
|
1863 |
|
$data_in = @file_get_contents('php://input'); |
|
1864 |
|
if ($data_in === FALSE) { |
|
1865 |
|
rg_log('Cannot get in stream (1)!'); |
|
1866 |
|
return FALSE; |
|
1867 |
|
} |
|
|
1863 |
|
while (1) { |
|
1864 |
|
$ret = @file_get_contents('php://input'); |
|
1865 |
|
if (empty($ret)) { |
|
1866 |
|
rg_log('DEBUG: php://input is empty!'); |
|
1867 |
|
$ret = FALSE; |
|
1868 |
|
break; |
|
1869 |
|
} |
1868 |
1870 |
|
|
1869 |
|
rg_log('DEBUG: data_in: ' . substr($data_in, 0, 32)); |
|
1870 |
|
if (strcmp($content_encoding, 'gzip') == 0) { |
|
1871 |
|
$data_in = @gzdecode($data_in); |
|
1872 |
|
if ($data_in === FALSE) { |
|
1873 |
|
rg_log('Cannot decompress!'); |
|
1874 |
|
return FALSE; |
|
|
1871 |
|
if (0) { // maybe for nginx/lighttpd |
|
1872 |
|
$f = @fopen('php://stdin', 'r'); |
|
1873 |
|
if ($f === FALSE) { |
|
1874 |
|
rg_log('Cannot open stdin!'); |
|
1875 |
|
break; |
1875 |
1876 |
} |
} |
1876 |
|
rg_log('DEBUG: after decompress: ' . substr($data_in, 0, 32)); |
|
|
1877 |
|
while (1) { |
|
1878 |
|
$x = @fread($f, 4); |
|
1879 |
|
if ($x === FALSE) { |
|
1880 |
|
rg_log('DEBUG: cannot read!'); |
|
1881 |
|
break; |
|
1882 |
|
} |
|
1883 |
|
rg_log('DEBUG: BLOCK: ' . $x); |
|
1884 |
|
$ret = $x; |
|
1885 |
|
break; |
|
1886 |
|
} |
|
1887 |
|
fclose($f); |
|
1888 |
|
} |
|
1889 |
|
|
|
1890 |
|
rg_log('DEBUG: data_in[0-31]: ' . substr($ret, 0, 32)); |
|
1891 |
|
if (strcmp($content_encoding, 'gzip') == 0) { |
|
1892 |
|
$ret = @gzdecode($ret); |
|
1893 |
|
if ($ret === FALSE) { |
|
1894 |
|
rg_log('Cannot decompress!'); |
|
1895 |
|
break; |
|
1896 |
|
} |
|
1897 |
|
rg_log('DEBUG: after decompress[0-31]: ' |
|
1898 |
|
. substr($ret, 0, 32)); |
|
1899 |
|
} |
|
1900 |
|
|
|
1901 |
|
break; |
1877 |
1902 |
} |
} |
1878 |
1903 |
|
|
1879 |
|
return $data_in; |
|
|
1904 |
|
return $ret; |
1880 |
1905 |
} |
} |
1881 |
1906 |
|
|
1882 |
1907 |
/* |
/* |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
1926 |
1951 |
header('Expires: Fri, 01 Jan 1980 00:00:00 GMT'); |
header('Expires: Fri, 01 Jan 1980 00:00:00 GMT'); |
1927 |
1952 |
header('Pragma: no-cache'); |
header('Pragma: no-cache'); |
1928 |
1953 |
header('Cache-Control: no-cache, max-age=0, must-revalidate'); |
header('Cache-Control: no-cache, max-age=0, must-revalidate'); |
|
1954 |
|
header('Content-Type: text/plain'); |
1929 |
1955 |
|
|
1930 |
1956 |
// if user is valid, retry auth |
// if user is valid, retry auth |
1931 |
1957 |
// if user is not valid, consider anonymous |
// if user is not valid, consider anonymous |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2002 |
2028 |
header($protocol . ' 401 Unauthorized status'); |
header($protocol . ' 401 Unauthorized status'); |
2003 |
2029 |
header('WWW-Authenticate: Basic' |
header('WWW-Authenticate: Basic' |
2004 |
2030 |
. ' realm="Use empty user if you have no account"'); |
. ' realm="Use empty user if you have no account"'); |
|
2031 |
|
echo 'RocketGit: Info: == Welcome to RocketGit! ==' . "\n"; |
|
2032 |
|
echo 'RocketGit: Info: you are connecting from IP ' . $rg['ip'] . '.' . "\n"; |
|
2033 |
|
echo 'RocketGit: Error: ' . $r['error'] . '!'; |
2005 |
2034 |
break; |
break; |
2006 |
2035 |
} |
} |
2007 |
2036 |
|
|
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2012 |
2041 |
. ' push=' . $r['push']); |
. ' push=' . $r['push']); |
2013 |
2042 |
if (($r['push'] === 1) && ($r['push_allowed'] !== 1)) { |
if (($r['push'] === 1) && ($r['push_allowed'] !== 1)) { |
2014 |
2043 |
// We have only anon push rights at this point. |
// We have only anon push rights at this point. |
2015 |
|
// If user is correct, but password not, we will ask |
|
|
2044 |
|
// If user is correct, but password is not, we will ask |
2016 |
2045 |
// the user to try again. If user is not correct, |
// the user to try again. If user is not correct, |
2017 |
2046 |
// we will go on with anon push access. |
// we will go on with anon push access. |
2018 |
2047 |
if ($empty_user |
if ($empty_user |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2021 |
2050 |
header($protocol . ' 401 Unauthorized status'); |
header($protocol . ' 401 Unauthorized status'); |
2022 |
2051 |
header('WWW-Authenticate: Basic' |
header('WWW-Authenticate: Basic' |
2023 |
2052 |
. ' realm="Use empty user if you have no account"'); |
. ' realm="Use empty user if you have no account"'); |
|
2053 |
|
echo 'RocketGit: Info: == Welcome to RocketGit! ==' . "\n"; |
|
2054 |
|
echo 'RocketGit: Info: you are connecting from IP ' . $rg['ip'] . '.' . "\n"; |
2024 |
2055 |
break; |
break; |
2025 |
2056 |
} |
} |
2026 |
2057 |
} else if ($r['push'] === 1) { |
} else if ($r['push'] === 1) { |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2029 |
2060 |
rg_log('DEBUG: it is a fetch'); |
rg_log('DEBUG: it is a fetch'); |
2030 |
2061 |
} |
} |
2031 |
2062 |
|
|
2032 |
|
$content_length = rg_var_str('CONTENT_LENGTH'); |
|
|
2063 |
|
$content_length = rg_var_int('CONTENT_LENGTH'); |
2033 |
2064 |
$content_encoding = rg_var_str('HTTP_CONTENT_ENCODING'); |
$content_encoding = rg_var_str('HTTP_CONTENT_ENCODING'); |
2034 |
2065 |
rg_log('DEBUG: cl=' . $content_length . ' ce=' . $content_encoding); |
rg_log('DEBUG: cl=' . $content_length . ' ce=' . $content_encoding); |
2035 |
2066 |
|
|
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2049 |
2080 |
$e = rg_exec($run, '', 'rg_echo', 'rg_git_band_2'); |
$e = rg_exec($run, '', 'rg_echo', 'rg_git_band_2'); |
2050 |
2081 |
if ($e['code'] != 0) |
if ($e['code'] != 0) |
2051 |
2082 |
rg_log('Error executing command: ' . $e['errmsg']); |
rg_log('Error executing command: ' . $e['errmsg']); |
|
2083 |
|
rg_log('Done!'); |
2052 |
2084 |
} else if (strcasecmp($rg['ct'], 'application/x-git-upload-pack-request') == 0) { |
} else if (strcasecmp($rg['ct'], 'application/x-git-upload-pack-request') == 0) { |
2053 |
2085 |
rg_log('DEBUG: git-upload-pack...'); |
rg_log('DEBUG: git-upload-pack...'); |
2054 |
2086 |
|
|
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2061 |
2093 |
rg_git_info_pack("\x02", '== Welcome to RocketGit! =='); |
rg_git_info_pack("\x02", '== Welcome to RocketGit! =='); |
2062 |
2094 |
rg_git_info_pack("\x02", 'you are connecting from IP ' |
rg_git_info_pack("\x02", 'you are connecting from IP ' |
2063 |
2095 |
. $rg['ip'] . '.'); |
. $rg['ip'] . '.'); |
2064 |
|
// If user does not correct to the correct URL, correct them |
|
|
2096 |
|
// If user does not connect to the correct URL, correct them |
2065 |
2097 |
if (!empty($host) && (strcasecmp($host, $rg['rg_http_host_no_port']) != 0)) |
if (!empty($host) && (strcasecmp($host, $rg['rg_http_host_no_port']) != 0)) |
2066 |
2098 |
rg_git_info_pack("\x02", 'Please use ' . $rg['rg_http_host_no_port'] |
rg_git_info_pack("\x02", 'Please use ' . $rg['rg_http_host_no_port'] |
2067 |
2099 |
. ' instead of ' . $host . '.'); |
. ' instead of ' . $host . '.'); |
2068 |
2100 |
putenv('ROCKETGIT_SHOW_INFO=0'); |
putenv('ROCKETGIT_SHOW_INFO=0'); |
2069 |
2101 |
*/ |
*/ |
2070 |
2102 |
|
|
2071 |
|
$run = '/usr/libexec/git-core/git-upload-pack' |
|
2072 |
|
. ' --stateless-rpc' |
|
2073 |
|
. ' ' . escapeshellarg($repo_path); |
|
2074 |
|
|
|
2075 |
|
$data_in = rg_process_gzip($content_length, $content_encoding); |
|
|
2103 |
|
$data_in = rg_process_input($content_length, |
|
2104 |
|
$content_encoding); |
2076 |
2105 |
if ($data_in === FALSE) |
if ($data_in === FALSE) |
2077 |
2106 |
break; |
break; |
2078 |
2107 |
|
|
|
2108 |
|
$run = '/usr/libexec/git-core/git-upload-pack' |
|
2109 |
|
. ' --stateless-rpc' |
|
2110 |
|
. ' ' . escapeshellarg($repo_path); |
2079 |
2111 |
$e = rg_exec($run, $data_in, 'rg_echo', 'rg_git_band_2'); |
$e = rg_exec($run, $data_in, 'rg_echo', 'rg_git_band_2'); |
2080 |
2112 |
if ($e['code'] != 0) |
if ($e['code'] != 0) |
2081 |
2113 |
rg_log('Error executing command: ' . $e['errmsg']); |
rg_log('Error executing command: ' . $e['errmsg']); |
|
2114 |
|
rg_log('Done!'); |
2082 |
2115 |
} else if (strcasecmp($rg['ct'], 'application/x-git-receive-pack-request') == 0) { |
} else if (strcasecmp($rg['ct'], 'application/x-git-receive-pack-request') == 0) { |
2083 |
2116 |
rg_log('DEBUG: git-receive-pack...'); |
rg_log('DEBUG: git-receive-pack...'); |
2084 |
2117 |
|
|
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2093 |
2126 |
. ' instead of ' . $host . '.'); |
. ' instead of ' . $host . '.'); |
2094 |
2127 |
putenv('ROCKETGIT_SHOW_INFO=0'); |
putenv('ROCKETGIT_SHOW_INFO=0'); |
2095 |
2128 |
|
|
2096 |
|
$run = '/usr/libexec/git-core/git-receive-pack' |
|
2097 |
|
. ' --stateless-rpc' |
|
2098 |
|
. ' ' . escapeshellarg($repo_path); |
|
|
2129 |
|
$max_nice = ini_get('post_max_size'); |
|
2130 |
|
$max = rg_mega2bytes($max_nice); |
|
2131 |
|
$max_nice = rg_1024($max); |
|
2132 |
|
$content_length = 1000000000; |
|
2133 |
|
if ($content_length > $max) { |
|
2134 |
|
rg_git_info_pack("\x02", 'Your push size (' |
|
2135 |
|
. rg_1024($content_length) . ')' |
|
2136 |
|
. ' is bigger than the' |
|
2137 |
|
. ' max allowed (' . $max_nice . ').'); |
|
2138 |
|
rg_git_info_pack("\x02", 'You may want to ask' |
|
2139 |
|
. ' the admin to raise the limit.'); |
|
2140 |
|
echo rg_git_flush(); |
|
2141 |
|
break; |
|
2142 |
|
} |
2099 |
2143 |
|
|
2100 |
|
$data_in = rg_process_gzip($content_length, $content_encoding); |
|
2101 |
|
if ($data_in === FALSE) |
|
|
2144 |
|
$data_in = rg_process_input($content_length, |
|
2145 |
|
$content_encoding); |
|
2146 |
|
if ($data_in === FALSE) { |
|
2147 |
|
// We have to send '200'. |
|
2148 |
|
// Else, we cannot send the hints |
|
2149 |
|
header($protocol . ' 200 Service unavailable'); |
|
2150 |
|
rg_git_info_pack("\x02", 'We could not process' |
|
2151 |
|
. ' the data (chunked).'); |
|
2152 |
|
rg_git_info_pack("\x02", 'Try to run \'git' |
|
2153 |
|
. ' config http.postBuffer 200000000\'.'); |
|
2154 |
|
rg_git_info_pack("\x02", 'The value must be' |
|
2155 |
|
. ' bigger than the biggest file pushed.'); |
|
2156 |
|
echo rg_git_flush(); |
2102 |
2157 |
break; |
break; |
|
2158 |
|
} |
2103 |
2159 |
|
|
|
2160 |
|
$run = '/usr/libexec/git-core/git-receive-pack' |
|
2161 |
|
. ' --stateless-rpc' |
|
2162 |
|
. ' ' . escapeshellarg($repo_path); |
2104 |
2163 |
$e = rg_exec($run, $data_in, 'rg_echo', 'rg_echo'); |
$e = rg_exec($run, $data_in, 'rg_echo', 'rg_echo'); |
2105 |
2164 |
if ($e['code'] != 0) |
if ($e['code'] != 0) |
2106 |
2165 |
rg_log('Error executing command: ' . $e['errmsg']); |
rg_log('Error executing command: ' . $e['errmsg']); |
|
2166 |
|
rg_log('Done!'); |
2107 |
2167 |
} else { |
} else { |
2108 |
2168 |
rg_log('Unknown service!'); |
rg_log('Unknown service!'); |
2109 |
2169 |
// TODO: send some errors, also above |
// TODO: send some errors, also above |