diff --git a/helper_scripts/import_dkim.php b/helper_scripts/import_dkim.php new file mode 100644 index 0000000000000000000000000000000000000000..1bcbda7a2c3f11d1cbc4998cae4969c69b814a59 --- /dev/null +++ b/helper_scripts/import_dkim.php @@ -0,0 +1,148 @@ + /dev/null', $tmp_output, $tmp_retval); +if ($tmp_retval != 0) { + exec('which amavisd 2> /dev/null', $tmp_output, $tmp_retval); + if ($tmp_retval == 0) $amavis = $tmp_output[0]; +} else $amavis = $tmp_output[0]; + +if (!isset($amavis)) die ("amavisd not found"); + + +echo "Importing dkim-settings from amavis.\n\nTo import the settings even when the public-key is not available, use ".$argv[0]." --force\nNOTE: In force-mode dkim will be set to 'no' if no public-key was found.\n\n"; + +if ( isset($argv) && isset ($argv[1]) && $argv[1] == '--force' ) $force = true; else $force = false; + +$client = new SoapClient(null, array('location' => $soap_location, + 'uri' => $soap_uri, + 'trace' => 1, + 'exceptions' => 1)); + + +exec($amavis.' showkeys', $tmp_output, $tmp_retval); + +foreach ( $tmp_output as $line ) { + //* get domain and private key-file + if ( preg_match('#^; key#', $line) ) { + $line_array = explode(' ', $line); + if ( $line_array[2] = 'domain' ) { + $domain = rtrim($line_array[3], ','); + $private_keyfile = $line_array[4]; + //* get the public-key from private-key + unset($public_key); + unset($pubkey); + unset($private_key); + $private_key = file_get_contents($private_keyfile); + if ( isset($private_key) && !empty($private_key)) { + exec('echo '.escapeshellarg($private_key).'|openssl rsa -pubout -outform PEM 2> /dev/null',$pubkey,$result); + $public_key=''; + foreach($pubkey as $values) $public_key=$public_key.$values."\n"; + } + } + } + + //* get selector + if ( isset($domain) ) { + if ( preg_match('/_domainkey.'.$domain.'.* TXT \(/', $line) ) { + $line_array = explode(' ', $line); + $selector = substr ( $line_array[0], 0, strpos($line_array[0], '.') ); + } + } + + if ( isset($domain) && isset($selector) && isset($private_keyfile) && isset($public_key) ) { + + try { + if ( !$session_id = $client->login($username, $password) ) { + echo 'SOAP-ERROR: Canīt login'; + } + + echo "\nprocessing ".$domain."...\n"; + + $record = $client->mail_domain_get_by_domain($session_id, $domain); + + if ( !empty($record) ) { + $record = $record[0]; + echo " OK: domain exists in the database\n"; + //* check if the public-key is available + exec($amavis.' testkeys '.escapeshellarg($domain).'', $test_output, $test_retval); + $pub_key = false; + if ( preg_match('/^TESTING.*'.$selector.'._domainkey.'.$domain.'.*pass/',$test_output[0]) ) $pub_key = true; + $client_id = $client->client_get_id($session_id, $record['sys_userid']); + unset($test_output); + if ( $pub_key ) { + $record['dkim_selector'] = $selector; + $record['dkim'] = 'y'; + if ( preg_match("/(^-----BEGIN PUBLIC KEY-----)[a-zA-Z0-9\r\n\/\+=]{1,221}(-----END PUBLIC KEY-----(\n|\r)?$)/", $record['dkim_public'] ) ) { + $record['dkim_public'] = $public_key; + echo " OK: public key\n"; + } else { + $record['dkim_public'] = ''; + $record['dkim'] = 'n'; + echo " ERROR: public key invalid\n disable dkim for ".$domain."\n"; + } + if ( preg_match("/(^-----BEGIN RSA PRIVATE KEY-----)[a-zA-Z0-9\r\n\/\+=]{1,850}(-----END RSA PRIVATE KEY-----(\n|\r)?$)/", $private_key) ) { + $record['dkim_private'] = $private_key; + echo " OK: private key\n"; + } else { + $record['dkim_private'] = ''; + $record['dkim'] = 'n'; + echo " ERROR: private key invalid\n disable dkim for ".$domain."\n"; + } + $client->mail_domain_update($session_id, $client_id, $record['domain_id'], $record); + echo " OK: updating database\n"; + } else { + echo " ERROR: no public-key available - skipping ".$domain."\n"; + } + } else { + echo " ERROR: domain not in the database - skipping ".$domain."\n"; + } + $client->logout($session_id); + } catch (SoapFault $e) { + echo $client->__getLastResponse(); + die('SOAP Error: '.$e->getMessage()); + } + unset($domain); + unset($selector); + } +} +?> diff --git a/helper_scripts/import_dkim.txt b/helper_scripts/import_dkim.txt new file mode 100644 index 0000000000000000000000000000000000000000..9509de4c405b139821fcffea67580c3906c259c2 --- /dev/null +++ b/helper_scripts/import_dkim.txt @@ -0,0 +1,10 @@ +This scripts stores all dkim-keys from the amavis-config to the ispconfig-database + +Create a remote-user with at least rights for mail_domain and clients and adjust the settings for + +$username = 'admin'; +$password = 'admin'; +$soap_location = 'http://192.168.0.105:8080/remote/index.php'; +$soap_uri = 'http://192.168.0.105:8080/remote/'; + +in import_dkim.php diff --git a/install/dist/lib/gentoo.lib.php b/install/dist/lib/gentoo.lib.php index 736fa4fa1db4b82c3ed525857519d735b27efa25..718681bbc1822a73e965cfd2005ec379bdd05ff9 100644 --- a/install/dist/lib/gentoo.lib.php +++ b/install/dist/lib/gentoo.lib.php @@ -290,7 +290,7 @@ class installer extends installer_base //* Configure master.cf and add a line for deliver $content = rf($conf["postfix"]["config_dir"].'/master.cf'); $deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DROhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'; - af($configdir.'/master.cf', $deliver_content); + af($config_dir.'/master.cf', $deliver_content); unset($content); unset($deliver_content); } diff --git a/server/plugins-available/mysql_clientdb_plugin.inc.php b/server/plugins-available/mysql_clientdb_plugin.inc.php index 146e17a2ec4cf895896cbb64d3ee89be88adf12e..13fe1432f1f7f2941be872ae545305d8594b4496 100644 --- a/server/plugins-available/mysql_clientdb_plugin.inc.php +++ b/server/plugins-available/mysql_clientdb_plugin.inc.php @@ -114,10 +114,10 @@ class mysql_clientdb_plugin { if($valid == false) continue; if($action == 'GRANT') { - if(!$link->query("GRANT " . ($user_read_only ? "SELECT" : "ALL") . " ON ".$link->escape_string($database_name).".* TO '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."';")) $success = false; - $app->log("GRANT " . ($user_read_only ? "SELECT" : "ALL") . " ON ".$link->escape_string($database_name).".* TO '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."'; success? " . ($success ? 'yes' : 'no'), LOGLEVEL_DEBUG); + if(!$link->query("GRANT " . ($user_read_only ? "SELECT" : "ALL") . " ON `".$link->escape_string($database_name)."`.* TO '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."';")) $success = false; + $app->log("GRANT " . ($user_read_only ? "SELECT" : "ALL") . " ON `".$link->escape_string($database_name)."`.* TO '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."'; success? " . ($success ? 'yes' : 'no'), LOGLEVEL_DEBUG); } elseif($action == 'REVOKE') { - if(!$link->query("REVOKE ALL PRIVILEGES ON ".$link->escape_string($database_name).".* FROM '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."';")) $success = false; + if(!$link->query("REVOKE ALL PRIVILEGES ON `".$link->escape_string($database_name)."`.* FROM '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."';")) $success = false; } elseif($action == 'DROP') { if(!$link->query("DROP USER '".$link->escape_string($database_user)."'@'$db_host';")) $success = false; } elseif($action == 'RENAME') { @@ -497,7 +497,7 @@ class mysql_clientdb_plugin { } - if($link->query('DROP DATABASE '.$link->escape_string($data['old']['database_name']))) { + if($link->query('DROP DATABASE `'.$link->escape_string($data['old']['database_name'].'`'))) { $app->log('Dropping MySQL database: '.$data['old']['database_name'], LOGLEVEL_DEBUG); } else { $app->log('Error while dropping MySQL database: '.$data['old']['database_name'].' '.$link->error, LOGLEVEL_WARNING);