心's profile真心的家PhotosBlogLists Tools Help

Blog


    May 09

    Subversion配置安装教程(二)

       今天接着昨天的内容讲Subversion的安全配置。在上一讲中我们在Apache的httpd.conf文件里加入了这样一节:
    <Location /svn>
    DAV svn
    SVNParentPath e:\SVN
    AuthType Basic
    AuthName "Subversion repositories"
    AuthUserFile passwd
    #AuthzSVNAccessFile svnaccessfile
    Require valid-user
    </Location> 
        下面我来解释一下这些配置信息用途:
    <Location /svn>
     说明我们所有的代码仓库在/svn这个虚拟目录下
     
    DAV svn
     说明Apache会使用svn这个module来解析这个虚拟目录
     
    SVNParentPath e:\SVN
     说明所有的代码仓库都在本地硬盘的e:\SVN下
     
    AuthType Basic
     使用最基本的认证校验,用户名/密码
     
    AuthName "Subversion repositories"
     说明在认证对话框弹出的时候,对话框的标题显示,你可以把它修改成你想要的任何提示信息,比如:AuthName "Warning"等等
     
    AuthUserFile passwd
     说明我们使用的access list文件的名字,在上一讲中我们建立的文件名字是passwd,所以这里是passwd。如果你建立的文件名字是其他的,这里要作相应的改动
     
    AuthzSVNAccessFile
     说明svn自己控制的access list文件,这个文件很重要,可以丰富svn的安全配置,在下面会讲到
     
    Require valid-user
     说明只有输入正确的用户名/密码才能访问
     

    上述的配置只能是最简单的安全配置,如果你想拥有更强大的安全配置,就需要加入一些东西了。比如:
    如果你想让所有的匿名用户能访问代码仓库,对某些特定用户才开放可写的权限,则需要把 
    Require valid-user
    改成
    <LimitExcept GET PROPFIND OPTIONS REPORT>
    Require valid-user
    </LimitExcept>
    如果你对于代码仓库里面某些目录还有更细致的访问控制,只用passwd就没办法啦,这个时候我们就需要AuthzSVNAccessFile文件了,去掉#AuthzSVNAccessFile svnaccessfile这一行前面的注释。Apache首先会使用passwd校验用户名和密码,然后会认证信息传给Subversion的AuthzSVNAccessFile模块,由这个模块作更进一步的权限控制。首先我们来新建一个文件svnaccessfile,内容如下:
    [groups]
    developers = user1,user2,user3,user4
    docs = user5,user6,user7
    #to allow everyone read access
    [/]
    * = r
    #allow all developers complete access
    @developers = rw
    #give the doc people write access to the docs folder
    [/project/trunk/doc]
    @docs = rw
    首先我们定义了两个group,一个是developer,代表开发组,另外一个是docs,代表文档撰写组,然后
    [/]
    * = r
    意思是对于所有的用户开放可读的权限。注意这里的[/],表示是对根目录下的所有代码仓库赋予权限。接着是
    @developers = rw
    [/project/trunk/doc]
    @docs=rw                                                                                                                                                                                                                                                                  这这里的@应该代表的是group的意思(这个还没有确认,是我自己猜测的,因为如果是直接给单一用户赋予权限,则不需要前面的@,哪位大侠可以证实一下我的猜测?欢迎指教)注意这里对于docs这个组,我们一样指定了目录路径,而不是对于整个代码仓库。
        这里再说说SVNParentPath,配置了SVNParentPath,以后每次在根目录下面加入新的repository就不需要再重新配置Subversion和Apache了,自动获取了根目录的配置信息,很方便。然而这也引发了另外一个问题,当你在浏览器地址栏里输入http://youserver/svn/的时候,服务器会报错,提示你没有权限访问访问这个url,我们想要的效果是浏览到这个url时能够把根目录下的所有的repository列出来。完成这个工作需要写点代码了,使用的工具可以是很多,这里使用php,当然我想用perl或者python一定是没有问题。首先要安装php,使apache支持php. 以下是参考了shg918的文档,在此表示感谢!

    首先去http://www3.skycn.com/soft/9122.html 下载php4.3.1,接下来我们来手动配置一下apache。
    将下载的php压缩文件解压,文件夹改名为php复制到你想放置的目录路径下,注意目录名不能有空格,否则apache会找不到相关的module,比如D:/php-4.3.10RC1-Win32。
    打开刚才解压的PHP目录,你会发现有一个叫做"php.ini-dist"的文件,这就是PHP的配置文件了,你需要把它改名成"php.ini",然后复制到系统目录windows(2K应该是winnt)下。打开这个配置文件,把; cgi.force_redirect = 1改成 cgi.force_redirect = 0,这样做是强迫不运行在cgi模式下,我们希望php工作在Apache的module模式下。
    PHP安装目录下的"php4ts.dll"必须要复制到windows系统的system32目录下。
    dlls和extensions目录里的所有文件拷到system32里。(我猜测这里是为了支持mysql等才需要作的,可能对我们来说并不需要。)
    打开Apache的配置文件http.conf,在module配置节末尾加上LoadModule php4_module D:/php-4.3.10RC1-Win32/sapi/php4apache2.dll和AddType application/x-httpd-php .php .php3 .php4
    Ok,配置完毕,现在Apache可以支持php了。现在用文本编辑器编写一个php文件,保存为svn_index.php,内容如下:
     
     
    <html>
     
    <head>
     
    <title>Subversion Repositories</title>
     
    </head>
     
    <body>
     
     
     
    <h2>Subversion Repositories</h2>
     
    <p>
     
    <?php
     
        $svnparentpath = "e:/svn";
     
        $svnparenturl = "/svn";
     
     
     
        $dh = opendir( $svnparentpath );
     
        if( $dh ) {
     
            while( $dir = readdir( $dh ) ) {
     
                $svndir = $svnparentpath . "/" . $dir;
     
                $svndbdir = $svndir . "/db";
     
                $svnfstypefile = $svndbdir . "/fs-type";
     
                if( is_dir( $svndir ) && is_dir( $svndbdir ) ) {
     
                    echo "<a href=\"" . $svnparenturl . "/" .
     
                            $dir . "\">" . $dir . "</a>\n";
     
                    if( file_exists( $svnfstypefile ) ) {
     
                        $handle = fopen ("$svnfstypefile", "r");
     
                        $buffer = fgets($handle, 4096);
     
                        fclose( $handle );
     
                        $buffer = chop( $buffer );
     
                        if( strcmp( $buffer, "fsfs" )==0 ) {
     
                            echo " (FSFS) <br />\n";
     
                        } else {
     
                            echo " (BDB) <br />\n";
     
                        }
     
                    } else {
     
                        echo " (BDB) <br />\n";
     
                    }
     
                }
     
            }
     
            closedir( $dh );
     
        }
     
    ?>
     
    </p>
     
    </body>
     
    </html>
     
    上述php文件中svnparentpath = "e:/svn";需要注意,你的subversion的代码仓库的根目录可能并不在e:/svn,请修改和你自己设置一样的路径。更改Apache的配置文件http.conf文件,把#LoadModule rewrite_module modules/mod_rewrite.so前面的注释去掉。然后在文件末尾加上如下几句:
    RewriteEngine on
    RewriteRule ^/svn$ /svn_index.php [PT]
    RewriteRule ^/svn/$ /svn_index.php [PT]
    RewriteRule ^/svn/index.html$ /svn_index.php [PT]
    好了,请从新在浏览器地址栏中输入http://youserver/svn ,你会发现Apache会把当前Subversion根目录下的所有代码仓库列出来了。如图

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://zhenxin0603.spaces.live.com/blog/cns!A7EBA72EFE1604C5!136.trak
    Weblogs that reference this entry
    • None