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

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

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