Annotation of loncom/build/add_domain_coordinator_privilege.pl, revision 1.1
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: #
! 17: # $Id: make_domain_coordinator.pl,v 1.12 2007/06/01 05:17:58 albertel Exp $
! 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:
! 90: usage: add_domain_coordinator_privledge.pl [USERNAME:DOMAIN] [NEWDOMAIN]
! 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: }
! 155: if (exists($rolesref->{'/'.$add_domain.'/_dc'})) {
! 156: my ($role,$end,$start) = split('_',$rolesref->{'/'.$add_domain.'/_dc'});
! 157: print(&mt("[_1] already has a dc priviledge for [_2].",
! 158: $user,$add_domain)."\n");
! 159: if ($start) {
! 160: print(&mt("Start date: [_1]",&Apache::lonlocal::locallocaltime($start)).
! 161: "\n");
! 162: if (!$end) {
! 163: print(&mt("No planned end date.")."\n");
! 164: }
! 165: if ($start < time() && (!$end || $end > time())) {
! 166: print(&mt("It is currently active."));
! 167: exit(0);
! 168: }
! 169: } elsif ($end) {
! 170: print(&mt("End date: [_1]",&Apache::lonlocal::locallocaltime($end)).
! 171: "\n");
! 172: if ($end > time()) {
! 173: print(&mt("It is currently active.")."\n");
! 174: exit(0);
! 175: }
! 176: }
! 177: if (!$start and !$end) {
! 178: print(&mt("It is currently active.")."\n");
! 179: exit(0);
! 180: }
! 181: }
! 182:
! 183: $rolesref->{'/'.$add_domain.'/_dc'}='dc'; # Set the domain coordinator role.
! 184: open(OUT, ">$udpath/roles.hist"); # roles.hist is the synchronous plain text.
! 185: foreach my $key (keys(%{$rolesref})) {
! 186: print(OUT $key.' : '.$rolesref->{$key}."\n");
! 187: }
! 188: close(OUT);
! 189: &LONCAPA::locking_hash_untie($rolesref);
! 190:
! 191:
! 192: `chown www:www $udpath/roles.hist`; # Must be writeable by httpd process.
! 193: `chown www:www $udpath/roles.db`; # Must be writeable by httpd process.
! 194:
! 195: =pod
! 196:
! 197: =item 2.
! 198:
! 199: You may further define the domain coordinator user (i.e. dc103)
! 200: by going to http://MACHINENAME/adm/createuser.
! 201:
! 202: =cut
! 203:
! 204: # Output success message, and inform sysadmin about how to further proceed.
! 205: print("$username is now a domain coordinator for $add_domain\n");
! 206: my $hostname=`hostname`; chomp($hostname); # Read in hostname.
! 207: print("http://$hostname/adm/createuser will allow you to further define".
! 208: " this user.\n"); # Output a suggested URL.
! 209:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>