Browse code

Rechtschreibfehler

Hanno authored on28/02/2019 12:19:22
Showing1 changed files
... ...
@@ -469,7 +469,7 @@ function set_user_include()
469 469
 function save_repo($repo, $permissions, $description)
470 470
 {
471 471
     if (!validate_name($repo)) {
472
-        system_failure("Der gewählte name entspricht nicht den Konventionen!");
472
+        system_failure("Der gewählte Name entspricht nicht den Konventionen!");
473 473
     }
474 474
     if (!array_key_exists($repo, list_repos()) && repo_exists_globally($repo)) {
475 475
         system_failure("Der gewählte Name existiert bereits auf diesem Server. Bitte wählen Sie einen spezifischeren Namen.");
Browse code

gitolite: Entferne Zeilenumbrüche aus dem SSH-Key

Bernd Wurst authored on11/12/2018 15:49:55
Showing1 changed files
... ...
@@ -287,6 +287,8 @@ function newkey($pubkey, $handle)
287 287
         system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich und Bindestrich benutzen.");
288 288
     }
289 289
 
290
+    $pubkey = trim(str_replace(array("\r", "\n"), ' ', $pubkey));
291
+
290 292
     $keyfile = $key_dir.'/'.$handle.'.pub';
291 293
     file_put_contents($keyfile, $pubkey);
292 294
 
Browse code

Erwarte das Datenverzeichnis außerhalb des webroot (momentan hardcoded 4 Ebenen über der include-Datei)

Bernd Wurst authored on07/12/2018 22:19:19
Showing1 changed files
... ...
@@ -16,12 +16,12 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
16 16
 
17 17
 require_role(ROLE_SYSTEMUSER);
18 18
 
19
-$data_dir = realpath(dirname(__FILE__).'/../data/');
19
+$data_dir = realpath(dirname(__FILE__).'/../../../../gitolite-data/');
20 20
 $config_file = $data_dir.'/gitolite-admin/conf/webinterface.conf';
21 21
 $config_dir = $data_dir.'/gitolite-admin/conf/webinterface';
22 22
 $key_dir = $data_dir.'/gitolite-admin/keydir';
23 23
 DEBUG("gitolite-data_dir: ".$data_dir);
24
-$git_wrapper = $data_dir . '/git-wrapper.sh';
24
+$git_wrapper = realpath(dirname(__FILE__).'/../scripts/git-wrapper.sh');
25 25
 
26 26
 
27 27
 
Browse code

remove whitespace in empty lines

Hanno authored on26/06/2018 23:36:40
Showing1 changed files
... ...
@@ -145,7 +145,7 @@ function list_users()
145 145
         DEBUG("user-config does not exist");
146 146
         return array();
147 147
     }
148
-  
148
+
149 149
     $lines = file($userconfig);
150 150
     $users = array();
151 151
     foreach ($lines as $line) {
... ...
@@ -172,7 +172,7 @@ function list_foreign_users()
172 172
         DEBUG("user-config does not exist");
173 173
         return array();
174 174
     }
175
-  
175
+
176 176
     $lines = file($userconfig);
177 177
     $users = array();
178 178
     foreach ($lines as $line) {
... ...
@@ -281,7 +281,7 @@ function newkey($pubkey, $handle)
281 281
 {
282 282
     global $key_dir, $config_dir;
283 283
     $username = $_SESSION['userinfo']['username'];
284
-  
284
+
285 285
     $handle = $username.'-'.$handle;
286 286
     if (! validate_name($handle) || (str_replace(".", "x", $handle) != $handle)) {
287 287
         system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich und Bindestrich benutzen.");
... ...
@@ -289,7 +289,7 @@ function newkey($pubkey, $handle)
289 289
 
290 290
     $keyfile = $key_dir.'/'.$handle.'.pub';
291 291
     file_put_contents($keyfile, $pubkey);
292
-  
292
+
293 293
     DEBUG("checking public key $keyfile");
294 294
     $proc = popen("/usr/bin/ssh-keygen -l -f '{$keyfile}' 2>&1", 'r');
295 295
     $output = fread($proc, 512);
... ...
@@ -299,7 +299,7 @@ function newkey($pubkey, $handle)
299 299
         unlink($keyfile);
300 300
         system_failure('Der angegebene SSH-Key scheint ungültig zu sein.');
301 301
     }
302
-  
302
+
303 303
 
304 304
     git_wrapper('add '.$keyfile);
305 305
 
... ...
@@ -316,7 +316,7 @@ function newkey($pubkey, $handle)
316 316
         file_put_contents($userconfig, "# user {$handle}\n".$content);
317 317
     }
318 318
     git_wrapper('add '.$userconfig);
319
-  
319
+
320 320
     git_wrapper('commit --allow-empty -m "added new key for '.$handle.'"');
321 321
     git_wrapper('push');
322 322
 }
... ...
@@ -369,7 +369,7 @@ function delete_key($handle)
369 369
         file_put_contents($userconfig, implode('', $newcontent));
370 370
     }
371 371
     git_wrapper('add '.$userconfig);
372
- 
372
+
373 373
     git_wrapper('commit -m "deleted key for '.$handle.'"');
374 374
     git_wrapper('push');
375 375
 }
... ...
@@ -423,7 +423,7 @@ function delete_repo($repo)
423 423
     if (!array_key_exists($repo, $repos)) {
424 424
         system_failure("Ein solches Repository existiert nicht!");
425 425
     }
426
-  
426
+
427 427
     global $config_dir;
428 428
     $username = $_SESSION['userinfo']['username'];
429 429
     $userconfig = $config_dir . '/' . $username . '.conf';
... ...
@@ -432,7 +432,7 @@ function delete_repo($repo)
432 432
     $data = remove_repo_from_array($data, $repo);
