Index: trunk/tools/subversion/users.php |
— | — | @@ -0,0 +1,69 @@ |
| 2 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> |
| 4 | +<head> |
| 5 | +<title>Wikimedia Subversion user list</title> |
| 6 | +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 7 | +</head> |
| 8 | +<body> |
| 9 | +<h1>Wikimedia Subversion user list</h1> |
| 10 | +<table border="1"> |
| 11 | +<tr> |
| 12 | +<th>Username</th> |
| 13 | +<th>Real name</th> |
| 14 | +</tr> |
| 15 | +<?php |
| 16 | + |
| 17 | +$time = microtime( true ); |
| 18 | +$lines = file( '/etc/passwd' ); |
| 19 | +exec( "HOME=/tmp /usr/bin/svn up /var/cache/svnusers 2>&1", $output, $retval ); |
| 20 | +if ( $retval ) { |
| 21 | + $error = implode( "\n", $output ); |
| 22 | +} else { |
| 23 | + $error = false; |
| 24 | +} |
| 25 | + |
| 26 | +foreach ( $lines as $line ) { |
| 27 | + $parts = explode( ':', trim( $line ) ); |
| 28 | + if ( !isset( $parts[2] ) || $parts[2] < 501 ) { |
| 29 | + continue; |
| 30 | + } |
| 31 | + $userInfo = getUserInfo( $parts[0] ); |
| 32 | + $encUsername = htmlspecialchars( $parts[0] ); |
| 33 | + $userInfo = array_map( 'htmlspecialchars', $userInfo ); |
| 34 | + $link = $userInfo['url'] ? "<a href=\"{$userInfo['url']}\">$encUsername</a>" : $encUsername; |
| 35 | + |
| 36 | + $rows[$parts[0]] = <<<EOT |
| 37 | +<tr> |
| 38 | +<td>$link</td> |
| 39 | +<td>{$userInfo['name']}</td> |
| 40 | +</tr> |
| 41 | + |
| 42 | +EOT; |
| 43 | +} |
| 44 | +ksort( $rows ); |
| 45 | +echo implode( '', $rows ) . "</table>\n"; |
| 46 | +echo "<!-- Request time: " . ( microtime( true ) - $time ) . " -->\n"; |
| 47 | +if ( $retval ) { |
| 48 | + echo "<p>Error: " . htmlspecialchars( $error ) . "</p>\n"; |
| 49 | +} |
| 50 | +echo "</html>\n"; |
| 51 | + |
| 52 | +function getUserInfo( $userName ) { |
| 53 | + $userInfo = array( |
| 54 | + 'name' => '', |
| 55 | + 'url' => '' |
| 56 | + ); |
| 57 | + $userFileLines = @file( "/var/cache/svnusers/$userName" ); |
| 58 | + if ( $userFileLines ) { |
| 59 | + foreach ( $userFileLines as $userLine ) { |
| 60 | + if ( preg_match( '/^([\w-]+):\s*(.*?)\s*$/', $userLine, $m ) ) { |
| 61 | + $field = strtolower( $m[1] ); |
| 62 | + $value = $m[2]; |
| 63 | + $userInfo[$field] = $value; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + return $userInfo; |
| 68 | +} |
| 69 | + |
| 70 | +?> |
Property changes on: trunk/tools/subversion/users.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 71 | + native |
Index: trunk/tools/subversion/add-svn-user |
— | — | @@ -0,0 +1,51 @@ |
| 2 | +#!/bin/bash |
| 3 | + |
| 4 | +name="$1" |
| 5 | +keyfile="$2" |
| 6 | +tmpfile= |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +if [ -z "$keyfile" ] |
| 11 | +then |
| 12 | + echo "Usage: add-svn-user <username> <keyfile>" |
| 13 | + echo "The keyfile should contain the user's SSH public key, and will be copied" |
| 14 | + echo "to their ~/.ssh/authorized_keys." |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +if [ "${keyfile:0:7}" == "http://" -o "${keyfile:0:8}" == "https://" ]; then |
| 19 | + echo "Fetching key file" |
| 20 | + url="$keyfile" |
| 21 | + tmpfile=`mktemp /tmp/add-svn-user.XXXXXXXX` |
| 22 | + keyfile="$tmpfile" |
| 23 | + wget -O "$keyfile" "$url" |
| 24 | +fi |
| 25 | + |
| 26 | +echo "Creating user $name" |
| 27 | +/usr/sbin/useradd -G svn -s /usr/local/bin/sillyshell "$name" |
| 28 | + |
| 29 | +echo "Creating /home/$name" |
| 30 | +mkdir -m 0700 "/home/$name" |
| 31 | + |
| 32 | +echo "Creating /home/$name/.ssh" |
| 33 | +mkdir -m 0700 "/home/$name/.ssh" |
| 34 | + |
| 35 | +echo "Creating /home/$name/.ssh/authorized_keys" |
| 36 | + |
| 37 | +if grep -q 'BEGIN SSH2 PUBLIC KEY' "$keyfile"; then |
| 38 | + ssh-keygen -i -f "$keyfile" > "/home/$name/.ssh/authorized_keys" |
| 39 | +else |
| 40 | + cp "$keyfile" "/home/$name/.ssh/authorized_keys" |
| 41 | +fi |
| 42 | +chmod 600 "/home/$name/.ssh/authorized_keys" |
| 43 | + |
| 44 | +echo "Fixing file ownership" |
| 45 | +chown -R "$name:$name" "/home/$name" |
| 46 | + |
| 47 | +if [ -n "$tmpfile" ]; then |
| 48 | + rm -f "$tmpfile" |
| 49 | +fi |
| 50 | + |
| 51 | +echo "Done." |
| 52 | + |
Property changes on: trunk/tools/subversion/add-svn-user |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 53 | + native |
Added: svn:executable |
2 | 54 | + * |