dcc202fb249a446ac15c7cf413b9f1b4a3f31b58
bernd First strike: list reposito...

bernd authored 12 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

5) Written by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
12) */
13) 
bernd First strike: list reposito...

bernd authored 12 years ago

14) require_role(ROLE_SYSTEMUSER);
15) 
Bernd Wurst Erwarte das Datenverzeichni...

Bernd Wurst authored 5 years ago

16) $data_dir = realpath(dirname(__FILE__).'/../../../../gitolite-data/');
bernd First strike: list reposito...

bernd authored 12 years ago

17) $config_file = $data_dir.'/gitolite-admin/conf/webinterface.conf';
18) $config_dir = $data_dir.'/gitolite-admin/conf/webinterface';
19) $key_dir = $data_dir.'/gitolite-admin/keydir';
20) DEBUG("gitolite-data_dir: ".$data_dir);
Bernd Wurst Erwarte das Datenverzeichni...

Bernd Wurst authored 5 years ago

21) $git_wrapper = realpath(dirname(__FILE__).'/../scripts/git-wrapper.sh');
bernd First strike: list reposito...

bernd authored 12 years ago

22) 
23) 
bernd Fürs erste feature-complete

bernd authored 12 years ago

24) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

25) function check_env()
bernd First strike: list reposito...

bernd authored 12 years ago

26) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

27)     global $git_wrapper, $data_dir, $config_file, $config_dir, $key_dir;
28)     if (!is_executable($git_wrapper)) {
29)         system_failure("git_wrapper.sh is not executable: {$git_wrapper}");
30)     }
31)     if (! (is_file($data_dir.'/sshkey') && is_file($data_dir.'/sshkey.pub'))) {
32)         system_failure("SSH-key not found. Please setup the gitolite-module correctly. Run ./data/initialize.sh");
33)     }
34)     if (! is_dir($data_dir.'/gitolite-admin')) {
35)         system_failure("Repository gitolite-admin ot found. Initial checkout must be made manually. Run ./data/initialize.sh");
36)     }
37)     if (! is_dir($config_dir)) {
38)         system_failure("gitolite-admin repository is not prepared.");
39)     }
40)     if (! (is_dir($key_dir) && is_writeable($config_file))) {
41)         system_failure("Repository gitolite-admin is corrupted or webinterface.conf is not writeable.");
42)     }
bernd First strike: list reposito...

bernd authored 12 years ago

43) }
44) 
45) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

46) function validate_name($name)
47) {
48)     return (preg_match('/^[[:alnum:]][[:alnum:]._-]*$/', $name));
bernd First draft of gitolite-mod...

bernd authored 12 years ago

49) }
50) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

51) function get_git_url($repo)
52) {
53)     $remote = git_wrapper('remote --verbose');
54)     DEBUG('gitolite-admin repo: '.$remote[0]);
55)     $url = preg_replace('#^.*\s+(\S+):gitolite-admin.*#', '$1', $remote[0]);
56)     DEBUG('URL: '.$url);
57)     return $url.':'.$repo;
bernd show URL

bernd authored 12 years ago

58) }
59) 
bernd First draft of gitolite-mod...

bernd authored 12 years ago

60) 
bernd First strike: list reposito...

bernd authored 12 years ago

61) function git_wrapper($commandline)
62) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

63)     global $git_wrapper, $data_dir;
64) 
65)     $command = $git_wrapper.' '.$commandline;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

66)     $output = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

67)     $retval = 0;
68)     DEBUG($command);
69)     exec($command, $output, $retval);
70)     DEBUG($output);
71)     DEBUG($retval);
72)     if ($retval > 0) {
73)         system_failure('Interner Fehler!');
74)         // FIXME: Hier sollte auf jeden Fall ein Logging angeworfen werden!
75)     }
76)     return $output;
bernd First strike: list reposito...

bernd authored 12 years ago

77) }
78) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

79) function refresh_gitolite()
bernd First strike: list reposito...

bernd authored 12 years ago

80) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

81)     check_env();
82)     git_wrapper('pull');
bernd First strike: list reposito...

bernd authored 12 years ago

83) }
84) 
85) 
86) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

87) function list_repos()
bernd First strike: list reposito...

bernd authored 12 years ago

88) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

89)     global $config_file, $config_dir;
90)     $username = $_SESSION['userinfo']['username'];
91)     $userconfig = $config_dir . '/' . $username . '.conf';
92)     DEBUG("using config file ".$userconfig);
93)     if (! is_file($userconfig)) {
94)         DEBUG("user-config does not exist");
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

95)         return [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

96)     }
97) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

98)     $repos = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

99)     $lines = file($userconfig);
100)     $current_repo = null;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

101)     $current_repo_users = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

102)     foreach ($lines as $line) {
103)         DEBUG("LINE: ".$line);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

104)         $m = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

105)         if (preg_match('/^(\S+) "[^"]+" = "([^"]+)"$/', $line, $m) != 0) {
106)             if (!array_key_exists($m[1], $repos)) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

107)                 $repos[$m[1]] = ['users' => null, 'description' => ''];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

108)             }
109)             DEBUG("found description: {$m[1]} = \"{$m[2]}\"");
110)             $repos[$m[1]]['description'] = $m[2];
111)         } elseif (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
112)             if (!array_key_exists($m[1], $repos)) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

113)                 $repos[$m[1]] = ['users' => null, 'description' => ''];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

114)             }
115)             if ($current_repo) {
116)                 $repos[$current_repo]['users'] = $current_repo_users;
117)             }
118)             DEBUG("found repo ".$m[1]);
119)             $current_repo = chop($m[1]);
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

120)             verify_input_identifier($current_repo);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

121)             $current_repo_users = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

122)         } elseif (preg_match('/^\s*(R|RW|RW\+)\s*=\s*([[:alnum:]][[:alnum:]._-]*)\s*$/', $line, $m) != 0) {
123)             DEBUG("found access rule: ".$m[1]." for ".$m[2]);
124)             $current_repo_users[chop($m[2])] = chop($m[1]);
125)         }
126)     }
127)     if ($current_repo) {
bernd Setze Berechtigung für gitw...

bernd authored 12 years ago

128)         $repos[$current_repo]['users'] = $current_repo_users;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

129)     }
130)     ksort($repos);
131)     DEBUG($repos);
132)     return $repos;
bernd First strike: list reposito...

bernd authored 12 years ago

133) }
134) 
135) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

136) function list_users()
137) {
138)     global $config_file, $config_dir;
139)     $username = $_SESSION['userinfo']['username'];
140)     $userconfig = $config_dir . '/' . $username . '.conf';
141)     DEBUG("using config file ".$userconfig);
142)     if (! is_file($userconfig)) {
143)         DEBUG("user-config does not exist");
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

144)         return [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

145)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

146) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

147)     $lines = file($userconfig);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

148)     $users = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

149)     foreach ($lines as $line) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

150)         $m = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

151)         if (preg_match('_# user ([^]]+)_', $line, $m) != 0) {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

152)             $currentuser = trim($m[1]);
153)             verify_input_identifier($currentuser);
154)             $users[] = $currentuser;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

155)         }
156)         if (preg_match('_^\s*repo .*_', $line) != 0) {
157)             break;
158)         }
159)     }
160)     sort($users);
161)     DEBUG($users);
162)     return $users;
bernd First draft of gitolite-mod...

bernd authored 12 years ago

163) }
bernd First strike: list reposito...

bernd authored 12 years ago

164) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

165) function list_foreign_users()
166) {
167)     global $config_file, $config_dir;
168)     $username = $_SESSION['userinfo']['username'];
169)     $userconfig = $config_dir . '/' . $username . '.conf';
170)     DEBUG("using config file ".$userconfig);
171)     if (! is_file($userconfig)) {
172)         DEBUG("user-config does not exist");
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

173)         return [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

174)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

175) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

176)     $lines = file($userconfig);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

177)     $users = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

178)     foreach ($lines as $line) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

179)         $m = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

180)         if (preg_match('_# foreign user ([^]]+)_', $line, $m) != 0) {
181)             $users[] = chop($m[1]);
182)         }
183)         if (preg_match('_^\s*repo .*_', $line) != 0) {
184)             break;
185)         }
186)     }
187)     sort($users);
188)     DEBUG($users);
189)     return $users;
Bernd Wurst add foreign git users and g...

Bernd Wurst authored 12 years ago

190) }
191) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

192) function get_pubkey($handle)
193) {
194)     global $key_dir;
195)     if (! validate_name($handle)) {
196)         return '';
197)     }
198)     $keyfile = $key_dir.'/'.$handle.'.pub';
199)     if (! file_exists($keyfile)) {
200)         return '';
201)     }
202)     return file_get_contents($keyfile);
bernd First draft of gitolite-mod...

bernd authored 12 years ago

203) }
204) 
205) 
206) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

207) function new_foreign_user($handle)
Bernd Wurst add foreign git users and g...

Bernd Wurst authored 12 years ago

208) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

209)     global $key_dir, $config_dir;
210)     $username = $_SESSION['userinfo']['username'];
211) 
212)     if (! validate_name($handle)) {
213)         system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich, Binderstrich und Punkt benutzen.");
214)     }
215) 
216)     if (in_array($handle, list_users())) {
217)         system_failure('Dieser GIT-Benutzer gehört zu diesem Kundenaccount.');
218)     }
219) 
220)     $keyfile = $key_dir.'/'.$handle.'.pub';
221)     if (! file_exists($keyfile)) {
222)         system_failure('Diesen GIT-Benutzer gibt es nicht');
223)     }
224) 
225)     $userconfig = $config_dir . '/' . $username . '.conf';
226)     DEBUG("using config file ".$userconfig);
227)     if (! is_file($userconfig)) {
228)         DEBUG("user-config does not exist, creating new one");
229)         file_put_contents($userconfig, '# user '.$handle."\n");
230)         set_user_include();
231)     } elseif (in_array($handle, list_foreign_users())) {
232)         # user ist schon eingetragen
233)     } else {
234)         $content = file_get_contents($userconfig);
235)         file_put_contents($userconfig, "# foreign user {$handle}\n".$content);
236)     }
237)     git_wrapper('add '.$userconfig);
238) 
239)     git_wrapper('commit --allow-empty -m "added new key for '.$handle.'"');
240)     git_wrapper('push');
Bernd Wurst add foreign git users and g...

Bernd Wurst authored 12 years ago

241) }
242) 
243) function delete_foreign_user($handle)
244) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

245)     global $config_dir;
246)     $username = $_SESSION['userinfo']['username'];
247) 
248)     $userconfig = $config_dir . '/' . $username . '.conf';
249)     DEBUG("using config file ".$userconfig);
250)     if (! is_file($userconfig)) {
251)         DEBUG("user-config does not exist, wtf?");
252)         system_failure("Es gibt für diesen Benutzer noch keine Konfiguration. Das sollte nicht sein!");
253)     } else {
254)         $content = file($userconfig);
255)         DEBUG("Old file:");
256)         DEBUG($content);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

257)         $newcontent = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

258)         foreach ($content as $line) {
259)             if (preg_match('/^# foreign user '.$handle.'$/', $line)) {
260)                 DEBUG("delete1: ".$line);
261)                 continue;
262)             }
263)             if (preg_match('/^\s*(R|RW|RW+)\s*=\s*'.$handle.'\s*$/', $line)) {
264)                 DEBUG("delete2: ".$line);
265)                 continue;
266)             }
267)             $newcontent[] = $line;
268)         }
269)         DEBUG("Modified file:");
270)         DEBUG($newcontent);
271)         file_put_contents($userconfig, implode('', $newcontent));
272)     }
273)     git_wrapper('add '.$userconfig);
274) 
275)     git_wrapper('commit -m "deleted foreign user '.$handle.' for '.$username.'"');
276)     git_wrapper('push');
Bernd Wurst add foreign git users and g...

Bernd Wurst authored 12 years ago

277) }
278) 
279) 
bernd First draft of gitolite-mod...

bernd authored 12 years ago

280) function newkey($pubkey, $handle)
bernd First strike: list reposito...

bernd authored 12 years ago

281) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

282)     global $key_dir, $config_dir;
283)     $username = $_SESSION['userinfo']['username'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

284) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

285)     $handle = $username.'-'.$handle;
286)     if (! validate_name($handle) || (str_replace(".", "x", $handle) != $handle)) {
287)         system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich und Bindestrich benutzen.");
288)     }
bernd First draft of gitolite-mod...

bernd authored 12 years ago

289) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

290)     $pubkey = trim(str_replace(["\r", "\n"], ' ', $pubkey));
Bernd Wurst gitolite: Entferne Zeilenum...

Bernd Wurst authored 5 years ago

291) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

292)     $keyfile = $key_dir.'/'.$handle.'.pub';
293)     file_put_contents($keyfile, $pubkey);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

294) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

295)     DEBUG("checking public key $keyfile");
296)     $proc = popen("/usr/bin/ssh-keygen -l -f '{$keyfile}' 2>&1", 'r');
297)     $output = fread($proc, 512);
298)     DEBUG($output);
299)     pclose($proc);
300)     if (preg_match('/.* is not a public key file.*/', $output)) {
301)         unlink($keyfile);
302)         system_failure('Der angegebene SSH-Key scheint ungültig zu sein.');
303)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

304) 
bernd SSH-Key auf plausibilität p...

