354c05a4ddd678c49bcbba458bffa7d13482139a
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) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

16) $data_dir = realpath(dirname(__FILE__) . '/../../../../gitolite-data/');
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);
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)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

31)     if (!(is_file($data_dir . '/sshkey') && is_file($data_dir . '/sshkey.pub'))) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

32)         system_failure("SSH-key not found. Please setup the gitolite-module correctly. Run ./data/initialize.sh");
33)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

34)     if (!is_dir($data_dir . '/gitolite-admin')) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

35)         system_failure("Repository gitolite-admin ot found. Initial checkout must be made manually. Run ./data/initialize.sh");
36)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

37)     if (!is_dir($config_dir)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

38)         system_failure("gitolite-admin repository is not prepared.");
39)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

40)     if (!(is_dir($key_dir) && is_writeable($config_file))) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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');
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

54)     DEBUG('gitolite-admin repo: ' . $remote[0]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

55)     $url = preg_replace('#^.*\s+(\S+):gitolite-admin.*#', '$1', $remote[0]);
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

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) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

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';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

92)     DEBUG("using config file " . $userconfig);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

93)     if (!is_file($userconfig)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

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)             }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

118)             DEBUG("found repo " . $m[1]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

123)             DEBUG("found access rule: " . $m[1] . " for " . $m[2]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

141)     DEBUG("using config file " . $userconfig);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

142)     if (!is_file($userconfig)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

170)     DEBUG("using config file " . $userconfig);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

171)     if (!is_file($userconfig)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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;
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

195)     if (!validate_name($handle)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

196)         return '';
197)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

198)     $keyfile = $key_dir . '/' . $handle . '.pub';
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

199)     if (!file_exists($keyfile)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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) 
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

212)     if (!validate_name($handle)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

220)     $keyfile = $key_dir . '/' . $handle . '.pub';
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

221)     if (!file_exists($keyfile)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

222)         system_failure('Diesen GIT-Benutzer gibt es nicht');
223)     }
224) 
225)     $userconfig = $config_dir . '/' . $username . '.conf';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

226)     DEBUG("using config file " . $userconfig);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

227)     if (!is_file($userconfig)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

228)         DEBUG("user-config does not exist, creating new one");
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

229)         file_put_contents($userconfig, '# foreign user ' . $handle . "\n");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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);
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

235)         file_put_contents($userconfig, "# foreign user {$handle}\n" . $content);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

236)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

237)     git_wrapper('add ' . $userconfig);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

238) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

239)     git_wrapper('commit --allow-empty -m "added new foreign user for ' . $handle . '"');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

249)     DEBUG("using config file " . $userconfig);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

250)     if (!is_file($userconfig)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

259)             if (preg_match('/^# foreign user ' . $handle . '$/', $line)) {
260)                 DEBUG("delete1: " . $line);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

261)                 continue;
262)             }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

263)             if (preg_match('/^\s*(R|RW|RW+)\s*=\s*' . $handle . '\s*$/', $line)) {
264)                 DEBUG("delete2: " . $line);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

265)                 continue;
266)             }
267)             $newcontent[] = $line;
268)         }
269)         DEBUG("Modified file:");
270)         DEBUG($newcontent);
271)         file_put_contents($userconfig, implode('', $newcontent));
272)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

273)     git_wrapper('add ' . $userconfig);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

274) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

275)     git_wrapper('commit -m "deleted foreign user ' . $handle . ' for ' . $username . '"');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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 Böck Spaces between string conca...

Hanno Böck authored 6 months ago

285)     $handle = $username . '-' . $handle;
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

286)     if (!validate_name($handle) || (str_replace(".", "x", $handle) != $handle)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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 Böck Spaces between string conca...

Hanno Böck authored 6 months ago

292)     $keyfile = $key_dir . '/' . $handle . '.pub';
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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 Böck Spaces between string conca...

Hanno Böck authored 6 months ago

306)     git_wrapper('add ' . $keyfile);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

307) 
308)     $userconfig = $config_dir . '/' . $username . '.conf';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

309)     DEBUG("using config file " . $userconfig);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

310)     if (!is_file($userconfig)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

311)         DEBUG("user-config does not exist, creating new one");
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

312)         file_put_contents($userconfig, '# user ' . $handle . "\n");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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);
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

318)         file_put_contents($userconfig, "# user {$handle}\n" . $content);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

319)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

320)     git_wrapper('add ' . $userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

321) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

322)     git_wrapper('commit --allow-empty -m "added new key for ' . $handle . '"');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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 Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

