Annotation of loncom/build/add_domain_coordinator_privilege.pl, revision 1.5

1.1       albertel    1: #!/usr/bin/perl
                      2: 
                      3: =pod
                      4: 
                      5: =head1 NAME
                      6: 
                      7: add_domain_coordinator_privilege.pl - Add domain coordinator to an
                      8: exisiting user on a LON-CAPA system.
                      9: 
                     10: =cut
                     11: 
                     12: # The LearningOnline Network
                     13: #
                     14: # add_domain_coordinator_privilege.pl - Add domain coordinator to an
                     15: #    exisiting user on a LON-CAPA system.
                     16: #
1.5     ! raeburn    17: # $Id: add_domain_coordinator_privilege.pl,v 1.4 2008/01/03 21:16:11 raeburn Exp $
1.1       albertel   18: #
                     19: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     20: #
                     21: # LON-CAPA is free software; you can redistribute it and/or modify
                     22: # it under the terms of the GNU General Public License as published by
                     23: # the Free Software Foundation; either version 2 of the License, or
                     24: # (at your option) any later version.
                     25: #
                     26: # LON-CAPA is distributed in the hope that it will be useful,
                     27: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     28: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     29: # GNU General Public License for more details.
                     30: #
                     31: # You should have received a copy of the GNU General Public License
                     32: # along with LON-CAPA; if not, write to the Free Software
                     33: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     34: #
                     35: # /home/httpd/html/adm/gpl.txt
                     36: #
                     37: # http://www.lon-capa.org/
                     38: #
                     39: ###
                     40: 
                     41: =pod
                     42: 
                     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 LON-CAPA, if not it aborts. 
                     55: 
                     56: =item *
                     57: 
                     58: Set roles.hist and roles.db
                     59: 
                     60: =back
                     61: 
                     62: =cut
                     63: 
                     64: # NOTE: I am interspersing the manual procedure with the automation.
                     65: # To see the manual procedure, do perldoc ./make_domain_coordinator.pl
                     66: 
                     67: # This is a standalone script.  It *could* alternatively use the
                     68: # lcuseradd script, however lcuseradd relies on certain system
                     69: # dependencies.  In order to have a focused performance, I am trying
                     70: # to avoid system dependencies until the LON-CAPA code base becomes
                     71: # more robust and well-boundaried.  make_domain_coordinator.pl should be able
                     72: # to run freely as possible, irrespective of the status of a LON-CAPA
                     73: # installation.
                     74: 
                     75: # ---------------------------------------------------- Configure general values
                     76: 
                     77: use lib '/home/httpd/lib/perl/';
                     78: use LONCAPA;
                     79: use Apache::lonnet;
                     80: use Apache::loncommon;
                     81: use Apache::lonlocal;
                     82: &Apache::lonlocal::get_language_handle();
                     83: 
                     84: =pod
                     85: 
                     86: =head1 OPTIONS
                     87: 
                     88: There are no flags to this script.
                     89: 
1.3       raeburn    90: usage: add_domain_coordinator_privilege.pl [USERNAME:DOMAIN] [NEWDOMAIN]
1.1       albertel   91: 
                     92: The first argument specifies the user name domain of an existing user.
                     93: 
                     94: The second argument specifies the domain to add to coordinate.
                     95: 
                     96: =cut
                     97: 
                     98: # ----------------------------------------------- So, are we invoked correctly?
                     99: # Two arguments or abort
                    100: if (@ARGV!=2) {
                    101:     die('usage: add_domain_coordinator_privilege.pl [USERNAME:DOMAIN] [NEWDOMAIN]'.
                    102: 	"\n");
                    103: }
                    104: my ($user,$add_domain)=(@ARGV);
                    105: my ($username,$domain)=split(':',$user);
                    106: if (!grep(/^\Q$add_domain\E$/,&Apache::lonnet::current_machine_domains())) {
                    107:     die('**** ERROR **** Domain '.$add_domain.' is unknown'."\n");
                    108: }
                    109: 
                    110: my $udpath=&propath($domain,$username);
                    111: if (!-d $udpath) {
                    112:     die ('**** ERROR **** '.$user.' is NOT already defined as a LON-CAPA '.
                    113: 	 'user.'."\n");
                    114: }
                    115: 
                    116: =pod
                    117: 
                    118: =head1 MANUAL PROCEDURE
                    119: 
                    120: There are 2 steps to manually recreating what this script performs
                    121: automatically.
                    122: 
                    123: You need to decide on two pieces of information
                    124: to create a domain coordinator.
                    125: 
                    126:  * USERNAME (kermit, albert, joe, etc)
                    127:  * DOMAIN (should be a domain for thsi machine from domain.tab)
                    128: 
                    129: The examples in these instructions will be based
                    130: on two example pieces of information:
                    131: 
                    132:  * USERNAME=dc103
                    133:  * DOMAIN=103
                    134: 
                    135: You will also need to know your "root" password
                    136: or your "www" password.
                    137: 
                    138: =over 4
                    139: 
                    140: =pod
                    141: 
                    142: =item 1. (as www). Run CVS:loncapa/doc/rolesmanip.pl:
                    143: 
                    144:  Command: [prompt %] perl rolesmanip.pl NEWDOMAIN USERNAME
                    145:  Example: [prompt %] perl rolesmanip.pl 103 dc103
                    146: 
                    147: =cut
                    148: 
                    149: use GDBM_File; # A simple key-value pairing database.
                    150: 
                    151: my $rolesref=&LONCAPA::locking_hash_tie("$udpath/roles.db",&GDBM_WRCREAT());
                    152: if (!$rolesref) {
                    153:     die('unable to tie roles db: '."$udpath/roles.db");
                    154: }
