Annotation of loncom/build/add_domain_coordinator_privilege.pl, revision 1.7
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.7 ! raeburn 17: # $Id: add_domain_coordinator_privilege.pl,v 1.6 2011/03/28 21:15:25 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:
83: =pod
84:
85: =head1 OPTIONS
86:
87: There are no flags to this script.
88:
1.3 raeburn 89: usage: add_domain_coordinator_privilege.pl [USERNAME:DOMAIN] [NEWDOMAIN]
1.1 albertel 90:
91: The first argument specifies the user name domain of an existing user.
92:
93: The second argument specifies the domain to add to coordinate.
94:
95: =cut
96:
1.6 raeburn 97: my ($user,$add_domain)=(@ARGV);
98: my $lang = &Apache::lonlocal::choose_language();
99: &Apache::lonlocal::get_language_handle(undef,$lang);
100:
101: if ($< != 0) { # Am I root?
102: print(&mt('You must be root in order to assign domain coordinator roles.').
103: "\n");
104: }
105:
1.1 albertel 106: # ----------------------------------------------- So, are we invoked correctly?
107: # Two arguments or abort
108: if (@ARGV!=2) {
1.6 raeburn 109: print(&mt('usage: [_1]','add_domain_coordinator_privilege.pl [USERNAME:DOMAIN] [NEWDOMAIN]').
1.1 albertel 110: "\n");
1.6 raeburn 111: exit;
1.1 albertel 112: }
113: my ($username,$domain)=split(':',$user);
114: if (!grep(/^\Q$add_domain\E$/,&Apache::lonnet::current_machine_domains())) {
1.6 raeburn 115: print(&mt('**** ERROR **** Domain [_1] is unknown.',$add_domain)."\n");
116: exit;
1.1 albertel 117: }
118:
119: my $udpath=&propath($domain,$username);
120: if (!-d $udpath) {
1.6 raeburn 121: print(&mt('**** ERROR **** [_1] is NOT already defined as a LON-CAPA '.
122: 'user.',$user)."\n");
123: exit;
1.1 albertel 124: }
125:
126: =pod
127:
128: =head1 MANUAL PROCEDURE
129:
130: There are 2 steps to manually recreating what this script performs
131: automatically.
132:
133: You need to decide on two pieces of information
134: to create a domain coordinator.
135:
136: * USERNAME (kermit, albert, joe, etc)
137: * DOMAIN (should be a domain for thsi machine from domain.tab)
138:
139: The examples in these instructions will be based
140: on two example pieces of information:
141:
142: * USERNAME=dc103
143: * DOMAIN=103
144:
145: You will also need to know your "root" password
146: or your "www" password.
147:
148: =over 4
149:
150: =pod
151:
152: =item 1. (as www). Run CVS:loncapa/doc/rolesmanip.pl:
153:
154: Command: [prompt %] perl rolesmanip.pl NEWDOMAIN USERNAME
155: Example: [prompt %] perl rolesmanip.pl 103 dc103
156:
157: =cut
158:
159: use GDBM_File; # A simple key-value pairing database.
160:
161: my $rolesref=&LONCAPA::locking_hash_tie("$udpath/roles.db",&GDBM_WRCREAT());
162: if (!$rolesref) {
1.6 raeburn 163: print(&mt('unable to tie [_1]',"roles db: $udpath/roles.db")."\n");
164: exit;
1.1 albertel 165: }
1.5 raeburn 166: my $status;
167: my $now = time;
1.1 albertel 168: if (exists($rolesref->{'/'.$add_domain.'/_dc'})) {
169: my ($role,$end,$start) = split('_',$rolesref->{'/'.$add_domain.'/_dc'});
1.3 raeburn 170: print(&mt("[_1] already has a dc privilege for [_2].",
1.1 albertel 171: $user,$add_domain)."\n");
172: if ($start) {
173: print(&mt("Start date: [_1]",&Apache::lonlocal::locallocaltime($start)).
174: "\n");
175: if (!$end) {
176: print(&mt("No planned end date.")."\n");
1.5 raeburn 177: } else {
178: print(&mt("End date: [_1]",&Apache::lonlocal::locallocaltime($end)).
179: "\n");
180: }
181: if (($start <= $now) && (!$end || $end > $now)) {
182: print(&mt("It is currently active.")."\n");
183: $status = 'active';
1.1 albertel 184: }
185: } elsif ($end) {
186: print(&mt("End date: [_1]",&Apache::lonlocal::locallocaltime($end)).
187: "\n");
1.5 raeburn 188: if ($end > $now) {
1.1 albertel 189: print(&mt("It is currently active.")."\n");
1.5 raeburn 190: $status = 'active';
1.1 albertel 191: }
192: }
1.5 raeburn 193: if ((!$start) && (!$end)) {
1.1 albertel 194: print(&mt("It is currently active.")."\n");
1.5 raeburn 195: $status = 'active';
1.1 albertel 196: }
1.5 raeburn 197: unless ($status eq 'active') {
198: print(&mt("It is currently not active. Proceeding to make role active now.")."\n");
199: }
200: }
201:
202: if ($status eq 'active') {
203: &LONCAPA::locking_hash_untie($rolesref);
204: exit(0);
1.1 albertel 205: }
206:
1.3 raeburn 207: my $now = time;
208: $rolesref->{'/'.$add_domain.'/_dc'}='dc_0_'.$now; # Set the domain coordinator role.
1.1 albertel 209: open(OUT, ">$udpath/roles.hist"); # roles.hist is the synchronous plain text.
210: foreach my $key (keys(%{$rolesref})) {
211: print(OUT $key.' : '.$rolesref->{$key}."\n");
212: }
213: close(OUT);
214: &LONCAPA::locking_hash_untie($rolesref);
215:
216:
217: `chown www:www $udpath/roles.hist`; # Must be writeable by httpd process.
218: `chown www:www $udpath/roles.db`; # Must be writeable by httpd process.
219:
1.3 raeburn 220: my %perlvar = %{&LONCAPA::Configuration::read_conf('loncapa.conf')};
221: my $dompath = $perlvar{'lonUsersDir'}.'/'.$domain;
222: my $domrolesref = &LONCAPA::locking_hash_tie("$dompath/nohist_domainroles.db",&GDBM_WRCREAT());
223:
224: if (!$domrolesref) {
1.6 raeburn 225: print(&mt('unable to tie [_1]',"nohist_domainroles db: $dompath/nohist_domainroles.db")."\n");
226: exit;
1.3 raeburn 227: }
228:
229: # Store in nohist_domainroles.db
230: my $domkey=&LONCAPA::escape('dc:'.$username.':'.$domain.'::'.$domain.':');
231: $domrolesref->{$domkey}= &LONCAPA::escape('0:'.$now);
232: &LONCAPA::locking_hash_untie($domrolesref);
233:
1.6 raeburn 234: system('/bin/chown',"www:www","$dompath/nohist_domainroles.db"); # Must be writeable by httpd process.
235: system('/bin/chown',"www:www","$dompath/nohist_domainroles.db.lock");
1.4 raeburn 236:
1.1 albertel 237: =pod
238:
239: =item 2.
240:
241: You may further define the domain coordinator user (i.e. dc103)
242: by going to http://MACHINENAME/adm/createuser.
243:
244: =cut
245:
246: # Output success message, and inform sysadmin about how to further proceed.
1.6 raeburn 247: print(&mt('[_1] is now a domain coordinator for [_2].',$username,$add_domain).
248: "\n");
1.7 ! raeburn 249: exit;
1.1 albertel 250:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>