Annotation of loncom/CrGenerate.pl, revision 1.3
1.1 foxr 1: #!/usr/bin/perl
2: # The LearningOnline Network
3: # CrGenerate - Generate a loncapa certificate request.
4: #
5: # $Id$
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27:
28:
29: # http://www.lon-capa.org/
30: #
31: #
32: # This script:
33: # 1. Generates a private host key and certificate request/
34: # 2. Decodes the private host key
35: # 3. Installs the private host key with appropriate permissions
36: # in the appropriate directory (sorry to be vague about this, but
37: # the installation directory is determined by external configuration
38: # info).
39: # 4. Constructs an email to the loncapa cluster administrator
40: # consisting of a generic heading and the certificate request as a MIME
41: # attachment.
42: # 5. Sends the email and
43: # 6. Cleans up after itself by removing any temp files generated.
44: #
45: #
46:
47:
48: # Import section:
49:
50: use strict;
51: use MIME::Entity;
52: use Mail::Mailer;
53: use LONCAPA::Configuration;
54:
55: # Global variable declarations:
56:
1.2 foxr 57: my $SSLCommand; # Full path to openssl command.
58: my $CertificateDirectory; # LONCAPA Certificate directory.
59: my $KeyFilename; # Key filename (within CertificateDirectory).
60: my $Passphrase="loncapawhatever"; # Initial passphrase for keyfile
61: my $RequestEmail; # Email address of loncapa cert admin.
1.1 foxr 62:
1.3 ! foxr 63:
! 64:
1.1 foxr 65: # Debug/log support:
66: #
1.2 foxr 67: my $DEBUG = 1; # 1 for on, 0 for off.
1.1 foxr 68:
69: # Send debugging to stderr.
70: # Parameters:
71: # msg - Message to send to stderr.
72: # Implicit Inputs:
73: # $DEBUG - message is only written if this is true.
74: #
75: sub Debug {
1.2 foxr 76: my $msg = shift;
1.1 foxr 77: if($DEBUG) {
78: print STDERR "$msg\n";
79: }
80: }
81:
1.3 ! foxr 82: #
! 83: # Read the LonCAPA web config files to get the values of the
! 84: # configuration global variables we need:
! 85: # Implicit inputs:
! 86: # loncapa.conf - configuration file to read (user specific).
! 87: # Implicit outputs (see global variables section):
! 88: # SSLCommand,
! 89: # CertificateDirectory
! 90: # KeyfileName
! 91: # RequestEmail
! 92: # Side-Effects:
! 93: # Exit with error if cannot complete.
! 94: #
! 95: sub ReadConfig {
! 96:
! 97: Debug("Reading configuration");
! 98: my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf');
! 99:
! 100: # Name of the SSL Program
! 101:
! 102: if($perlvarref->{SSLProgram}) {
! 103: $SSLCommand = $perlvarref->{SSLProgram};
! 104: Debug("SSL Command: $SSLCommand");
! 105: }
! 106: else {
! 107: die "Unable to read the SSLCommand configuration option\n";
! 108: }
! 109:
! 110: # Where the certificates, and host key are installed:
1.1 foxr 111:
1.3 ! foxr 112: if($perlvarref->{lonCertificateDirectory}) {
! 113: $CertificateDirectory = $perlvarref->{lonCertificateDirectory};
! 114: Debug("Local certificate Directory: $CertificateDirectory");
! 115: }
! 116: else {
! 117: die "Unable to read SSLDirectory configuration option\n";
! 118: }
! 119: # The name of the host key file (to be installed in SSLDirectory).
! 120: #
! 121: if($perlvarref->{lonnetPrivateKey}) {
! 122: $KeyFilename = $perlvarref->{lonnetPrivateKey};
! 123: Debug("Private key will be installed as $KeyFilename");
! 124: }
! 125: else {
! 126: die "Unable to read lonnetPrivateKey conrig paraemter\n";
! 127: }
! 128: # The email address to which the certificate request is sent:
! 129:
! 130: if($perlvarref->{SSLEmail}) {
! 131: $RequestEmail = $perlvarref->{SSLEmail};
! 132: Debug("Certificate request will be sent to $RequestEmail");
! 133: }
! 134: else {
! 135: die "Could not read SSLEmail coniguration key";
! 136: }
! 137: }
1.1 foxr 138: sub GenerateRequest {}
139: sub InstallKey {}
140: sub MailRequest {}
141: sub Cleanup {}
142:
143:
144:
145: # Entry point:
146:
147: Debug("Starting program");
148: ReadConfig; # Read loncapa apache config file.
149: GenerateRequest; # Generate certificate request.
150: InstallKey; # Install the user's key.
151: MailRequest; # Mail certificate request to loncapa
152: Cleanup; # Cleanup temp files created.
153:
154: Debug("Done");
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>