@@ -111,7 +111,7 @@ function check_system($data) {
111111
112112 //* When we can use 60-dkim for the dkim-keys create the file if it does not exists.
113113 if (substr_compare ($ amavis_configfile , '60-dkim ' , -7 ) === 0 && !file_exists ($ amavis_configfile ))
114- file_put_contents ($ amavis_configfile , '' );
114+ $ app -> system -> file_put_contents ($ amavis_configfile , '' );
115115
116116 if ( $ amavis_configfile == '' || !is_writeable ($ amavis_configfile ) ) {
117117 $ app ->log ('Amavis-config not found or not writeable. ' , LOGLEVEL_ERROR );
@@ -123,7 +123,8 @@ function check_system($data) {
123123 !empty ($ mail_config ['dkim_path ' ]) &&
124124 isset ($ data ['new ' ]['dkim_private ' ]) &&
125125 !empty ($ data ['new ' ]['dkim_private ' ]) &&
126- $ mail_config ['dkim_path ' ] != '/ '
126+ $ mail_config ['dkim_path ' ] != '/ ' &&
127+ $ app ->system ->checkpath ($ mail_config ['dkim_path ' ])
127128 ) {
128129 if (!is_dir ($ mail_config ['dkim_path ' ])) {
129130 $ app ->log ('DKIM Path ' .$ mail_config ['dkim_path ' ].' not found - (re)created. ' , LOGLEVEL_DEBUG );
@@ -137,8 +138,7 @@ function check_system($data) {
137138 }
138139 if (!empty ($ amavis_user )) {
139140 mkdir ($ mail_config ['dkim_path ' ], 0750 , true );
140- exec ('chown ' .$ amavis_user .' ' .escapeshellarg ($ mail_config ['dkim_path ' ]));
141- unset($ amavis_user );
141+ $ app ->system ->chown ($ mail_config ['dkim_path ' ], $ amavis_user );
142142 } else {
143143 mkdir ($ mail_config ['dkim_path ' ], 0755 , true );
144144 $ app ->log ('No user amavis or vscan found - using root for ' .$ mail_config ['dkim_path ' ]
@@ -152,7 +152,7 @@ function check_system($data) {
152152 }
153153
154154 } else {
155- $ app ->log ('Unable to write DKIM settings - no DKIM-Path defined ' , LOGLEVEL_ERROR );
155+ $ app ->log ('Unable to write DKIM settings - no or invalid DKIM-Path defined ' , LOGLEVEL_ERROR );
156156 $ check =false ;
157157 }
158158 return $ check ;
@@ -161,23 +161,24 @@ function check_system($data) {
161161 /**
162162 * This function restarts amavis
163163 */
164- function restart_amavis () {
165- global $ app , $ conf ;
166- $ pos_init =array (
167- $ conf ['init_scripts ' ].'/amavis ' ,
168- $ conf ['init_scripts ' ].'/amavisd '
169- );
170- $ initfile ='' ;
171- foreach ($ pos_init as $ init ) {
172- if (is_executable ($ init )) {
173- $ initfile =$ init ;
174- break ;
175- }
176- }
177- $ app ->log ('Restarting amavis: ' .$ initfile .'. ' , LOGLEVEL_DEBUG );
178- exec (escapeshellarg ($ initfile ).' restart ' , $ output );
179- foreach ($ output as $ logline ) $ app ->log ($ logline , LOGLEVEL_DEBUG );
180- }
164+ function restart_amavis () {
165+ global $ app , $ conf ;
166+ $ pos_init =array (
167+ $ conf ['init_scripts ' ].'/amavis ' ,
168+ $ conf ['init_scripts ' ].'/amavisd '
169+ );
170+ $ initfile ='' ;
171+ foreach ($ pos_init as $ init ) {
172+ if (is_executable ($ init )) {
173+ $ initfile =$ init ;
174+ break ;
175+ }
176+ }
177+ if ( $ initfile == '' ) $ initfile = 'service amavis ' ;
178+ $ app ->log ('Restarting amavis: ' .$ initfile .'. ' , LOGLEVEL_DEBUG );
179+ exec (escapeshellarg ($ initfile ).' restart ' , $ output );
180+ foreach ($ output as $ logline ) $ app ->log ($ logline , LOGLEVEL_DEBUG );
181+ }
181182
182183 /**
183184 * This function writes the keyfiles (public and private)
@@ -189,15 +190,15 @@ function restart_amavis() {
189190 function write_dkim_key ($ key_file , $ key_value , $ key_domain ) {
190191 global $ app , $ mailconfig ;
191192 $ success =false ;
192- if (! file_put_contents ($ key_file .'.private ' , $ key_value ) === false ) {
193+ if ( $ app -> system -> file_put_contents ($ key_file .'.private ' , $ key_value ) ) {
193194 $ app ->log ('Saved DKIM Private-key to ' .$ key_file .'.private ' , LOGLEVEL_DEBUG );
194195 $ success =true ;
195196 /* now we get the DKIM Public-key */
196197 exec ('cat ' .escapeshellarg ($ key_file .'.private ' ).'|openssl rsa -pubout 2> /dev/null ' , $ pubkey , $ result );
197198 $ public_key ='' ;
198199 foreach ($ pubkey as $ values ) $ public_key =$ public_key .$ values ."\n" ;
199200 /* save the DKIM Public-key in dkim-dir */
200- if (! file_put_contents ($ key_file .'.public ' , $ public_key ) === false )
201+ if ( $ app -> system -> file_put_contents ($ key_file .'.public ' , $ public_key ) )
201202 $ app ->log ('Saved DKIM Public to ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
202203 else $ app ->log ('Unable to save DKIM Public to ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
203204 } else {
@@ -214,11 +215,11 @@ function write_dkim_key($key_file, $key_value, $key_domain) {
214215 function remove_dkim_key ($ key_file , $ key_domain ) {
215216 global $ app ;
216217 if (file_exists ($ key_file .'.private ' )) {
217- exec ( ' rm -f ' . escapeshellarg ($ key_file .'.private ' ) );
218+ $ app -> system -> unlink ($ key_file .'.private ' );
218219 $ app ->log ('Deleted the DKIM Private-key for ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
219220 } else $ app ->log ('Unable to delete the DKIM Private-key for ' .$ key_domain .' (not found). ' , LOGLEVEL_DEBUG );
220221 if (file_exists ($ key_file .'.public ' )) {
221- exec ( ' rm -f ' . escapeshellarg ($ key_file .'.public ' ) );
222+ $ app -> system -> unlink ($ key_file .'.public ' );
222223 $ app ->log ('Deleted the DKIM Public-key for ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
223224 } else $ app ->log ('Unable to delete the DKIM Public-key for ' .$ key_domain .' (not found). ' , LOGLEVEL_DEBUG );
224225 }
@@ -239,20 +240,20 @@ function add_to_amavis($key_domain, $selector, $old_selector) {
239240 //* If we are using seperate config-files with amavis remove existing keys from 50-user to avoid duplicate keys
240241 if (substr_compare ($ amavis_configfile , '60-dkim ' , -7 ) === 0 ) {
241242 $ temp_configfile = str_replace ('60-dkim ' , '50-user ' , $ amavis_configfile );
242- $ temp_config = file_get_contents ($ temp_configfile );
243+ $ temp_config = $ app -> system -> file_get_contents ($ temp_configfile );
243244 if (preg_match ($ search_regex , $ temp_config )) {
244245 $ temp_config = preg_replace ($ search_regex , '' , $ temp_config )."\n" ;
245- file_put_contents ($ temp_configfile , $ temp_config );
246+ $ app -> system -> file_put_contents ($ temp_configfile , $ temp_config );
246247 }
247248 unset($ temp_configfile );
248249 unset($ temp_config );
249250 }
250251
251252 $ key_value ="dkim_key(' " .$ key_domain ."', ' " .$ selector ."', ' " .$ mail_config ['dkim_path ' ]."/ " .$ key_domain .".private'); \n" ;
252- $ amavis_config = file_get_contents ($ amavis_configfile );
253+ $ amavis_config = $ app -> system -> file_get_contents ($ amavis_configfile );
253254 $ amavis_config = preg_replace ($ search_regex , '' , $ amavis_config ).$ key_value ;
254255
255- if (file_put_contents ($ amavis_configfile , $ amavis_config )) {
256+ if ( $ app -> system -> file_put_contents ($ amavis_configfile , $ amavis_config ) ) {
256257 $ app ->log ('Adding DKIM Private-key to amavis-config. ' , LOGLEVEL_DEBUG );
257258 $ restart = true ;
258259 } else {
@@ -271,24 +272,24 @@ function remove_from_amavis($key_domain) {
271272
272273 $ restart = false ;
273274 $ amavis_configfile = $ this ->get_amavis_config ();
274- $ amavis_config = file_get_contents ($ amavis_configfile );
275+ $ amavis_config = $ app -> system -> file_get_contents ($ amavis_configfile );
275276
276277 $ search_regex = "/( \n| \r)?dkim_key.* " .$ key_domain .".*( \n| \r)?/ " ;
277278
278279 if (preg_match ($ search_regex , $ amavis_config )) {
279280 $ amavis_config = preg_replace ($ search_regex , '' , $ amavis_config );
280- file_put_contents ($ amavis_configfile , $ amavis_config );
281+ $ app -> system -> file_put_contents ($ amavis_configfile , $ amavis_config );
281282 $ app ->log ('Deleted the DKIM settings from amavis-config for ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
282283 $ restart = true ;
283284 }
284285
285286 //* If we are using seperate config-files with amavis remove existing keys from 50-user, too
286287 if (substr_compare ($ amavis_configfile , '60-dkim ' , -7 ) === 0 ) {
287288 $ temp_configfile = str_replace ('60-dkim ' , '50-user ' , $ amavis_configfile );
288- $ temp_config = file_get_contents ($ temp_configfile );
289+ $ temp_config = $ app -> system -> file_get_contents ($ temp_configfile );
289290 if (preg_match ($ search_regex , $ temp_config )) {
290291 $ temp_config = preg_replace ($ search_regex , '' , $ temp_config );
291- file_put_contents ($ temp_configfile , $ temp_config );
292+ $ app -> system -> file_put_contents ($ temp_configfile , $ temp_config );
292293 $ restart = true ;
293294 }
294295 unset($ temp_configfile );
0 commit comments