Subversion Repositories sysadmin_scripts

Rev

Rev 179 | Rev 184 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
179 rodolico 1
#! /usr/bin/env perl
2
 
182 rodolico 3
# copies server certificates to target, then restarts services
4
# If called with one parameter (hostname), will copy all .crt
5
# and .key files matching hostname (ie, hostname*.crt and 
6
# hostname*.key.
7
#
8
# assumes root user on this system can connect to hostname as
9
# root.
10
#
11
# restarts service apache2 on hostname after copy.
12
#
13
# assumes crt and key files are in $serverCertDir
14
 
179 rodolico 15
use strict;
16
use warnings;
17
 
182 rodolico 18
use FindBin;
19
use File::Spec;
20
use Cwd 'abs_path';
21
use File::Basename;
22
 
23
my $binDir = dirname( abs_path( __FILE__ ) ) . '/';
24
my $config = $binDir . "makeCert.conf";
25
 
26
my $configFile;    # prototype for the domain specific config file
27
my $caCRT;         # location of the CA crt file
28
my $caKey;         # location of the CA Key file
29
my $serverCertDir; # where to put the server certs
30
my $certDays;      # number of days a Server certificate is valid for, not used here
31
my $caDays;        # number of days a CA is good for
32
 
33
die "Config File $config not found\n" unless -f $config;
34
die "openssl config file $sslConfig not found\n" unless -f $sslConfig;
35
 
36
# load the config file
37
eval `cat $config`;
38
 
179 rodolico 39
my $targetDir = '/etc/certificates/';
40
my $remoteCommand = 'chmod 644 /etc/certificates/* && chown root:root /etc/certificates/* && service apache2 reload';
41
my $hostname = shift;
42
my $certname = shift;
43
 
182 rodolico 44
die "Usage: $0 hostname [certname]\n" unless $hostname;
45
$certname .= '*' unless $certname;
179 rodolico 46
 
182 rodolico 47
`scp $serverCertDir$certname.crt $serverCertDir$certname.key $hostname:$targetDir`;
179 rodolico 48
`ssh $hostname '$remoteCommand'`;
49
 
50
print "$hostname updated and web server restarted\n";
51
 
52
1;