433 433
     file_put_contents($userconfig, implode('', $data));
434 434
     git_wrapper('add '.$userconfig);
435
-  
435
+
436 436
     git_wrapper('commit --allow-empty -m "deleted repo '.$repo.'"');
437 437
     git_wrapper('push');
438 438
 }
... ...
@@ -501,7 +501,7 @@ function save_repo($repo, $permissions, $description)
501 501
     }
502 502
     file_put_contents($userconfig, implode('', $data));
503 503
     git_wrapper('add '.$userconfig);
504
-  
504
+
505 505
     git_wrapper('commit --allow-empty -m "written repo '.$repo.'"');
506 506
     git_wrapper('push');
507 507
 }
Browse code

Fix coding style with php-cs-checker, see https://cs.sensiolabs.org/

Hanno authored on26/06/2018 13:58:19
Showing1 changed files
... ...
@@ -8,7 +8,7 @@ Written 2008-2018 by schokokeks.org Hosting, namely
8 8
 
9 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 10
 
11
-You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
12 12
 http://creativecommons.org/publicdomain/zero/1.0/
13 13
 
14 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.
... ...
@@ -16,7 +16,7 @@ Nevertheless, in case you use a significant part of this code, we ask (but not r
16 16
 
17 17
 require_role(ROLE_SYSTEMUSER);
18 18
 
19
-$data_dir = realpath( dirname(__FILE__).'/../data/' );
19
+$data_dir = realpath(dirname(__FILE__).'/../data/');
20 20
 $config_file = $data_dir.'/gitolite-admin/conf/webinterface.conf';
21 21
 $config_dir = $data_dir.'/gitolite-admin/conf/webinterface';
22 22
 $key_dir = $data_dir.'/gitolite-admin/keydir';
... ...
@@ -25,482 +25,483 @@ $git_wrapper = $data_dir . '/git-wrapper.sh';
25 25
 
26 26
 
27 27
 
28
-function check_env() 
28
+function check_env()
29 29
 {
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
-  }
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
+    }
46 46
 }
47 47
 
48 48
 
49
-function validate_name($name) {
50
-  return (preg_match('/^[[:alnum:]][[:alnum:]._-]*$/', $name));
49
+function validate_name($name)
50
+{
51
+    return (preg_match('/^[[:alnum:]][[:alnum:]._-]*$/', $name));
51 52
 }
52 53
 
53
-function get_git_url($repo) {
54
-  $remote = git_wrapper('remote --verbose');
55
-  DEBUG('gitolite-admin repo: '.$remote[0]);
56
-  $url = preg_replace('#^.*\s+(\S+):gitolite-admin.*#', '$1', $remote[0]);
57
-  DEBUG('URL: '.$url);
58
-  return $url.':'.$repo;
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;
59 61
 }
60 62
 
61 63
 
62 64
 function git_wrapper($commandline)
63 65
 {
64
-  global $git_wrapper, $data_dir;
65
-
66
-  $command = $git_wrapper.' '.$commandline;
67
-  $output = array();
68
-  $retval = 0;
69
-  DEBUG($command);
70
-  exec($command, $output, $retval);
71
-  DEBUG($output);
72
-  DEBUG($retval);
73
-  if ($retval > 0) {
74
-    system_failure('Interner Fehler!');
75
-    // FIXME: Hier sollte auf jeden Fall ein Logging angeworfen werden!
76
-  }
77
-  return $output;
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;
78 80
 }
79 81
 
80
-function refresh_gitolite() 
82
+function refresh_gitolite()
81 83
 {
82
-  check_env();
83
-  git_wrapper('pull');
84
+    check_env();
85
+    git_wrapper('pull');
84 86
 }
85 87
 
86 88
 
87 89
 
88
-function list_repos() 
90
+function list_repos()
89 91
 {
90
-  global $config_file, $config_dir;
91
-  $username = $_SESSION['userinfo']['username'];
92
-  $userconfig = $config_dir . '/' . $username . '.conf';
93
-  DEBUG("using config file ".$userconfig);
94
-  if (! is_file($userconfig)) {
95
-    DEBUG("user-config does not exist");
96
-    return array();
97
-  }
98
-
99
-  $repos = array();
100
-  $lines = file($userconfig);
101
-  $current_repo = NULL;
102
-  $current_repo_users = array();
103
-  foreach ($lines as $line) {
104
-    DEBUG("LINE: ".$line);
105
-    $m = array();
106
-    if (preg_match('/^(\S+) "[^"]+" = "([^"]+)"$/', $line, $m) != 0) {
107
-      if (!array_key_exists($m[1], $repos)) {
108
-        $repos[$m[1]] = array('users' => NULL, 'description' => '');
109
-      }
110
-      DEBUG("found description: {$m[1]} = \"{$m[2]}\"");
111
-      $repos[$m[1]]['description'] = $m[2];
112
-    } elseif (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
113
-      if (!array_key_exists($m[1], $repos)) {
114
-        $repos[$m[1]] = array('users' => NULL, 'description' => '');
115
-      }
116
-      if ($current_repo) {
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) {
117 130
         $repos[$current_repo]['users'] = $current_repo_users;
118
-      }
119
-      DEBUG("found repo ".$m[1]);
120
-      $current_repo = chop($m[1]);
121
-      $current_repo_users = array();
122
-    } else if (preg_match('/^\s*(R|RW|RW\+)\s*=\s*([[:alnum:]][[:alnum:]._-]*)\s*$/', $line, $m) != 0) {
123
-      DEBUG("found access rule: ".$m[1]." for ".$m[2]);
124
-      $current_repo_users[chop($m[2])] = chop($m[1]);
125
-    }
126
-  }
127
-  if ($current_repo) {
128
-    $repos[$current_repo]['users'] = $current_repo_users;
129
-  }
130
-  ksort($repos);
131
-  DEBUG($repos);
132
-  return $repos;
131
+    }
132
+    ksort($repos);
133
+    DEBUG($repos);
134
+    return $repos;
133 135
 }
