Annotation of loncom/build/make_domain_coordinator.pl, revision 1.2
1.1 harris41 1: #!/usr/bin/perl
2:
3: =pod
4:
5: =head1 NAME
6:
7: make_domain_coordinator.pl - Make a domain coordinator on a LON-CAPA system
8:
1.2 ! harris41 9: =cut
! 10:
! 11: # The LearningOnline Network
! 12: # make_domain_coordinator.pl - Make a domain coordinator on a system
! 13: #
! 14: # $Id: make_domain_coordinator.pl,v 1.1 2002/03/02 03:49:18 harris41 Exp $
! 15: #
! 16: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 17: #
! 18: # LON-CAPA is free software; you can redistribute it and/or modify
! 19: # it under the terms of the GNU General Public License as published by
! 20: # the Free Software Foundation; either version 2 of the License, or
! 21: # (at your option) any later version.
! 22: #
! 23: # LON-CAPA is distributed in the hope that it will be useful,
! 24: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 25: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 26: # GNU General Public License for more details.
! 27: #
! 28: # You should have received a copy of the GNU General Public License
! 29: # along with LON-CAPA; if not, write to the Free Software
! 30: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 31: #
! 32: # /home/httpd/html/adm/gpl.txt
! 33: #
! 34: # http://www.lon-capa.org/
! 35: #
! 36: # YEAR=2002
! 37: # 3/1,3/3,3/4 Scott Harrison
! 38: #
! 39: ###
! 40:
! 41: =pod
! 42:
1.1 harris41 43: =head1 DESCRIPTION
44:
45: Automates the steps for domain coordinator creation. This
46: program also describes a manual procedure (see below).
47:
48: These are the steps that are executed on the linux operating system:
49:
50: =over 4
51:
52: =item *
53:
54: Tests to see if user already exists for linux system or for
55: LON-CAPA, if so aborts
56:
57: =item *
58:
59: Creates a linux system user
60:
61: =item *
62:
63: Sets password
64:
65: =item *
66:
67: Creates a LON-CAPA lonUsers directory for user
68:
69: =item *
70:
71: Sets LON-CAPA password mechanism to be "unix"
72:
73: =item *
74:
75: Set roles.hist and roles.db
76:
77: =back
78:
79: =cut
80:
81: # NOTE: I am interspersing the manual procedure with the automation.
82: # To see the manual procedure, do perldoc ./make_domain_coordinator.pl
83:
84: # This is a standalone script. It *could* alternatively use the
85: # lcuseradd script, however lcuseradd relies on certain system
86: # dependencies. make_domain_coordinator.pl should be able
87: # to run freely as possible irrespective of the status of a LON-CAPA
88: # installation.
89:
90: # ---------------------------------------------------- Configure general values
91:
92: my %perlvar;
93: $perlvar{'lonUsersDir'}='/home/httpd/lonUsers';
94:
95:
96: =pod
97:
98: =head1 OPTIONS
99:
100: There are no flags to this script.
101:
102: usage: make_domain_coordinator.pl [USERNAME] [DOMAIN]
103:
104: The password is accepted through standard input.
105:
106: The first argument
107: specifies the user name of the domain coordinator and
108: should consist of only alphanumeric characters.
109:
110: The second argument specifies the password for the domain
111: coordinator and should only consist of printable ASCII
112: characters and be a string of length greater than 5 characters.
113:
114: =cut
115:
116: # ----------------------------------------------- So, are we invoked correctly?
117: # Two arguments or abort
118: if (@ARGV!=2) {
119: die 'usage: make_domain_coordinator.pl [USERNAME] [DOMAIN] '."\n".
120: '(and password through standard input)'."\n";
121: }
122: my ($username,$domain)=(@ARGV); shift @ARGV; shift @ARGV;
123: unless ($username=~/^\w+$/ and $username!~/\_/) {
124: die 'Username '.$username.' must consist only of alphanumeric characters'.
125: "\n";
126: }
127: unless ($domain=~/^\w+$/ and $domain!~/\_/) {
128: die 'Domain '.$domain.' must consist only of alphanumeric characters'.
129: "\n";
130: }
131:
132: my $passwd=<>; # read in password from standard input
133: chomp($passwd);
134:
135: if (length($passwd)<6 or length($passwd)>30) {
136: die 'Password is an unreasonable length.'."\n";
137: }
138: my $pbad=0;
139: foreach (split(//,$passwd)) {if ((ord($_)<32)||(ord($_)>126)){$pbad=1;}}
140: if ($pbad) {
141: die 'Password must consist of standard ASCII characters'."\n";
142: }
143:
144: # And does user already exist
145:
146: if (-d "/home/$username") {
147: die ($username.' is already a linux operating system user.'."\n");
148: }
149: my $udpath=propath($domain,$username);
150: if (-d $udpath) {
151: die ($username.' is already defined as a LON-CAPA user.'."\n");
152: }
153:
154: =pod
155:
156: =head1 MANUAL PROCEDURE
157:
158: There are 10 steps to a manual procedure.
159:
160: You need to decide on three pieces of information
161: to create a domain coordinator.
162:
163: * USERNAME (kermit, albert, joe, etc)
164: * DOMAIN (should be the same as lonDefDomain in /etc/httpd/conf/access.conf)
165: * PASSWORD (don't tell me)
166:
167: The examples in these instructions will be based
168: on three example pieces of information:
169:
170: * USERNAME=dc103
171: * DOMAIN=103
172: * PASSWORD=sesame
173:
174: You will also need to know your "root" password
175: and your "www" password.
176:
177: =over 4
178:
179: =item 1.
180:
181: login as root on your Linux system
182: [prompt %] su
183:
184: =cut
185:
186: # ------------------------------------------------------------ So, are we root?
187:
188: if ($< != 0) {
189: die 'You must be root in order to generate a domain coordinator.'."\n";
190: }
191:
192: =pod
193:
194: =item 2 (as root). add the user
195:
196: Command: [prompt %] /usr/sbin/useradd USERNAME
197: Example: [prompt %] /usr/sbin/useradd dc103
198:
199: =cut
200:
201: # ----------------------------------------------------------- /usr/sbin/useradd
202:
203: $username=~s/\W//g; # an extra filter, just to be sure
204: `/usr/sbin/useradd $username`;
205:
206: =pod
207:
208: =item 3 (as root). enter in a password
209:
210: Command: [prompt %] passwd USERNAME
211: New UNIX password: PASSWORD
212: Retype new UNIX passwd: PASSWORD
213: Example: [prompt %] passwd dc103
214: New UNIX password: sesame
215: Retype new UNIX passwd: sesame
216:
217: =cut
218:
219: $username=~s/\W//g; # an extra filter, just to be sure
220: $pbad=0;
221: foreach (split(//,$passwd)) {if ((ord($_)<32)||(ord($_)>126)){$pbad=1;}}
222: if ($pbad) {
223: die 'Password must consist of standard ASCII characters'."\n";
224: }
225: open OUT,"|passwd --stdin $username";
226: print OUT $passwd."\n";
227: close OUT;
228:
229: =pod
230:
231: =cut
232:
233: =pod
234:
235: =item 4. login as user=www
236:
237: Command: [prompt %] su www
238: Password: WWWPASSWORD
239:
240: =item 5. (as www). cd /home/httpd/lonUsers
241:
242: =item 6. (as www) Create user directory for your new user.
243:
244: Let U equal first letter of USERNAME
245: Let S equal second letter of USERNAME
246: Let E equal third letter of USERNAME
247: Command: [prompt %] install -d DOMAIN/U/S/E/USERNAME
248: Example: [prompt %] install -d 103/d/c/1/dc103
249:
250: =cut
251:
252: `install -o www -g www -d $udpath`;
253:
254: =pod
255:
256: =item 7. (as www) Enter the newly created user directory.
257:
258: Command: [prompt %] cd DOMAIN/U/S/E/USERNAME
259: Example: [prompt %] cd 103/d/c/1/dc103
260:
261: =item 8. (as www). Set your password mechanism to 'unix'
262:
263: Command: [prompt %] echo "unix:" > passwd
264:
265: =cut
266:
267: open OUT, ">$udpath/passwd";
268: print OUT 'unix:'."\n";
269: close OUT;
270: `chown www:www $udpath/passwd`;
271:
272: =pod
273:
274: =item 9. (as www). Run CVS:loncapa/doc/rolesmanip.pl:
275:
276: Command: [prompt %] perl rolesmanip.pl DOMAIN USERNAME
277: Example: [prompt %] perl rolesmanip.pl 103 dc103
278:
279: =cut
280:
281: use GDBM_File;
282: my %hash;
283: tie(%hash,'GDBM_File',"$udpath/roles.db",
284: &GDBM_WRCREAT,0640);
285:
286: $hash{'/'.$domain.'/_dc'}='dc';
287: open OUT, ">$udpath/roles.hist";
288: map {
289: print OUT $_.' : '.$hash{$_}."\n";
290: } keys %hash;
291: close OUT;
292:
293: untie %hash;
294: `chown www:www $udpath/roles.hist`;
295: `chown www:www $udpath/roles.db`;
296:
297: =pod
298:
299: =item 10.
300:
301: You may further define the domain coordinator user (i.e. dc103)
302: by going to http://MACHINENAME/adm/createuser.
303:
304: =cut
305:
306: print "$username is now a domain coordinator\n";
307: my $hostname=`hostname`; chomp $hostname;
308: print "http://$hostname/adm/createuser will allow you to further define".
309: " this user.\n";
310:
311: # ----------------------------------------------------------------- SUBROUTINES
312: sub propath {
313: my ($udom,$uname)=@_;
314: $udom=~s/\W//g;
315: $uname=~s/\W//g;
316: my $subdir=$uname.'__';
317: $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
318: my $proname="$perlvar{'lonUsersDir'}/$udom/$subdir/$uname";
319: return $proname;
320: }
321:
322: =pod
323:
1.2 ! harris41 324: =head1 AUTHOR
1.1 harris41 325:
326: Scott Harrison, harris41@msu.edu
327:
328: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>