1.5     ! raeburn   155: my $status;
        !           156: my $now = time;
1.1       albertel  157: if (exists($rolesref->{'/'.$add_domain.'/_dc'})) {
                    158:     my ($role,$end,$start) = split('_',$rolesref->{'/'.$add_domain.'/_dc'});
1.3       raeburn   159:     print(&mt("[_1] already has a dc privilege for [_2].",
1.1       albertel  160: 	      $user,$add_domain)."\n");
                    161:     if ($start) {
                    162: 	print(&mt("Start date: [_1]",&Apache::lonlocal::locallocaltime($start)).
                    163: 	      "\n");
                    164: 	if (!$end) {
                    165: 	    print(&mt("No planned end date.")."\n");
1.5     ! raeburn   166: 	} else {
        !           167:             print(&mt("End date: [_1]",&Apache::lonlocal::locallocaltime($end)).
        !           168:                   "\n");
        !           169:         }
        !           170: 	if (($start <= $now) && (!$end || $end > $now)) {
        !           171: 	    print(&mt("It is currently active.")."\n");
        !           172: 	    $status = 'active';
1.1       albertel  173: 	}
                    174:     } elsif ($end) {
                    175: 	print(&mt("End date: [_1]",&Apache::lonlocal::locallocaltime($end)).
                    176: 	      "\n");
1.5     ! raeburn   177: 	if ($end > $now) {
1.1       albertel  178: 	    print(&mt("It is currently active.")."\n");
1.5     ! raeburn   179: 	    $status = 'active';
1.1       albertel  180: 	}
                    181:     }
1.5     ! raeburn   182:     if ((!$start) && (!$end)) {
1.1       albertel  183: 	print(&mt("It is currently active.")."\n");
1.5     ! raeburn   184: 	$status = 'active';
1.1       albertel  185:     }
1.5     ! raeburn   186:     unless ($status eq 'active') {
        !           187:         print(&mt("It is currently not active. Proceeding to make role active now.")."\n");
        !           188:     }
        !           189: }
        !           190: 
        !           191: if ($status eq 'active') {
        !           192:     &LONCAPA::locking_hash_untie($rolesref);
        !           193:     exit(0);
1.1       albertel  194: }
                    195: 
1.3       raeburn   196: my $now = time;
                    197: $rolesref->{'/'.$add_domain.'/_dc'}='dc_0_'.$now; # Set the domain coordinator role.
1.1       albertel  198: open(OUT, ">$udpath/roles.hist"); # roles.hist is the synchronous plain text.
                    199: foreach my $key (keys(%{$rolesref})) {
                    200:     print(OUT $key.' : '.$rolesref->{$key}."\n");
                    201: }
                    202: close(OUT);
                    203: &LONCAPA::locking_hash_untie($rolesref);
                    204: 
                    205: 
                    206: `chown www:www $udpath/roles.hist`; # Must be writeable by httpd process.
                    207: `chown www:www $udpath/roles.db`; # Must be writeable by httpd process.
                    208: 
1.3       raeburn   209: my %perlvar = %{&LONCAPA::Configuration::read_conf('loncapa.conf')};
                    210: my $dompath = $perlvar{'lonUsersDir'}.'/'.$domain;
                    211: my $domrolesref = &LONCAPA::locking_hash_tie("$dompath/nohist_domainroles.db",&GDBM_WRCREAT());
                    212: 
                    213: if (!$domrolesref) {
                    214:     die('unable to tie nohist_domainroles db: '."$dompath/nohist_domainroles.db");
                    215: }
                    216: 
                    217: # Store in nohist_domainroles.db
                    218: my $domkey=&LONCAPA::escape('dc:'.$username.':'.$domain.'::'.$domain.':');
                    219: $domrolesref->{$domkey}= &LONCAPA::escape('0:'.$now);
                    220: &LONCAPA::locking_hash_untie($domrolesref);
                    221: 
1.4       raeburn   222:  system('/bin/chown',"www:www","$dompath/nohist_domainroles.db"); # Must be writeable by httpd process.
                    223:  system('/bin/chown',"www:www","$dompath/nohist_domainroles.db.lock");
                    224: 
1.1       albertel  225: =pod
                    226: 
                    227: =item 2.
                    228: 
                    229: You may further define the domain coordinator user (i.e. dc103)
                    230: by going to http://MACHINENAME/adm/createuser.
                    231: 
                    232: =cut
                    233: 
                    234: # Output success message, and inform sysadmin about how to further proceed.
                    235: print("$username is now a domain coordinator for $add_domain\n");
                    236: 

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