134 136
 
135 137
 
136
-function list_users() {
137
-  global $config_file, $config_dir;
138
-  $username = $_SESSION['userinfo']['username'];
139
-  $userconfig = $config_dir . '/' . $username . '.conf';
140
-  DEBUG("using config file ".$userconfig);
141
-  if (! is_file($userconfig)) {
142
-    DEBUG("user-config does not exist");
143
-    return array();
144
-  }
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
+    }
145 148
   
146
-  $lines = file($userconfig);
147
-  $users = array();
148
-  foreach ($lines as $line) {
149
-    $m = array();
150
-    if (preg_match('_# user ([^]]+)_', $line, $m) != 0) {
151
-      $users[] = chop($m[1]);
152
-    }
153
-    if (preg_match('_^\s*repo .*_', $line) != 0) {
154
-      break;
155
-    }
156
-  }
157
-  sort($users);
158
-  DEBUG($users);
159
-  return $users;
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;
160 163
 }
161 164
 
162
-function list_foreign_users() {
163
-  global $config_file, $config_dir;
164
-  $username = $_SESSION['userinfo']['username'];
165
-  $userconfig = $config_dir . '/' . $username . '.conf';
166
-  DEBUG("using config file ".$userconfig);
167
-  if (! is_file($userconfig)) {
168
-    DEBUG("user-config does not exist");
169
-    return array();
170
-  }
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
+    }
171 175
   
172
-  $lines = file($userconfig);
173
-  $users = array();
174
-  foreach ($lines as $line) {
175
-    $m = array();
176
-    if (preg_match('_# foreign user ([^]]+)_', $line, $m) != 0) {
177
-      $users[] = chop($m[1]);
178
-    }
179
-    if (preg_match('_^\s*repo .*_', $line) != 0) {
180
-      break;
181
-    }
182
-  }
183
-  sort($users);
184
-  DEBUG($users);
185
-  return $users;
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;
186 190
 }
187 191
 
188
-function get_pubkey($handle) {
189
-  global $key_dir;
190
-  if (! validate_name($handle)) {
191
-    return '';
192
-  }
193
-  $keyfile = $key_dir.'/'.$handle.'.pub';
194
-  if (! file_exists($keyfile)) {
195
-    return '';
196
-  }
197
-  return file_get_contents($keyfile);
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);
198 203
 }
199 204
 
200 205
 
201 206
 
202
-function new_foreign_user($handle) 
207
+function new_foreign_user($handle)
203 208
 {
204
-  global $key_dir, $config_dir;
205
-  $username = $_SESSION['userinfo']['username'];
206
-
207
-  if (! validate_name($handle)) {
208
-    system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich, Binderstrich und Punkt benutzen.");
209
-  }
210
-
211
-  if (in_array($handle, list_users())) {
212
-    system_failure('Dieser GIT-Benutzer gehört zu diesem Kundenaccount.');
213
-  }
214
-
215
-  $keyfile = $key_dir.'/'.$handle.'.pub';
216
-  if (! file_exists($keyfile) ) {
217
-    system_failure('Diesen GIT-Benutzer gibt es nicht');
218
-  }
219
-
220
-  $userconfig = $config_dir . '/' . $username . '.conf';
221
-  DEBUG("using config file ".$userconfig);
222
-  if (! is_file($userconfig)) {
223
-    DEBUG("user-config does not exist, creating new one");
224
-    file_put_contents($userconfig, '# user '.$handle."\n");
225
-    set_user_include();
226
-  } elseif (in_array($handle, list_foreign_users())) {
227
-    # user ist schon eingetragen
228
-  } else {
229
-    $content = file_get_contents($userconfig);
230
-    file_put_contents($userconfig, "# foreign user {$handle}\n".$content);
231
-  }
232
-  git_wrapper('add '.$userconfig);
233
-
234
-  git_wrapper('commit --allow-empty -m "added new key for '.$handle.'"');
235
-  git_wrapper('push');
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');
236 241
 }
237 242
 
238 243
 function delete_foreign_user($handle)
239 244
 {
240
-  global $config_dir;
241
-  $username = $_SESSION['userinfo']['username'];
242
-
243
-  $userconfig = $config_dir . '/' . $username . '.conf';
244
-  DEBUG("using config file ".$userconfig);
245
-  if (! is_file($userconfig)) {
246
-    DEBUG("user-config does not exist, wtf?");
247
-    system_failure("Es gibt für diesen Benutzer noch keine Konfiguration. Das sollte nicht sein!");
248
-  } else {
249
-    $content = file($userconfig);
250
-    DEBUG("Old file:");
251
-    DEBUG($content);
252
-    $newcontent = array();
253
-    foreach ($content as $line) {
254
-      if (preg_match('/^# foreign user '.$handle.'$/', $line)) {
255
-        DEBUG("delete1: ".$line);
256
-        continue;
257
-      }
258
-      if (preg_match('/^\s*(R|RW|RW+)\s*=\s*'.$handle.'\s*$/', $line)) {
259
-        DEBUG("delete2: ".$line);
260
-        continue;
261
-      }
262
-      $newcontent[] = $line;
263
-    }
264
-    DEBUG("Modified file:");
265
-    DEBUG($newcontent);
266
-    file_put_contents($userconfig, implode('', $newcontent));
267
-  }
268
-  git_wrapper('add '.$userconfig);
269
-
270
-  git_wrapper('commit -m "deleted foreign user '.$handle.' for '.$username.'"');
271
-  git_wrapper('push');
272
-  
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');
273 277
 }
274 278
 
275 279
 
