Annotation of loncom/build/add_domain_coordinator_privilege.pl, revision 1.4
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.4 ! raeburn 17: # $Id: add_domain_coordinator_privilege.pl,v 1.3 2007/12/31 16:49:23 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: }
155: if (exists($rolesref->{'/'.$add_domain.'/_dc'})) {
156: my ($role,$end,$start) = split('_',$rolesref->{'/'.$add_domain.'/_dc'});
1.3 raeburn 157: print(&mt("[_1] already has a dc privilege for [_2].",
1.1 albertel 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: }
1.2 albertel 181: print(&mt("It is currently not active. Proceeding to re-enable")."\n");
1.1 albertel 182: }
183:
1.3 raeburn 184: my $now = time;
185: $rolesref->{'/'.$add_domain.'/_dc'}='dc_0_'.$now; # Set the domain coordinator role.
1.1 albertel 186: open(OUT, ">$udpath/roles.hist"); # roles.hist is the synchronous plain text.
187: foreach my $key (keys(%{$rolesref})) {
188: print(OUT $key.' : '.$rolesref->{$key}."\n");
189: }
190: close(OUT);
191: &LONCAPA::locking_hash_untie($rolesref);
192:
193:
194: `chown www:www $udpath/roles.hist`; # Must be writeable by httpd process.
195: `chown www:www $udpath/roles.db`; # Must be writeable by httpd process.
196:
1.3 raeburn 197: my %perlvar = %{&LONCAPA::Configuration::read_conf('loncapa.conf')};
198: my $dompath = $perlvar{'lonUsersDir'}.'/'.$domain;
199: my $domrolesref = &LONCAPA::locking_hash_tie("$dompath/nohist_domainroles.db",&GDBM_WRCREAT());
200:
201: if (!$domrolesref) {
202: die('unable to tie nohist_domainroles db: '."$dompath/nohist_domainroles.db");
203: }
204:
205: # Store in nohist_domainroles.db
206: my $domkey=&LONCAPA::escape('dc:'.$username.':'.$domain.'::'.$domain.':');
207: $domrolesref->{$domkey}= &LONCAPA::escape('0:'.$now);
208: &LONCAPA::locking_hash_untie($domrolesref);
209:
1.4 ! raeburn 210: system('/bin/chown',"www:www","$dompath/nohist_domainroles.db"); # Must be writeable by httpd process.
! 211: system('/bin/chown',"www:www","$dompath/nohist_domainroles.db.lock");
! 212:
1.1 albertel 213: =pod
214:
215: =item 2.
216:
217: You may further define the domain coordinator user (i.e. dc103)
218: by going to http://MACHINENAME/adm/createuser.
219:
220: =cut
221:
222: # Output success message, and inform sysadmin about how to further proceed.
223: print("$username is now a domain coordinator for $add_domain\n");
224: my $hostname=`hostname`; chomp($hostname); # Read in hostname.
225: print("http://$hostname/adm/createuser will allow you to further define".
226: " this user.\n"); # Output a suggested URL.
227:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>