diff options
author | Aleksander Machniak <machniak@kolabsys.com> | 2016-05-06 15:38:14 +0200 |
---|---|---|
committer | Aleksander Machniak <machniak@kolabsys.com> | 2016-05-06 15:38:14 +0200 |
commit | c8c73c853b1c05d80b76b82fabbe337d9c3fb61e (patch) | |
tree | a44b5c034e0e3a3121e0986598e2873a5cb6e408 | |
parent | 0a4930ca58f121280c7a2e5ba29335ee55b3ceaf (diff) | |
download | webadmin-c8c73c853b1c05d80b76b82fabbe337d9c3fb61e.tar.gz |
Add --dry-run argument to purge-deleted-domains
-rwxr-xr-x | bin/purge-deleted-domains | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/bin/purge-deleted-domains b/bin/purge-deleted-domains index d5cb215..4a90673 100755 --- a/bin/purge-deleted-domains +++ b/bin/purge-deleted-domains @@ -34,6 +34,7 @@ $CONF = Conf::get_instance(); $username = $CONF->get('ldap', 'bind_dn'); $password = $CONF->get('ldap', 'bind_pw'); $domain = $CONF->get('kolab', 'primary_domain'); +$dry_run = in_array('--dry-run', $argv); // see https://cgit.kolab.org/webadmin/tree/lib/kolab_api_controller.php#n292 session_start(); @@ -49,7 +50,7 @@ if (empty($domains)) { // delete domains foreach ($domains as $dn => $domain) { - delete_domain($dn, $domain); + delete_domain($dn, $domain, $dry_run); } @@ -81,7 +82,7 @@ function list_deleted_domains() return $result['list']; } -function delete_domain($domain_dn, $domain) +function delete_domain($domain_dn, $domain, $dry_run = false) { global $LDAP, $CONF; @@ -106,27 +107,33 @@ function delete_domain($domain_dn, $domain) $inetdomainbasedn = "dc=" . implode(',dc=', explode('.', $domain_name)); } - // only deletes associateddomain=domain.tld,cn=kolab,cn=config - if (!$LDAP->delete_entry($domain_dn)) { - echo "Error: Failed to delete $domain_dn.\n"; - return; - } - $entries = array(); $entries[] = $inetdomainbasedn; - $cn = str_replace('.', '_', $domain_name); + $cn = str_replace('.', '_', $domain_name); if ($LDAP->get_entry_attribute("cn={$cn},cn=ldbm database,cn=plugins,cn=config", 'nsuniqueid')) { $entries[] = "cn={$cn},cn=ldbm database,cn=plugins,cn=config"; } - $cn = str_replace(array(',', '='), array('\2C', '\3D'), $inetdomainbasedn); + $cn = str_replace(array(',', '='), array('\2C', '\3D'), $inetdomainbasedn); if ($LDAP->get_entry_attribute("cn={$cn},cn=mapping tree,cn=config", 'nsuniqueid')) { $entries[] = "cn={$cn},cn=mapping tree,cn=config"; } + if ($dry_run) { + echo "Deleting $domain_dn\n"; + } + // only deletes associateddomain=domain.tld,cn=kolab,cn=config + else if (!$LDAP->delete_entry($domain_dn)) { + echo "Error: Failed to delete $domain_dn.\n"; + return; + } + foreach ($entries as $dn) { - if (!$LDAP->delete_entry_recursive($dn)) { + if ($dry_run) { + echo "Deleting $dn\n"; + } + else if (!$LDAP->delete_entry_recursive($dn)) { echo "Error: Failed to delete $dn.\n"; return; } |