332)     if (!validate_name($handle)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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 Böck Spaces between string conca...

Hanno Böck authored 6 months ago

341)     $keyfile = $key_dir . '/' . $handle . '.pub';
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

342)     if (!file_exists($keyfile)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

343)         system_failure("Der angegebene Schlüssel scheint nicht mehr vorhanden zu sein. Bitte manuelle Korrektur anfordern!");
344)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

345)     git_wrapper('rm ' . $keyfile);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

346) 
347) 
348)     $userconfig = $config_dir . '/' . $username . '.conf';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

349)     DEBUG("using config file " . $userconfig);
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

350)     if (!is_file($userconfig)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

359)             if (preg_match('/^# user ' . $handle . '$/', $line)) {
360)                 DEBUG("delete1: " . $line);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

361)                 continue;
362)             }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

363)             if (preg_match('/^\s*(R|RW|RW+)\s*=\s*' . $handle . '\s*$/', $line)) {
364)                 DEBUG("delete2: " . $line);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

365)                 continue;
366)             }
367)             $newcontent[] = $line;
368)         }
369)         DEBUG("Modified file:");
370)         DEBUG($newcontent);
371)         file_put_contents($userconfig, implode('', $newcontent));
372)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

373)     git_wrapper('add ' . $userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

374) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

375)     git_wrapper('commit -m "deleted key for ' . $handle . '"');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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)         }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

395)         if (!$inside && !preg_match('/^' . $repo . '\s.*/', $line)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

409)         if (is_file(realpath($config_dir . '/' . $f))) {
410)             $data = file(realpath($config_dir . '/' . $f));
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

411)             foreach ($data as $line) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

412)                 if (preg_match('/^\s*repo ' . $repo . '\s*$/', $line) != 0) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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';
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

432)     DEBUG("using config file " . $userconfig);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

433)     $data = file($userconfig);
434)     $data = remove_repo_from_array($data, $repo);
435)     file_put_contents($userconfig, implode('', $data));
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

436)     git_wrapper('add ' . $userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

437) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

438)     git_wrapper('commit --allow-empty -m "deleted repo ' . $repo . '"');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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) {
Bernd Wurst fixed global variable missing

Bernd Wurst authored 8 months ago

445)     global $config_file, $config_dir;
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

446)     $username = $_SESSION['userinfo']['username'];
Bernd Wurst Fehler beim Hinzufügen frem...

Bernd Wurst authored 8 months ago

447)     $userconfig = $config_dir . '/' . $username . '.conf';
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

448)     if (!file_exists($userconfig)) {
449)         // Erzeuge eine leere Konfiguration damit das Include auf jeden Fall funktionieren kann
450)         file_put_contents($userconfig, '');
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

451)         git_wrapper('add ' . $userconfig);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

452)     }
453)     $found = false;
454)     $data = file($config_file);
455)     foreach ($data as $line) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

456)         if (preg_match('#webinterface/' . $username . '\.conf#', $line)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

457)             $found = true;
458)         }
459)     }
460)     if (!$found) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

461)         $includeline = 'include  "webinterface/' . $username . '.conf"';
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

462)         $data = chop(file_get_contents($config_file));
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

463)         $data = $data . "\n" . $includeline . "\n";
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

464)         file_put_contents($config_file, $data);
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

465)         git_wrapper('add ' . $config_file);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

466)     }
bernd Gitolite: Erzeuge include f...

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno authored 5 years ago

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

Hanno Böck authored 6 months ago

481)     DEBUG("using config file " . $userconfig);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

482)     $data = [];
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

483)     if (!is_file($userconfig)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

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

bernd authored 12 years ago

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

Hanno authored 5 years ago

490)     $repos = list_repos();
491)     if (array_key_exists($repo, $repos)) {
492)         $data = remove_repo_from_array($data, $repo);
493)     }
494) 
495)     $data[] = "\n";
496)     if ($description) {
497)         $description = preg_replace('/\[\'"\r\n/', '', $description);
498)         $realname = $_SESSION['userinfo']['name'];
499)         $data[] = "{$repo} \"{$realname}\" = \"{$description}\"\n";
500)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

501)     $data[] = 'repo ' . $repo . "\n";
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

502)     foreach ($permissions as $user => $perm) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

503)         $data[] = '  ' . $perm . ' = ' . $user . "\n";
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

504)     }
505)     file_put_contents($userconfig, implode('', $data));
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

506)     git_wrapper('add ' . $userconfig);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

507) 
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

508)     git_wrapper('commit --allow-empty -m "written repo ' . $repo . '"');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

509)     git_wrapper('push');