276 280
 function newkey($pubkey, $handle)
277 281
 {
278
-  global $key_dir, $config_dir;
279
-  $username = $_SESSION['userinfo']['username'];
282
+    global $key_dir, $config_dir;
283
+    $username = $_SESSION['userinfo']['username'];
280 284
   
281
-  $handle = $username.'-'.$handle;
282
-  if (! validate_name($handle) || (str_replace(".", "x", $handle) != $handle)) {
283
-    system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich und Bindestrich benutzen.");
284
-  }
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
+    }
285 289
 
286
-  $keyfile = $key_dir.'/'.$handle.'.pub';
287
-  file_put_contents($keyfile, $pubkey);
290
+    $keyfile = $key_dir.'/'.$handle.'.pub';
291
+    file_put_contents($keyfile, $pubkey);
288 292
   
289
-  DEBUG("checking public key $keyfile");
290
-  $proc = popen("/usr/bin/ssh-keygen -l -f '{$keyfile}' 2>&1", 'r');
291
-  $output = fread($proc, 512);
292
-  DEBUG($output);
293
-  pclose($proc);
294
-  if (preg_match('/.* is not a public key file.*/', $output)) {
295
-    unlink($keyfile);
296
-    system_failure('Der angegebene SSH-Key scheint ungültig zu sein.');
297
-  }
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
+    }
298 302
   
299 303
 
300
-  git_wrapper('add '.$keyfile);
301
-
302
-  $userconfig = $config_dir . '/' . $username . '.conf';
303
-  DEBUG("using config file ".$userconfig);
304
-  if (! is_file($userconfig)) {
305
-    DEBUG("user-config does not exist, creating new one");
306
-    file_put_contents($userconfig, '# user '.$handle."\n");
307
-    set_user_include();
308
-  } elseif (in_array($handle, list_users())) {
309
-    # user ist schon eingetragen, nur neuer Key
310
-  } else {
311
-    $content = file_get_contents($userconfig);
312
-    file_put_contents($userconfig, "# user {$handle}\n".$content);
313
-  }
314
-  git_wrapper('add '.$userconfig);
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);
315 319
   
316
-  git_wrapper('commit --allow-empty -m "added new key for '.$handle.'"');
317
-  git_wrapper('push');
320
+    git_wrapper('commit --allow-empty -m "added new key for '.$handle.'"');
321
+    git_wrapper('push');
318 322
 }
319 323
 
320 324
 
321 325
 function delete_key($handle)
322 326
 {
323
-  global $key_dir, $config_dir;
324
-  $username = $_SESSION['userinfo']['username'];
325
-
326
-  if (! validate_name($handle)) {
327
-    system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich, Binderstrich und Punkt benutzen.");
328
-  }
329
-  if (!in_array($handle, list_users())) {
330
-    DEBUG("key {$handle} not in");
331
-    DEBUG(list_users());
332
-    system_failure("Den angegebenen Key scheint es nicht zu geben");
333
-  }
334
-
335
-  $keyfile = $key_dir.'/'.$handle.'.pub';
336
-  if (! file_exists($keyfile)) {
337
-    system_failure("Der angegebene Schlüssel scheint nicht mehr vorhanden zu sein. Bitte manuelle Korrektur anfordern!");
338
-  } 
339
-  git_wrapper('rm '.$keyfile);
340
-
341
-
342
-  $userconfig = $config_dir . '/' . $username . '.conf';
343
-  DEBUG("using config file ".$userconfig);
344
-  if (! is_file($userconfig)) {
345
-    DEBUG("user-config does not exist, wtf?");
346
-    system_failure("Es gibt für diesen Benutzer noch keine Konfiguration. Das sollte nicht sein!");
347
-  } else {
348
-    $content = file($userconfig);
349
-    DEBUG("Old file:");
350
-    DEBUG($content);
351
-    $newcontent = array();
352
-    foreach ($content as $line) {
353
-      if (preg_match('/^# user '.$handle.'$/', $line)) {
354
-        DEBUG("delete1: ".$line);
355
-        continue;
356
-      }
357
-      if (preg_match('/^\s*(R|RW|RW+)\s*=\s*'.$handle.'\s*$/', $line)) {
358
-        DEBUG("delete2: ".$line);
359
-        continue;
360
-      }
361
-      $newcontent[] = $line;
362
-    }
363
-    DEBUG("Modified file:");
364
-    DEBUG($newcontent);
365
-    file_put_contents($userconfig, implode('', $newcontent));
366
-  }
367
-  git_wrapper('add '.$userconfig);
368
- 
369
-  git_wrapper('commit -m "deleted key for '.$handle.'"');
370
-  git_wrapper('push');
327
+    global $key_dir, $config_dir;
328
+    $username = $_SESSION['userinfo']['username'];
371 329
 
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
+    }
372 338
 
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);
372
+ 
373
+    git_wrapper('commit -m "deleted key for '.$handle.'"');
374
+    git_wrapper('push');
373 375
 }
374 376
 
375 377
 
376
-function remove_repo_from_array($data, $repo) {
377
-  DEBUG("Request to remove repo »{$repo}«...");
378
-  $inside = false;
379
-  $outdata = array();
380
-  $blank = true;
381
-  foreach ($data as $line) {
382
-    if ($blank && chop($line) == '') {
383
-      continue;
384
-    }
385
-    $blank = (chop($line) == '');
386
-    $m = array();
387
-    if (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
388
-      $inside = ($m[1] == $repo);
389
-    }
390
-    if (! $inside && ! preg_match('/^'.$repo.'\s.*/', $line)) {
391
-      $outdata[] = $line;
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
+        }
392 396
     }
393
-  }
394
-  DEBUG($outdata);
395
-  return $outdata;
397
+    DEBUG($outdata);
398
+    return $outdata;
396 399
 }
