Rename PostfixadminDb, RoundcubeDb without the Db suffix.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 6 Oct 2013 20:06:57 +0000 (16:06 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 6 Oct 2013 20:06:57 +0000 (16:06 -0400)
Make PostfixadminDb a regular plugin.

19 files changed:
bin/mailshears
doc/README
lib/common/configuration.rb
lib/common/davical_plugin.rb
lib/common/dovecot_plugin.rb [moved from lib/common/dovecot_mailstore_plugin.rb with 96% similarity]
lib/common/postfixadmin_plugin.rb [moved from lib/common/postfixadmin_db_plugin.rb with 88% similarity]
lib/common/roundcube_plugin.rb [moved from lib/common/roundcube_db_plugin.rb with 95% similarity]
lib/mv/plugins/dovecot.rb [moved from lib/mv/plugins/dovecot_mailstore.rb with 78% similarity]
lib/mv/plugins/roundcube.rb [moved from lib/mv/plugins/roundcube_db.rb with 90% similarity]
lib/prune/plugins/agendav.rb
lib/prune/plugins/davical.rb
lib/prune/plugins/dovecot.rb [moved from lib/prune/plugins/dovecot_mailstore.rb with 79% similarity]
lib/prune/plugins/postfixadmin.rb [new file with mode: 0644]
lib/prune/plugins/roundcube.rb [new file with mode: 0644]
lib/prune/plugins/roundcube_db.rb [deleted file]
lib/rm/plugins/dovecot.rb [moved from lib/rm/plugins/dovecot_mailstore.rb with 81% similarity]
lib/rm/plugins/postfixadmin.rb [moved from lib/rm/plugins/postfixadmin_db.rb with 97% similarity]
lib/rm/plugins/roundcube.rb [moved from lib/rm/plugins/roundcube_db.rb with 93% similarity]
mailshears.example.conf.yml

index 37d660175dff6b1f055c73d3320b3031a04a2e06..cb8ee4122d33b1cd4d5ee8c07625dab9dbe333d8 100755 (executable)
@@ -57,9 +57,6 @@ cfg.plugins.each do |plugin_file|
   require "#{mode_name}/plugins/#{plugin_file}"
 end
 
-# Always enabled, for now.
-require "#{mode_name}/plugins/postfixadmin_db"
-
 # And the runners.
 require "#{mode_name}/#{mode_name}_runner"
 require "#{mode_name}/#{mode_name}_dummy_runner"
index 1f065587ccbf25f5d660e6936f1e567f99668fba..353742403fe198363c23fddc43da00f94331d8f0 100644 (file)
@@ -46,10 +46,9 @@ while.
 
 Mailshears gets a list of users and domains from your PostfixAdmin
 database. It then delegates to the plugins. A plugin represents
-something that you would like to clean up. For example, the
-DovecotMailstore plugin represents the physical mail
-files/directories. The RoundcubeDb plugin represents a Roundcube SQL
-database.
+something that you would like to clean up. For example, the Dovecot
+plugin represents the physical mail files/directories. The Roundcube
+plugin represents a Roundcube SQL database.
 
 Each plugin knows how to get a list of its own users and domains. If
 there's a user or domain in the plugin list that isn't in the
index b2a37d01177551cb51c56752e601c7a66f43a976..43ef03b3e726f5fd694b44c6bac1a4416a0e5d52 100644 (file)
@@ -41,15 +41,15 @@ class Configuration
 
     d['i_mean_business'] = false
 
-    d['dbhost'] = 'localhost'
-    d['dbport'] = 5432
-    d['dbopts'] = ''
-    d['dbtty'] = ''
-    d['dbuser'] = 'postgres'
-    d['dbpass'] = ''
-    d['dbname'] = 'postfix'
-
-    d['plugins'] = ['dovecot_mailstore', 'roundcube_db']
+    d['postfixadmin_dbhost'] = 'localhost'
+    d['postfixadmin_dbport'] = 5432
+    d['postfixadmin_dbopts'] = ''
+    d['postfixadmin_dbtty'] = ''
+    d['postfixadmin_dbuser'] = 'postgres'
+    d['postfixadmin_dbpass'] = ''
+    d['postfixadmin_dbname'] = 'postfixadmin'
+
+    d['plugins'] = ['postfixadmin', 'dovecot', 'roundcube']
 
     d['mail_root'] = '/var/spool/mail/vhosts'
 
index 1cc06ce0dd397d7e4e26443aa68871b82511e8df..c8a67261c16c23cad6da901128cd281e7e384076 100644 (file)
@@ -82,7 +82,8 @@ module DavicalPlugin
                                   @db_user,
                                   @db_pass)
 
