puppet 4 foo
[mirror/dsa-puppet.git] / modules / portforwarder / templates / xinetd.erb
1 ##
2 ## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE.
3 ## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git
4 ##
5
6 <%=
7 lines = []
8
9 template = 'service @@TARGET_HOST@@@@TARGET_PORT@@
10 {
11         protocol        = tcp
12         port            = @@LOCAL_BIND@@
13         type            = UNLISTED
14
15         bind            = 127.0.0.1
16         socket_type     = stream
17         wait            = no
18         user            = portforwarder
19         group           = portforwarder
20         instances       = 10
21         server          = /usr/bin/ssh
22         server_args     = -o PreferredAuthentications=publickey -o EscapeChar=none -o BatchMode=yes -C @@SSH_OPTIONS@@ @@TARGET_HOST@@ forward-to @@TARGET_PORT@@
23         cps             = 0 0
24 }
25 '
26
27 config = YAML.load(File.open('/etc/puppet/modules/portforwarder/misc/config.yaml').read)
28 if config[@fqdn]
29         config[fqdn].each do |service|
30                 target_port = service['target_port']
31                 target_host = service['target_host']
32                 local_bind = service['source_bind_port']
33                 ssh_options = service['ssh_options'] || ""
34
35                 lines << "# to #{target_port.to_s}:target_host from local port #{local_bind.to_s}"
36                 if target_port.nil? or target_host.nil? or local_bind.nil?
37                         lines << "# insufficient config values"
38                 else
39                         p = template.clone
40                         p.gsub!('@@TARGET_HOST@@', target_host)
41                         p.gsub!('@@TARGET_PORT@@', target_port.to_s)
42                         p.gsub!('@@LOCAL_BIND@@', local_bind.to_s)
43                         p.gsub!('@@SSH_OPTIONS@@', ssh_options.to_s)
44                         lines << p
45                 end
46         end
47 end
48 lines.join("\n")
49 %>