Gitolite: Erzeuge include für die User-Config
bernd

bernd commited on 2012-02-07 12:56:52
Zeige 1 geänderte Dateien mit 30 Einfügungen und 0 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@2173 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -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
   }
339 369