-      sql_query =  "SELECT username FROM usr"
+      # User #1 is the super-user, and not tied to an email address.
+      sql_query =  "SELECT username FROM usr WHERE user_no > 1"
 
       connection.query(sql_query) do |result|
         usernames = result.field_values('username')
similarity index 96%
rename from lib/common/dovecot_mailstore_plugin.rb
rename to lib/common/dovecot_plugin.rb
index 90aa02c8fde2b582c93afda07902a36ea17c5722..2496bae2eade64be5889c4a5057b8ac00e4b5228 100644 (file)
@@ -1,8 +1,8 @@
 require 'common/plugin'
 require 'common/filesystem'
 
-module DovecotMailstorePlugin
-  # Code that all DovecotMailstore plugins (Prune, Rm, Mv...) will
+module DovecotPlugin
+  # Code that all Dovecot plugins (Prune, Rm, Mv...) will
   # share.  That is, we implement the Plugin interface.
   include Plugin
 
similarity index 88%
rename from lib/common/postfixadmin_db_plugin.rb
rename to lib/common/postfixadmin_plugin.rb
index da40879ed07c03214cab62d2984d5a5da86b7cf6..4bfda9dcdece7e7216856b17ff96745c031313e7 100644 (file)
@@ -1,21 +1,21 @@
 require 'common/plugin'
 require 'pg'
 
-module PostfixadminDbPlugin
-  # Code that all PostfixadminDb plugins (Prune, Rm, Mv...) will
+module PostfixadminPlugin
+  # Code that all Postfixadmin plugins (Prune, Rm, Mv...) will
   # share.  That is, we implement the Plugin interface.
   include Plugin
 
   def initialize()
 
     cfg = Configuration.new()
-    @db_host = cfg.dbhost
-    @db_port = cfg.dbport
-    @db_opts = cfg.dbopts
-    @db_tty  = cfg.dbtty
-    @db_name = cfg.dbname
-    @db_user = cfg.dbuser
-    @db_pass = cfg.dbpass
+    @db_host = cfg.postfixadmin_dbhost
+    @db_port = cfg.postfixadmin_dbport
+    @db_opts = cfg.postfixadmin_dbopts
+    @db_tty  = cfg.postfixadmin_dbtty
+    @db_name = cfg.postfixadmin_dbname
+    @db_user = cfg.postfixadmin_dbuser
+    @db_pass = cfg.postfixadmin_dbpass
   end
 
 
similarity index 95%
rename from lib/common/roundcube_db_plugin.rb
rename to lib/common/roundcube_plugin.rb
index df5413fdb0cc7a797dc2fd1f7070f3809b7f2abc..8e9d62259d78fd9819bc2ef77bc97c3c2b0fa96c 100644 (file)
@@ -1,7 +1,7 @@
 require 'common/plugin'
 
-module RoundcubeDbPlugin
-  # Code that all RoundcubeDb plugins (Prune, Rm, Mv...) will share.
+module RoundcubePlugin
+  # Code that all Roundcube plugins (Prune, Rm, Mv...) will share.
   # That is, we implement the Plugin interface.
   include Plugin
 
similarity index 78%
rename from lib/mv/plugins/dovecot_mailstore.rb
rename to lib/mv/plugins/dovecot.rb
index f16f1165af99ad055384e20862594829d2db72bd..0eb688861442aba8e07e8cad640a92ce7ec30abc 100644 (file)
@@ -1,11 +1,11 @@
 require 'common/filesystem'
 require 'common/mailstore'
-require 'common/dovecot_mailstore_plugin'
+require 'common/dovecot_plugin'
 require 'mv/mv_plugin'
 
-class DovecotMailstoreMv < Mailstore
+class DovecotMv < Mailstore
 
-  include DovecotMailstorePlugin
+  include DovecotPlugin
   include MvPlugin
 
 
similarity index 90%
rename from lib/mv/plugins/roundcube_db.rb
rename to lib/mv/plugins/roundcube.rb
index fa29aa6a6e67bdda9817bb6e5ee292a68950bc5f..50a52c302cd2a25613f4c463eb5232c7a756b055 100644 (file)
@@ -1,11 +1,11 @@
 require 'pg'
 
-require 'common/roundcube_db_plugin'
+require 'common/roundcube_plugin'
 require 'mv/mv_plugin'
 
-class RoundcubeDbMv
+class RoundcubeMv
 
-  include RoundcubeDbPlugin
+  include RoundcubePlugin
   include MvPlugin
 
 
