-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
gencert.pl
executable file
·47 lines (40 loc) · 985 Bytes
/
gencert.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl -w
use strict;
my $hostname = "controlfloor.test";
my $mainip = "127.0.0.1";
my $template = "cert.tmpl";
my $template_data = slurp( $template );
$template_data =~ s/HOSTNAME/$hostname/g;
$template_data =~ s/IPADDR/$mainip/g;
open( my $outfh, ">cert.conf" );
print $outfh $template_data;
my $ips = get_ips();
my $index = 2;
for my $ip ( @$ips ) {
print $outfh "DNS.$index = $ip\n";
$index++;
}
close( $outfh );
`openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt -config cert.conf -subj "/C=US/ST=Washington/L=Seattle/O=Dis/CN=$hostname"`;
sub slurp {
my $file = shift;
open( my $fh, "<$file" );
my $data;
{
local $/ = undef;
$data = <$fh>;
}
close( $fh );
return $data;
}
sub get_ips {
my @lines = `ifconfig`;
my @ips;
for my $line ( @lines ) {
next if( $line !~ m/inet / );
if( $line =~ m/inet ([0-9.]+) / ) {
push( @ips, $1 );
}
}
return \@ips;
}