summaryrefslogtreecommitdiff
path: root/provider_base/files/service-definitions/eip-service.json.erb
blob: 09b65bbb8fd264322ea91c3fc63a44d8fc4dbc9c (plain)
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
50
<%=
  def underscore(words)
    words = words.to_s.dup
    words.downcase!
    words.gsub! /[^a-z]/, '_'
    words
  end

  def gateway_definition(node)
    gateway = {}
    gateway["capabilities"] = node.openvpn.pick(:ports, :protocols, :user_ips, :adblock, :filter_dns)
    gateway["capabilities"]["transport"] = ["openvpn"]
    gateway["host"] = node.domain.full
    gateway["cluster"] = underscore(node.openvpn.location)
    gateway
  end

  hsh = {}
  hsh["serial"] = 1
  hsh["version"] = 1
  clusters = {}
  gateways = []
  nodes_like_me[:services => 'openvpn'].each_node do |node|
    if node.openvpn.gateway_address
      gateway = gateway_definition(node)
      gateway["ip_address"] = node.openvpn.gateway_address
      gateway["capabilities"]["free"] = false
      gateways << gateway
    end
    if node.openvpn.free_gateway_address && node.openvpn.free_gateway_address != "REQUIRED"
      gateway = gateway_definition(node)
      gateway["ip_address"] = node.openvpn.free_gateway_address
      gateway["capabilities"]["free"] = true
      gateway["capabilities"]["rate_limit"] = node.openvpn.free_rate_limit
      gateways << gateway
    end
    clusters[gateway["cluster"]] ||= {
      "name" => gateway["cluster"],
      "label" => {"en" => node.openvpn.location}
    }
  end
  hsh["gateways"] = gateways
  hsh["clusters"] = clusters.values
  hsh["openvpn_configuration"] = {
    "tls-cipher" => "DHE-RSA-AES128-SHA",
    "auth" => "SHA1",
    "cipher" => "AES-128-CBC"
  }
  generate_json hsh
%>