]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Get prune working, at least in a simple case.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 6 Oct 2013 22:55:50 +0000 (18:55 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 6 Oct 2013 22:55:50 +0000 (18:55 -0400)
bin/mailshears
lib/prune/plugins/postfixadmin.rb
lib/prune/plugins/roundcube.rb
lib/prune/prune_dummy_runner.rb
lib/prune/prune_runner.rb
lib/rm/rm_dummy_runner.rb

index cb8ee4122d33b1cd4d5ee8c07625dab9dbe333d8..441708e674401e62dd0657ebe5e9e9184a7644d6 100755 (executable)
@@ -118,79 +118,4 @@ plugin_class.includers.each do |plugin_class_includer|
   # *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
index d085489f5b9ffb274877157d05e55b0768799572..62e564710166468e142ddabc5fe9f6d3c404bf2e 100644 (file)
@@ -1,24 +1,10 @@
-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
index 77eacfcb6fe5f1f09722769aaa82360c68c53334..1ad8cdb786b989c3c86d9be1b868a9f4e85c4992 100644 (file)
@@ -18,7 +18,7 @@ class RoundcubePrune < RoundcubeRm
 
   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
 
index 8e9fcd9f14280e43af55c7fe10a43940e61efeb1..4274bef8f08db79990e9e98cc42e15d2c129619e 100644 (file)
@@ -1,10 +1,32 @@
 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
index 789ed573623ef3b72cd0e5d983c45e9f1bbc68c1..74455d6b2ba8903655ce385b8e4c16d81ad4ccf6 100644 (file)
@@ -1,10 +1,35 @@
 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
index 9bdd13f5f47fb2dc1b71e7c012545c47c08e7e4a..091d32881bb9940f5f72c5ff2f67c3ba0030010e 100644 (file)
@@ -6,14 +6,11 @@ class RmDummyRunner
   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