# *target arguments as well, to turn ARGV back into an array.
runner.run(plugin, *ARGV)
- puts ""
-end
-
-
-
-Kernel.exit(0)
-
-
-begin
- # Get a list of domains from the Postfixadmin database.
- db_domains = pgadb.get_domains_from_db()
-rescue DatabaseError => e
- puts "There was an error connecting to the database: #{e.to_s}"
- Kernel.exit(ExitCodes::DATABASE_ERROR)
-end
-
-begin
- # And the accounts.
- db_accounts = pgadb.get_accounts_from_db()
-rescue DatabaseError => e
- puts "There was an error connecting to the database: #{e.to_s}"
- Kernel.exit(ExitCodes::DATABASE_ERROR)
-end
-
-
-Plugin.includers.each do |plugin_class_includer|
- plugin = plugin_class_includer.new()
-
- begin
- leftover_domains = plugin.get_leftover_domains(db_domains)
- rescue StandardError => e
- puts "There was an error retrieving domains from the filesystem: #{e.to_s}"
- Kernel.exit(ExitCodes::FILESYSTEM_ERROR)
- end
-
- begin
- leftover_accounts = plugin.get_leftover_accounts(db_accounts)
- rescue StandardError => e
- puts "There was an error retrieving accounts from the filesystem: #{e.to_s}"
- Kernel.exit(ExitCodes::FILESYSTEM_ERROR)
- end
-
- if leftover_domains.size > 0 or leftover_accounts.size > 0
- puts make_header(plugin_class.to_s())
-
- leftover_domains.each do |domain|
- puts "Found: #{domain} (#{plugin.describe_domain(domain)})"
- end
-
- leftover_accounts.each do |account|
- puts "Found: #{account} (#{plugin.describe_account(account)})"
- end
-
- if cfg.i_mean_business
- # We have to delete the accounts before the domain,
- # otherwise they'd already be gone.
- leftover_accounts.each do |account|
- # Get the description before we delete the domain.
- # This can still fail if the account's domain is gone.
- account_description = plugin.describe_account(account)
- plugin.delete_account(account)
- puts "Removed: #{account} (#{account_description})"
- end
-
- leftover_domains.each do |domain|
- # Get the description before we delete the domain.
- domain_description = plugin.describe_domain(domain)
- plugin.delete_domain(domain)
- puts "Removed: #{domain} (#{domain_description})"
- end
- end
-
- puts ""
- end
-
end
-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
-
+ # We don't need the ability to remove "left over" accounts or
+ # domains, since "left over" is with respect to what's in
+ # PostfixAdmin. In other words, the other plugins check themselves
+ # against PostfixAdmin, it doesn't make sense to check PostfixAdmin
+ # against itself.
end
def get_leftover_accounts(db_accounts)
# Get a list of all users who have logged in to Roundcube.
- rc_accounts = self.list__users()
+ rc_accounts = self.list_users()
return rc_accounts - db_accounts
end
require 'common/runner'
+# This is always needed, regardless of which plugin is running.
+require 'prune/plugins/postfixadmin'
+
class PruneDummyRunner
include Runner
def run(plugin)
- puts "Not implemented"
+ # We don't want to check the PostfixAdmin database against itself.
+ return if plugin.class == PostfixadminPrune
+
+ pfa = PostfixadminPrune.new()
+
+ db_users = pfa.list_users()
+ db_domains = pfa.list_domains()
+
+ leftover_users = plugin.get_leftover_accounts(db_users)
+ leftover_domains = plugin.get_leftover_domains(db_domains)
+
+ leftover_users.each do |user|
+ user_description = plugin.describe_account(user)
+ report(plugin, "Would remove user: #{user} (#{user_description})")
+ end
+
+ leftover_domains.each do |domain|
+ domain_description = plugin.describe_domain(domain)
+ report(plugin, "Would remove domain: #{domain} (#{domain_description})")
+ end
end
end
require 'common/runner'
+# This is always needed, regardless of which plugin is running.
+require 'prune/plugins/postfixadmin'
+
class PruneRunner
include Runner
def run(plugin)
- puts "Not implemented"
+ # We don't want to check the PostfixAdmin database against itself.
+ return if plugin.class == PostfixadminPrune
+
+ pfa = PostfixadminPrune.new()
+
+ db_users = pfa.list_users()
+ db_domains = pfa.list_domains()
+
+ leftover_users = plugin.get_leftover_accounts(db_users)
+ leftover_domains = plugin.get_leftover_domains(db_domains)
+
+ leftover_users.each do |user|
+ user_description = plugin.describe_account(user)
+ plugin.delete_account(user)
+ report(plugin, "Removed user: #{user} (#{user_description})")
+ end
+
+ leftover_domains.each do |domain|
+ domain_description = plugin.describe_domain(domain)
+ plugin.delete_domain(domain)
+ report(plugin, "Removed domain: #{domain} (#{domain_description})")
+ end
+
end
end
def run(plugin, *targets)
targets.each do |target|
if target.include?('@') then
- puts "Would remove account: #{target}"
- # TODO: remove from postfixadmin as well.
+ user_description = plugin.describe_account(target)
+ report(plugin, "Would remove user: #{user} (#{user_description})")
else
- usernames = plugin.get_domain_usernames(target)
- usernames.each { |u| run(plugin, u) }
-
- puts "Would remove domain: #{target}"
- # TODO: remove from postfixadmin as well.
+ domain_description = plugin.describe_domain(target)
+ report(plugin, "Would remove domain: #{domain} (#{domain_description})")
end
end