@@ -87,10 +87,11 @@ function get_amavis_config() {
8787 break ;
8888 }
8989 }
90- //* If we can use seperate config-files with amavis use 60-dkim
91- if (substr_compare ($ amavis_configfile , '50-user ' , -7 ) === 0 )
90+ if (substr_compare ($ amavis_configfile , '50-user ' , -7 ) === 0 ) {
9291 $ amavis_configfile = str_replace ('50-user ' , '60-dkim ' , $ amavis_configfile );
93-
92+ } else { //* fake 60-dkim on system with a monolithic amavis-config
93+ $ amavis_configfile = str_replace ('amavisd.conf ' , '60-dkim ' , $ amavis_configfile );
94+ }
9495 return $ amavis_configfile ;
9596 }
9697
@@ -109,7 +110,7 @@ function check_system($data) {
109110 /* check for amavis-config */
110111 $ amavis_configfile = $ this ->get_amavis_config ();
111112
112- //* When we can use 60-dkim for the dkim-keys create the file if it does not exists.
113+ //* Create the file if it does not exists.
113114 if (substr_compare ($ amavis_configfile , '60-dkim ' , -7 ) === 0 && !file_exists ($ amavis_configfile ))
114115 $ app ->system ->touch ($ amavis_configfile );
115116
@@ -120,12 +121,7 @@ function check_system($data) {
120121
121122 /* dir for dkim-keys writeable? */
122123 $ mail_config = $ app ->getconf ->get_server_config ($ conf ['server_id ' ], 'mail ' );
123- if ( isset ($ mail_config ['dkim_path ' ]) &&
124- !empty ($ mail_config ['dkim_path ' ]) &&
125- // isset($data['new']['dkim_private']) &&
126- // !empty($data['new']['dkim_private']) &&
127- $ mail_config ['dkim_path ' ] != '/ '
128- ) {
124+ if (isset ($ mail_config ['dkim_path ' ]) && !empty ($ mail_config ['dkim_path ' ]) && $ mail_config ['dkim_path ' ] != '/ ' ) {
129125 if (!is_dir ($ mail_config ['dkim_path ' ])) {
130126 $ app ->log ('DKIM Path ' .$ mail_config ['dkim_path ' ].' not found - (re)created. ' , LOGLEVEL_DEBUG );
131127 if ($ app ->system ->is_user ('amavis ' )) {
@@ -239,16 +235,18 @@ function add_to_amavis($key_domain, $selector, $old_selector) {
239235
240236 $ search_regex = "/( \n| \r)?dkim_key\(\' " .$ key_domain ."\',\ \'( " .$ selector ."| " .$ old_selector ."){1}?\'.*/ " ;
241237
242- //* If we are using seperate config-files with amavis remove existing keys from 50-user to avoid duplicate keys
238+ //* If we are using seperate config-files (no faked 60-dkim) with amavis remove existing keys from 50-user to avoid duplicate keys
243239 if (substr_compare ($ amavis_configfile , '60-dkim ' , -7 ) === 0 ) {
244240 $ temp_configfile = str_replace ('60-dkim ' , '50-user ' , $ amavis_configfile );
245- $ temp_config = $ app ->system ->file_get_contents ($ temp_configfile , true );
246- if (preg_match ($ search_regex , $ temp_config )) {
247- $ temp_config = preg_replace ($ search_regex , '' , $ temp_config )."\n" ;
248- $ app ->system ->file_put_contents ($ temp_configfile , $ temp_config , true );
241+ if (file_exists ($ temp_configfile )) {
242+ $ temp_config = $ app ->system ->file_get_contents ($ temp_configfile , true );
243+ if (preg_match ($ search_regex , $ temp_config )) {
244+ $ temp_config = preg_replace ($ search_regex , '' , $ temp_config )."\n" ;
245+ $ app ->system ->file_put_contents ($ temp_configfile , $ temp_config , true );
246+ }
247+ unset($ temp_config );
249248 }
250249 unset($ temp_configfile );
251- unset($ temp_config );
252250 }
253251
254252 $ key_value ="dkim_key(' " .$ key_domain ."', ' " .$ selector ."', ' " .$ mail_config ['dkim_path ' ]."/ " .$ key_domain .".private'); \n" ;
@@ -285,17 +283,19 @@ function remove_from_amavis($key_domain) {
285283 $ restart = true ;
286284 }
287285
288- //* If we are using seperate config-files with amavis remove existing keys from 50-user, too
286+ //* If we are using seperate config-files (no faked 60-dkim) with amavis remove existing keys from 50-user to avoid duplicate keys
289287 if (substr_compare ($ amavis_configfile , '60-dkim ' , -7 ) === 0 ) {
290288 $ temp_configfile = str_replace ('60-dkim ' , '50-user ' , $ amavis_configfile );
291- $ temp_config = $ app ->system ->file_get_contents ($ temp_configfile , true );
292- if (preg_match ($ search_regex , $ temp_config )) {
293- $ temp_config = preg_replace ($ search_regex , '' , $ temp_config );
294- $ app ->system ->file_put_contents ($ temp_configfile , $ temp_config , true );
295- $ restart = true ;
289+ if (file_exists ($ temp_configfile )) {
290+ $ temp_config = $ app ->system ->file_get_contents ($ temp_configfile , true );
291+ if (preg_match ($ search_regex , $ temp_config )) {
292+ $ temp_config = preg_replace ($ search_regex , '' , $ temp_config );
293+ $ app ->system ->file_put_contents ($ temp_configfile , $ temp_config , true );
294+ $ restart = true ;
295+ }
296+ unset($ temp_configfile );
297+ unset($ temp_config );
296298 }
297- unset($ temp_configfile );
298- unset($ temp_config );
299299 }
300300
301301 return $ restart ;
0 commit comments