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

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

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