-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.php
More file actions
118 lines (103 loc) · 3.02 KB
/
build.php
File metadata and controls
118 lines (103 loc) · 3.02 KB
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
<?php
//Flydragon<ipv6china@comsenz.com
$pageTitle="发布配置文件";
include_once("common.php");
include_once("view/header.php");
define('DEBUG',false);
if($_SERVER['REQUEST_METHOD'] == 'POST'){
/////// httpasswd
$fp=fopen($releaseDir.'/httpasswd','wb+');
if(!$fp) die("Can't open httpasswd file!");
$pwContent='';
$allUsers=$redis->sMembers('user:all');
sort($allUsers);
foreach($allUsers as $user){
$passwd=$redis->hGet('user:'.$user.':info', 'password');
$username=$redis->hGet('user:'.$user.':info', 'username');
$department=$redis->hGet('user:'.$user.':info', 'department');
$pwContent.="# $username $department\n$user:$passwd\n\n";
}
//写入文件
if(fwrite($fp, $pwContent) === FALSE){
die("无法写入文件httpasswd");
}
fclose($fp);
if(DEBUG){
print <<<EOT
<h2>密码文件httpasswd</h2>
<pre>
$pwContent
</pre>
EOT;
}
////// authz
$fp=fopen($releaseDir.'/authz', 'wb+');
if(!$fp) die("Can't open httpasswd file!");
$authContent='';
$authContent.="[groups]\n";
$allGroups=$redis->sMembers('group:all');
sort($allGroups);
//组列表
foreach($allGroups as $group){
$members=implode(',',$redis->sMembers('group:'.$group.':members'));
$groupname=$redis->hGet('group:'.$group.':info', 'groupname');
$department=$redis->hGet('group:'.$group.':info', 'department');
$authContent.="# $groupname $department\n$group = $members\n";
}
$authContent.="\n";
function createPath($projectpath){
$count = substr_count($projectpath, '/');
if($count == 1)
$projectpath=str_replace('/','',$projectpath).':/';
else {
$projectpath=preg_replace("/\/(\w+)\/(.*)/i","\${1}:/\$2",$projectpath);
}
$r="[$projectpath]";
return $r;
}
//项目及授权列表
$allProjects=$redis->sMembers('project:all');
sort($allProjects);
foreach($allProjects as $projectpath){
$project=md5($projectpath);
$projectname=$redis->hGet('project:'.$project.':info', 'projectname');
$department=$redis->hGet('project:'.$project.':info', 'department');
$authContent .= "# $projectname $department \n". createPath($projectpath)."\n";
$ros=$redis->sMembers('project:'.$project.':ro');
$grws=$redis->sMembers('project:'.$project.':grw');
$gros=$redis->sMembers('project:'.$project.':gro');
$rws=$redis->sMembers('project:'.$project.':rw');
foreach($grws as $grw)
$authContent.="@$grw = rw\n";
foreach($gros as $gro)
$authContent.="@$gro = r\n";
foreach($rws as $rw)
$authContent.="$rw = rw\n";
foreach($ros as $ro)
$authContent.="$ro = r\n";
$authContent.="* = \n\n";
}
//写入文件
if(fwrite($fp, $authContent) === FALSE){
die("无法写入文件authz");
}
fclose($fp);
echo "<h1> 发布成功</h1>";
if(DEBUG){
print <<<EOT
<h2>认证文件authz</h2>
<pre>
$authContent
</pre>
EOT;
}
backupDatabase($redis,$_POST['buildmsg']);
} else {
print <<<EOT
<h1>$pageTitle</h1>
<form action="build.php" method=POST>
发布原因:<input type="text" name="buildmsg" value="" style="width:200px;">
<input type="submit" >
</form>
EOT;
}