397 400
 
398 401
 
399
-function repo_exists_globally($repo) 
402
+function repo_exists_globally($repo)
400 403
 {
401
-  global $config_dir;
402
-  $files = scandir($config_dir);
403
-  foreach ($files as $f) {
404
-    if (is_file(realpath($config_dir.'/'.$f))) {
405
-      $data = file(realpath($config_dir.'/'.$f));
406
-      foreach ($data as $line) {
407
-        if (preg_match('/^\s*repo '.$repo.'\s*$/', $line) != 0) {
408
-          return true;
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
+            }
409 414
         }
410
-      }
411 415
     }
412
-  }
413
-  return false;
416
+    return false;
414 417
 }
415 418
 
416 419
 
417
-function delete_repo($repo) 
420
+function delete_repo($repo)
418 421
 {
419
-  $repos = list_repos();
420
-  if (!array_key_exists($repo, $repos)) {
421
-    system_failure("Ein solches Repository existiert nicht!");
422
-  }
422
+    $repos = list_repos();
423
+    if (!array_key_exists($repo, $repos)) {
424
+        system_failure("Ein solches Repository existiert nicht!");
425
+    }
423 426
   
424
-  global $config_dir;
425
-  $username = $_SESSION['userinfo']['username'];
426
-  $userconfig = $config_dir . '/' . $username . '.conf';
427
-  DEBUG("using config file ".$userconfig);
428
-  $data = file($userconfig);
429
-  $data = remove_repo_from_array($data, $repo);
430
-  file_put_contents($userconfig, implode('', $data));
431
-  git_wrapper('add '.$userconfig);
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);
432 435
   
433
-  git_wrapper('commit --allow-empty -m "deleted repo '.$repo.'"');
434
-  git_wrapper('push');
436
+    git_wrapper('commit --allow-empty -m "deleted repo '.$repo.'"');
437
+    git_wrapper('push');
435 438
 }
436 439
 
437 440
 
438 441
 function set_user_include()
439 442
 {
440
-  global $config_file, $userconfig;
441
-  $username = $_SESSION['userinfo']['username'];
442
-  if (!file_exists($userconfig))
443
-  {
444
-    // Erzeuge eine leere Konfiguration damit das Include auf jeden Fall funktionieren kann
445
-    file_put_contents($userconfig, '');
446
-    git_wrapper('add '.$userconfig);
447
-  }
448
-  $found = false;
449
-  $data = file($config_file);
450
-  foreach ($data as $line) {
451
-    if (preg_match('#webinterface/'.$username.'\.conf#', $line)) {
452
-      $found = true;
453
-    }
454
-  }
455
-  if (!$found) {
456
-    $includeline = 'include  "webinterface/'.$username.'.conf"';
457
-    $data = chop(file_get_contents($config_file));
458
-    $data = $data."\n".$includeline."\n";
459
-    file_put_contents($config_file, $data);
460
-    git_wrapper('add '.$config_file);
461
-  }
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
+    }
462 464
 }
463 465
 
464 466
 
465
-function save_repo($repo, $permissions, $description) 
467
+function save_repo($repo, $permissions, $description)
466 468
 {
467
-  if (!validate_name($repo)) {
468
-    system_failure("Der gewählte name entspricht nicht den Konventionen!");
469
-  }
470
-  if (!array_key_exists($repo, list_repos()) && repo_exists_globally($repo)) {
471
-    system_failure("Der gewählte Name existiert bereits auf diesem Server. Bitte wählen Sie einen spezifischeren Namen.");
472
-  } 
473
-  global $config_dir;
474
-  $username = $_SESSION['userinfo']['username'];
475
-  $userconfig = $config_dir . '/' . $username . '.conf';
476
-  DEBUG("using config file ".$userconfig);
477
-  $data = array();
478
-  if (! is_file($userconfig)) {
479
-    DEBUG("user-config does not exist, creating new one");
480
-    set_user_include();
481
-  } else {
482
-    $data = file($userconfig);
483
-  }
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
+    }
484 486
 
485
-  $repos = list_repos();
486
-  if (array_key_exists($repo, $repos)) {
487
-    $data = remove_repo_from_array($data, $repo);
488
-  }
489
-
490
-  $data[] = "\n";
491
-  if ($description) {
492
-    $description = preg_replace('/\[\'"\r\n/', '', $description);
493
-    $realname = $_SESSION['userinfo']['name'];
494
-    $data[] = "{$repo} \"{$realname}\" = \"{$description}\"\n";
495
-  }
496
-  $data[] = 'repo '.$repo."\n";
497
-  foreach ($permissions as $user => $perm) {
498
-    $data[] = '  '.$perm.' = '.$user."\n";
499
-  }
500
-  file_put_contents($userconfig, implode('', $data));
501
-  git_wrapper('add '.$userconfig);
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);
502 504
   
503
-  git_wrapper('commit --allow-empty -m "written repo '.$repo.'"');
504
-  git_wrapper('push');
505
+    git_wrapper('commit --allow-empty -m "written repo '.$repo.'"');
506
+    git_wrapper('push');
505 507
 }
506
-
Browse code

Copyright year update