index 15787734517c2345a19eb24e1e1a24e78bb657c0..083a3e42731c6aeb59391b2d96a8387885a77cd6 100644 (file)
@@ -1,23 +1,23 @@
 require 'pg'
 
-require 'common/agendav_plugin'
 require 'prune/prune_plugin'
 require 'rm/plugins/agendav'
 
 class AgendavPrune < AgendavRm
 
-  include AgendavPlugin
   include PrunePlugin
 
   def get_leftover_domains(db_domains)
-    # AgenDAV doesn't have a concept of domains.
+    # AgenDAV doesn't have a concept of domains. We could parse the
+    # usernames to see what domains are present, but the point is
+    # moot: all leftover accounts will be pruned anyway.
     return []
   end
 
 
   def get_leftover_accounts(db_accounts)
     # Get a list of all users who have logged in to AgenDAV.
-    ad_accounts = self.get_agendav_usernames()
+    ad_accounts = self.list_users()
     return ad_accounts - db_accounts
   end
 
index ae21d9f186a859309fc58584e7d8d010c490b926..d13684eb26414a4cb6cd5f44c6cadbd9550ad274 100644 (file)
@@ -1,6 +1,5 @@
 require 'pg'
 
-require 'common/davical_plugin'
 require 'prune/prune_plugin'
 require 'rm/plugins/davical'
 
@@ -9,52 +8,22 @@ class DavicalPrune < DavicalRm
   # DAViCal only supports Postgres, so even if we ever are
   # database-agnostic, this plugin can't be.
   #
-  include DavicalPlugin
   include PrunePlugin
 
 
   def get_leftover_domains(db_domains)
-    # AgenDAV doesn't have a concept of domains.
+    # DAViCal doesn't have a concept of domains. We could parse the
+    # usernames to see what domains are present, but the point is
+    # moot: all leftover accounts will be pruned anyway.
     return []
   end
 
 
   def get_leftover_accounts(db_accounts)
     # Get a list of all users who have logged in to DAViCal.
-    davical_accounts = self.get_davical_usernames()
+    davical_accounts = self.list_users()
     return davical_accounts - db_accounts
   end
 
 
-  protected;
-
-  def get_davical_usernames()
-    usernames = []
-
-    begin
-      connection = PGconn.connect(@db_host,
-                                  @db_port,
-                                  @db_opts,
-                                  @db_tty,
-                                  @db_name,
-                                  @db_user,
-                                  @db_pass)
-
-      # User #1 is the super-user, and not tied to an email address.
-      sql_query  = 'SELECT username FROM usr WHERE user_no > 1;'
-
-      connection.query(sql_query) do |result|
-        usernames = result.field_values('username')
-      end
-
-      connection.close()
-    rescue PGError => e
-      # Pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
-    end
-
-    return usernames
-  end
-
-
 end
similarity index 79%
rename from lib/prune/plugins/dovecot_mailstore.rb
rename to lib/prune/plugins/dovecot.rb
index eddd822f0bfff4c04fbf2d9bcf2da51aba17d23f..88e5c1cb875351293758c945608f8a1a5f363590 100644 (file)
@@ -1,10 +1,8 @@
-require 'common/dovecot_mailstore_plugin'
 require 'prune/prune_plugin'
-require 'rm/plugins/dovecot_mailstore'
+require 'rm/plugins/dovecot'
 
-class DovecotMailstorePrune < DovecotMailstoreRm
+class DovecotPrune < DovecotRm
 
-  include DovecotMailstorePlugin
   include PrunePlugin
 
 
