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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

149)     $lines = file($userconfig);
150)     $users = array();
151)     foreach ($lines as $line) {
152)         $m = array();
153)         if (preg_match('_# user ([^]]+)_', $line, $m) != 0) {
154)             $users[] = chop($m[1]);
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");
173)         return array();
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);
177)     $users = array();
178)     foreach ($lines as $line) {
179)         $m = array();
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);
257)         $newcontent = array();
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 Fix coding style with php-c...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

322) }
323) 
324) 
bernd First draft of gitolite-mod...

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

375) }
bernd Fürs erste feature-complete

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

397)     DEBUG($outdata);
398)     return $outdata;
bernd Fürs erste feature-complete

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

414)         }
415)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

438) }
439) 
bernd Gitolite: Erzeuge include f...

bernd authored 12 years ago

440) 
441) function set_user_include()
442) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

464) }
465) 
466) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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