Bernd Wurst authored on13/01/2018 06:07:05
Showing1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 /*
3 3
 This file belongs to the Webinterface of schokokeks.org Hosting
4 4
 
5
-Written 2008-2014 by schokokeks.org Hosting, namely
5
+Written 2008-2018 by schokokeks.org Hosting, namely
6 6
   Bernd Wurst <bernd@schokokeks.org>
7 7
   Hanno Böck <hanno@schokokeks.org>
8 8
 
Browse code

Prüfung des eingegebenen SSH-Key war fehlerhaft, jetzt korrigiert

Bernd Wurst authored on20/09/2016 09:25:42
Showing1 changed files
... ...
@@ -286,8 +286,10 @@ function newkey($pubkey, $handle)
286 286
   $keyfile = $key_dir.'/'.$handle.'.pub';
287 287
   file_put_contents($keyfile, $pubkey);
288 288
   
289
-  $proc = popen("/usr/bin/ssh-keygen -l -f '{$keyfile}'", 'r');
289
+  DEBUG("checking public key $keyfile");
290
+  $proc = popen("/usr/bin/ssh-keygen -l -f '{$keyfile}' 2>&1", 'r');
290 291
   $output = fread($proc, 512);
292
+  DEBUG($output);
291 293
   pclose($proc);
292 294
   if (preg_match('/.* is not a public key file.*/', $output)) {
293 295
     unlink($keyfile);
Browse code

Verbiete Punkt im GIT-Username

Bernd Wurst authored on26/04/2014 07:05:37
Showing1 changed files
... ...
@@ -279,8 +279,8 @@ function newkey($pubkey, $handle)
279 279
   $username = $_SESSION['userinfo']['username'];
280 280
   
281 281
   $handle = $username.'-'.$handle;
