Indefero

Indefero Commit Details


Date:2008-12-03 14:04:32 (16 years 18 days ago)
Author:Baptiste Michaud
Branch:dev, develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:39cf9f985aaf55eab38765e1f004922174bae88b
Parents: 7cc244ec06feafab75f636703d02e9f4c611f693
Message:Added a plugin to synchronize subversion repositories.

Changes:

File differences

src/IDF/Plugin/SyncSvn.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008 CĂ©ondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
require_once 'File/Passwd/Authdigest.php'; // $ pear install File_Passwd
/**
* This classes is a plugin which allows to synchronise access rights between indefero
* and a DAV powered SVN repository.
*/
class IDF_Plugin_SyncSvn
{
/**
* Entry point of the each plugins.
*/
static function entry($signal, $params){
// if not actif, do nothing
if ($signal == 'IDF_Project::created'){
$project = $params['project'];
$plug = new IDF_Plugin_SyncSVN();
//$plug->processSVNCreate($project->shortname);
}else if ($signal == 'IDF_Project::membershipsUpdated'){
$project = $params['project'];
$plug = new IDF_Plugin_SyncSVN();
$plug->processSyncAuthz($project);
}else if ($signal == 'IDF_User::passwordUpdated'){
$plug = new IDF_Plugin_SyncSVN();
$plug->processSyncPasswd($params['user']);
}else {
// do nothing
}
}
/**
* Run svnadmin command to create a usable SVN repository
* @param Project name
*/
function processSVNCreate($shortname){
$svn_path = Pluf::f('idf_plugin_syncsvn_svn_path');
$svn_import_path = Pluf::f('idf_plugin_syncsvn_svn_import_path');
$chown_user = Pluf::f('idf_plugin_syncsvn_svn_import_path');
$c = 0;
$createsvn = "svnadmin create ".$svn_path."/".$shortname;
Pluf_Utils::runExternal($createsvn, $c);
if ($svn_import_path != ""){
//perform initial import
// TODO
}
if ($chown_user != ""){
$chown = "chown ".$chown_user." ".$svn_path."/".$shortname." -R";
Pluf_Utils::runExternal($chown, $c);
}
}
/**
* Synchronise an user's password
* @param $user Pluf_User
*/
function processSyncPasswd($user){
$passwd_file = Pluf::f('idf_plugin_syncsvn_passwd_file');
$ht = new File_Passwd_Authbasic($passwd_file);
$ht->parse();
$ht->setMode(FILE_PASSWD_SHA); // not anymore a option
$ht->addUser($user, $this->getSVNPass($user));
$ht->save();
}
/**
* Synchronize the authz file and the passwd file for the project
* @param $project IDF_Project
*/
function processSyncAuthz($project){
//synchronise authz file
$this->SyncAccess();
//synchronise pass file for
$this->generateProjectPasswd($project);
}
/**
* Get the repository password for the user
*/
function getSVNPass($user){
return substr(sha1($user->password.Pluf::f('secret_key')), 0, 8);
}
/**
* For a particular project: update all passwd information
*/
function generateProjectPasswd($project){
$passwd_file = Pluf::f('idf_plugin_syncsvn_passwd_file');
$ht = new File_Passwd_Authbasic($passwd_file);
$ht->setMode(FILE_PASSWD_SHA); // not anymore a option
$ht->parse();
$mem = $project->getMembershipData();
$members = $mem['members'];
$owners = $mem['owners'];
foreach($owners as $v){
$ht->addUser($v->login, $this->getSVNPass($v));
}
foreach($members as $v){
$ht->addUser($v->login, $this->getSVNPass($v));
}
$ht->save();
}
/**
* Generate the dav_svn.authz file
*/
function SyncAccess(){
$authz_file = Pluf::f('idf_plugin_syncsvn_authz_file');
$access_owners = Pluf::f('idf_plugin_syncsvn_access_owners');
$access_members = Pluf::f('idf_plugin_syncsvn_access_members');
$access_all = Pluf::f('idf_plugin_syncsvn_access_all');
$access_all_pivate = Pluf::f('idf_plugin_syncsvn_access_all_pivate');
$projects = Pluf::factory('IDF_Project')->getList();
$fcontent = "";
// for each project
foreach($projects as $project){
$conf = new IDF_Conf();
$conf->setProject($project);
if ($conf->getVal('scm', "") == "svn"){
$mem = $project->getMembershipData();
$members = $mem['members'];
$owners = $mem['owners'];
// [shortname:/]
$fcontent .= "[".$project->shortname.":/]\n";
// login = rw
foreach($owners as $v){
$fcontent .= $v->login." = ".$access_owners."\n";
}
// login = rw
foreach($members as $v){
$fcontent .= $v->login." = ".$access_members."\n";
}
// access for all users
if ($project->private == true){
$fcontent .= "* = ".$access_all_pivate."\n";
}else{
$fcontent .= "* = ".$access_all."\n";
}
$fcontent .= "\n";
} //end if SVN
}
file_put_contents($authz_file, $fcontent, LOCK_EX);
return 0;
}
}
?>

Archive Download the corresponding diff file

Page rendered in 0.07395s using 13 queries.