Skip to content

Instantly share code, notes, and snippets.

@voidcontext
Last active August 29, 2015 14:07
Show Gist options
  • Save voidcontext/bc783fce77dddb8c4dcc to your computer and use it in GitHub Desktop.
Save voidcontext/bc783fce77dddb8c4dcc to your computer and use it in GitHub Desktop.
OpenVPN client config generator
#!/usr/bin/perl
# vim: expandtab ts=2 sw=2
use warnings;
use strict;
use File::Slurp qw{read_file};
my $remote = $ARGV[0];
my $client= $ARGV[1];
my $path = $ARGV[2] || '/etc/openvpn/easy-rsa/keys/';
my $data = do { local $/; <DATA> };
my $ca = read_file($path . '/ca.crt');
my $cert = read_file($path . '/' . $client . '.crt');
my $key = read_file($path . '/' . $client . '.key');
$data =~ s/\$remote/$remote/;
$data =~ s/\$ca/$ca/;
$data =~ s/\$cert/$cert/;
$data =~ s/\$key/$key/;
print $data;
__DATA__
client
dev tun
proto udp
remote $remote 1194
remote-cert-tls server
resolv-retry infinite
nobind
persist-key
persist-tun
comp-lzo
verb 3
<ca>
$ca
</ca>
<cert>
$cert
</cert>
<key>
$key
</key>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment