Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonhardt Wille authored and Leonhardt Wille committed Mar 11, 2010
0 parents commit adb2b8c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Empty file added README.md
Empty file.
27 changes: 27 additions & 0 deletions etc/security/hosts_allowed.yml
@@ -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"
27 changes: 27 additions & 0 deletions usr/sbin/resolver
@@ -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.