@@ -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 ' ]
@@ -161,23 +161,23 @@ 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+ $ app ->log ('Restarting amavis: ' .$ initfile .'. ' , LOGLEVEL_DEBUG );
178+ exec (escapeshellarg ($ initfile ).' restart ' , $ output );
179+ foreach ($ output as $ logline ) $ app ->log ($ logline , LOGLEVEL_DEBUG );
180+ }
181181
182182 /**
183183 * This function writes the keyfiles (public and private)
@@ -189,15 +189,15 @@ function restart_amavis() {
189189 function write_dkim_key ($ key_file , $ key_value , $ key_domain ) {
190190 global $ app , $ mailconfig ;
191191 $ success =false ;
192- if (!file_put_contents ($ key_file .'.private ' , $ key_value ) === false ) {
192+ if (!$ app -> system -> file_put_contents ($ key_file .'.private ' , $ key_value ) === false ) {
193193 $ app ->log ('Saved DKIM Private-key to ' .$ key_file .'.private ' , LOGLEVEL_DEBUG );
194194 $ success =true ;
195195 /* now we get the DKIM Public-key */
196196 exec ('cat ' .escapeshellarg ($ key_file .'.private ' ).'|openssl rsa -pubout 2> /dev/null ' , $ pubkey , $ result );
197197 $ public_key ='' ;
198198 foreach ($ pubkey as $ values ) $ public_key =$ public_key .$ values ."\n" ;
199199 /* save the DKIM Public-key in dkim-dir */
200- if (!file_put_contents ($ key_file .'.public ' , $ public_key ) === false )
200+ if (!$ app -> system -> file_put_contents ($ key_file .'.public ' , $ public_key ) === false )
201201 $ app ->log ('Saved DKIM Public to ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
202202 else $ app ->log ('Unable to save DKIM Public to ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
203203 } else {
@@ -214,11 +214,11 @@ function write_dkim_key($key_file, $key_value, $key_domain) {
214214 function remove_dkim_key ($ key_file , $ key_domain ) {
215215 global $ app ;
216216 if (file_exists ($ key_file .'.private ' )) {
217- exec ( ' rm -f ' . escapeshellarg ($ key_file .'.private ' ) );
217+ $ app -> system -> unlink ($ key_file .'.private ' );
218218 $ app ->log ('Deleted the DKIM Private-key for ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
219219 } else $ app ->log ('Unable to delete the DKIM Private-key for ' .$ key_domain .' (not found). ' , LOGLEVEL_DEBUG );
220220 if (file_exists ($ key_file .'.public ' )) {
221- exec ( ' rm -f ' . escapeshellarg ($ key_file .'.public ' ) );
221+ $ app -> system -> unlink ($ key_file .'.public ' );
222222 $ app ->log ('Deleted the DKIM Public-key for ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
223223 } else $ app ->log ('Unable to delete the DKIM Public-key for ' .$ key_domain .' (not found). ' , LOGLEVEL_DEBUG );
224224 }
@@ -239,20 +239,20 @@ function add_to_amavis($key_domain, $selector, $old_selector) {
239239 //* If we are using seperate config-files with amavis remove existing keys from 50-user to avoid duplicate keys
240240 if (substr_compare ($ amavis_configfile , '60-dkim ' , -7 ) === 0 ) {
241241 $ temp_configfile = str_replace ('60-dkim ' , '50-user ' , $ amavis_configfile );
242- $ temp_config = file_get_contents ($ temp_configfile );
242+ $ temp_config = $ app -> system -> file_get_contents ($ temp_configfile );
243243 if (preg_match ($ search_regex , $ temp_config )) {
244244 $ temp_config = preg_replace ($ search_regex , '' , $ temp_config )."\n" ;
245- file_put_contents ($ temp_configfile , $ temp_config );
245+ $ app -> system -> file_put_contents ($ temp_configfile , $ temp_config );
246246 }
247247 unset($ temp_configfile );
248248 unset($ temp_config );
249249 }
250250
251251 $ key_value ="dkim_key(' " .$ key_domain ."', ' " .$ selector ."', ' " .$ mail_config ['dkim_path ' ]."/ " .$ key_domain .".private'); \n" ;
252- $ amavis_config = file_get_contents ($ amavis_configfile );
252+ $ amavis_config = $ app -> system -> file_get_contents ($ amavis_configfile );
253253 $ amavis_config = preg_replace ($ search_regex , '' , $ amavis_config ).$ key_value ;
254254
255- if (file_put_contents ($ amavis_configfile , $ amavis_config )) {
255+ if ( $ app -> system -> file_put_contents ($ amavis_configfile , $ amavis_config ) ) {
256256 $ app ->log ('Adding DKIM Private-key to amavis-config. ' , LOGLEVEL_DEBUG );
257257 $ restart = true ;
258258 } else {
@@ -271,24 +271,24 @@ function remove_from_amavis($key_domain) {
271271
272272 $ restart = false ;
273273 $ amavis_configfile = $ this ->get_amavis_config ();
274- $ amavis_config = file_get_contents ($ amavis_configfile );
274+ $ amavis_config = $ app -> system -> file_get_contents ($ amavis_configfile );
275275
276276 $ search_regex = "/( \n| \r)?dkim_key.* " .$ key_domain .".*( \n| \r)?/ " ;
277277
278278 if (preg_match ($ search_regex , $ amavis_config )) {
279279 $ amavis_config = preg_replace ($ search_regex , '' , $ amavis_config );
280- file_put_contents ($ amavis_configfile , $ amavis_config );
280+ $ app -> system -> file_put_contents ($ amavis_configfile , $ amavis_config );
281281 $ app ->log ('Deleted the DKIM settings from amavis-config for ' .$ key_domain .'. ' , LOGLEVEL_DEBUG );
282282 $ restart = true ;
283283 }
284284
285285 //* If we are using seperate config-files with amavis remove existing keys from 50-user, too
286286 if (substr_compare ($ amavis_configfile , '60-dkim ' , -7 ) === 0 ) {
287287 $ temp_configfile = str_replace ('60-dkim ' , '50-user ' , $ amavis_configfile );
288- $ temp_config = file_get_contents ($ temp_configfile );
288+ $ temp_config = $ app -> system -> file_get_contents ($ temp_configfile );
289289 if (preg_match ($ search_regex , $ temp_config )) {
290290 $ temp_config = preg_replace ($ search_regex , '' , $ temp_config );
291- file_put_contents ($ temp_configfile , $ temp_config );
291+ $ app -> system -> file_put_contents ($ temp_configfile , $ temp_config );
292292 $ restart = true ;
293293 }
294294 unset($ temp_configfile );
0 commit comments