Annotation of loncom/build/make_domain_coordinator.pl, revision 1.6

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: #
1.6     ! harris41   14: # $Id: make_domain_coordinator.pl,v 1.5 2002/06/10 02:01:16 harris41 Exp $
1.2       harris41   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: 
1.3       harris41  104: The password is accepted through standard input
                    105: and should only consist of printable ASCII
                    106: characters and be a string of length greater than 5 characters.
1.1       harris41  107: 
                    108: The first argument
                    109: specifies the user name of the domain coordinator and
                    110: should consist of only alphanumeric characters.
                    111: 
1.3       harris41  112: The second argument specifies the domain of the computer
                    113: coordinator and should consist of only alphanumeric characters.
1.1       harris41  114: 
                    115: =cut
                    116: 
                    117: # ----------------------------------------------- So, are we invoked correctly?
                    118: # Two arguments or abort
                    119: if (@ARGV!=2) {
                    120:     die 'usage: make_domain_coordinator.pl [USERNAME] [DOMAIN] '."\n".
                    121: 	'(and password through standard input)'."\n";
                    122: }
                    123: my ($username,$domain)=(@ARGV); shift @ARGV; shift @ARGV;
                    124: unless ($username=~/^\w+$/ and $username!~/\_/) {
                    125:     die 'Username '.$username.' must consist only of alphanumeric characters'.
                    126: 	"\n";
                    127: }
                    128: unless ($domain=~/^\w+$/ and $domain!~/\_/) {
                    129:     die 'Domain '.$domain.' must consist only of alphanumeric characters'.
                    130: 	"\n";
                    131: }
                    132: 
