Subversion Repositories sysadmin_scripts

Rev

Rev 179 | Rev 184 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 179 Rev 182
Line 1... Line 1...
1
#! /usr/bin/env perl
1
#! /usr/bin/env perl
2
 
2
 
-
 
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
 
3
use strict;
15
use strict;
4
use warnings;
16
use warnings;
5
 
17
 
-
 
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
 
6
my $targetDir = '/etc/certificates/';
39
my $targetDir = '/etc/certificates/';
7
my $remoteCommand = 'chmod 644 /etc/certificates/* && chown root:root /etc/certificates/* && service apache2 reload';
40
my $remoteCommand = 'chmod 644 /etc/certificates/* && chown root:root /etc/certificates/* && service apache2 reload';
8
my $hostname = shift;
41
my $hostname = shift;
9
my $certname = shift;
42
my $certname = shift;
10
 
43
 
11
die "Usage: $0 hostname certname\n" unless $hostname && $certname;
44
die "Usage: $0 hostname [certname]\n" unless $hostname;
-
 
45
$certname .= '*' unless $certname;
12
 
46
 
13
`scp $certname.crt $certname.key $hostname:$targetDir`;
47
`scp $serverCertDir$certname.crt $serverCertDir$certname.key $hostname:$targetDir`;
14
`ssh $hostname '$remoteCommand'`;
48
`ssh $hostname '$remoteCommand'`;
15
 
49
 
16
print "$hostname updated and web server restarted\n";
50
print "$hostname updated and web server restarted\n";
17
 
51
 
18
1;
52
1;