Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Leonhardt Wille
authored and
Leonhardt Wille
committed
Mar 11, 2010
0 parents
commit adb2b8c
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |