From b3ec773c64fe3abc29445ca7093f819f1577ede0 Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Tue, 26 Mar 2019 16:37:26 +0100 Subject: [PATCH] Ensure that check_occurence_name say false if an empty string is given Also add some comments & fix code indent --- lib/domain.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/domain.php b/lib/domain.php index 0e33f93..1e6dea7 100644 --- a/lib/domain.php +++ b/lib/domain.php @@ -17,25 +17,37 @@ function domain_add($name, $IP, $with_mxs, $gmail=false) { $exec_cmd .= ' -m mail,10'; $exec_cmd .= ' -m backup.quai13.net.,20'; } -# mail('tech@evolix.fr', '[TAF] Ajouter '.$name.' sur quai13-backup', wordwrap('Ajouter le domaine '.$name.' à la directive relay_domains dans le fichier /etc/postfix/main.cf sur quai13-backup, pour mettre en place le MX secondaire du domaine.', 70)); } $exec_cmd .= " -a $IP $name"; - //echo $exec_cmd."\n"; sudoexec($exec_cmd, $exec_output, $exec_return); return array($exec_cmd, $exec_return, $exec_output); } +/** + * Ensure that the domain (or list of domains) do no exists in any other + * apache config file. Either as a ServerName or ServerAlias + * + * @param string $name Domain (or list of domains separated by commas) + * + * @return boolean True if one occurence is found. Else otherwise + */ function check_occurence_name($name) { - $exploded_names = explode(',', $name); + // If no domain are given, that should be okay + if(strlen($name) === 0){ + return false; + } + + $exploded_names = explode(',', $name); - foreach ($exploded_names as $current_name) { - $check_occurence_cmd = 'web-add.sh check-occurence ' . $current_name; - sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); - if ($check_occurence_return == 0) return true; - } + foreach ($exploded_names as $current_name) { + $check_occurence_cmd = 'web-add.sh check-occurence ' . escapeshellarg($current_name); + + sudoexec($check_occurence_cmd, $check_occurence_output, $check_occurence_return); + if ($check_occurence_return == 0) return true; + } - return false; + return false; }