c42127d3cab5c78430e578a07038f54f8cdff459
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) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 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) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) 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.
15) */
16) 
bernd First strike: list reposito...

bernd authored 12 years ago

17) require_role(ROLE_SYSTEMUSER);
18) 
Bernd Wurst Erwarte das Datenverzeichni...

Bernd Wurst authored 5 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 5 years ago

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

bernd authored 12 years ago

25) 
26) 
bernd Fürs erste feature-complete

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

46) }
47) 
48) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

52) }
53) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

61) }
62) 
bernd First draft of gitolite-mod...

bernd authored 12 years ago

63) 
bernd First strike: list reposito...

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

80) }
81) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

84)     check_env();
85)     git_wrapper('pull');
bernd First strike: list reposito...

bernd authored 12 years ago

86) }
87) 
88) 
89) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

92)     global $config_file, $config_dir;
93)     $username = $_SESSION['userinfo']['username'];
94)     $userconfig = $config_dir . '/' . $username . '.conf';
95)     DEBUG("using config file ".$userconfig);
96)     if (! is_file($userconfig)) {
97)         DEBUG("user-config does not exist");
98)         return array();
99)     }
100) 
101)     $repos = array();
102)     $lines = file($userconfig);
103)     $current_repo = null;
104)     $current_repo_users = array();
105)     foreach ($lines as $line) {
106)         DEBUG("LINE: ".$line);
107)         $m = array();
108)         if (preg_match('/^(\S+) "[^"]+" = "([^"]+)"$/', $line, $m) != 0) {
109)             if (!array_key_exists($m[1], $repos)) {
110)                 $repos[$m[1]] = array('users' => null, 'description' => '');
111)             }
112)             DEBUG("found description: {$m[1]} = \"{$m[2]}\"");
113)             $repos[$m[1]]['description'] = $m[2];
114)         } elseif (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
115)             if (!array_key_exists($m[1], $repos)) {
116)                 $repos[$m[1]] = array('users' => null, 'description' => '');
117)             }
118)             if ($current_repo) {
119)                 $repos[$current_repo]['users'] = $current_repo_users;
120)             }
121)             DEBUG("found repo ".$m[1]);
122)             $current_repo = chop($m[1]);
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

123)             verify_input_identifier($current_repo);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

132)     }
133)     ksort($repos);
134)     DEBUG($repos);
135)     return $repos;
bernd First strike: list reposito...

bernd authored 12 years ago

136) }
137) 
138) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

139) function list_users()
140) {
141)     global $config_file, $config_dir;
142)     $username = $_SESSION['userinfo']['username'];
143)     $userconfig = $config_dir . '/' . $username . '.conf';
144)     DEBUG("using config file ".$userconfig);
145)     if (! is_file($userconfig)) {
146)         DEBUG("user-config does not exist");
147)         return array();
148)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

150)     $lines = file($userconfig);
151)     $users = array();
152)     foreach ($lines as $line) {
153)         $m = array();
154)         if (preg_match('_# user ([^]]+)_', $line, $m) != 0) {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

155)             $currentuser = trim($m[1]);
156)             verify_input_identifier($currentuser);
157)             $users[] = $currentuser;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

168) function list_foreign_users()
169) {
170)     global $config_file, $config_dir;
171)     $username = $_SESSION['userinfo']['username'];
172)     $userconfig = $config_dir . '/' . $username . '.conf';
173)     DEBUG("using config file ".$userconfig);
174)     if (! is_file($userconfig)) {
175)         DEBUG("user-config does not exist");
176)         return array();
177)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 12 years ago

193) }
194) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

206) }
207) 
208) 
209) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Bernd Wurst authored 12 years ago

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

Hanno authored 5 years ago

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

Bernd Wurst authored 12 years ago

244) }
245) 
246) function delete_foreign_user($handle)
247) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

248)     global $config_dir;
249)     $username = $_SESSION['userinfo']['username'];
250) 
251)     $userconfig = $config_dir . '/' . $username . '.conf';
252)     DEBUG("using config file ".$userconfig);
253)     if (! is_file($userconfig)) {
254)         DEBUG("user-config does not exist, wtf?");
255)         system_failure("Es gibt für diesen Benutzer noch keine Konfiguration. Das sollte nicht sein!");
256)     } else {
257)         $content = file($userconfig);
258)         DEBUG("Old file:");
259)         DEBUG($content);
260)         $newcontent = array();
261)         foreach ($content as $line) {
262)             if (preg_match('/^# foreign user '.$handle.'$/', $line)) {
263)                 DEBUG("delete1: ".$line);
264)                 continue;
265)             }
266)             if (preg_match('/^\s*(R|RW|RW+)\s*=\s*'.$handle.'\s*$/', $line)) {
267)                 DEBUG("delete2: ".$line);
268)                 continue;
269)             }
270)             $newcontent[] = $line;
271)         }
272)         DEBUG("Modified file:");
273)         DEBUG($newcontent);
274)         file_put_contents($userconfig, implode('', $newcontent));
275)     }
276)     git_wrapper('add '.$userconfig);
277) 
278)     git_wrapper('commit -m "deleted foreign user '.$handle.' for '.$username.'"');
279)     git_wrapper('push');
Bernd Wurst add foreign git users and g...

