File inc/user.inc.php changed (mode: 100644) (index cbb14f1..d163e79) |
... |
... |
function rg_user_list_to_full_info($db, $list) |
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_input($content_length, $content_encoding) |
|
|
1858 |
|
function rg_process_input($content_length, $content_encoding, &$err) |
1859 |
1859 |
{ |
{ |
|
1860 |
|
$te = rg_var_str('HTTP_TRANSFER_ENCODING'); |
|
1861 |
|
|
1860 |
1862 |
rg_log_enter('DEBUG: process_input: cl=' . $content_length |
rg_log_enter('DEBUG: process_input: cl=' . $content_length |
1861 |
|
. ' content_encoding=' . $content_encoding); |
|
|
1863 |
|
. ' content_encoding=' . $content_encoding |
|
1864 |
|
. ' te=' . $te); |
1862 |
1865 |
|
|
|
1866 |
|
$ret = FALSE; |
1863 |
1867 |
while (1) { |
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 |
|
$max_nice = ini_get('post_max_size'); |
|
1869 |
|
$max = rg_mega2bytes($max_nice); |
|
1870 |
|
$max_nice = rg_1024($max); |
|
1871 |
|
if ($content_length > $max) { |
|
1872 |
|
$err = 'Your push size (' . rg_1024($content_length) . ')' |
|
1873 |
|
. ' is bigger than the max allowed' |
|
1874 |
|
. ' (' . $max_nice . ').' . "\n" |
|
1875 |
|
. 'You may want to ask the admin to raise' |
|
1876 |
|
. ' the limits (post_max_size).'; |
|
1877 |
|
break; |
|
1878 |
|
} |
|
1879 |
|
|
|
1880 |
|
if ($content_length == 0) { |
|
1881 |
|
if (strcasecmp($te, 'chunked') != 0) { |
|
1882 |
|
$err = 'No Content-Length header and' |
|
1883 |
|
. ' Transfer-Encoding is not' |
|
1884 |
|
. ' "chunked". Please let us know.'; |
|
1885 |
|
rg_internal_error($err); |
|
1886 |
|
break; |
|
1887 |
|
} |
|
1888 |
|
|
|
1889 |
|
// TODO: Sadly, we are not able to do the streaming! |
|
1890 |
|
// It is not available to php-fpm! |
1870 |
1891 |
|
|
1871 |
|
if (0) { // maybe for nginx/lighttpd |
|
1872 |
|
$f = @fopen('php://stdin', 'r'); |
|
1873 |
|
if ($f === FALSE) { |
|
1874 |
|
rg_log('Cannot open stdin!'); |
|
|
1892 |
|
rg_git_info_pack("\x02", 'We could not process' |
|
1893 |
|
. ' the data (chunked).'); |
|
1894 |
|
|
|
1895 |
|
|
|
1896 |
|
$err = 'You are trying to push chunked encoding data' |
|
1897 |
|
. ' but php-fpm does not support it.' . "\n" |
|
1898 |
|
. ' Try to run' |
|
1899 |
|
. ' \'git config http.postBuffer 200000000\'.' . "\n" |
|
1900 |
|
. ' The value must be bigger than what you' |
|
1901 |
|
. ' want to push.'; |
1875 |
1902 |
break; |
break; |
1876 |
|
} |
|
1877 |
|
while (1) { |
|
1878 |
|
$x = @fread($f, 4); |
|
1879 |
|
if ($x === FALSE) { |
|
1880 |
|
rg_log('DEBUG: cannot read!'); |
|
|
1903 |
|
|
|
1904 |
|
rg_log('DEBUG: have to read data from php://stdin'); |
|
1905 |
|
sleep(3); |
|
1906 |
|
// 'stdin' is not good because fd0 is associated with /dev/null |
|
1907 |
|
$f = @fopen('php://stdin', 'rb'); |
|
1908 |
|
$f2 = @fopen('php://input', 'rb'); |
|
1909 |
|
rg_log('DEBUG: f=' . $f . ' f2=' . $f2); |
|
1910 |
|
if ($f === FALSE) { |
|
1911 |
|
rg_log('Cannot open stdin!'); |
1881 |
1912 |
break; |
break; |
1882 |
1913 |
} |
} |
1883 |
|
rg_log('DEBUG: BLOCK: ' . $x); |
|
1884 |
|
$ret = $x; |
|
1885 |
|
break; |
|
1886 |
|
} |
|
1887 |
|
fclose($f); |
|
|
1914 |
|
rg_log('DEBUG: start reading from php://stdin'); |
|
1915 |
|
while (1) { |
|
1916 |
|
$x = @fread($f, 65536); |
|
1917 |
|
rg_log('DEBUG: x='); |
|
1918 |
|
if ($x === FALSE) { |
|
1919 |
|
rg_log('DEBUG: cannot read!'); |
|
1920 |
|
break; |
|
1921 |
|
} |
|
1922 |
|
rg_log('DEBUG: BLOCK: ' . $x); |
|
1923 |
|
$ret = $x; |
|
1924 |
|
break; |
|
1925 |
|
} |
|
1926 |
|
fclose($f); |
|
1927 |
|
} else { // Content-Length > 0 |
|
1928 |
|
// TODO: we should just pass the file descriptor |
|
1929 |
|
// (with stream filter gzip if needed) |
|
1930 |
|
// and not buffer the whole content. |
|
1931 |
|
$ret = @file_get_contents('php://input'); |
|
1932 |
|
if (empty($ret)) { |
|
1933 |
|
$err = 'No input provided. Please let us know.'; |
|
1934 |
|
rg_internal_error($err); |
|
1935 |
|
$ret = FALSE; |
|
1936 |
|
break; |
|
1937 |
|
} |
|
1938 |
|
rg_log('DEBUG: php://input returned ' . strlen($ret) . ' bytes'); |
1888 |
1939 |
} |
} |
1889 |
1940 |
|
|
1890 |
1941 |
rg_log('DEBUG: data_in[0-31]: ' . substr($ret, 0, 32)); |
rg_log('DEBUG: data_in[0-31]: ' . substr($ret, 0, 32)); |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2086 |
2137 |
|
|
2087 |
2138 |
header('Content-Type: application/x-git-upload-pack-result'); |
header('Content-Type: application/x-git-upload-pack-result'); |
2088 |
2139 |
|
|
2089 |
|
// TODO: seems I cannot do this here - |
|
2090 |
|
// seems remote receive-pack expects ACK/NAK first: |
|
|
2140 |
|
// TODO: seems I cannot do this here: |
|
2141 |
|
// remote receive-pack expects ACK/NAK first: |
2091 |
2142 |
// fatal: git fetch_pack: expected ACK/NAK, got '... |
// fatal: git fetch_pack: expected ACK/NAK, got '... |
|
2143 |
|
// Should I send NAK first? |
2092 |
2144 |
/* |
/* |
2093 |
2145 |
rg_git_info_pack("\x02", '== Welcome to RocketGit! =='); |
rg_git_info_pack("\x02", '== Welcome to RocketGit! =='); |
2094 |
2146 |
rg_git_info_pack("\x02", 'you are connecting from IP ' |
rg_git_info_pack("\x02", 'you are connecting from IP ' |
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2101 |
2153 |
*/ |
*/ |
2102 |
2154 |
|
|
2103 |
2155 |
$data_in = rg_process_input($content_length, |
$data_in = rg_process_input($content_length, |
2104 |
|
$content_encoding); |
|
|
2156 |
|
$content_encoding, $err); |
2105 |
2157 |
if ($data_in === FALSE) |
if ($data_in === FALSE) |
2106 |
2158 |
break; |
break; |
2107 |
2159 |
|
|
|
... |
... |
function rg_user_http_git($db, $rg, $paras) |
2126 |
2178 |
. ' instead of ' . $host . '.'); |
. ' instead of ' . $host . '.'); |
2127 |
2179 |
putenv('ROCKETGIT_SHOW_INFO=0'); |
putenv('ROCKETGIT_SHOW_INFO=0'); |
2128 |
2180 |
|
|
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 |
|
} |
|
2143 |
|
|
|
2144 |
2181 |
$data_in = rg_process_input($content_length, |
$data_in = rg_process_input($content_length, |
2145 |
|
$content_encoding); |
|
|
2182 |
|
$content_encoding, $err); |
2146 |
2183 |
if ($data_in === FALSE) { |
if ($data_in === FALSE) { |
2147 |
2184 |
// We have to send '200'. |
// We have to send '200'. |
2148 |
2185 |
// Else, we cannot send the hints |
// Else, we cannot send the hints |
2149 |
2186 |
header($protocol . ' 200 Service unavailable'); |
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.'); |
|
|
2187 |
|
rg_git_info_pack("\x02", $err); |
2156 |
2188 |
echo rg_git_flush(); |
echo rg_git_flush(); |
2157 |
2189 |
break; |
break; |
2158 |
2190 |
} |
} |