Class: WireGuard::Admin::Templates::Server

Inherits:
ERB
  • Object
show all
Defined in:
lib/wire_guard/admin/templates/server.rb

Overview

Configuration template for a WireGuard::Admin::Server

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server:, network:, clients:) ⇒ Server

Returns a new instance of Server.



35
36
37
38
39
40
# File 'lib/wire_guard/admin/templates/server.rb', line 35

def initialize(server:, network:, clients:)
  @server = server
  @network = network
  @clients = clients
  super(self.class.template, trim_mode: '<>')
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



33
34
35
# File 'lib/wire_guard/admin/templates/server.rb', line 33

def clients
  @clients
end

#networkObject (readonly)

Returns the value of attribute network.



33
34
35
# File 'lib/wire_guard/admin/templates/server.rb', line 33

def network
  @network
end

#serverObject (readonly)

Returns the value of attribute server.



33
34
35
# File 'lib/wire_guard/admin/templates/server.rb', line 33

def server
  @server
end

Class Method Details

.templateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wire_guard/admin/templates/server.rb', line 12

def self.template
  "    # WireGuard configuration for <%= server.name %>\n    # generated by wg-admin\n\n    [Interface]\n    Address = <%= server.ip %>/<%= network.prefix %>\n    ListenPort = <%= server.port %>\n    PrivateKey = <%= server.private_key %>\n    # PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o <%= server.device %> -j MASQUERADE\n    # PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o <%= server.device %> -j MASQUERADE\n    <% clients.each do |client| %>\n\n    [Peer]\n    # Name = <%= client.name %>\n    PublicKey = <%= client.public_key %>\n    AllowedIPs = <%= client.ip %>/<%= client.ip.prefix %>\n    <% end %>\n  SERVER_TEMPLATE\nend\n"

Instance Method Details

#renderObject



42
43
44
# File 'lib/wire_guard/admin/templates/server.rb', line 42

def render
  result(binding)
end