forked from labriqueinternet/configuration_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-dotcube-ldn.rb
executable file
·49 lines (43 loc) · 1.73 KB
/
generate-dotcube-ldn.rb
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
48
49
#!/usr/bin/env ruby
#
# Copyright (C) 2015 Sebastien Badia <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 of
# the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# http://internetcu.be/dotcubefiles.html
# https://wiki.ldn-fai.net/wiki/Ajouter_un_compte_VPN
require 'json'
require 'yaml'
if ARGV.length != 1
puts "generate-dotcube.rb LOGIN"
exit 1
end
user = ARGV[0]
vpn = {}
common = JSON.load(File.read('/srv/dotcube/dotcube-common.json'))
yaml = YAML.load_file('/srv/puppet/production/puppet/hiera/ldn.yaml')
if ! File.exist?("/srv/ca-openvpn-clients/keys/#{user}.crt")
puts "user #{user} seems not present..."
exit 1
end
vpn['ip6_net'] = yaml['openvpn::users'][user]['prefix']
vpn['ip4_addr'] = yaml['openvpn::users'][user]['ipv4']
vpn['crt_server_ca'] = File.read('/root/ca_server.crt').strip.tr("\n", '|')
vpn['crt_client'] = File.read("/srv/ca-openvpn-clients/keys/#{user}.crt").strip.tr("\n", '|')[/-----.*-----/]
vpn['crt_client_key'] = File.read("/srv/ca-openvpn-clients/keys/#{user}.key").strip.tr("\n", '|')
File.open("/srv/dotcube/#{user}.cube","w") do |f|
f.write(JSON.pretty_generate(common.merge(vpn)))
end
puts "dotcube file generated /srv/dotcube/#{user}.cube"