Make PostfixadminDb a regular plugin.
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"
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
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'
@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')
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
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
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
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
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
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
require 'pg'
-require 'common/davical_plugin'
require 'prune/prune_plugin'
require 'rm/plugins/davical'
# 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
-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
--- /dev/null
+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
--- /dev/null
+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
+++ /dev/null
-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
# 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
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
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)
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