282
-  if (! validate_name($handle)) {
283
-    system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich, Binderstrich und Punkt benutzen.");
282
+  if (! validate_name($handle) || (str_replace(".", "x", $handle) != $handle)) {
283
+    system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich und Bindestrich benutzen.");
284 284
   }
285 285
 
286 286
   $keyfile = $key_dir.'/'.$handle.'.pub';
Browse code

Lizenzinfos in eigenes Modul ausgelagert und Copyright auf 2014 angepasst

Bernd Wurst authored on08/02/2014 05:45:07
Showing1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 /*
3 3
 This file belongs to the Webinterface of schokokeks.org Hosting
4 4
 
5
-Written 2008-2013 by schokokeks.org Hosting, namely
5
+Written 2008-2014 by schokokeks.org Hosting, namely
6 6
   Bernd Wurst <bernd@schokokeks.org>
7 7
   Hanno Böck <hanno@schokokeks.org>
8 8
 
Browse code

Updated copyright notice (2012 => 2013)

Bernd Wurst authored on19/01/2013 10:49:50
Showing1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 /*
3 3
 This file belongs to the Webinterface of schokokeks.org Hosting
4 4
 
5
-Written 2008-2012 by schokokeks.org Hosting, namely
5
+Written 2008-2013 by schokokeks.org Hosting, namely
6 6
   Bernd Wurst <bernd@schokokeks.org>
7 7
   Hanno Böck <hanno@schokokeks.org>
8 8
 
Browse code

add foreign git users and grant permissions to them

Bernd Wurst authored on12/03/2012 09:31:30
Showing1 changed files
... ...
@@ -133,7 +133,6 @@ function list_repos()
133 133
 }
134 134
 
135 135
 
136
-
137 136
 function list_users() {
138 137
   global $config_file, $config_dir;
139 138
   $username = $_SESSION['userinfo']['username'];
... ...
@@ -160,6 +159,32 @@ function list_users() {
160 159
   return $users;
161 160
 }
162 161
 
162
+function list_foreign_users() {
163
+  global $config_file, $config_dir;
164
+  $username = $_SESSION['userinfo']['username'];
165
+  $userconfig = $config_dir . '/' . $username . '.conf';
166
+  DEBUG("using config file ".$userconfig);
167
+  if (! is_file($userconfig)) {
168
+    DEBUG("user-config does not exist");
169
+    return array();
170
+  }
171
+  
172
+  $lines = file($userconfig);
173
+  $users = array();
174
+  foreach ($lines as $line) {
175
+    $m = array();
176
+    if (preg_match('_# foreign user ([^]]+)_', $line, $m) != 0) {
177
+      $users[] = chop($m[1]);
178
+    }
179
+    if (preg_match('_^\s*repo .*_', $line) != 0) {
180
+      break;
181
+    }
182
+  }
183
+  sort($users);
184
+  DEBUG($users);
185
+  return $users;
186
+}
187
+
163 188
 function get_pubkey($handle) {
164 189
   global $key_dir;
165 190
   if (! validate_name($handle)) {
... ...
@@ -174,6 +199,80 @@ function get_pubkey($handle) {
174 199
 
175 200
 
176 201
 
202
+function new_foreign_user($handle) 
203
+{
204
+  global $key_dir, $config_dir;
205
+  $username = $_SESSION['userinfo']['username'];
206
+
207
+  if (! validate_name($handle)) {
208
+    system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich, Binderstrich und Punkt benutzen.");
209
+  }
210
+
211
+  if (in_array($handle, list_users())) {
212
+    system_failure('Dieser GIT-Benutzer gehört zu diesem Kundenaccount.');
213
+  }
214
+
215
+  $keyfile = $key_dir.'/'.$handle.'.pub';
216
+  if (! file_exists($keyfile) ) {
217
+    system_failure('Diesen GIT-Benutzer gibt es nicht');
218
+  }
219
+
220
+  $userconfig = $config_dir . '/' . $username . '.conf';
221
+  DEBUG("using config file ".$userconfig);
222
+  if (! is_file($userconfig)) {
223
+    DEBUG("user-config does not exist, creating new one");
224
+    file_put_contents($userconfig, '# user '.$handle."\n");
225
+    set_user_include();
226
+  } elseif (in_array($handle, list_foreign_users())) {
227
+    # user ist schon eingetragen
228
+  } else {
229
+    $content = file_get_contents($userconfig);
230
+    file_put_contents($userconfig, "# foreign user {$handle}\n".$content);
231
+  }
232
+  git_wrapper('add '.$userconfig);
233
+
234
+  git_wrapper('commit --allow-empty -m "added new key for '.$handle.'"');
235
+  git_wrapper('push');
236
+}
237
+
238
+function delete_foreign_user($handle)
239
+{
240
+  global $config_dir;
241
+  $username = $_SESSION['userinfo']['username'];
242
+
243
+  $userconfig = $config_dir . '/' . $username . '.conf';
244
+  DEBUG("using config file ".$userconfig);
245
+  if (! is_file($userconfig)) {
246
+    DEBUG("user-config does not exist, wtf?");
247
+    system_failure("Es gibt für diesen Benutzer noch keine Konfiguration. Das sollte nicht sein!");
248
+  } else {
249
+    $content = file($userconfig);
250
+    DEBUG("Old file:");
251
+    DEBUG($content);
252
+    $newcontent = array();
253
+    foreach ($content as $line) {
254
+      if (preg_match('/^# foreign user '.$handle.'$/', $line)) {
255
+        DEBUG("delete1: ".$line);
256
+        continue;
257
+      }
258
+      if (preg_match('/^\s*(R|RW|RW+)\s*=\s*'.$handle.'\s*$/', $line)) {
259
+        DEBUG("delete2: ".$line);
260
+        continue;
261
+      }
262
+      $newcontent[] = $line;
263
+    }
264
+    DEBUG("Modified file:");
265
+    DEBUG($newcontent);
266
+    file_put_contents($userconfig, implode('', $newcontent));
267
+  }
268
+  git_wrapper('add '.$userconfig);
269
+
270
+  git_wrapper('commit -m "deleted foreign user '.$handle.' for '.$username.'"');
271
+  git_wrapper('push');
272
+  
273
+}
274
+
275
+
177 276
 function newkey($pubkey, $handle)
178 277
 {
179 278
   global $key_dir, $config_dir;
... ...
@@ -231,7 +330,6 @@ function delete_key($handle)
231 330
     system_failure("Den angegebenen Key scheint es nicht zu geben");
232 331
   }
233 332
 
234
-  // FIXME: Muss man den SSH-Key auf Plausibilität prüfen? Aus Sicherheitsgründen vermutlich nicht.
235 333
   $keyfile = $key_dir.'/'.$handle.'.pub';
236 334
   if (! file_exists($keyfile)) {
237 335
     system_failure("Der angegebene Schlüssel scheint nicht mehr vorhanden zu sein. Bitte manuelle Korrektur anfordern!");
Browse code

Added license tags for CC0, README and COPYING

Bernd Wurst authored on11/03/2012 15:40:04
Showing1 changed files
... ...
@@ -1,4 +1,19 @@
1 1
 <?php
2
+/*
3
+This file belongs to the Webinterface of schokokeks.org Hosting
4
+
5
+Written 2008-2012 by schokokeks.org Hosting, namely
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
+
11
+You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
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
+
2 17
 require_role(ROLE_SYSTEMUSER);
3 18
 
4 19
 $data_dir = realpath( dirname(__FILE__).'/../data/' );
Browse code

Gitolite: Erzeuge include für die User-Config

git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2173 87cf0b9e-d624-0410-a070-f6ee81989793

bernd authored on07/02/2012 12:56:52
Showing1 changed files
... ...
@@ -188,6 +188,7 @@ function newkey($pubkey, $handle)
188 188
   if (! is_file($userconfig)) {
189 189
     DEBUG("user-config does not exist, creating new one");
190 190
     file_put_contents($userconfig, '# user '.$handle."\n");
191
+    set_user_include();
191 192
   } elseif (in_array($handle, list_users())) {
192 193
     # user ist schon eingetragen, nur neuer Key
193 194
   } else {
... ...
@@ -318,6 +319,34 @@ function delete_repo($repo)
318 319
   git_wrapper('push');
319 320
 }
320 321
 
322
+
323
+function set_user_include()
324
+{
325
+  global $config_file, $userconfig;
326
+  $username = $_SESSION['userinfo']['username'];
327
+  if (!file_exists($userconfig))
328
+  {
329
+    // Erzeuge eine leere Konfiguration damit das Include auf jeden Fall funktionieren kann
330
+    file_put_contents($userconfig, '');
331
+    git_wrapper('add '.$userconfig);
332
+  }
333
+  $found = false;
334
+  $data = file($config_file);
335
+  foreach ($data as $line) {
336
+    if (preg_match('#webinterface/'.$username.'\.conf#', $line)) {
337
+      $found = true;
338
+    }
339
+  }
340
+  if (!$found) {
341
+    $includeline = 'include  "webinterface/'.$username.'.conf"';
342
+    $data = chop(file_get_contents($config_file));
343
+    $data = $data."\n".$includeline."\n";
344
+    file_put_contents($config_file, $data);
345
+    git_wrapper('add '.$config_file);
346
+  }
347
+}
348
+
349
+
321 350
 function save_repo($repo, $permissions, $description) 
322 351
 {
323 352
   if (!validate_name($repo)) {
... ...
@@ -333,6 +362,7 @@ function save_repo($repo, $permissions, $description)
333 362
   $data = array();
334 363
   if (! is_file($userconfig)) {
335 364
     DEBUG("user-config does not exist, creating new one");
365
+    set_user_include();
336 366
   } else {
337 367
     $data = file($userconfig);
338 368
   }
Browse code

GIT-URL eingebaut

git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2098 87cf0b9e-d624-0410-a070-f6ee81989793

bernd authored on21/12/2011 16:51:54
Showing1 changed files
... ...
@@ -344,7 +344,7 @@ function save_repo($repo, $permissions, $description)
344 344
 
345 345
   $data[] = "\n";
346 346
   if ($description) {
347
-    $description = preg_replace('/[\'"\r\n/', '', $description);
347
+    $description = preg_replace('/\[\'"\r\n/', '', $description);
348 348
     $realname = $_SESSION['userinfo']['name'];
349 349
     $data[] = "{$repo} \"{$realname}\" = \"{$description}\"\n";
350 350
   }
Browse code

SSH-Key auf plausibilität prüfen

git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2097 87cf0b9e-d624-0410-a070-f6ee81989793

bernd authored on21/12/2011 16:51:54
Showing1 changed files
... ...
@@ -169,9 +169,18 @@ function newkey($pubkey, $handle)
169 169
     system_failure("Der eingegebene Name enthält ungültige Zeichen. Bitte nur Buchstaben, Zahlen, Unterstrich, Binderstrich und Punkt benutzen.");
170 170
   }
171 171
 
172
-  // FIXME: Muss man den SSH-Key auf Plausibilität prüfen? Aus Sicherheitsgründen vermutlich nicht.
173 172
   $keyfile = $key_dir.'/'.$handle.'.pub';
174 173
   file_put_contents($keyfile, $pubkey);
174
+  
175
+  $proc = popen("/usr/bin/ssh-keygen -l -f '{$keyfile}'", 'r');
176
+  $output = fread($proc, 512);
177
+  pclose($proc);
178
+  if (preg_match('/.* is not a public key file.*/', $output)) {
179
+    unlink($keyfile);
180
+    system_failure('Der angegebene SSH-Key scheint ungültig zu sein.');
181
+  }
182
+  
183
+
175 184
   git_wrapper('add '.$keyfile);
