/[gforge]/gforge/cronjobs/cvs-cron/usergroup.php
ViewVC logotype

Contents of /gforge/cronjobs/cvs-cron/usergroup.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Tue Mar 4 17:16:44 2003 UTC (21 years, 2 months ago) by bigdisk
Branch: MAIN
CVS Tags: debian_version_3_0-rc1
further cleanup of the backend scripts - almost done

1 #! /usr/bin/php4 -f
2 <?php
3
4 require_once('squal_pre.php');
5
6 //
7 // Default values for the script
8 //
9 define('DEFAULT_SHELL','/bin/grap');
10 define('USER_ID_ADD',10000);
11 define('GROUP_ID_ADD',50000);
12 define('USER_DEFAULT_GROUP','users');
13
14 //
15 // Get the users' unix_name and password out of the database
16 // ONLY USERS WITH CVS COMMIT PRIVS ARE ADDED
17 //
18 $res = db_query("SELECT distinct users.user_name,users.unix_pw,users.user_id
19 FROM users,user_group
20 WHERE users.user_id=user_group.user_id
21 AND user_group.cvs_flags='1'
22 AND users.status='A'
23 ORDER BY user_id ASC");
24
25 $users =& util_result_column_to_array($res,'user_name');
26 $user_ids =& util_result_column_to_array($res,'user_id');
27 $user_pws =& util_result_column_to_array($res,'unix_pw');
28
29 //
30 // Read in the "default" users
31 //
32 $h = fopen("/etc/passwd.org","r");
33 $passwdcontents = fread($h,filesize("/etc/passwd.org"));
34 fclose($h);
35 $passwdlines = explode("\n",$passwdcontents);
36
37 //
38 // Write the "default" users to a temp file
39 //
40 $h2 = fopen("/etc/passwd.new","w");
41 for($k = 0; $k < count($passwdlines); $k++) {
42 $passwdline = explode(":",$passwdlines[$k]);
43 $def_users[$passwdline[0]]=1;
44 fwrite($h2,$passwdlines[$k]."\n");
45 }
46
47 //
48 // Now append the users from the gforge database
49 //
50 for($i = 0; $i < count($users); $i++) {
51
52 if ($def_users[$users[$i]]) {
53
54 //this username was already existing in the "default" file
55
56 } else {
57
58 $line = $users[$i] . ":x:" . ($user_ids[$i] + USER_ID_ADD) . ":" . ($user_ids[$i] + USER_ID_ADD) . "::/home/$users[$i]:".DEFAULT_SHELL."\n";
59 fwrite($h2,$line);
60
61 }
62
63 }
64
65 fclose($h2);
66
67 //
68 // this is where we add users to /etc/shadow
69 //
70 $h3 = fopen("/etc/shadow.org","r");
71 $shadowcontents = fread($h3,filesize("/etc/shadow.org"));
72 fclose($h3);
73 $shadowlines = explode("\n",$shadowcontents);
74
75 //
76 // Write the "default" shadow to a temp file
77 //
78 $h4 = fopen("/etc/shadow.new","w");
79 for($k = 0; $k < count($shadowlines); $k++) {
80 $shadowline = explode(":",$shadowlines[$k]);
81 $def_shadow[$shadowline[0]]=1;
82 fwrite($h4,$shadowlines[$k]."\n");
83 }
84
85 //
86 // Now append the users from the gforge database
87 //
88 for($i = 0; $i < count($users); $i++) {
89
90 if ($def_shadow[$users[$i]]) {
91
92 //this username was already existing in the "default" file
93
94 } else {
95
96 $line = $users[$i] . ":" . $user_pws[$i] . ":12090:0:99999:7:::\n";
97 fwrite($h4,$line);
98
99 }
100
101 }
102
103 fclose($h4);
104
105 //
106 // Read the groups from the "default" file
107 //
108 $h5 = fopen("/etc/group.org","r");
109 $groupcontents = fread($h5,filesize("/etc/group.org"));
110 fclose($h5);
111 $grouplines = explode("\n",$groupcontents);
112
113 //
114 // Write the "default" groups to a temp file
115 //
116 $h6 = fopen("/etc/group.new","w");
117 for($k = 0; $k < count($grouplines); $k++) {
118 $groupline = explode(":",$grouplines[$k]);
119 $def_group[$groupline[0]]=1;
120 fwrite($h6,$grouplines[$k]."\n");
121 }
122
123 //
124 // Add the groups from the gforge database
125 //
126 $res=db_query("SELECT group_id,unix_group_name FROM groups WHERE status='A'");
127 for($i = 0; $i < db_numrows($res); $i++) {
128 $groups[] = db_result($res,$i,'unix_group_name');
129 $gids[db_result($res,$i,'unix_group_name')]=db_result($res,$i,'group_id')+GROUP_ID_ADD;
130 }
131
132 for($i = 0; $i < count($users); $i++) {
133
134 if ($def_group[$groups[$i]]) {
135
136 //this username was already existing in the "default" file
137
138 } else {
139
140 $line = $groups[$i] . ":x:" . ($gids[$groups[$i]]) . ":\n";
141
142 fwrite($h6, $line);
143
144 }
145
146 }
147
148 fclose($h6);
149
150 //
151 // have to re-read the group file since we just modified it
152 //
153 $h7 = fopen("/etc/group.new","r");
154 $groupcontent = fread($h7,filesize("/etc/group.new"));
155 fclose($h7);
156
157 $grouplines = explode("\n",$groupcontent);
158
159 //
160 // this is where we add users to groups in /etc/groups
161 //
162 for($i = 0; $i < count($users); $i++) {
163 $res6 = db_query("select groups.group_id,groups.unix_group_name
164 FROM user_group,groups
165 WHERE user_group.user_id='$user_ids[$i]'
166 AND groups.group_id=user_group.group_id");
167 $rows = db_numrows($res6);
168
169 for($k = 0; $k < $rows; $k++) {
170 $group_id = db_result($res6,$k,'group_id');
171 $group = db_result($res6,$k,'unix_group_name');
172
173 for($j = 0; $j < count($grouplines); $j++) {
174 list($group_name,$group_pw,$group_id,$members) = explode(":",$grouplines[$j]);
175
176 if($group_name == $group) {
177 $memberslist = explode(",",$members);
178
179 foreach($memberslist as $member) {
180 if($member == $users[$i]) {
181 continue 3;
182 }
183 }
184 if($memberslist[0] == "" && count($memberslist) == 1)
185 $grouplines[$j] = $grouplines[$j] . "$users[$i]";
186 else
187 $grouplines[$j] = $grouplines[$j] . ",$users[$i]";
188 }
189 }
190 }
191 }
192
193 $h8 = fopen("/etc/group.new","w");
194 foreach($grouplines as $line)
195 fwrite($h8,$line."\n");
196 fclose($h8);
197
198 //
199 // this is where we give a user a home
200 //
201 foreach($users as $user) {
202 if (is_dir("/home/".$user)) {
203
204 } else {
205 @mkdir("/home/".$user);
206 system("chown $user:".USER_DEFAULT_GROUP." /home/".$user);
207 }
208 }
209
210 ?>

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26