bd14df05efb463fce898d696ff6187c86a69f489
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) 
Bernd Wurst gitolite: Entferne Zeilenum...

Bernd Wurst authored 5 years ago

290)     $pubkey = trim(str_replace(array("\r", "\n"), ' ', $pubkey));
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);
357)         $newcontent = array();
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;
384)     $outdata = array();
385)     $blank = true;
386)     foreach ($data as $line) {
387)         if ($blank && chop($line) == '') {
388)             continue;
389)         }
390)         $blank = (chop($line) == '');
391)         $m = array();
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);
481)     $data = array();
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');