create lighttpd conf files for vhosting
simply add include "incl-domains.conf" to your main lighttpd.conf file
1 2 #!/usr/bin/env ruby -w 3 # 4 # light_conf_editor.rb 5 # 6 # Created by yo on 25.12.05. 7 # 8 # 9 # Description 10 # Creates lighttpd conf files 11 # 12 # usage: light_conf_editor add || remove domainname username 13 # example: light_conf_editor add bigcurl.com yo 14 # example: light_conf_editor remove bigcurl.com yo 15 16 path_to_lighttpd_conf="/etc/lighttpd" 17 18 def remove_include_from_conf(domainname, username, path_to_lighttpd_conf) 19 temp_file="" 20 File.open("#{path_to_lighttpd_conf}/incl-domains.conf", "a+") unless FileTest.exist?("#{path_to_lighttpd_conf}/incl-domains.conf") 21 File.open("#{path_to_lighttpd_conf}/incl-domains.conf", "r") do |file| 22 file.each_line do |line| 23 temp_file.concat(line) unless line.include? "include \"domains/#{username}/#{domainname}.conf\"" 24 end 25 end 26 27 File.open("#{path_to_lighttpd_conf}/incl-domains.conf", "w") do |file| 28 file.puts(temp_file) 29 end 30 31 end 32 33 def remove_conf_from_folder(domainname, username, path_to_lighttpd_conf) 34 File.delete("#{path_to_lighttpd_conf}/domains/#{username}/#{domainname}.conf") if FileTest.exists?( "#{path_to_lighttpd_conf}/domains/#{username}/#{domainname}.conf" ) 35 36 end 37 38 def add_new_conf_in_folder(include_template, domainname, username, path_to_lighttpd_conf) 39 Dir.mkdir( "#{path_to_lighttpd_conf}/domains") unless FileTest.directory?( "#{path_to_lighttpd_conf}/domains/" ) 40 Dir.mkdir( "#{path_to_lighttpd_conf}/domains/#{username}/") unless FileTest.directory?( "#{path_to_lighttpd_conf}/domains/#{username}") 41 42 aFile = File.new("#{path_to_lighttpd_conf}/domains/#{username}/#{domainname}.conf","w") 43 aFile.puts(include_template) 44 aFile.close 45 end 46 47 def add_new_include_in_conf(domainname, username, path_to_lighttpd_conf) 48 File.open("#{path_to_lighttpd_conf}/incl-domains.conf", "a+") do |file| 49 file.puts("include \"domains/#{username}/#{domainname}.conf\"") 50 end 51 end 52 53 def show_usage 54 print "usage: light_conf_editor add domainname username || remove domainname username\n" 55 end 56 57 58 if(ARGV.length < 3) 59 show_usage 60 exit(1) 61 end 62 63 domainname = ARGV[1] 64 65 username = ARGV[2] 66 if(ARGV[0]=="remove") 67 remove_include_from_conf(domainname, username, path_to_lighttpd_conf) 68 remove_conf_from_folder(domainname, username, path_to_lighttpd_conf) 69 end 70 71 72 if(ARGV[0]=="add") 73 74 include_template = "$HTTP[\"host\"] =~ \"#{domainname}$\" { 75 var.username = \"#{username}\" 76 var.servername = \"#{domainname}\" 77 include \"incl-docroot.conf\" 78 79 server.dir-listing = \"enable\" 80 dir-listing.hide-dotfiles = \"enable\" 81 }" 82 83 remove_include_from_conf(domainname, username, path_to_lighttpd_conf) 84 remove_conf_from_folder(domainname, username, path_to_lighttpd_conf) 85 86 add_new_conf_in_folder(include_template, domainname, username, path_to_lighttpd_conf) 87 add_new_include_in_conf(domainname, username, path_to_lighttpd_conf) 88 89 end 90 91