bernd authored 12 years ago

305) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

306)     git_wrapper('add '.$keyfile);
307) 
308)     $userconfig = $config_dir . '/' . $username . '.conf';
309)     DEBUG("using config file ".$userconfig);
310)     if (! is_file($userconfig)) {
311)         DEBUG("user-config does not exist, creating new one");
312)         file_put_contents($userconfig, '# user '.$handle."\n");
313)         set_user_include();
314)     } elseif (in_array($handle, list_users())) {
315)         # user ist schon eingetragen, nur neuer Key
316)     } else {
317)         $content = file_get_contents($userconfig);
318)         file_put_contents($userconfig, "# user {$handle}\n".$content);
319)     }
320)     git_wrapper('add '.$userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

321) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

322)     git_wrapper('commit --allow-empty -m "added new key for '.$handle.'"');
323)     git_wrapper('push');
bernd First strike: list reposito...

bernd authored 12 years ago

324) }
325) 
326) 
bernd First draft of gitolite-mod...

bernd authored 12 years ago

327) function delete_key($handle)
328) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

329)     global $key_dir, $config_dir;
330)     $username = $_SESSION['userinfo']['username'];
bernd First draft of gitolite-mod...

bernd authored 12 years ago

331) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

332)     if (! validate_name($handle)) {
333)         system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich, Binderstrich und Punkt benutzen.");
334)     }
335)     if (!in_array($handle, list_users())) {
336)         DEBUG("key {$handle} not in");
337)         DEBUG(list_users());
338)         system_failure("Den angegebenen Key scheint es nicht zu geben");
339)     }
bernd First draft of gitolite-mod...

bernd authored 12 years ago

340) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

341)     $keyfile = $key_dir.'/'.$handle.'.pub';
342)     if (! file_exists($keyfile)) {
343)         system_failure("Der angegebene Schlüssel scheint nicht mehr vorhanden zu sein. Bitte manuelle Korrektur anfordern!");
344)     }
345)     git_wrapper('rm '.$keyfile);
346) 
347) 
348)     $userconfig = $config_dir . '/' . $username . '.conf';
349)     DEBUG("using config file ".$userconfig);
350)     if (! is_file($userconfig)) {
351)         DEBUG("user-config does not exist, wtf?");
352)         system_failure("Es gibt für diesen Benutzer noch keine Konfiguration. Das sollte nicht sein!");
353)     } else {
354)         $content = file($userconfig);
355)         DEBUG("Old file:");
356)         DEBUG($content);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

357)         $newcontent = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

358)         foreach ($content as $line) {
359)             if (preg_match('/^# user '.$handle.'$/', $line)) {
360)                 DEBUG("delete1: ".$line);
361)                 continue;
362)             }
363)             if (preg_match('/^\s*(R|RW|RW+)\s*=\s*'.$handle.'\s*$/', $line)) {
364)                 DEBUG("delete2: ".$line);
365)                 continue;
366)             }
367)             $newcontent[] = $line;
368)         }
369)         DEBUG("Modified file:");
370)         DEBUG($newcontent);
371)         file_put_contents($userconfig, implode('', $newcontent));
372)     }
373)     git_wrapper('add '.$userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

374) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

375)     git_wrapper('commit -m "deleted key for '.$handle.'"');
376)     git_wrapper('push');
bernd First draft of gitolite-mod...

bernd authored 12 years ago

377) }
bernd Fürs erste feature-complete

bernd authored 12 years ago

378) 
379) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

380) function remove_repo_from_array($data, $repo)
381) {
382)     DEBUG("Request to remove repo »{$repo}«...");
383)     $inside = false;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

384)     $outdata = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

385)     $blank = true;
386)     foreach ($data as $line) {
387)         if ($blank && chop($line) == '') {
388)             continue;
389)         }
390)         $blank = (chop($line) == '');
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

391)         $m = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

392)         if (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
393)             $inside = ($m[1] == $repo);
394)         }
395)         if (! $inside && ! preg_match('/^'.$repo.'\s.*/', $line)) {
396)             $outdata[] = $line;
397)         }
bernd Fürs erste feature-complete

bernd authored 12 years ago

398)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

399)     DEBUG($outdata);
400)     return $outdata;
bernd Fürs erste feature-complete

bernd authored 12 years ago

401) }
402) 
403) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

404) function repo_exists_globally($repo)
bernd Fürs erste feature-complete

bernd authored 12 years ago

405) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

406)     global $config_dir;
407)     $files = scandir($config_dir);
408)     foreach ($files as $f) {
409)         if (is_file(realpath($config_dir.'/'.$f))) {
410)             $data = file(realpath($config_dir.'/'.$f));
411)             foreach ($data as $line) {
412)                 if (preg_match('/^\s*repo '.$repo.'\s*$/', $line) != 0) {
413)                     return true;
414)                 }
415)             }
bernd Fürs erste feature-complete

bernd authored 12 years ago

416)         }
417)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

418)     return false;
bernd Fürs erste feature-complete

bernd authored 12 years ago

419) }
420) 
421) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

422) function delete_repo($repo)
bernd Fürs erste feature-complete

bernd authored 12 years ago

423) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

424)     $repos = list_repos();
425)     if (!array_key_exists($repo, $repos)) {
426)         system_failure("Ein solches Repository existiert nicht!");
427)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

428) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

429)     global $config_dir;
430)     $username = $_SESSION['userinfo']['username'];
431)     $userconfig = $config_dir . '/' . $username . '.conf';
432)     DEBUG("using config file ".$userconfig);
433)     $data = file($userconfig);
434)     $data = remove_repo_from_array($data, $repo);
435)     file_put_contents($userconfig, implode('', $data));
436)     git_wrapper('add '.$userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

437) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

438)     git_wrapper('commit --allow-empty -m "deleted repo '.$repo.'"');
439)     git_wrapper('push');
bernd Fürs erste feature-complete

bernd authored 12 years ago

440) }
441) 
bernd Gitolite: Erzeuge include f...

bernd authored 12 years ago

442) 
443) function set_user_include()
444) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

445)     global $config_file, $userconfig;
446)     $username = $_SESSION['userinfo']['username'];
447)     if (!file_exists($userconfig)) {
448)         // Erzeuge eine leere Konfiguration damit das Include auf jeden Fall funktionieren kann
449)         file_put_contents($userconfig, '');
450)         git_wrapper('add '.$userconfig);
451)     }
452)     $found = false;
453)     $data = file($config_file);
454)     foreach ($data as $line) {
455)         if (preg_match('#webinterface/'.$username.'\.conf#', $line)) {
456)             $found = true;
457)         }
458)     }
459)     if (!$found) {
460)         $includeline = 'include  "webinterface/'.$username.'.conf"';
461)         $data = chop(file_get_contents($config_file));
462)         $data = $data."\n".$includeline."\n";
463)         file_put_contents($config_file, $data);
464)         git_wrapper('add '.$config_file);
465)     }
bernd Gitolite: Erzeuge include f...

bernd authored 12 years ago

466) }
467) 
468) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

469) function save_repo($repo, $permissions, $description)
bernd Fürs erste feature-complete

bernd authored 12 years ago

470) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

471)     if (!validate_name($repo)) {
Hanno Rechtschreibfehler

Hanno authored 5 years ago

472)         system_failure("Der gewählte Name entspricht nicht den Konventionen!");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

473)     }
474)     if (!array_key_exists($repo, list_repos()) && repo_exists_globally($repo)) {
475)         system_failure("Der gewählte Name existiert bereits auf diesem Server. Bitte wählen Sie einen spezifischeren Namen.");
476)     }
477)     global $config_dir;
478)     $username = $_SESSION['userinfo']['username'];
479)     $userconfig = $config_dir . '/' . $username . '.conf';
480)     DEBUG("using config file ".$userconfig);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

481)     $data = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

482)     if (! is_file($userconfig)) {
483)         DEBUG("user-config does not exist, creating new one");
484)         set_user_include();
485)     } else {
486)         $data = file($userconfig);
487)     }
bernd Fürs erste feature-complete

bernd authored 12 years ago

488) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

489)     $repos = list_repos();
490)     if (array_key_exists($repo, $repos)) {
491)         $data = remove_repo_from_array($data, $repo);
492)     }
493) 
494)     $data[] = "\n";
495)     if ($description) {
496)         $description = preg_replace('/\[\'"\r\n/', '', $description);
497)         $realname = $_SESSION['userinfo']['name'];
498)         $data[] = "{$repo} \"{$realname}\" = \"{$description}\"\n";
499)     }
500)     $data[] = 'repo '.$repo."\n";
501)     foreach ($permissions as $user => $perm) {
502)         $data[] = '  '.$perm.' = '.$user."\n";
503)     }
504)     file_put_contents($userconfig, implode('', $data));
505)     git_wrapper('add '.$userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

506) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

507)     git_wrapper('commit --allow-empty -m "written repo '.$repo.'"');
508)     git_wrapper('push');