Class: VhostAdmin::Base
- Inherits:
-
Object
- Object
- VhostAdmin::Base
- Defined in:
- lib/vhost_admin/base.rb
Constant Summary collapse
- CONFIG_FILE =
'.vhost_admin.conf'
Instance Method Summary collapse
- #add_domain(domain, password, user = nil) ⇒ Object
- #config_file ⇒ Object
- #create_config ⇒ Object
- #delete_domain(domain, user = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #load_config ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/vhost_admin/base.rb', line 9 def initialize(={}) @config = load_config @crypt = [:crypt] || false end |
Instance Method Details
#add_domain(domain, password, user = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vhost_admin/base.rb', line 40 def add_domain(domain, password, user=nil) begin unless File.exist?(@config['apache_conf_file']) FileUtils.touch(@config['apache_conf_file']) end if include_apache_domain?(domain) raise "#{domain} is already registered in the apache config file." end user = user || domain add_unix_user(user, password) add_apache_domain(domain, user) add_mail_domain(domain, password) rescue => error exit_with_error(error) end end |
#config_file ⇒ Object
37 38 39 |
# File 'lib/vhost_admin/base.rb', line 37 def config_file File.(CONFIG_FILE, ENV['HOME']) end |
#create_config ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vhost_admin/base.rb', line 23 def create_config config = { 'apache_conf_file' => '/etc/httpd/conf/virtual/virtualhosts.conf', 'home_dir_base' => '/var/www/vhost', 'mail_dir_base' => '/mail', 'backup_dir' => '/root/deletetmp', 'quota_user' => 'quota1gb', 'encrypt' => 'cleartext' } open(config_file, 'w') do |f| f.write config.to_yaml end File.chmod(0600, config_file) end |
#delete_domain(domain, user = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vhost_admin/base.rb', line 57 def delete_domain(domain, user=nil) begin user = user || domain backup_domain_data(domain, user) delete_domain_data(domain, user) res = apache_test if res puts "Apache test is OK!" exec("apachectl graceful") end rescue => error exit_with_error(error) end end |
#load_config ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vhost_admin/base.rb', line 13 def load_config unless File.exist?(config_file) create_config puts "configure file: #{config_file} was generated.\nPlease execute after edit it." exit end open(config_file) do |f| YAML.load(f.read) end end |