List of commits:
Subject Hash Author Date (UTC)
cosmetic abe44edadda9da7c639b7bd8c9e13e6058555669 Catalin(ux) M. BOIE 2020-11-30 10:21:01
gpg functions and test ecb9e05c99a2b73edfba5014329e362d8c6e9246 Catalin(ux) M. BOIE 2020-11-09 07:38:11
Stats page is not rendered for bots. 29ca3f62ac460b64eb0a10fbb8bdfdf4a1767dc5 Catalin(ux) M. BOIE 2020-10-13 05:48:43
Added rate limit options 60e939a52577a01603f9f386ffaf1a9712f99ab6 Catalin(ux) M. BOIE 2020-10-07 05:02:25
Improved bots list and clean old entries 9da0a014040753734beabfecb298b8956fc25fe3 Catalin(ux) M. BOIE 2020-10-05 06:34:43
builder: use secrets only if available 4fe47afc60435508ad90f62c51d489ac3c20b4d0 Catalin(ux) M. BOIE 2020-08-28 07:29:14
worker: use secrets only if available 5371e918e294a46cc38c765371a1caf7a3083eef Catalin(ux) M. BOIE 2020-08-28 07:28:12
builder: do not break meta variable 1d8207b1a782ab039406dbd087cdc9bb5ea0b898 Catalin(ux) M. BOIE 2020-08-28 07:27:48
Whitespace 86086337c5323b073f517bc59c18aba0808fb4f3 Catalin(ux) M. BOIE 2020-08-24 07:22:13
Bump version to 0.73 7cac4d7a31116ac9ad86e0babeb0c1aace5dd852 Catalin(ux) M. BOIE 2020-08-23 15:32:03
duilder update f691d84aa0aa70ef60a7487f247ed1a9ab1e3ab1 Catalin(ux) M. BOIE 2020-08-23 15:31:38
Bot prevention should not be active for edit operation 371c60a486ea989fafb66266cab71ea9f7db0269 Catalin(ux) M. BOIE 2020-08-23 15:02:13
TODO update 32591f3b1cf054bd70411592e5a82f5898d7da2f Catalin(ux) M. BOIE 2020-08-23 15:01:51
Show also by which protocol a user is connecting d35b5b12103f9a72a3e8788e7c48532b9c1e5b89 Catalin(ux) M. BOIE 2020-08-23 15:01:30
Fixed a small locking issue (unlock without lock) 0d1e7915545de251eea7f3bce468647fc2df1bf9 Catalin(ux) M. BOIE 2020-08-23 15:00:58
Give up the cache if we cannot connect in 150ms dad6cf20f9f4bdbfe2026809a404e852e7cd8e53 Catalin(ux) M. BOIE 2020-08-23 15:00:20
Limit the number of repositories in the discover page a0de6d683b59934168ef8415c9ec716aef68b195 Catalin(ux) M. BOIE 2020-08-23 14:58:37
Added support for other branch then master (main prefered) 1108f43c3639ffcc06f1314d901640564fae7483 Catalin(ux) M. BOIE 2020-08-23 14:55:51
Added possibility for admin to mail users 05068314021bbdf6f26bc92bee47177b170b2a1c Catalin(ux) M. BOIE 2020-08-23 14:43:10
CSS: small fixes e4a39879513e000b5d9be588201916950fa629fc Catalin(ux) M. BOIE 2020-08-23 14:03:23
Commit abe44edadda9da7c639b7bd8c9e13e6058555669 - cosmetic
Author: Catalin(ux) M. BOIE
Author date (UTC): 2020-11-30 10:21
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2020-11-30 10:21
Parent(s): ecb9e05c99a2b73edfba5014329e362d8c6e9246
Signer:
Signing key:
Signing status: N
Tree: c2ce435b34c825f8a46cee7c929053085bd282fa
File Lines added Lines deleted
scripts/remote.php 57 58
File scripts/remote.php changed (mode: 100644) (index 46d7156..308edbe)
1 1 <?php <?php
2 2 // It is called by a remote client that does a push/fetch by git/ssh. // It is called by a remote client that does a push/fetch by git/ssh.
3 3 error_reporting(E_ALL); error_reporting(E_ALL);
4 ini_set("track_errors", "On");
5
6 require_once("/etc/rocketgit/config.php");
7
8 $INC = dirname(__FILE__) . "/../inc";
9 require_once($INC . "/init.inc.php");
10 require_once($INC . "/util.inc.php");
11 require_once($INC . "/log.inc.php");
12 require_once($INC . "/sql.inc.php");
13 require_once($INC . "/struct.inc.php");
14 require_once($INC . "/user.inc.php");
15 require_once($INC . "/repo.inc.php");
16 require_once($INC . "/prof.inc.php");
17 require_once($INC . "/ssh.inc.php");
18 require_once($INC . "/keys.inc.php");
19 require_once($INC . "/fixes.inc.php");
20 require_once($INC . "/plan.inc.php");
21 require_once($INC . '/stats.inc.php');
22 require_once($INC . "/ver.php");
23
24 rg_prof_start("remote.php");
25
26 rg_log_set_file($rg_log_dir . "/remote.log");
4 ini_set('track_errors', 'On');
5
6 require_once('/etc/rocketgit/config.php');
7
8 require_once(__DIR__ . '/../init.inc.php');
9 require_once(__DIR__ . '/../util.inc.php');
10 require_once(__DIR__ . '/../log.inc.php');
11 require_once(__DIR__ . '/../sql.inc.php');
12 require_once(__DIR__ . '/../struct.inc.php');
13 require_once(__DIR__ . '/../user.inc.php');
14 require_once(__DIR__ . '/../repo.inc.php');
15 require_once(__DIR__ . '/../prof.inc.php');
16 require_once(__DIR__ . '/../ssh.inc.php');
17 require_once(__DIR__ . '/../keys.inc.php');
18 require_once(__DIR__ . '/../fixes.inc.php');
19 require_once(__DIR__ . '/../plan.inc.php');
20 require_once(__DIR__ . '/../stats.inc.php');
21 require_once(__DIR__ . '/../ver.php');
22
23 rg_prof_start('remote.php');
24
25 rg_log_set_file($rg_log_dir . '/remote.log');
27 26
28 27 $rg = array(); $rg = array();
29 28 $rg['start'] = microtime(TRUE); $rg['start'] = microtime(TRUE);
30 29
31 30 function info($str) function info($str)
32 31 { {
33 rg_log("Sending: " . $str);
34 $str2 = "RocketGit: Info: " . $str . "\n";
32 rg_log('Sending: ' . $str);
33 $str2 = 'RocketGit: Info: ' . $str . "\n";
35 34 if (isset($_SERVER['SSH_CONNECTION'])) { if (isset($_SERVER['SSH_CONNECTION'])) {
36 35 // ssh // ssh
37 36 fwrite(STDERR, $str2); fwrite(STDERR, $str2);
 
... ... function info($str)
43 42
44 43 function fatal($str) function fatal($str)
45 44 { {
46 rg_log("Sending: " . $str);
47 $str2 = "RocketGit: Error: " . $str . "\n";
45 rg_log('Sending: ' . $str);
46 $str2 = 'RocketGit: Error: ' . $str . "\n";
48 47 if (isset($_SERVER['SSH_CONNECTION'])) { if (isset($_SERVER['SSH_CONNECTION'])) {
49 48 // ssh // ssh
50 49 fwrite(STDERR, $str2); fwrite(STDERR, $str2);
 
... ... function fatal($str)
65 64 @stream_set_write_buffer(STDERR, 0); @stream_set_write_buffer(STDERR, 0);
66 65
67 66
68 rg_log("Start ($rocketgit_version)...");
67 rg_log('Start (' . $rocketgit_version . ')...');
69 68 // DEBUG SELinux // DEBUG SELinux
70 $label = @file_get_contents("/proc/self/attr/current");
69 $label = @file_get_contents('/proc/self/attr/current');
71 70 if (!empty($label)) if (!empty($label))
72 71 rg_log('SELINUX: ' . $label); rg_log('SELINUX: ' . $label);
73 72
74 73 rg_sql_app('rg-remote-' . $rg_log_sid); rg_sql_app('rg-remote-' . $rg_log_sid);
75 74 $db = rg_sql_open($rg_sql); $db = rg_sql_open($rg_sql);
76 75 if ($db === FALSE) if ($db === FALSE)
77 fatal("Internal error (db)!");
76 fatal('Internal error (db)!');
78 77
79 78 // Force ste state loading, for sure we will need it // Force ste state loading, for sure we will need it
80 79 rg_cache_get('state'); rg_cache_get('state');
81 80
82 81 if (rg_struct_ok($db) === FALSE) if (rg_struct_ok($db) === FALSE)
83 fatal("We are in a short maintenance window. Try again later.");
82 fatal('We are in a short maintenance window. Try again later.');
84 83
85 84 $rg['hostname'] = rg_state_get($db, 'hostname'); $rg['hostname'] = rg_state_get($db, 'hostname');
86 85 $rg['http_allow'] = rg_state_get($db, 'http_allow'); $rg['http_allow'] = rg_state_get($db, 'http_allow');
 
... ... $login_ui = array('uid' => 0,
97 96 'organization' => 0); 'organization' => 0);
98 97
99 98 if (isset($_SERVER['SSH_CONNECTION'])) { if (isset($_SERVER['SSH_CONNECTION'])) {
100 rg_log("SSH connection: " . $_SERVER['SSH_CONNECTION']);
99 rg_log('SSH connection: ' . $_SERVER['SSH_CONNECTION']);
101 100
102 101 rg_stats_conns_set('type', 'ssh'); rg_stats_conns_set('type', 'ssh');
103 102
 
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
106 105
107 106 // first parameter must be uid of the user // first parameter must be uid of the user
108 107 $login_uid = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 0; $login_uid = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 0;
109 rg_log("uid is $login_uid.");
108 rg_log('uid is ' . $login_uid);
110 109
111 110 // second parameter must be the ssh key id // second parameter must be the ssh key id
112 111 $key_id = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 0; $key_id = isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : 0;
113 112 // TODO: because of build system, 0 may be valid. // TODO: because of build system, 0 may be valid.
114 113 //if ($key_id == 0) //if ($key_id == 0)
115 // fatal("key_id not provided!");
116 rg_log("key_id is $key_id.");
114 // fatal('key_id not provided!');
115 rg_log('key_id is ' . $key_id);
117 116
118 117 // Third para is 'flags' // Third para is 'flags'
119 118 $flags = isset($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : ''; $flags = isset($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : '';
120 119 rg_log('flags=' . $flags); rg_log('flags=' . $flags);
121 120
122 121 if (!isset($_SERVER['SSH_ORIGINAL_COMMAND'])) if (!isset($_SERVER['SSH_ORIGINAL_COMMAND']))
123 $cmd_repo = "";
122 $cmd_repo = '';
124 123 else else
125 124 $cmd_repo = trim($_SERVER['SSH_ORIGINAL_COMMAND']); $cmd_repo = trim($_SERVER['SSH_ORIGINAL_COMMAND']);
126 125
127 $ssh_client = getenv("SSH_CLIENT");
128 $_t = explode(" ", $ssh_client);
126 $ssh_client = getenv('SSH_CLIENT');
127 $_t = explode(' ', $ssh_client);
129 128 $rg['ip'] = rg_fix_ip($_t[0]); $rg['ip'] = rg_fix_ip($_t[0]);
130 129 rg_stats_conns_set('ip', $rg['ip']); rg_stats_conns_set('ip', $rg['ip']);
131 130
 
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
138 137 if (strstr($flags, 'N')) { if (strstr($flags, 'N')) {
139 138 $login_ui = rg_user_info($db, $login_uid, '', ''); $login_ui = rg_user_info($db, $login_uid, '', '');
140 139 if ($login_ui['exists'] != 1) if ($login_ui['exists'] != 1)
141 fatal("User does not exists (conn).");
140 fatal('User does not exists (conn).');
142 141 info('you are connecting as user \'' info('you are connecting as user \''
143 142 . $login_ui['username'] . '\'.' . "\n"); . $login_ui['username'] . '\'.' . "\n");
144 143
 
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
159 158 $_r = rg_keys_update_use($db, $login_ui['uid'], $key_id, $rg['ip'], $_r = rg_keys_update_use($db, $login_ui['uid'], $key_id, $rg['ip'],
160 159 $cmd_repo); $cmd_repo);
161 160 if ($_r !== TRUE) if ($_r !== TRUE)
162 rg_internal_error("Cannot update key last_use!");
161 rg_internal_error('Cannot update key last_use!');
163 162
164 163 if ($must_exit) { if ($must_exit) {
165 164 rg_stats_conns_insert($db); rg_stats_conns_insert($db);
 
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
171 170
172 171 rg_stats_conns_set('type', 'git-over-ssh'); rg_stats_conns_set('type', 'git-over-ssh');
173 172 } else { } else {
174 rg_log("git-daemon connection...");
173 rg_log('git-daemon connection...');
175 174 rg_log_ml('_SERVER: ' . print_r($_SERVER, true)); rg_log_ml('_SERVER: ' . print_r($_SERVER, true));
176 175
177 176 rg_stats_conns_set('type', 'git'); rg_stats_conns_set('type', 'git');
 
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
185 184 while (1) { while (1) {
186 185 $r = @fread(STDIN, 8000); $r = @fread(STDIN, 8000);
187 186 if ($r === FALSE) if ($r === FALSE)
188 fatal('Error in receive: ' . rg_php_err());
187 fatal('Error in receive: ' . rg_php_err() . '.');
189 188
190 189 if (empty($r)) if (empty($r))
191 fatal("Too less data ($line_len/$len) received!");
190 fatal('Too less data (' . $line_len . '/' . $len . ') received!');
192 191
193 192 $line .= $r; $line .= $r;
194 193 $line_len += strlen($r); $line_len += strlen($r);
195 rg_log("line=[$line]");
194 rg_log('line=[' . $line . ']');
196 195 if ($line_len < 4) if ($line_len < 4)
197 196 fatal('Line is too short [' . $line . ']!'); fatal('Line is too short [' . $line . ']!');
198 197
 
... ... if (isset($_SERVER['SSH_CONNECTION'])) {
210 209 $v = explode(':', $host_port); $v = explode(':', $host_port);
211 210 $host = $v[0]; $host = $v[0];
212 211
213 $rg['ip'] = rg_fix_ip(getenv("REMOTE_HOST"));
212 $rg['ip'] = rg_fix_ip(getenv('REMOTE_HOST'));
214 213 rg_stats_conns_set('ip', $rg['ip']); rg_stats_conns_set('ip', $rg['ip']);
215 214 } }
216 215
 
... ... rg_stats_conns_set('cmd', $rg['cmd']);
225 224
226 225 // extract repository name // extract repository name
227 226 $rg['url'] = substr($cmd_repo, strlen($rg['cmd'])); // skip cmd $rg['url'] = substr($cmd_repo, strlen($rg['cmd'])); // skip cmd
228 $rg['url'] = trim($rg['url'], "' ");
227 $rg['url'] = trim($rg['url'], '\' ');
229 228 rg_stats_conns_set('url', $rg['url']); rg_stats_conns_set('url', $rg['url']);
230 $_t = ltrim($rg['url'], "/");
229 $_t = ltrim($rg['url'], '/');
231 230 $_t = preg_replace('/\.git$/' , '', $_t); $_t = preg_replace('/\.git$/' , '', $_t);
232 $_t = explode("/", $_t);
233 if (strcmp($_t[0], "user") == 0) {
234 $prefix = "/user";
235 $user = isset($_t[1]) ? $_t[1] : "";
236 $repo = isset($_t[2]) ? $_t[2] : "";
231 $_t = explode('/', $_t);
232 if (strcmp($_t[0], 'user') == 0) {
233 $prefix = '/user';
234 $user = isset($_t[1]) ? $_t[1] : '';
235 $repo = isset($_t[2]) ? $_t[2] : '';
237 236 } else { } else {
238 $prefix = "";
239 $user = isset($_t[0]) ? $_t[0] : "";
240 $repo = isset($_t[1]) ? $_t[1] : "";
237 $prefix = '';
238 $user = isset($_t[0]) ? $_t[0] : '';
239 $repo = isset($_t[1]) ? $_t[1] : '';
241 240 } }
242 241
243 242 rg_log('ip=[' . $rg['ip'] . '] host=[' . $host . '] cmd=[' . $rg['cmd'] . ']' rg_log('ip=[' . $rg['ip'] . '] host=[' . $host . '] cmd=[' . $rg['cmd'] . ']'
 
... ... rg_log_ml('DEBUG: repo_fetch_push_helper: ' . print_r($r, TRUE));
261 260 if (($r['ok'] !== 1) || ($r['allow'] !== 1)) if (($r['ok'] !== 1) || ($r['allow'] !== 1))
262 261 fatal($r['errmsg']); fatal($r['errmsg']);
263 262
264 $run = "git-shell -c \"" . $rg['cmd'] . " " . escapeshellarg($r['repo_path']) . "\"";
263 $run = 'git-shell -c "' . $rg['cmd'] . ' ' . escapeshellarg($r['repo_path']) . '"';
265 264 //$run = $rg['cmd'] . ' ' . escapeshellarg($r['repo_path']); //$run = $rg['cmd'] . ' ' . escapeshellarg($r['repo_path']);
266 rg_log("Running [$run]...");
265 rg_log('Running [' . $run . ']...');
267 266 rg_prof_start($rg['cmd']); rg_prof_start($rg['cmd']);
268 267 // TODO: shouldn't we use rg_exec to capture stderr? // TODO: shouldn't we use rg_exec to capture stderr?
269 268 passthru($run, $ret); passthru($run, $ret);
270 269 rg_prof_end($rg['cmd']); rg_prof_end($rg['cmd']);
271 rg_log("[$run] returned $ret.");
270 rg_log('returned ' . $ret);
272 271
273 272 if (!strstr($flags, 'W')) { if (!strstr($flags, 'W')) {
274 273 $repo_id = 0; $repo_id = 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://rocketgit.com/user/catalinux/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/rocketgit

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main