Try to get sshkey
[mirror/dsa-puppet.git] / modules / portforwarder / templates / authorized_keys.erb
1 <%=
2 def getportforwarderkey(host)
3         key = nil
4         begin
5                 facts = YAML.load(File.open("/var/lib/puppet/yaml/facts/#{host}.yaml").read)
6                 return facts.values['portforwarder_key']
7         rescue Exception => e
8         end
9         return key
10 end
11
12
13 lines = []
14 config = YAML.load(File.open('/etc/puppet/modules/portforwarder/misc/config.yaml').read)
15 config.each_pair do |sourcehost, services|
16         ##lines << "# sourcehost is #{sourcehost}"
17         services.each do |service|
18                 ##lines << "# targethost is #{service['target_host']}, my hostname #{hostname}, fqdn is #{fqdn}"
19                 next if service['target_host'] != fqdn
20
21                 sshkey = getportforwarderkey(sourcehost)
22                 remote_ip = keyinfo[sourcehost][0]['ipHostNumber'].join(',')
23                 forward_to_port = service['target_port']
24                 local_bind = '127.0.0.2'
25
26                 lines << "# from #{sourcehost} on local port #{service['source_bind_port']}"
27                 if sshkey.nil? or remote_ip.nil? or forward_to_port.nil? or local_bind.nil?
28                         lines << "# insufficient config values"
29                 else
30                         lines << "from=\"#{remote_ip}\",command=\"/bin/nc -s #{local_bind} 127.0.0.1 #{forward_to_port}\",no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding #{sshkey}"
31                 end
32         end
33 end
34 lines.join("\n")
35 %>