1.5       harris41  133: print "Password: "; $|=1;
1.1       harris41  134: my $passwd=<>; # read in password from standard input
                    135: chomp($passwd);
                    136: 
                    137: if (length($passwd)<6 or length($passwd)>30) {
                    138:     die 'Password is an unreasonable length.'."\n";
                    139: }
                    140: my $pbad=0;
                    141: foreach (split(//,$passwd)) {if ((ord($_)<32)||(ord($_)>126)){$pbad=1;}}
                    142: if ($pbad) {
                    143:     die 'Password must consist of standard ASCII characters'."\n";
                    144: }
                    145: 
                    146: # And does user already exist
                    147: 
                    148: if (-d "/home/$username") {
                    149:     die ($username.' is already a linux operating system user.'."\n");
                    150: }
                    151: my $udpath=propath($domain,$username);
                    152: if (-d $udpath) {
                    153:     die ($username.' is already defined as a LON-CAPA user.'."\n");
                    154: }
                    155: 
                    156: =pod
                    157: 
                    158: =head1 MANUAL PROCEDURE
                    159: 
                    160: There are 10 steps to a manual procedure.
                    161: 
                    162: You need to decide on three pieces of information
                    163: to create a domain coordinator.
                    164: 
                    165:  * USERNAME (kermit, albert, joe, etc)
1.6     ! harris41  166:  * DOMAIN (should be the same as lonDefDomain in /etc/httpd/conf/loncapa.conf)
1.1       harris41  167:  * PASSWORD (don't tell me)
                    168: 
                    169: The examples in these instructions will be based
                    170: on three example pieces of information:
                    171: 
                    172:  * USERNAME=dc103
                    173:  * DOMAIN=103
                    174:  * PASSWORD=sesame
                    175: 
                    176: You will also need to know your "root" password
                    177: and your "www" password.
                    178: 
                    179: =over 4
                    180: 
                    181: =item 1.
                    182: 
                    183: login as root on your Linux system
                    184:  [prompt %] su
                    185: 
                    186: =cut
                    187: 
                    188: # ------------------------------------------------------------ So, are we root?
                    189: 
                    190: if ($< != 0) {
                    191:   die 'You must be root in order to generate a domain coordinator.'."\n";
                    192: }
                    193: 
                    194: =pod
                    195: 
                    196: =item 2 (as root). add the user
                    197: 
                    198:  Command: [prompt %] /usr/sbin/useradd USERNAME
                    199:  Example: [prompt %] /usr/sbin/useradd dc103
                    200: 
                    201: =cut
                    202: 
                    203: # ----------------------------------------------------------- /usr/sbin/useradd
                    204: 
                    205: $username=~s/\W//g; # an extra filter, just to be sure
                    206: `/usr/sbin/useradd $username`;
                    207: 
                    208: =pod
                    209: 
                    210: =item 3 (as root). enter in a password
                    211: 
                    212:  Command: [prompt %] passwd USERNAME
                    213:           New UNIX password: PASSWORD
                    214:           Retype new UNIX passwd: PASSWORD
                    215:  Example: [prompt %] passwd dc103
                    216:           New UNIX password: sesame
                    217:           Retype new UNIX passwd: sesame
                    218: 
                    219: =cut
                    220: 
                    221: $username=~s/\W//g; # an extra filter, just to be sure
                    222: $pbad=0;
                    223: foreach (split(//,$passwd)) {if ((ord($_)<32)||(ord($_)>126)){$pbad=1;}}
                    224: if ($pbad) {
                    225:     die 'Password must consist of standard ASCII characters'."\n";
                    226: }
                    227: open OUT,"|passwd --stdin $username";
                    228: print OUT $passwd."\n";
                    229: close OUT;
                    230: 
                    231: =pod
                    232: 
                    233: =cut
                    234: 
                    235: =pod
                    236: 
                    237: =item 4. login as user=www
                    238: 
                    239:  Command: [prompt %] su www
                    240:  Password: WWWPASSWORD
                    241: 
                    242: =item 5. (as www). cd /home/httpd/lonUsers
                    243: 
                    244: =item 6. (as www) Create user directory for your new user.
                    245: 
                    246:  Let U equal first letter of USERNAME
                    247:  Let S equal second letter of USERNAME
                    248:  Let E equal third letter of USERNAME
                    249:  Command: [prompt %] install -d DOMAIN/U/S/E/USERNAME
                    250:  Example: [prompt %] install -d 103/d/c/1/dc103
                    251: 
                    252: =cut
                    253: 
                    254: `install -o www -g www -d $udpath`;
                    255: 
                    256: =pod
                    257: 
                    258: =item 7. (as www) Enter the newly created user directory.
                    259: 
                    260:  Command: [prompt %] cd DOMAIN/U/S/E/USERNAME
                    261:  Example: [prompt %] cd 103/d/c/1/dc103
                    262: 
                    263: =item 8. (as www). Set your password mechanism to 'unix' 
                    264: 
                    265:  Command: [prompt %] echo "unix:" > passwd
                    266: 
                    267: =cut
                    268: 
                    269: open OUT, ">$udpath/passwd";
                    270: print OUT 'unix:'."\n";
                    271: close OUT;
                    272: `chown www:www $udpath/passwd`;
                    273: 
                    274: =pod
                    275: 
                    276: =item 9. (as www). Run CVS:loncapa/doc/rolesmanip.pl:
                    277: 
                    278:  Command: [prompt %] perl rolesmanip.pl DOMAIN USERNAME
                    279:  Example: [prompt %] perl rolesmanip.pl 103 dc103
                    280: 
                    281: =cut
                    282: 
                    283: use GDBM_File;
                    284: my %hash;
                    285:         tie(%hash,'GDBM_File',"$udpath/roles.db",
                    286: 	    &GDBM_WRCREAT,0640);
                    287: 
                    288: $hash{'/'.$domain.'/_dc'}='dc';
                    289: open OUT, ">$udpath/roles.hist";
                    290: map {
                    291:     print OUT $_.' : '.$hash{$_}."\n";
                    292: } keys %hash;
                    293: close OUT;
                    294: 
                    295: untie %hash;
                    296: `chown www:www $udpath/roles.hist`;
                    297: `chown www:www $udpath/roles.db`;
                    298: 
                    299: =pod
                    300: 
                    301: =item 10.
                    302: 
                    303: You may further define the domain coordinator user (i.e. dc103)
                    304: by going to http://MACHINENAME/adm/createuser.
                    305: 
                    306: =cut
                    307: 
                    308: print "$username is now a domain coordinator\n";
                    309: my $hostname=`hostname`; chomp $hostname;
                    310: print "http://$hostname/adm/createuser will allow you to further define".
                    311:       " this user.\n";
                    312: 
                    313: # ----------------------------------------------------------------- SUBROUTINES
                    314: sub propath {
                    315:     my ($udom,$uname)=@_;
                    316:     $udom=~s/\W//g;
                    317:     $uname=~s/\W//g;
                    318:     my $subdir=$uname.'__';
                    319:     $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
                    320:     my $proname="$perlvar{'lonUsersDir'}/$udom/$subdir/$uname";
                    321:     return $proname;
                    322: }
                    323: 
                    324: =pod
                    325: 
1.2       harris41  326: =head1 AUTHOR
1.1       harris41  327: 
                    328: Scott Harrison, harris41@msu.edu
                    329: 
                    330: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>