diff --git a/lib/prune/plugins/postfixadmin.rb b/lib/prune/plugins/postfixadmin.rb
new file mode 100644 (file)
index 0000000..d085489
--- /dev/null
@@ -0,0 +1,24 @@
+require 'pg'
+
+require 'prune/prune_plugin'
+require 'rm/plugins/postfixadmin'
+
+class PostfixadminPrune < PostfixadminRm
+
+  include PrunePlugin
+
+  #def get_leftover_domains(db_domains)
+    # AgenDAV doesn't have a concept of domains. We could parse the
+    # usernames to see what domains are present, but the point is
+    # moot: all leftover accounts will be pruned anyway.
+  #return []
+#end
+
+
+  #def get_leftover_accounts(db_accounts)
+    # Get a list of all users who have logged in to AgenDAV.
+  #ad_accounts = self.list_users()
+   # return ad_accounts - db_accounts
+  #end
+
+end
diff --git a/lib/prune/plugins/roundcube.rb b/lib/prune/plugins/roundcube.rb
new file mode 100644 (file)
index 0000000..77eacfc
--- /dev/null
@@ -0,0 +1,25 @@
+require 'pg'
+
+require 'prune/prune_plugin'
+require 'rm/plugins/roundcube'
+
+class RoundcubePrune < RoundcubeRm
+
+  include PrunePlugin
+
+
+  def get_leftover_domains(db_domains)
+    # Roundcube doesn't have a concept of domains. We could parse the
+    # usernames to see what domains are present, but the point is
+    # moot: all leftover accounts will be pruned anyway.
+    return []
+  end
+
+
+  def get_leftover_accounts(db_accounts)
+    # Get a list of all users who have logged in to Roundcube.
+    rc_accounts = self.list__users()
+    return rc_accounts - db_accounts
+  end
+
+end
diff --git a/lib/prune/plugins/roundcube_db.rb b/lib/prune/plugins/roundcube_db.rb
deleted file mode 100644 (file)
index 6515a7b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'pg'
-
-require 'common/roundcube_db_plugin'
-require 'prune/prune_plugin'
-require 'rm/plugins/roundcube_db'
-
-class RoundcubeDbPrune < RoundcubeDbRm
-
-  include RoundcubeDbPlugin
-  include PrunePlugin
-
-
-  def get_leftover_domains(db_domains)
-    # Roundcube doesn't have a concept of domains.
-    return []
-  end
-
-
-  def get_leftover_accounts(db_accounts)
-    # Get a list of all users who have logged in to Roundcube.
-    rc_accounts = self.get_roundcube_usernames()
-    return rc_accounts - db_accounts
-  end
-
-end
similarity index 81%
rename from lib/rm/plugins/dovecot_mailstore.rb
rename to lib/rm/plugins/dovecot.rb
index 8647b01a1685e0e4382f865900bdb26bd9d7a73a..4283e9c2267f9b0088febcd4d5b45ea423ddb660 100644 (file)
@@ -1,12 +1,12 @@
 # Needed for rm_r.
 require 'fileutils'
 
-require 'common/dovecot_mailstore_plugin'
+require 'common/dovecot_plugin'
 require 'rm/rm_plugin'
 
-class DovecotMailstoreRm
+class DovecotRm
 
-  include DovecotMailstorePlugin
+  include DovecotPlugin
   include RmPlugin
 
 
similarity index 97%
rename from lib/rm/plugins/postfixadmin_db.rb
rename to lib/rm/plugins/postfixadmin.rb
index ca91b8beb553f545b00f8de85c5cc475bef594fa..3883e866103e71dff7cf75ecb37681cebca7ca11 100644 (file)
@@ -1,11 +1,11 @@
 require 'pg'
 
-require 'common/postfixadmin_db_plugin'
+require 'common/postfixadmin_plugin'
 require 'rm/rm_plugin'
 
-class PostfixadminDbRm
+class PostfixadminRm
 
-  include PostfixadminDbPlugin
+  include PostfixadminPlugin
   include RmPlugin
 
 
similarity index 93%
rename from lib/rm/plugins/roundcube_db.rb
rename to lib/rm/plugins/roundcube.rb
index 5cda273643029ef808c9b184621017779f92806e..3dbee8ea61b948033f6ffd8df94ba86d31535e24 100644 (file)
@@ -1,11 +1,11 @@
 require 'pg'
 
-require 'common/roundcube_db_plugin'
+require 'common/roundcube_plugin'
 require 'rm/rm_plugin'
 
-class RoundcubeDbRm
+class RoundcubeRm
 
-  include RoundcubeDbPlugin
+  include RoundcubePlugin
   include RmPlugin
 
   def delete_account(account)
index 2ab0fdc97ab681a1c642c811bef5a015c7ec5657..fd703ff485183a9eb04eb277fed06058df961a34 100644 (file)
@@ -1,14 +1,14 @@
 i_mean_business: false
 
-dbhost: localhost
-dbport: 5432
-dbopts:
-dbtty:
-dbuser: postgres
-dbpass:
-dbname: postfix
+postfixadmin_dbhost: localhost
+postfixadmin_dbport: 5432
+postfixadmin_dbopts:
+postfixadmin_dbtty:
+postfixadmin_dbuser: postgres
+postfixadmin_dbpass:
+postfixadmin_dbname: postfixadmin
 
-plugins: [dovecot_mailstore, roundcube_db, agendav, davical]
+plugins: [postfixadmin, dovecot, roundcube, agendav, davical]
 
 mail_root: /var/spool/mail/vhosts