fax.rb: # a small hack to fetch fax entries from the company LDAP addressbook # use as: # ruby ldap2hylafax.rb | iconv -f UTF8 -t WINDOWS-1253 > /samba/common/hylafax.phb require 'ldap' ldap_host = 'localhost' ldap_port = LDAP::LDAP_PORT ldap_base_dn = 'dc=mycompany,dc=com' ldap_filter = 'facsimileTelephoneNumber=*' # hylafax addressbook entries: # entry_name|fax|to|company|location|voiceno|remarks|resolution| ldap_attrs = %w[cn facsimileTelephoneNumber cn o l telephoneNumber street] begin ldap_conn = LDAP::Conn.new(ldap_host, ldap_port.to_i) STDOUT << 'PBOOK1.1' ldap_conn.bind { ldap_conn.search(ldap_base_dn, LDAP::LDAP_SCOPE_SUBTREE, ldap_filter) { |entry| ldap_attrs.each { |attr| v = entry.vals(attr) STDOUT << (v.is_a?(Array)? v[0].collect{|x| x.gsub(/\|/,'')} : '') << '|' } # 0 = low resolution fax, 1 = hires STDOUT << '0|' } } rescue LDAP::ResultError => msg STDERR << msg.to_s << "\n" rescue Exception => ex STDERR << ex.to_s << "\n" end