Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit adb2b8ccf62fc9147688cac4e7a6a2dbc9cc38e1 Leonhardt Wille committed Mar 11, 2010
Showing with 54 additions and 0 deletions.
  1. 0 README.md
  2. +27 −0 etc/security/hosts_allowed.yml
  3. +27 −0 usr/sbin/resolver
No changes.
@@ -0,0 +1,27 @@
+# Configuration file for allow_hosts script by Leo
+# Allowed hostnames
+hostnames:
+ emma: emma-mobil.kicks-ass.net
+ erich: erich.homelinux.org
+ flo: flobraeuer.dyndns.info
+
+# Files to change
+# The script looks after a BEGIN allowed_hosts ... END allowed_hosts block in each file
+# For each entry in the hostnames section, the contents of the block will be replaced
+# by a comment and configuration line specified for each file.
+# The text has to be enclosed by double quotes.
+# The following variables can be used (using #{variable}):
+# ip
+# host
+# name
+# After each line, a newline character is automatically inserted.
+
+files:
+ ssh:
+ path: 'access.conf'
+ comment: "# #{name}/#{host}"
+ line: "+ : root : #{ip}"
+ postgres:
+ path: 'pg_hba.conf'
+ comment: "# #{name}/#{host}"
+ line: "hostssl\tall\t\tall\t\t#{ip}/32\tmd5"
@@ -0,0 +1,27 @@
+require 'yaml'
+require 'resolv'
+require 'ftools'
+puts "#{Time.now}\nip-resolver.rb © Leonhardt Wille"
+config = YAML::load_file('hosts_allowed.yml')
+config['files'].each do |k,file|
+ File.copy(file['path'],file['path']+".bak",true)
+ puts "Opening #{file['path']}"
+ fd=File.open(file['path'], 'r+')
+ line = file['line']
+ comment = file['comment']
+ lines=config['hostnames'].collect do |name,host|
+ puts "\tWriting entry #{name}"
+ ip=Resolv.getaddress host
+ eval "\"#{comment}\n#{line}\n\""
+ end
+ content=fd.read
+ if content.gsub!(/(# BEGIN allowed_hosts\n)(.*)(\n# END allowed_hosts)/m,"# BEGIN allowed_hosts\n#{lines}\n# END allowed_hosts")
+ fd.rewind
+ puts "\tsaving file"
+ fd.write content
+ else
+ raise "#BEGIN ... #END block not found."
+ end
+ puts "\tclosing #{file['path']}"
+ fd.close
+end

0 comments on commit adb2b8c

Please sign in to comment.