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
Showing4 changed files
... ...
@@ -6,7 +6,6 @@ include("git.php");
6 6
 $section = 'git_git';
7 7
 
8 8
 $repos = list_repos();
9
-
10 9
 $users = list_users();
11 10
 
12 11
 $action = '';
... ...
@@ -28,9 +27,9 @@ $form .= '<tr><td>Berechtigungen</td><td>';
28 27
 foreach ($users as $user) {
29 28
   $r = $rw = $rwplus = '';
30 29
   if (isset($_GET['repo']) && isset($repos[$_GET['repo']])) {
31
-    $repo = $repos[$_GET['repo']];
32
-    if (isset($repo[$user])) {
33
-      switch ($repo[$user]) {
30
+    $permissions = $repos[$_GET['repo']]['users'];
31
+    if (isset($permissions[$user])) {
32
+      switch ($permissions[$user]) {
34 33
         case 'RW+': $rwplus = ' selected="selected"';
35 34
                     break;
36 35
         case 'RW': $rw = ' selected="selected"';
... ...
@@ -40,8 +39,12 @@ foreach ($users as $user) {
40 39
       }
41 40
     }
42 41
   }
43
-  $form .= $user.': <select name="'.$user.'"><option value="-">Zugriff verweigern</option><option value="r"'.$r.'>Lesezugriff erlauben</option><option value="rw"'.$rw.'>Lese- und Schreibzugriff</option><option value="rwplus"'.$rwplus.'>erweiterter Lese- und Schreibzugriff (inkl. &quot;rewind&quot;)</option></select><br />';
42
+  $form .= '<p>'.$user.': <select name="'.$user.'"><option value="-">Zugriff verweigern</option><option value="r"'.$r.'>Lesezugriff erlauben</option><option value="rw"'.$rw.'>Lese- und Schreibzugriff</option><option value="rwplus"'.$rwplus.'>erweiterter Lese- und Schreibzugriff (inkl. &quot;rewind&quot;)</option></select></p>';
44 43
 }
44
+$checked = (isset($_GET['repo']) && isset($repos[$_GET['repo']]) && isset($repos[$_GET['repo']]['users']['gitweb']) && $repos[$_GET['repo']]['users']['gitweb'] == 'R') ? ' checked="checked"' : '';
45
+$description = (isset($_GET['repo']) && isset($repos[$_GET['repo']])) ? $repos[$_GET['repo']]['description'] : '';
46
+$form .= '<p><input type="checkbox" name="gitweb" id="gitweb" value="r"'.$checked.' /> <label for="gitweb">Öffentlicher Lesezugriff via gitweb</label><br />
47
+<label for="description">Beschreibung des Repository:</label> <input type="text" name="description" id="description" value="'.$description.'" /></p>';
45 48
 $form .= '</td></tr></table>';
46 49
 $form .= '<p><input type="submit" value="Speichern" /></p>';
47 50
 
... ...
@@ -18,10 +18,11 @@ if (count($repos) == 0) {
18 18
   output("<h3>Ihre GIT-Repositories</h3>"); 
19 19
 }
20 20
 
21
-foreach ($repos as $repo => $access) {
21
+foreach ($repos as $repo => $settings) {
22
+  $description = $settings['description'] ? '<br /><em>"'.$settings['description'].'"</em>' : '';
22 23
   $url = get_git_url($repo);
23
-  output("<div><p><strong>{$repo}</strong> ".internal_link('edit', icon_edit('Zugriffsrechte bearbeiten'), 'repo='.$repo)." ".internal_link('delete', icon_delete('Repository löschen'), 'repo='.$repo)."<br />{$url}</p><ul>");
24
-  foreach ($access as $user => $rights) {
24
+  output("<div><p><strong>{$repo}</strong> ".internal_link('edit', icon_edit('Zugriffsrechte bearbeiten'), 'repo='.$repo)." ".internal_link('delete', icon_delete('Repository löschen'), 'repo='.$repo)."{$description}<br />{$url}</p><ul>");
25
+  foreach ($settings['users'] as $user => $rights) {
25 26
     $grant = '';
26 27
     switch ($rights) {
27 28
       case 'R': $grant = 'Lesezugriff';
... ...
@@ -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";
335
+  if ($description) {
336
+    $realname = $_SESSION['userinfo']['name'];
337
+    $data[] = "{$repo} \"{$realname}\" = \"{$description}\"\n";
338
+  }
321 339
   $data[] = 'repo '.$repo."\n";
322 340
   foreach ($permissions as $user => $perm) {
323 341
     $data[] = '  '.$perm.' = '.$user."\n";
... ...
@@ -43,7 +43,11 @@ if ($_GET['action'] == 'newuser') {
43 43
       }
44 44
     }
45 45
   }
46
-  save_repo($_POST['repo'], $permissions);
46
+  if ($_POST['gitweb'] == 'r') {
47
+    $permissions['gitweb'] = 'R';
48
+  }
49
+  $description = $_POST['description'];
50
+  save_repo($_POST['repo'], $permissions, $description);
47 51
   if (! $debugmode)
48 52
     header('Location: git');
49 53
   die();