#!/usr/bin/ruby # # Copyright (c) 2004 Peter Palfrader # # All rights reserved. # require "ldap" require "getoptlong" require "myldap" require "yaml" require "html/template" config = YAML::load( File.open( '/etc/noreply/config' ) ) ldap = MyLDAP.new(config, "ldap2uucp") systems = [] begin ldap.conn.search(config['basedn'], LDAP::LDAP_SCOPE_SUBTREE, '(&(objectclass=tnUUCPSystem)'+ '(tnHost='+config['thishost']+'))') {|e| systemname = e.vals("tnUUCPSysName").pop; sshkey = e.vals("tnSSHKey").pop; # FIXME: only first used password = e.vals("tnUUCPPassword").pop systems.push( { 'system' => systemname, 'password' => password, 'sshkey' => sshkey } ) } rescue LDAP::ResultError => msg $stderr.print(msg) exit 1; end spool = "/var/spool/uucp" existingdirs = Dir.entries( spool ).delete_if { |e| ((e =~ /^\./) != nil) || !File.stat( spool + '/' + e ).directory?} systems.each{ |s| existingdirs.delete( s['system'] ) }; STDERR.puts "The following orphaned nodes have dirs in the uucp spool: " + existingdirs.join(", ") unless (existingdirs.empty?) # # /etc/uucp/passwd # templ = HTML::Template.new templ.set_html(< # end autogenerated stuff EOF ) templ.param({ 'systems' => systems }) File.open("/etc/uucp/passwd", "w").write( templ.output ); # # /etc/uucp/sys # templ = HTML::Template.new templ.set_html(< system time any called-login protocol it # end autogenerated stuff EOF ) templ.param({ 'systems' => systems }) File.open("/etc/uucp/sys", "w").write( templ.output ); # # ~uucp/.ssh/authorized_keys # templ = HTML::Template.new templ.set_html(< # no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="/usr/sbin/uucico -D -l" # end autogenerated stuff EOF ) templ.param({ 'systems' => systems }) File.open("/var/spool/uucp/.ssh/authorized_keys", "w").write( templ.output );