Bernd Wurst authored 12 years ago

280) }
281) 
282) 
bernd First draft of gitolite-mod...

bernd authored 12 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

292) 
Bernd Wurst gitolite: Entferne Zeilenum...

Bernd Wurst authored 5 years ago

293)     $pubkey = trim(str_replace(array("\r", "\n"), ' ', $pubkey));
294) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

327) }
328) 
329) 
bernd First draft of gitolite-mod...

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

344)     $keyfile = $key_dir.'/'.$handle.'.pub';
345)     if (! file_exists($keyfile)) {
346)         system_failure("Der angegebene Schlüssel scheint nicht mehr vorhanden zu sein. Bitte manuelle Korrektur anfordern!");
347)     }
348)     git_wrapper('rm '.$keyfile);
349) 
350) 
351)     $userconfig = $config_dir . '/' . $username . '.conf';
352)     DEBUG("using config file ".$userconfig);
353)     if (! is_file($userconfig)) {
354)         DEBUG("user-config does not exist, wtf?");
355)         system_failure("Es gibt für diesen Benutzer noch keine Konfiguration. Das sollte nicht sein!");
356)     } else {
357)         $content = file($userconfig);
358)         DEBUG("Old file:");
359)         DEBUG($content);
360)         $newcontent = array();
361)         foreach ($content as $line) {
362)             if (preg_match('/^# user '.$handle.'$/', $line)) {
363)                 DEBUG("delete1: ".$line);
364)                 continue;
365)             }
366)             if (preg_match('/^\s*(R|RW|RW+)\s*=\s*'.$handle.'\s*$/', $line)) {
367)                 DEBUG("delete2: ".$line);
368)                 continue;
369)             }
370)             $newcontent[] = $line;
371)         }
372)         DEBUG("Modified file:");
373)         DEBUG($newcontent);
374)         file_put_contents($userconfig, implode('', $newcontent));
375)     }
376)     git_wrapper('add '.$userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

380) }
bernd Fürs erste feature-complete

bernd authored 12 years ago

381) 
382) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

383) function remove_repo_from_array($data, $repo)
384) {
385)     DEBUG("Request to remove repo »{$repo}«...");
386)     $inside = false;
387)     $outdata = array();
388)     $blank = true;
389)     foreach ($data as $line) {
390)         if ($blank && chop($line) == '') {
391)             continue;
392)         }
393)         $blank = (chop($line) == '');
394)         $m = array();
395)         if (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
396)             $inside = ($m[1] == $repo);
397)         }
398)         if (! $inside && ! preg_match('/^'.$repo.'\s.*/', $line)) {
399)             $outdata[] = $line;
400)         }
bernd Fürs erste feature-complete

bernd authored 12 years ago

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

Hanno authored 5 years ago

402)     DEBUG($outdata);
403)     return $outdata;
bernd Fürs erste feature-complete

bernd authored 12 years ago

404) }
405) 
406) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

422) }
423) 
424) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

443) }
444) 
bernd Gitolite: Erzeuge include f...

bernd authored 12 years ago

445) 
446) function set_user_include()
447) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

469) }
470) 
471) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

476)     }
477)     if (!array_key_exists($repo, list_repos()) && repo_exists_globally($repo)) {
478)         system_failure("Der gewählte Name existiert bereits auf diesem Server. Bitte wählen Sie einen spezifischeren Namen.");
479)     }
480)     global $config_dir;
481)     $username = $_SESSION['userinfo']['username'];
482)     $userconfig = $config_dir . '/' . $username . '.conf';
483)     DEBUG("using config file ".$userconfig);
484)     $data = array();
485)     if (! is_file($userconfig)) {
486)         DEBUG("user-config does not exist, creating new one");
487)         set_user_include();
488)     } else {
489)         $data = file($userconfig);
490)     }
bernd Fürs erste feature-complete

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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