From 451f1c3175c1a3c8670f51ebc907102d8c99820d Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 19 Apr 2012 08:54:01 -0400 Subject: [PATCH] Switch from constants to variables in the Configuration module. This should keep Ruby from complaining when users override the defaults. Change the local config path from $HOME/.mailshears.conf to $HOME/.mailshears.conf.rb so that Ruby will actually load it. --- README | 2 +- bin/mailshears | 16 ++++----- lib/default_configuration.rb | 36 ++++++++++----------- lib/mailshears.rb | 4 +-- lib/mailshears/plugins/dovecot_mailstore.rb | 2 +- lib/mailshears/plugins/roundcube_db.rb | 14 ++++---- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/README b/README index 77ad551..1fd643c 100644 --- a/README +++ b/README @@ -36,7 +36,7 @@ Right now, mailshears is targeted at one type of setup: You put it in a directory somewhere, and run bin/mailshears. To make it do anything, you'll need to create a config file. The default is stored in lib/default_configuration.rb; I suggest you copy that to -$HOME/.mailshears.conf and edit it to fit your environment. +$HOME/.mailshears.conf.rb and edit it to fit your environment. You'll probably want to set up a cron job to run it every once in a while. diff --git a/bin/mailshears b/bin/mailshears index 01dcb30..b1a5e00 100755 --- a/bin/mailshears +++ b/bin/mailshears @@ -15,13 +15,13 @@ require 'mailshears' -pgadb = PostfixadminDb.new(Configuration::DBHOST, - Configuration::DBPORT, - Configuration::DBOPTS, - Configuration::DBTTY, - Configuration::DBNAME, - Configuration::DBUSER, - Configuration::DBPASS) +pgadb = PostfixadminDb.new(Configuration::dbhost, + Configuration::dbport, + Configuration::dbopts, + Configuration::dbtty, + Configuration::dbname, + Configuration::dbuser, + Configuration::dbpass) begin @@ -84,7 +84,7 @@ Plugin.includers.each do |plugin_class| puts "Found: #{account} (#{plugin.describe_account(account)})" end - if Configuration::I_MEAN_BUSINESS + if Configuration::i_mean_business # We have to delete the accounts before the domain, # otherwise they'd already be gone. leftover_accounts.each do |account| diff --git a/lib/default_configuration.rb b/lib/default_configuration.rb index 7f3b892..fa20472 100644 --- a/lib/default_configuration.rb +++ b/lib/default_configuration.rb @@ -1,38 +1,38 @@ module Configuration # Really delete domains/accounts, or just find them? This parameter - # could also be called, "I_TRUST_MAILSHEARS_NOT_TO_DO_ANYTHING_BAD". - I_MEAN_BUSINESS = false + # could also be called, "i_trust_mailshears_not_to_do_anything_bad". + i_mean_business = false # How to connect to your user/domain database. At the moment, this # is PostfixAdmin. # # These should be obvious except for the ones that aren't. You can # identify the non-obvious ones by my having left them blank. - DBHOST = 'localhost' - DBPORT = 5432 - DBOPTS = '' - DBTTY = '' - DBUSER = 'postgres' - DBPASS = '' - DBNAME = 'postfix' + dbhost = 'localhost' + dbport = 5432 + dbopts = '' + dbtty = '' + dbuser = 'postgres' + dbpass = '' + dbname = 'postfix' # This defines which plugins we'll use. The rest of the # configuration is plugin-specific. - PLUGINS = ['dovecot_mailstore', 'roundcube_db'] + plugins = ['dovecot_mailstore', 'roundcube_db'] # Where your mailboxes are stored. The exact format could # theoretically change in the future, but for now, the # DovecotMailstore class is going to assume that the mailboxes are # stored beneath this directory in / format. - MAIL_ROOT = '/var/spool/mail/vhosts' + mail_root = '/var/spool/mail/vhosts' # Roundcube-specific configuration. - ROUNDCUBE_DBHOST = 'localhost' - ROUNDCUBE_DBPORT = 5432 - ROUNDCUBE_DBOPTS = '' - ROUNDCUBE_DBTTY = '' - ROUNDCUBE_DBUSER = 'postgres' - ROUNDCUBE_DBPASS = '' - ROUNDCUBE_DBNAME = 'roundcube' + roundcube_dbhost = 'localhost' + roundcube_dbport = 5432 + roundcube_dbopts = '' + roundcube_dbtty = '' + roundcube_dbuser = 'postgres' + roundcube_dbpass = '' + roundcube_dbname = 'roundcube' end diff --git a/lib/mailshears.rb b/lib/mailshears.rb index 0402d60..e159b09 100644 --- a/lib/mailshears.rb +++ b/lib/mailshears.rb @@ -8,14 +8,14 @@ require 'mailshears/postfixadmin_db' # Load the default config file first, and let the user override it. require 'default_configuration' -userconf_path = ENV['HOME'] + '/.mailshears.conf' +userconf_path = ENV['HOME'] + '/.mailshears.conf.rb' begin # Don't crash if it doesn't exist. Maybe he likes the defaults? require userconf_path rescue LoadError end -Configuration::PLUGINS.each do |plugin_file| +Configuration::plugins.each do |plugin_file| require "mailshears/plugins/#{plugin_file}" end diff --git a/lib/mailshears/plugins/dovecot_mailstore.rb b/lib/mailshears/plugins/dovecot_mailstore.rb index c50b117..965d2d2 100644 --- a/lib/mailshears/plugins/dovecot_mailstore.rb +++ b/lib/mailshears/plugins/dovecot_mailstore.rb @@ -11,7 +11,7 @@ class DovecotMailstore < Mailstore include Plugin def initialize - @domain_root = Configuration::MAIL_ROOT + @domain_root = Configuration::mail_root end def describe_domain(domain) diff --git a/lib/mailshears/plugins/roundcube_db.rb b/lib/mailshears/plugins/roundcube_db.rb index cb2e055..c86d314 100644 --- a/lib/mailshears/plugins/roundcube_db.rb +++ b/lib/mailshears/plugins/roundcube_db.rb @@ -5,13 +5,13 @@ class RoundcubeDb include Plugin def initialize() - @db_host = Configuration::ROUNDCUBE_DBHOST - @db_port = Configuration::ROUNDCUBE_DBPORT - @db_opts = Configuration::ROUNDCUBE_DBOPTS - @db_tty = Configuration::ROUNDCUBE_DBTTY - @db_name = Configuration::ROUNDCUBE_DBNAME - @db_user = Configuration::ROUNDCUBE_DBUSER - @db_pass = Configuration::ROUNDCUBE_DBPASS + @db_host = Configuration::roundcube_dbhost + @db_port = Configuration::roundcube_dbport + @db_opts = Configuration::roundcube_dbopts + @db_tty = Configuration::roundcube_dbtty + @db_name = Configuration::roundcube_dbname + @db_user = Configuration::roundcube_dbuser + @db_pass = Configuration::roundcube_dbpass end -- 2.44.2