176 185
 
177 186
   $userconfig = $config_dir . '/' . $username . '.conf';
Browse code

Sortiere Repositories und USer alphabetisch

git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2096 87cf0b9e-d624-0410-a070-f6ee81989793

bernd authored on21/12/2011 16:51:54
Showing1 changed files
... ...
@@ -112,6 +112,7 @@ function list_repos()
112 112
   if ($current_repo) {
113 113
     $repos[$current_repo]['users'] = $current_repo_users;
114 114
   }
115
+  ksort($repos);
115 116
   DEBUG($repos);
116 117
   return $repos;
117 118
 }
... ...
@@ -139,6 +140,7 @@ function list_users() {
139 140
       break;
140 141
     }
141 142
   }
143
+  sort($users);
142 144
   DEBUG($users);
143 145
   return $users;
144 146
 }
... ...
@@ -333,6 +335,7 @@ function save_repo($repo, $permissions, $description)
333 335
 
334 336
   $data[] = "\n";
335 337
   if ($description) {
338
+    $description = preg_replace('/[\'"\r\n/', '', $description);
336 339
     $realname = $_SESSION['userinfo']['name'];
337 340
     $data[] = "{$repo} \"{$realname}\" = \"{$description}\"\n";
338 341
   }
Browse code

Setze Berechtigung für gitweb und Beschreibung

git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2094 87cf0b9e-d624-0410-a070-f6ee81989793

bernd authored on21/12/2011 16:51:53
Showing1 changed files
... ...
@@ -88,9 +88,18 @@ function list_repos()
88 88
   foreach ($lines as $line) {
89 89
     DEBUG("LINE: ".$line);
90 90
     $m = array();
91
-    if (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
91
+    if (preg_match('/^(\S+) "[^"]+" = "([^"]+)"$/', $line, $m) != 0) {
92
+      if (!array_key_exists($m[1], $repos)) {
93
+        $repos[$m[1]] = array('users' => NULL, 'description' => '');
94
+      }
95
+      DEBUG("found description: {$m[1]} = \"{$m[2]}\"");
96
+      $repos[$m[1]]['description'] = $m[2];
97
+    } elseif (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
98
+      if (!array_key_exists($m[1], $repos)) {
99
+        $repos[$m[1]] = array('users' => NULL, 'description' => '');
100
+      }
92 101
       if ($current_repo) {
93
-        $repos[$current_repo] = $current_repo_users;
102
+        $repos[$current_repo]['users'] = $current_repo_users;
94 103
       }
95 104
       DEBUG("found repo ".$m[1]);
96 105
       $current_repo = chop($m[1]);
... ...
@@ -101,7 +110,7 @@ function list_repos()
101 110
     }
102 111
   }
103 112
   if ($current_repo) {
104
-    $repos[$current_repo] = $current_repo_users;
113
+    $repos[$current_repo]['users'] = $current_repo_users;
105 114
   }
106 115
   DEBUG($repos);
107 116
   return $repos;
... ...
@@ -241,12 +250,17 @@ function remove_repo_from_array($data, $repo) {
241 250
   DEBUG("Request to remove repo »{$repo}«...");
242 251
   $inside = false;
243 252
   $outdata = array();
253
+  $blank = true;
244 254
   foreach ($data as $line) {
255
+    if ($blank && chop($line) == '') {
256
+      continue;
257
+    }
258
+    $blank = (chop($line) == '');
245 259
     $m = array();
246 260
     if (preg_match('_^\s*repo (\S+)\s*$_', $line, $m) != 0) {
247 261
       $inside = ($m[1] == $repo);
248 262
     }
249
-    if (! $inside) {
263
+    if (! $inside && ! preg_match('/^'.$repo.'\s.*/', $line)) {
250 264
       $outdata[] = $line;
251 265
     }
252 266
   }
... ...
@@ -293,7 +307,7 @@ function delete_repo($repo)
293 307
   git_wrapper('push');
294 308
 }
295 309
 
296
-function save_repo($repo, $permissions) 
310
+function save_repo($repo, $permissions, $description) 
297 311
 {
298 312
   if (!validate_name($repo)) {
299 313
     system_failure("Der gewählte name entspricht nicht den Konventionen!");
... ...
@@ -318,6 +332,10 @@ function save_repo($repo, $permissions)
318 332
   }
319 333
 
320 334
   $data[] = "\n";