Enigma: Delete user keys when using deluser.sh script

pull/5268/merge
Aleksander Machniak 9 years ago
parent ac1cd3719c
commit 3f01232625

@ -2,6 +2,7 @@ CHANGELOG Roundcube Webmail
===========================
- Update TinyMCE to version 4.3.13 (#5309)
- Enigma: Delete user keys when using deluser.sh script
- Enigma: Fix redundant list-secret-keys/list-public-keys calls on signing/encryption
- Enigma: Implement PGP encryption and signing in one go (#5302)
- Enigma: Display signature verification status for encrypted+signed messages (#5302)

@ -21,7 +21,7 @@
*/
class enigma extends rcube_plugin
{
public $task = 'mail|settings';
public $task = 'mail|settings|cli';
public $rc;
public $engine;
public $ui;
@ -85,6 +85,9 @@ class enigma extends rcube_plugin
$this->ui->add_css();
}
}
else if ($this->rc->task == 'cli') {
$this->add_hook('user_delete_commit', array($this, 'user_delete'));
}
$this->add_hook('refresh', array($this, 'refresh'));
}
@ -508,4 +511,16 @@ class enigma extends rcube_plugin
return $p;
}
/**
* Handle delete_user_commit hook
*/
function user_delete($p)
{
$this->load_engine();
$p['abort'] = $p['abort'] || !$this->engine->delete_user_data($p['username']);
return $p;
}
}

@ -1353,4 +1353,53 @@ class enigma_engine
$part->mimetype == 'application/pgp-keys'
);
}
/**
* Removes all user keys and assigned data
*
* @param string Username
*
* @return bool True on success, False on failure
*/
public function delete_user_data($username)
{
$homedir = $this->rc->config->get('enigma_pgp_homedir', INSTALL_PATH . 'plugins/enigma/home');
$homedir .= DIRECTORY_SEPARATOR . $username;
return self::delete_dir($homedir);
}
/**
* Recursive method to remove directory with its content
*
* @param string Directory
*/
public static function delete_dir($dir)
{
// This code can be executed from command line, make sure
// we have permissions to delete keys directory
if (!is_writable($dir)) {
rcube::raise_error("Unable to delete $dir", false, true);
return false;
}
if ($content = scandir($dir)) {
foreach ($content as $filename) {
if ($filename != '.' && $filename != '..') {
$filename = $dir . DIRECTORY_SEPARATOR . $filename;
if (is_dir($filename)) {
self::delete_dir($filename);
}
else {
unlink($filename);
}
}
}
rmdir($dir);
}
return true;
}
}

Loading…
Cancel
Save