Răsfoiți Sursa

check_return_code function

Serghey Rodin 12 ani în urmă
părinte
comite
80d5dd9ab0

+ 4 - 7
web/add/cron/index.php

@@ -44,13 +44,10 @@ if (!empty($_POST['ok'])) {
         exec (VESTA_CMD."v-add-cron-job ".$user." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
         $v_type = $_POST['v_type'];
         $v_charset = $_POST['v_charset'];
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-            unset($v_password);
-            unset($output);
-        } else {
+        check_return_code($return_var,$output);
+        unset($v_password);
+        unset($output);
+        if (empty($_SESSION['error_msg'])) {
             $_SESSION['ok_msg'] = __('CRON_CREATED_OK');
             unset($v_min);
             unset($v_hour);

+ 11 - 15
web/add/db/index.php

@@ -62,14 +62,9 @@ if (!empty($_POST['ok'])) {
         exec (VESTA_CMD."v-add-database ".$user." ".$v_database." ".$v_dbuser." ".$v_password." ".$v_type." 'default' ".$v_charset, $output, $return_var);
         $v_type = $_POST['v_type'];
         $v_charset = $_POST['v_charset'];
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-            unset($v_password);
-            unset($output);
-        }
-        if ((!empty($v_db_email)) && ($return_var == 0)) {
+        check_return_code($return_var,$output);
+        unset($output);
+        if ((!empty($v_db_email)) && (empty($_SESSION['error_msg']))) {
             list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"]);
             if ($_POST['v_type'] == 'mysql') $db_admin_link = "http://".$http_host."/phpmyadmin/";
             if ($_POST['v_type'] == 'pgsql') $db_admin_link = "http://".$http_host."/phppgadmin/";
@@ -80,13 +75,14 @@ if (!empty($_POST['ok'])) {
             $mailtext = __('DATABASE_READY',$user."_".$_POST['v_database'],$user."_".$_POST['v_dbuser'],$_POST['v_password'],$db_admin_link);
             send_email($to, $subject, $mailtext, $from);
         }
-        $_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
-        unset($v_database);
-        unset($v_dbuser);
-        unset($v_password);
-        unset($v_type);
-        unset($v_charset);
-        unset($output);
+        if (empty($_SESSION['error_msg'])) {
+            $_SESSION['ok_msg'] = __('DATABASE_CREATED_OK',$user."_".$_POST['v_database'],$user."_".$_POST['v_database']);
+            unset($v_database);
+            unset($v_dbuser);
+            unset($v_password);
+            unset($v_type);
+            unset($v_charset);
+        }
     }
 }
 

+ 5 - 21
web/add/dns/index.php

@@ -41,34 +41,22 @@ if (!empty($_POST['ok'])) {
     } else {
         // Add DNS
         exec (VESTA_CMD."v-add-dns-domain ".$user." ".$v_domain." ".$v_ip." ".$v_ns1." ".$v_ns2." ".$v_ns3." ".$v_ns4, $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
 
         // Change Expiriation date
         if ((!empty($_POST['v_exp'])) && ($_POST['v_exp'] != date('Y-m-d', strtotime('+1 year')))) {
             $v_exp = escapeshellarg($_POST['v_exp']);
             exec (VESTA_CMD."v-change-dns-domain-exp ".$user." ".$v_domain." ".$v_exp, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
         // Change TTL
-        if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400')) {
+        if ((!empty($_POST['v_ttl'])) && ($_POST['v_ttl'] != '14400') && (empty($_SESSION['error_msg']))) {
             $v_ttl = escapeshellarg($_POST['v_ttl']);
             exec (VESTA_CMD."v-change-dns-domain-ttl ".$user." ".$v_domain." ".$v_ttl, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
@@ -108,11 +96,7 @@ if (!empty($_POST['ok_rec'])) {
         // Add DNS Record
         exec (VESTA_CMD."v-add-dns-record ".$user." ".$v_domain." ".$v_rec." ".$v_type." ".$v_val." ".$v_priority, $output, $return_var);
         $v_type = $_POST['v_type'];
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
         if (empty($_SESSION['error_msg'])) {
             $_SESSION['ok_msg'] = __('DNS_RECORD_CREATED_OK',$_POST[v_rec],$_POST[v_domain]);

+ 3 - 8
web/add/ip/index.php

@@ -55,19 +55,14 @@ if ($_SESSION['user'] == 'admin') {
             exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface."  ".$v_owner." '".$ip_status."' ".$v_name." ".$v_nat, $output, $return_var);
             $v_owner = $_POST['v_owner'];
             $v_interface = $_POST['v_interface'];
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-                unset($v_password);
-                unset($output);
-            } else {
+            check_return_code($return_var,$output);
+            unset($output);
+            if (empty($_SESSION['error_msg'])) {
                 $_SESSION['ok_msg'] = __('IP_CREATED_OK',$_POST['v_ip'],$_POST['v_ip']);
                 unset($v_ip);
                 unset($v_netmask);
                 unset($v_name);
                 unset($v_nat);
-                unset($output);
             }
         }
     }

+ 132 - 150
web/add/mail/index.php

@@ -12,171 +12,153 @@ include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html');
 // Panel
 top_panel($user,$TAB);
 
-// Are you admin?
-//if ($_SESSION['user'] == 'admin') {
-    // Mail Domain
-    if (!empty($_POST['ok'])) {
-        if (empty($_POST['v_domain'])) $errors[] = __('domain');
-        if (!empty($_POST['v_antispam'])) {
-            $v_antispam = 'yes';
-        } else {
-            $v_antispam = 'no';
-        }
-
-        if (!empty($_POST['v_antivirus'])) {
-            $v_antivirus = 'yes';
-        } else {
-            $v_antivirus = 'no';
-        }
+// Mail Domain
+if (!empty($_POST['ok'])) {
+    if (empty($_POST['v_domain'])) $errors[] = __('domain');
+    if (!empty($_POST['v_antispam'])) {
+        $v_antispam = 'yes';
+    } else {
+        $v_antispam = 'no';
+    }
 
-        if (!empty($_POST['v_dkim'])) {
-            $v_dkim = 'yes';
-        } else {
-            $v_dkim = 'no';
-        }
+    if (!empty($_POST['v_antivirus'])) {
+        $v_antivirus = 'yes';
+    } else {
+        $v_antivirus = 'no';
+    }
 
-        // Protect input
-        $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
-        $v_domain = escapeshellarg($v_domain);
-        $v_domain = strtolower($v_domain);
-
-        // Check for errors
-        if (!empty($errors[0])) {
-            foreach ($errors as $i => $error) {
-                if ( $i == 0 ) {
-                    $error_msg = $error;
-                } else {
-                    $error_msg = $error_msg.", ".$error;
-                }
-            }
-            $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
-        } else {
-
-            // Add mail domain
-            exec (VESTA_CMD."v-add-mail-domain ".$user." ".$v_domain." ".$v_antispam." ".$v_antivirus." ".$v_dkim, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
-            unset($output);
+    if (!empty($_POST['v_dkim'])) {
+        $v_dkim = 'yes';
+    } else {
+        $v_dkim = 'no';
+    }
 
-            if (empty($_SESSION['error_msg'])) {
-                $_SESSION['ok_msg'] = __('MAIL_DOMAIN_CREATED_OK',$_POST['v_domain'],$_POST['v_domain']);
-                unset($v_domain);
+    // Protect input
+    $v_domain = preg_replace("/^www./i", "", $_POST['v_domain']);
+    $v_domain = escapeshellarg($v_domain);
+    $v_domain = strtolower($v_domain);
+
+    // Check for errors
+    if (!empty($errors[0])) {
+        foreach ($errors as $i => $error) {
+            if ( $i == 0 ) {
+                $error_msg = $error;
+            } else {
+                $error_msg = $error_msg.", ".$error;
             }
         }
-    }
+        $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
+    } else {
 
+        // Add mail domain
+        exec (VESTA_CMD."v-add-mail-domain ".$user." ".$v_domain." ".$v_antispam." ".$v_antivirus." ".$v_dkim, $output, $return_var);
+        check_return_code($return_var,$output);
+        unset($output);
 
-    // Mail Account
-    if (!empty($_POST['ok_acc'])) {
-        // Check input
-        if (empty($_POST['v_domain'])) $errors[] = __('domain');
-        if (empty($_POST['v_account'])) $errors[] = __('account');
-        if (empty($_POST['v_password'])) $errors[] = __('password');
-
-        // Protect input
-        $v_domain = escapeshellarg($_POST['v_domain']);
-        $v_domain = strtolower($v_domain);
-        $v_account = escapeshellarg($_POST['v_account']);
-        $v_password = escapeshellarg($_POST['v_password']);
-        $v_quota = escapeshellarg($_POST['v_quota']);
-        $v_aliases = $_POST['v_aliases'];
-        $v_fwd = $_POST['v_fwd'];
-
-        if (empty($_POST['v_quota'])) $v_quota = 0;
-        if ((!empty($_POST['v_quota'])) || (!empty($_POST['v_aliases'])) || (!empty($_POST['v_fwd'])) ) $v_adv = 'yes';
-
-        // Check for errors
-        if (!empty($errors[0])) {
-            foreach ($errors as $i => $error) {
-                if ( $i == 0 ) {
-                    $error_msg = $error;
-                } else {
-                    $error_msg = $error_msg.", ".$error;
-                }
-            }
-            $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
-        } else {
-            // Add Mail Account
-            exec (VESTA_CMD."v-add-mail-account ".$user." ".$v_domain." ".$v_account." ".$v_password." ".$v_quota, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
+        if (empty($_SESSION['error_msg'])) {
+            $_SESSION['ok_msg'] = __('MAIL_DOMAIN_CREATED_OK',$_POST['v_domain'],$_POST['v_domain']);
+            unset($v_domain);
+        }
+    }
+}
+
+
+// Mail Account
+if (!empty($_POST['ok_acc'])) {
+    // Check input
+    if (empty($_POST['v_domain'])) $errors[] = __('domain');
+    if (empty($_POST['v_account'])) $errors[] = __('account');
+    if (empty($_POST['v_password'])) $errors[] = __('password');
+
+    // Protect input
+    $v_domain = escapeshellarg($_POST['v_domain']);
+    $v_domain = strtolower($v_domain);
+    $v_account = escapeshellarg($_POST['v_account']);
+    $v_password = escapeshellarg($_POST['v_password']);
+    $v_quota = escapeshellarg($_POST['v_quota']);
+    $v_aliases = $_POST['v_aliases'];
+    $v_fwd = $_POST['v_fwd'];
+
+    if (empty($_POST['v_quota'])) $v_quota = 0;
+    if ((!empty($_POST['v_quota'])) || (!empty($_POST['v_aliases'])) || (!empty($_POST['v_fwd'])) ) $v_adv = 'yes';
+
+    // Check for errors
+    if (!empty($errors[0])) {
+        foreach ($errors as $i => $error) {
+            if ( $i == 0 ) {
+                $error_msg = $error;
+            } else {
+                $error_msg = $error_msg.", ".$error;
             }
-
-            // Add Aliases
-            if ((!empty($_POST['v_aliases'])) && (empty($_SESSION['error_msg']))) {
-                $valiases = preg_replace("/\n/", " ", $_POST['v_aliases']);
-                $valiases = preg_replace("/,/", " ", $valiases);
-                $valiases = preg_replace('/\s+/', ' ',$valiases);
-                $valiases = trim($valiases);
-                $aliases = explode(" ", $valiases);
-                foreach ($aliases as $alias) {
-                    $alias = escapeshellarg($alias);
-                    if (empty($_SESSION['error_msg'])) {
-                        exec (VESTA_CMD."v-add-mail-account-alias ".$user." ".$v_domain." ".$v_account." ".$alias, $output, $return_var);
-                        if ($return_var != 0) {
-                            $error = implode('<br>', $output);
-                            if (empty($error)) $error = __('Error: vesta did not return any output.');
-                            $_SESSION['error_msg'] = $error;
-                        }
-                    }
-                    unset($output);
+        }
+        $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
+    } else {
+        // Add Mail Account
+        exec (VESTA_CMD."v-add-mail-account ".$user." ".$v_domain." ".$v_account." ".$v_password." ".$v_quota, $output, $return_var);
+        check_return_code($return_var,$output);
+        unset($output);
+
+        // Add Aliases
+        if ((!empty($_POST['v_aliases'])) && (empty($_SESSION['error_msg']))) {
+            $valiases = preg_replace("/\n/", " ", $_POST['v_aliases']);
+            $valiases = preg_replace("/,/", " ", $valiases);
+            $valiases = preg_replace('/\s+/', ' ',$valiases);
+            $valiases = trim($valiases);
+            $aliases = explode(" ", $valiases);
+            foreach ($aliases as $alias) {
+                $alias = escapeshellarg($alias);
+                if (empty($_SESSION['error_msg'])) {
+                    exec (VESTA_CMD."v-add-mail-account-alias ".$user." ".$v_domain." ".$v_account." ".$alias, $output, $return_var);
+                    check_return_code($return_var,$output);
                 }
+                unset($output);
             }
+        }
 
-            // Add Forwads
-            if ((!empty($_POST['v_fwd'])) && (empty($_SESSION['error_msg']))) {
-                $vfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
-                $vfwd = preg_replace("/,/", " ", $vfwd);
-                $vfwd = preg_replace('/\s+/', ' ',$vfwd);
-                $vfwd = trim($vfwd);
-                $fwd = explode(" ", $vfwd);
-                foreach ($fwd as $forward) {
-                    $forward = escapeshellarg($forward);
-                    if (empty($_SESSION['error_msg'])) {
-                        exec (VESTA_CMD."v-add-mail-account-forward ".$user." ".$v_domain." ".$v_account." ".$forward, $output, $return_var);
-                        if ($return_var != 0) {
-                            $error = implode('<br>', $output);
-                            if (empty($error)) $error = __('Error: vesta did not return any output.');
-                            $_SESSION['error_msg'] = $error;
-                        }
-                    }
-                    unset($output);
+        // Add Forwads
+        if ((!empty($_POST['v_fwd'])) && (empty($_SESSION['error_msg']))) {
+            $vfwd = preg_replace("/\n/", " ", $_POST['v_fwd']);
+            $vfwd = preg_replace("/,/", " ", $vfwd);
+            $vfwd = preg_replace('/\s+/', ' ',$vfwd);
+            $vfwd = trim($vfwd);
+            $fwd = explode(" ", $vfwd);
+            foreach ($fwd as $forward) {
+                $forward = escapeshellarg($forward);
+                if (empty($_SESSION['error_msg'])) {
+                    exec (VESTA_CMD."v-add-mail-account-forward ".$user." ".$v_domain." ".$v_account." ".$forward, $output, $return_var);
+                    check_return_code($return_var,$output);
                 }
-            }
-
-            unset($output);
-            if (empty($_SESSION['error_msg'])) {
-                list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
-                $_SESSION['ok_msg'] = __('MAIL_ACCOUNT_CREATED_OK',$_POST['v_account'],$_POST[v_domain],$_POST['v_account'],$_POST[v_domain]);
-                $_SESSION['ok_msg'] .= " / <a href=http://".$http_host."/webmail target='_blank'>" . __('open webmail') . "</a>";
-                unset($v_account);
-                unset($v_password);
-                unset($v_password);
-                unset($v_aliases);
-                unset($v_fwd);
-                unset($v_quota);
+                unset($output);
             }
         }
+        unset($output);
+
+        if (empty($_SESSION['error_msg'])) {
+            list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
+            $_SESSION['ok_msg'] = __('MAIL_ACCOUNT_CREATED_OK',$_POST['v_account'],$_POST[v_domain],$_POST['v_account'],$_POST[v_domain]);
+            $_SESSION['ok_msg'] .= " / <a href=http://".$http_host."/webmail target='_blank'>" . __('open webmail') . "</a>";
+            unset($v_account);
+            unset($v_password);
+            unset($v_password);
+            unset($v_aliases);
+            unset($v_fwd);
+            unset($v_quota);
+        }
     }
-
-
-    if ((empty($_GET['domain'])) && (empty($_POST['domain'])))  {
-        $v_domain = (isset($_GET['domain'])?$_GET['domain']:'');
-        include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
-        unset($_SESSION['error_msg']);
-        unset($_SESSION['ok_msg']);
-    } else {
-        $v_domain = $_GET['domain'];
-        include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
-        unset($_SESSION['error_msg']);
-        unset($_SESSION['ok_msg']);
-    }
-//}
+}
+
+
+if ((empty($_GET['domain'])) && (empty($_POST['domain'])))  {
+    $v_domain = (isset($_GET['domain'])?$_GET['domain']:'');
+    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail.html');
+    unset($_SESSION['error_msg']);
+    unset($_SESSION['ok_msg']);
+} else {
+    $v_domain = $_GET['domain'];
+    include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/add_mail_acc.html');
+    unset($_SESSION['error_msg']);
+    unset($_SESSION['ok_msg']);
+}
 
 // Footer
 include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');

+ 1 - 5
web/add/package/index.php

@@ -111,11 +111,7 @@ if ($_SESSION['user'] == 'admin') {
             // Add new package
             if (empty($_SESSION['error_msg'])) {
                 exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
 

+ 3 - 5
web/add/user/index.php

@@ -61,11 +61,9 @@ if ($_SESSION['user'] == 'admin') {
 
         if (empty($_SESSION['error_msg'])) {
             exec (VESTA_CMD."v-add-user ".$v_username." ".$v_password." ".$v_email." ".$v_package." ".$v_fname." ".$v_lname, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            } else {
+            check_return_code($return_var,$output);
+            unset($output);
+            if (empty($_SESSION['error_msg'])) {
                 exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
                 if (!empty($v_notify)) {
                     $to = $_POST['v_notify'];

+ 17 - 70
web/add/web/index.php

@@ -97,32 +97,20 @@ $v_ftp_email = $panel[$user]['CONTACT'];
         if (empty($_SESSION['error_msg'])) {
             // Add WEB
             exec (VESTA_CMD."v-add-web-domain ".$user." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
 
             // Add DNS
             if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) {
                 exec (VESTA_CMD."v-add-dns-domain ".$user." ".$v_domain." ".$v_ip, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
 
             // Add Mail
             if (($_POST['v_mail'] == 'on') && (empty($_SESSION['error_msg']))) {
                 exec (VESTA_CMD."v-add-mail-domain ".$user." ".$v_domain, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
 
@@ -140,20 +128,12 @@ $v_ftp_email = $panel[$user]['CONTACT'];
                         $alias = escapeshellarg($alias);
                         if (empty($_SESSION['error_msg'])) {
                             exec (VESTA_CMD."v-add-web-domain-alias ".$user." ".$v_domain." ".$alias." 'no'", $output, $return_var);
-                            if ($return_var != 0) {
-                                $error = implode('<br>', $output);
-                                if (empty($error)) $error = __('Error code:',$return_var);
-                                $_SESSION['error_msg'] = $error;
-                            }
+                            check_return_code($return_var,$output);
                         }
                         unset($output);
                         if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) {
                             exec (VESTA_CMD."v-add-dns-on-web-alias ".$user." ".$v_domain." ".$alias." 'no'", $output, $return_var);
-                            if ($return_var != 0) {
-                                $error = implode('<br>', $output);
-                                if (empty($error)) $error = __('Error code:',$return_var);
-                                $_SESSION['error_msg'] = $error;
-                            }
+                            check_return_code($return_var,$output);
                             unset($output);
                         }
                     }
@@ -164,11 +144,7 @@ $v_ftp_email = $panel[$user]['CONTACT'];
                 $alias = 'www.'.$alias;
                 $alias = escapeshellarg($alias);
                 exec (VESTA_CMD."v-delete-web-domain-alias ".$user." ".$v_domain." ".$alias." 'no'", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
             }
 
 
@@ -177,11 +153,7 @@ $v_ftp_email = $panel[$user]['CONTACT'];
                 $ext = str_replace(' ', '', $v_proxy_ext);
                 $ext = escapeshellarg($ext);
                 exec (VESTA_CMD."v-add-web-domain-proxy ".$user." ".$v_domain." '' ".$ext." 'no'", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
 
@@ -216,11 +188,7 @@ $v_ftp_email = $panel[$user]['CONTACT'];
 
                 $v_ssl_home = escapeshellarg($_POST['v_ssl_home']);
                 exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
 
@@ -228,22 +196,14 @@ $v_ftp_email = $panel[$user]['CONTACT'];
             if ((!empty($_POST['v_stats'])) && ($_POST['v_stats'] != 'none' ) && (empty($_SESSION['error_msg']))) {
                 $v_stats = escapeshellarg($_POST['v_stats']);
                 exec (VESTA_CMD."v-add-web-domain-stats ".$user." ".$v_domain." ".$v_stats, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
 
                 if ((!empty($_POST['v_stats_user'])) && (empty($_SESSION['error_msg']))) {
                     $v_stats_user = escapeshellarg($_POST['v_stats_user']);
                     $v_stats_password = escapeshellarg($_POST['v_stats_password']);
                     exec (VESTA_CMD."v-add-web-domain-stats-user ".$user." ".$v_domain." ".$v_stats_user." ".$v_stats_password, $output, $return_var);
-                    if ($return_var != 0) {
-                        $error = implode('<br>', $output);
-                        if (empty($error)) $error = __('Error code:',$return_var);
-                        $_SESSION['error_msg'] = $error;
-                    }
+                    check_return_code($return_var,$output);
                     unset($v_stats_user);
                     unset($v_stats_password);
                     unset($output);
@@ -256,11 +216,8 @@ $v_ftp_email = $panel[$user]['CONTACT'];
                 $v_ftp_user = escapeshellarg($_POST['v_ftp_user']);
                 $v_ftp_password = escapeshellarg($_POST['v_ftp_password']);
                 exec (VESTA_CMD."v-add-web-domain-ftp ".$user." ".$v_domain." ".$v_ftp_user." ".$v_ftp_password, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                } else {
+                check_return_code($return_var,$output);
+                if (empty($_SESSION['error_msg'])) {
                     if (!empty($v_ftp_email)) {
                         $to = $_POST['v_ftp_email'];
                         $subject = __("FTP login credentials");
@@ -278,30 +235,20 @@ $v_ftp_email = $panel[$user]['CONTACT'];
 
             if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) {
                 exec (VESTA_CMD."v-restart-dns", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
 
             if (empty($_SESSION['error_msg'])) {
                 exec (VESTA_CMD."v-restart-web", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
+                unset($output);
             }
 
             if (empty($_SESSION['error_msg'])) {
                 exec (VESTA_CMD."v-restart-proxy", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
+                unset($output);
             }
 
             if (empty($_SESSION['error_msg'])) {

+ 3 - 10
web/edit/cron/index.php

@@ -26,11 +26,8 @@ if (empty($_GET['job'])) {
 
 $v_job = escapeshellarg($_GET['job']);
 exec (VESTA_CMD."v-list-cron-job ".$user." ".$v_job." 'json'", $output, $return_var);
-if ($return_var != 0) {
-    $error = implode('<br>', $output);
-    if (empty($error)) $error = __('Error code:',$return_var);
-    $_SESSION['error_msg'] = $error;
-} else {
+check_return_code($return_var,$output);
+if (empty($_SESSION['error_msg'])) {
     $data = json_decode(implode('', $output), true);
     unset($output);
     $v_username = $user;
@@ -62,11 +59,7 @@ if ($return_var != 0) {
             $v_wday = escapeshellarg($_POST['v_wday']);
             $v_cmd = escapeshellarg($_POST['v_cmd']);
             exec (VESTA_CMD."v-change-cron-job ".$v_username." ".$v_job." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $v_cmd = $_POST['v_cmd'];
         }

+ 2 - 5
web/edit/db/index.php

@@ -25,11 +25,8 @@ if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
 
 $v_database = escapeshellarg($_GET['database']);
 exec (VESTA_CMD."v-list-database ".$user." ".$v_database." 'json'", $output, $return_var);
-if ($return_var != 0) {
-    $error = implode('<br>', $output);
-    if (empty($error)) $error = __('Error code:',$return_var);
-    $_SESSION['error_msg'] = $error;
-} else {
+check_return_code($return_var,$output);
+if (empty($_SESSION['error_msg'])) {
     $data = json_decode(implode('', $output), true);
     unset($output);
     $v_username = $user;

+ 13 - 55
web/edit/dns/index.php

@@ -28,14 +28,10 @@ if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
 if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
     $v_domain = escapeshellarg($_GET['domain']);
     exec (VESTA_CMD."v-list-dns-domain ".$user." ".$v_domain." json", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = __('Error code:',$return_var);
-        $_SESSION['error_msg'] = $error;
-    } else {
+    check_return_code($return_var,$output);
+    if (empty($_SESSION['error_msg'])) {
         $data = json_decode(implode('', $output), true);
         unset($output);
-
         $v_username = $user;
         $v_domain = $_GET['domain'];
         $v_ip = $data[$v_domain]['IP'];
@@ -51,7 +47,6 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
         } else {
             $v_status =  'active';
         }
-
         exec (VESTA_CMD."v-list-dns-templates json", $output, $return_var);
         $templates = json_decode(implode('', $output), true);
         unset($output);
@@ -65,11 +60,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
         if (($v_ip != $_POST['v_ip']) && (empty($_SESSION['error_msg']))) {
             $v_ip = escapeshellarg($_POST['v_ip']);
             exec (VESTA_CMD."v-change-dns-domain-ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $restart_dns = 'yes';
             unset($output);
         }
@@ -78,11 +69,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
         if (( $_SESSION['user'] == 'admin') && ($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
             $v_template = escapeshellarg($_POST['v_template']);
             exec (VESTA_CMD."v-change-dns-domain-tpl ".$v_username." ".$v_domain." ".$v_template." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $restart_dns = 'yes';
         }
@@ -91,11 +78,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
         if (($v_soa != $_POST['v_soa']) && (empty($_SESSION['error_msg']))) {
             $v_soa = escapeshellarg($_POST['v_soa']);
             exec (VESTA_CMD."v-change-dns-domain-soa ".$v_username." ".$v_domain." ".$v_soa." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $restart_dns = 'yes';
         }
@@ -104,11 +87,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
         if (($v_exp != $_POST['v_exp']) && (empty($_SESSION['error_msg']))) {
             $v_exp = escapeshellarg($_POST['v_exp']);
             exec (VESTA_CMD."v-change-dns-domain-exp ".$v_username." ".$v_domain." ".$v_exp." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $restart_dns = 'yes';
         }
@@ -117,11 +96,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
         if (($v_ttl != $_POST['v_ttl']) && (empty($_SESSION['error_msg']))) {
             $v_ttl = escapeshellarg($_POST['v_ttl']);
             exec (VESTA_CMD."v-change-dns-domain-ttl ".$v_username." ".$v_domain." ".$v_ttl." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $restart_dns = 'yes';
         }
@@ -129,17 +104,13 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
         // Restart dns
         if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-restart-dns", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
+            unset($output);
         }
 
         if (empty($_SESSION['error_msg'])) {
             $_SESSION['ok_msg'] = __('Changes has been saved.');
         }
-
     }
 
     if ($_SESSION['user'] == 'admin') {
@@ -153,11 +124,8 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
     $v_domain = escapeshellarg($_GET['domain']);
     $v_record_id = escapeshellarg($_GET['record_id']);
     exec (VESTA_CMD."v-list-dns-records ".$user." ".$v_domain." 'json'", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = __('Error code:',$return_var);
-        $_SESSION['error_msg'] = $error;
-    } else {
+    check_return_code($return_var,$output);
+    if (empty($_SESSION['error_msg'])) {
         $data = json_decode(implode('', $output), true);
         unset($output);
         $v_username = $user;
@@ -185,12 +153,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
             $v_val = escapeshellarg($_POST['v_val']);
             $v_priority = escapeshellarg($_POST['v_priority']);
             exec (VESTA_CMD."v-change-dns-record ".$v_username." ".$v_domain." ".$v_record_id." ".$v_val." ".$v_priority, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
-
+            check_return_code($return_var,$output);
             $v_val = $_POST['v_val'];
             $restart_dns = 'yes';
             unset($output);
@@ -199,15 +162,10 @@ if ((!empty($_GET['domain'])) && (empty($_GET['record_id'])))  {
         if (($_GET['record_id'] != $_POST['v_record_id']) && (empty($_SESSION['error_msg']))) {
             $v_old_record_id = escapeshellarg($_GET['record_id']);
             exec (VESTA_CMD."v-change-dns-record-id ".$v_username." ".$v_domain." ".$v_old_record_id." ".$v_record_id, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
-
         if (empty($_SESSION['error_msg'])) {
             $_SESSION['ok_msg'] = __('Changes has been saved.');
         }

+ 7 - 30
web/edit/ip/index.php

@@ -24,11 +24,8 @@ if ($_SESSION['user'] == 'admin') {
 
     $v_ip = escapeshellarg($_GET['ip']);
     exec (VESTA_CMD."v-list-sys-ip ".$v_ip." 'json'", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = __('Error code:',$return_var);
-        $_SESSION['error_msg'] = $error;
-    } else {
+    check_return_code($return_var,$output);
+    if (empty($_SESSION['error_msg'])) {
         $data = json_decode(implode('', $output), true);
         unset($output);
         $v_username = $user;
@@ -61,21 +58,13 @@ if ($_SESSION['user'] == 'admin') {
             // Change Status
             if (($v_ipstatus == 'shared') && (empty($_POST['v_shared'])) && (empty($_SESSION['error_msg']))) {
                 exec (VESTA_CMD."v-change-sys-ip-status ".$v_ip." 'dedicated'", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
                 $v_dedicated = 'yes'; 
             }
             if (($v_ipstatus == 'dedicated') && (!empty($_POST['v_shared'])) && (empty($_SESSION['error_msg']))) {
                 exec (VESTA_CMD."v-change-sys-ip-status ".$v_ip." 'shared'", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
                 unset($v_dedicated);
             }
@@ -84,11 +73,7 @@ if ($_SESSION['user'] == 'admin') {
             if (($v_owner != $_POST['v_owner']) && (empty($_SESSION['error_msg']))) {
                 $v_owner = escapeshellarg($_POST['v_owner']);
                 exec (VESTA_CMD."v-change-sys-ip-owner ".$v_ip." ".$v_owner, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 $v_owner = $_POST['v_owner'];
                 unset($output);
             }
@@ -97,11 +82,7 @@ if ($_SESSION['user'] == 'admin') {
             if (($v_name != $_POST['v_name']) && (empty($_SESSION['error_msg']))) {
                 $v_name = escapeshellarg($_POST['v_name']);
                 exec (VESTA_CMD."v-change-sys-ip-name ".$v_ip." ".$v_name, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
 
@@ -109,11 +90,7 @@ if ($_SESSION['user'] == 'admin') {
             if (($v_nat != $_POST['v_nat']) && (empty($_SESSION['error_msg']))) {
                 $v_nat = escapeshellarg($_POST['v_nat']);
                 exec (VESTA_CMD."v-change-sys-ip-nat ".$v_ip." ".$v_nat, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
 

+ 23 - 101
web/edit/mail/index.php

@@ -28,11 +28,8 @@ if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
 if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
     $v_domain = escapeshellarg($_GET['domain']);
     exec (VESTA_CMD."v-list-mail-domain ".$user." ".$v_domain." json", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = __('Error code:',$return_var);
-        $_SESSION['error_msg'] = $error;
-    } else {
+    check_return_code($return_var,$output);
+    if (empty($_SESSION['error_msg'])) {
         $data = json_decode(implode('', $output), true);
         unset($output);
         $v_username = $user;
@@ -57,42 +54,26 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
         // Antispam
         if (($v_antispam == 'yes') && (empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-delete-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_antispam = 'no';
             unset($output);
         }
         if (($v_antispam == 'no') && (!empty($_POST['v_antispam'])) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-add-mail-domain-antispam ".$v_username." ".$v_domain, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_antispam = 'yes';
             unset($output);
         }
         // Antivirus
         if (($v_antivirus == 'yes') && (empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-delete-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_antivirus = 'no';
             unset($output);
         }
         if (($v_antivirus == 'no') && (!empty($_POST['v_antivirus'])) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-add-mail-domain-antivirus ".$v_username." ".$v_domain, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_antivirus = 'yes';
             unset($output);
         }
@@ -103,21 +84,13 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
         // DKIM
         if (($v_dkim == 'yes') && (empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-delete-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_dkim = 'no';
             unset($output);
         }
         if (($v_dkim == 'no') && (!empty($_POST['v_dkim'])) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-add-mail-domain-dkim ".$v_username." ".$v_domain, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_dkim = 'yes';
             unset($output);
         }
@@ -125,11 +98,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
         // Catchall
         if ((!empty($v_catchall)) && (empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-delete-mail-domain-catchall ".$v_username." ".$v_domain, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_catchall = '';
             unset($output);
         }
@@ -137,22 +106,14 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
             if ($v_catchall != $_POST['v_catchall']) {
                 $v_catchall = escapeshellarg($_POST['v_catchall']);
                 exec (VESTA_CMD."v-change-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
             }
         }
         if ((empty($v_catchall)) && (!empty($_POST['v_catchall'])) && (empty($_SESSION['error_msg']))) {
             $v_catchall = escapeshellarg($_POST['v_catchall']);
             exec (VESTA_CMD."v-add-mail-domain-catchall ".$v_username." ".$v_domain." ".$v_catchall, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
         if (empty($_SESSION['error_msg'])) {
@@ -167,11 +128,8 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
     $v_domain = escapeshellarg($_GET['domain']);
     $v_account = escapeshellarg($_GET['account']);
     exec (VESTA_CMD."v-list-mail-account ".$user." ".$v_domain." ".$v_account." 'json'", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = __('Error code:',$return_var);
-        $_SESSION['error_msg'] = $error;
-    } else {
+    check_return_code($return_var,$output);
+    if (empty($_SESSION['error_msg'])) {
         $data = json_decode(implode('', $output), true);
         unset($output);
         $v_username = $user;
@@ -208,11 +166,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
         if (($v_password != $_POST['v_password']) && (empty($_SESSION['error_msg']))) {
             $v_password = escapeshellarg($_POST['v_password']);
             exec (VESTA_CMD."v-change-mail-account-password ".$v_username." ".$v_domain." ".$v_account." ".$v_password, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_password = "••••••••";
             unset($output);
         }
@@ -225,11 +179,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
                 $v_quota = escapeshellarg($_POST['v_quota']);
             }
             exec (VESTA_CMD."v-change-mail-account-quota ".$v_username." ".$v_domain." ".$v_account." ".$v_quota, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
@@ -245,11 +195,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
             foreach ($result as $alias) {
                 if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
                     exec (VESTA_CMD."v-delete-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
-                    if ($return_var != 0) {
-                        $error = implode('<br>', $output);
-                        if (empty($error)) $error = __('Error code:',$return_var);
-                        $_SESSION['error_msg'] = $error;
-                    }
+                    check_return_code($return_var,$output);
                     unset($output);
                 }
             }
@@ -257,11 +203,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
             foreach ($result as $alias) {
                 if ((empty($_SESSION['error_msg'])) && (!empty($alias))) {
                     exec (VESTA_CMD."v-add-mail-account-alias ".$v_username." ".$v_domain." ".$v_account." '".$alias."'", $output, $return_var);
-                    if ($return_var != 0) {
-                        $error = implode('<br>', $output);
-                        if (empty($error)) $error = __('Error code:',$return_var);
-                        $_SESSION['error_msg'] = $error;
-                    }
+                    check_return_code($return_var,$output);
                     unset($output);
                 }
             }
@@ -278,11 +220,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
             foreach ($result as $forward) {
                 if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
                     exec (VESTA_CMD."v-delete-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
-                    if ($return_var != 0) {
-                        $error = implode('<br>', $output);
-                        if (empty($error)) $error = __('Error code:',$return_var);
-                        $_SESSION['error_msg'] = $error;
-                    }
+                    check_return_code($return_var,$output);
                     unset($output);
                 }
             }
@@ -290,11 +228,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
             foreach ($result as $forward) {
                 if ((empty($_SESSION['error_msg'])) && (!empty($forward))) {
                     exec (VESTA_CMD."v-add-mail-account-forward ".$v_username." ".$v_domain." ".$v_account." '".$forward."'", $output, $return_var);
-                    if ($return_var != 0) {
-                        $error = implode('<br>', $output);
-                        if (empty($error)) $error = __('Error code:',$return_var);
-                        $_SESSION['error_msg'] = $error;
-                    }
+                    check_return_code($return_var,$output);
                     unset($output);
                 }
             }
@@ -303,11 +237,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
         // Autoreply
         if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
             exec (VESTA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $v_autoreply = 'no';
             $v_autoreply_message = '';
@@ -317,26 +247,18 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account'])))  {
                 $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
                 $v_autoreply_message = escapeshellarg($v_autoreply_message);
                 exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
                 $v_autoreply_message = $_POST['v_autoreply_message'];
             }
         }
-            if (($v_autoreply == 'no') && (!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
+        if (($v_autoreply == 'no') && (!empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) {
             if (empty($_POST['v_autoreply_message'])) $_SESSION['error_msg'] = $_SESSION['error_msg'] = __('Field "%s" can not be blank.','atoreply');
             if (empty($_SESSION['error_msg'])) {
                 $v_autoreply_message = str_replace("\r\n", "\n", $_POST['v_autoreply_message']);
                 $v_autoreply_message = escapeshellarg($v_autoreply_message);
                 exec (VESTA_CMD."v-add-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account." ".$v_autoreply_message, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
                 $v_autoreply = 'yes';
                 $v_autoreply_message = $_POST['v_autoreply_message'];

+ 5 - 15
web/edit/package/index.php

@@ -24,11 +24,8 @@ if ($_SESSION['user'] == 'admin') {
 
     $v_package = escapeshellarg($_GET['package']);
     exec (VESTA_CMD."v-list-user-package ".$v_package." 'json'", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = __('Error code:',$return_var);
-        $_SESSION['error_msg'] = $error;
-    } else {
+    check_return_code($return_var,$output);
+    if (empty($_SESSION['error_msg'])) {
         $data = json_decode(implode('', $output), true);
         unset($output);
 
@@ -172,11 +169,7 @@ if ($_SESSION['user'] == 'admin') {
                 // Rewrite package
                 if (empty($_SESSION['error_msg'])) {
                     exec (VESTA_CMD."v-add-user-package ".$tmpdir." ".$v_package." 'yes'", $output, $return_var);
-                    if ($return_var != 0) {
-                        $error = implode('<br>', $output);
-                        if (empty($error)) $error = __('Error code:',$return_var);
-                        $_SESSION['error_msg'] = $error;
-                    }
+                    check_return_code($return_var,$output);
                     unset($output);
                 }
 
@@ -186,11 +179,8 @@ if ($_SESSION['user'] == 'admin') {
 
                 // Propogate new package
                 exec (VESTA_CMD."v-update-user-package ".$v_package." 'json'", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
+                unset($output);
 
                 if (empty($_SESSION['error_msg'])) {
                     $_SESSION['ok_msg'] = __('Changes has been saved.');

+ 17 - 69
web/edit/user/index.php

@@ -22,11 +22,8 @@ if ($_SESSION['user'] == 'admin') {
     // Check user
     $v_username = escapeshellarg($_GET['user']);
     exec (VESTA_CMD."v-list-user ".$v_username." json", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = __('Error code:',$return_var);
-        $_SESSION['error_msg'] = $error;
-    } else {
+    check_return_code($return_var,$output);
+    if (empty($_SESSION['error_msg'])) {
         $data = json_decode(implode('', $output), true);
         unset($output);
         $v_username = $_GET['user'];
@@ -73,11 +70,7 @@ if ($_SESSION['user'] == 'admin') {
         if (($v_password != $_POST['v_password']) && (empty($_SESSION['error_msg']))) {
             $v_password = escapeshellarg($_POST['v_password']);
             exec (VESTA_CMD."v-change-user-password ".$v_username." ".$v_password, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_password = "••••••••";
             unset($output);
         }
@@ -86,11 +79,7 @@ if ($_SESSION['user'] == 'admin') {
         if (($v_package != $_POST['v_package']) && (empty($_SESSION['error_msg']))) {
             $v_package = escapeshellarg($_POST['v_package']);
             exec (VESTA_CMD."v-change-user-package ".$v_username." ".$v_package, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
@@ -98,13 +87,8 @@ if ($_SESSION['user'] == 'admin') {
         if (($v_language != $_POST['v_language']) && (empty($_SESSION['error_msg']))) {
             $v_language = escapeshellarg($_POST['v_language']);
             exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            } else {
-                if ($_GET['user'] == 'admin')  $_SESSION['language'] = $_POST['v_language'];
-            }
+            check_return_code($return_var,$output);
+            if (($_GET['user'] == 'admin') && (empty($_SESSION['error_msg']))) $_SESSION['language'] = $_POST['v_language'];
             unset($output);
         }
 
@@ -112,11 +96,7 @@ if ($_SESSION['user'] == 'admin') {
         if (($v_shell != $_POST['v_shell']) && (empty($_SESSION['error_msg']))) {
             $v_shell = escapeshellarg($_POST['v_shell']);
             exec (VESTA_CMD."v-change-user-shell ".$v_username." ".$v_shell, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
@@ -128,11 +108,7 @@ if ($_SESSION['user'] == 'admin') {
             } else {
                 $v_email = escapeshellarg($_POST['v_email']);
                 exec (VESTA_CMD."v-change-user-contact ".$v_username." ".$v_email, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
             }
             unset($output);
         }
@@ -142,11 +118,7 @@ if ($_SESSION['user'] == 'admin') {
             $v_fname = escapeshellarg($_POST['v_fname']);
             $v_lname = escapeshellarg($_POST['v_lname']);
             exec (VESTA_CMD."v-change-user-name ".$v_username." ".$v_fname." ".$v_lname, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
@@ -160,11 +132,7 @@ if ($_SESSION['user'] == 'admin') {
             if (!empty($_POST['v_ns3'])) $ns_cmd = $ns_cmd." ".$v_ns3;
             if (!empty($_POST['v_ns4'])) $ns_cmd = $ns_cmd." ".$v_ns4;
             exec ($ns_cmd, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
@@ -188,11 +156,8 @@ if ($_SESSION['user'] == 'admin') {
     // Check user
     $v_username = escapeshellarg($_GET['user']);
     exec (VESTA_CMD."v-list-user ".$v_username." json", $output, $return_var);
-    if ($return_var != 0) {
-        $error = implode('<br>', $output);
-        if (empty($error)) $error = __('Error code:',$return_var);
-        $_SESSION['error_msg'] = $error;
-    } else {
+    check_return_code($return_var,$output);
+    if (empty($_SESSION['error_msg'])) {
         $data = json_decode(implode('', $output), true);
         unset($output);
         $v_username = $_GET['user'];
@@ -230,11 +195,7 @@ if ($_SESSION['user'] == 'admin') {
         if (($v_password != $_POST['v_password']) && (empty($_SESSION['error_msg']))) {
             $v_password = escapeshellarg($_POST['v_password']);
             exec (VESTA_CMD."v-change-user-password ".$v_username." ".$v_password, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_password = "••••••••";
             unset($output);
         }
@@ -243,13 +204,8 @@ if ($_SESSION['user'] == 'admin') {
         if (($v_language != $_POST['v_language']) && (empty($_SESSION['error_msg']))) {
             $v_language = escapeshellarg($_POST['v_language']);
             exec (VESTA_CMD."v-change-user-language ".$v_username." ".$v_language, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            } else {
-                $_SESSION['language'] = $_POST['v_language'];
-            }
+            check_return_code($return_var,$output);
+            if (empty($_SESSION['error_msg'])) $_SESSION['language'] = $_POST['v_language'];
             unset($output);
         }
 
@@ -257,11 +213,7 @@ if ($_SESSION['user'] == 'admin') {
         if (($v_email != $_POST['v_email']) && (empty($_SESSION['error_msg']))) {
             $v_email = escapeshellarg($_POST['v_email']);
             exec (VESTA_CMD."v-change-user-contact ".$v_username." ".$v_email, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 
@@ -275,11 +227,7 @@ if ($_SESSION['user'] == 'admin') {
             if (!empty($_POST['v_ns3'])) $ns_cmd = $ns_cmd." ".$v_ns3;
             if (!empty($_POST['v_ns4'])) $ns_cmd = $ns_cmd." ".$v_ns4;
             exec ($ns_cmd, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
         }
 

+ 39 - 146
web/edit/web/index.php

@@ -28,11 +28,8 @@ if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
 // Check domain
 $v_domain = escapeshellarg($_GET['domain']);
 exec (VESTA_CMD."v-list-web-domain ".$user." ".$v_domain." json", $output, $return_var);
-if ($return_var != 0) {
-    $error = implode('<br>', $output);
-    if (empty($error)) $error = __('Error code:',$return_var);
-    $_SESSION['error_msg'] = $error;
-} else {
+check_return_code($return_var,$output);
+if (empty($_SESSION['error_msg'])) {
     $data = json_decode(implode('', $output), true);
     unset($output);
     $v_username = $user;
@@ -98,22 +95,14 @@ if (!empty($_POST['save'])) {
     if (($v_ip != $_POST['v_ip']) && (empty($_SESSION['error_msg']))) {
         $v_ip = escapeshellarg($_POST['v_ip']);
         exec (VESTA_CMD."v-change-web-domain-ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         $restart_web = 'yes';
         unset($output);
         exec (VESTA_CMD."v-list-dns-domain ".$v_username." ".$v_domain." json", $output, $return_var);
         if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) {
             unset($output);
             exec (VESTA_CMD."v-change-dns-domain-ip ".$v_username." ".$v_domain." ".$v_ip." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $restart_dns = 'yes';
         }
         unset($output);
@@ -121,11 +110,7 @@ if (!empty($_POST['save'])) {
             exec (VESTA_CMD."v-list-dns-domain ".$v_username." '".$v_alias."' json", $output, $return_var);
             if ((empty($_SESSION['error_msg'])) && ($return_var == 0 )) {
                 exec (VESTA_CMD."v-change-dns-domain-ip ".$v_username." '".$v_alias."' ".$v_ip, $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 $restart_dns = 'yes';
             }
             unset($output);
@@ -136,11 +121,7 @@ if (!empty($_POST['save'])) {
     if (( $_SESSION['user'] == 'admin') && ($v_template != $_POST['v_template']) && (empty($_SESSION['error_msg']))) {
         $v_template = escapeshellarg($_POST['v_template']);
         exec (VESTA_CMD."v-change-web-domain-tpl ".$v_username." ".$v_domain." ".$v_template." 'no'", $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
         $restart_web = 'yes';
     }
@@ -159,11 +140,7 @@ if (!empty($_POST['save'])) {
                 $restart_web = 'yes';
                 $v_template = escapeshellarg($_POST['v_template']);
                 exec (VESTA_CMD."v-delete-web-domain-alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
 
                 if (empty($_SESSION['error_msg'])) {
@@ -171,11 +148,7 @@ if (!empty($_POST['save'])) {
                     unset($output);
                     if ($return_var == 0) {
                         exec (VESTA_CMD."v-delete-dns-on-web-alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var);
-                        if ($return_var != 0) {
-                            $error = implode('<br>', $output);
-                            if (empty($error)) $error = __('Error code:',$return_var);
-                            $_SESSION['error_msg'] = $error;
-                        }
+                        check_return_code($return_var,$output);
                         $restart_dns = 'yes';
                     }
                     unset($output);
@@ -189,22 +162,14 @@ if (!empty($_POST['save'])) {
                 $restart_web = 'yes';
                 $v_template = escapeshellarg($_POST['v_template']);
                 exec (VESTA_CMD."v-add-web-domain-alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var);
-                if ($return_var != 0) {
-                    $error = implode('<br>', $output);
-                    if (empty($error)) $error = __('Error code:',$return_var);
-                    $_SESSION['error_msg'] = $error;
-                }
+                check_return_code($return_var,$output);
                 unset($output);
                 if (empty($_SESSION['error_msg'])) {
                     exec (VESTA_CMD."v-list-dns-domain ".$v_username." ".$v_domain, $output, $return_var);
                     unset($output);
                     if ($return_var == 0) {
                         exec (VESTA_CMD."v-add-dns-on-web-alias ".$v_username." ".$v_domain." '".$alias."' 'no'", $output, $return_var);
-                        if ($return_var != 0) {
-                            $error = implode('<br>', $output);
-                            if (empty($error)) $error = __('Error code:',$return_var);
-                            $_SESSION['error_msg'] = $error;
-                        }
+                        check_return_code($return_var,$output);
                         $restart_dns = 'yes';
                     }
                 }
@@ -216,11 +181,7 @@ if (!empty($_POST['save'])) {
     // Proxy
     if ((!empty($v_proxy)) && (empty($_POST['v_proxy'])) && (empty($_SESSION['error_msg']))) {
         exec (VESTA_CMD."v-delete-web-domain-proxy ".$v_username." ".$v_domain." 'no'", $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
         unset($v_proxy);
         $restart_proxy = 'yes';
@@ -235,11 +196,7 @@ if (!empty($_POST['save'])) {
             $ext = str_replace(', ', ",", $ext);
             if (!empty($_POST['v_proxy_template'])) $v_proxy_template = $_POST['v_proxy_template'];
             exec (VESTA_CMD."v-change-web-domain-proxy-tpl ".$v_username." ".$v_domain." ".escapeshellarg($v_proxy_template)." ".escapeshellarg($ext)." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_proxy_ext = str_replace(',', ', ', $ext);
             unset($output);
             $restart_proxy = 'yes';
@@ -256,11 +213,7 @@ if (!empty($_POST['save'])) {
             $v_proxy_ext = str_replace(',', ', ', $ext);
         }
         exec (VESTA_CMD."v-add-web-domain-proxy ".$v_username." ".$v_domain." ".escapeshellarg($v_proxy_template)." ".escapeshellarg($ext)." 'no'", $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
         $restart_proxy = 'yes';
     }
@@ -268,11 +221,7 @@ if (!empty($_POST['save'])) {
     // SSL
     if (( $v_ssl == 'yes' ) && (empty($_POST['v_ssl'])) && (empty($_SESSION['error_msg']))) {
         exec (VESTA_CMD."v-delete-web-domain-ssl ".$v_username." ".$v_domain." 'no'", $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
         $v_ssl = 'no';
         $restart_web = 'yes';
@@ -307,11 +256,7 @@ if (!empty($_POST['save'])) {
             }
 
             exec (VESTA_CMD."v-change-web-domain-sslcert ".$user." ".$v_domain." ".$tmpdir." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $restart_web = 'yes';
             $v_ssl_crt = $_POST['v_ssl_crt'];
@@ -323,11 +268,7 @@ if (!empty($_POST['save'])) {
         if ( $v_ssl_home != $_POST['v_ssl_home'] ) {
             $v_ssl_home = escapeshellarg($_POST['v_ssl_home']);
             exec (VESTA_CMD."v-change-web-domain-sslhome ".$user." ".$v_domain." ".$v_ssl_home." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             $v_ssl_home = $_POST['v_ssl_home'];
             unset($output);
         }
@@ -371,11 +312,7 @@ if (!empty($_POST['save'])) {
                 fclose($fp);
             }
             exec (VESTA_CMD."v-add-web-domain-ssl ".$user." ".$v_domain." ".$tmpdir." ".$v_ssl_home." 'no'", $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $v_ssl = 'yes';
             $restart_web = 'yes';
@@ -389,43 +326,27 @@ if (!empty($_POST['save'])) {
     // Web Stats
     if ((!empty($v_stats)) && ($_POST['v_stats'] == 'none') && (empty($_SESSION['error_msg']))) {
         exec (VESTA_CMD."v-delete-web-domain-stats ".$v_username." ".$v_domain, $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
         $v_stats = '';
     }
     if ((!empty($v_stats)) && ($_POST['v_stats'] != $v_stats) && (empty($_SESSION['error_msg']))) {
         $v_stats = escapeshellarg($_POST['v_stats']);
         exec (VESTA_CMD."v-change-web-domain-stats ".$v_username." ".$v_domain." ".$v_stats, $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
     }
     if ((empty($v_stats)) && ($_POST['v_stats'] != 'none') && (empty($_SESSION['error_msg']))) {
         $v_stats = escapeshellarg($_POST['v_stats']);
         exec (VESTA_CMD."v-add-web-domain-stats ".$v_username." ".$v_domain." ".$v_stats, $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
     }
 
     // Web Stats Auth
     if ((!empty($v_stats_user)) && (empty($_POST['v_stats_auth'])) && (empty($_SESSION['error_msg']))) {
         exec (VESTA_CMD."v-delete-web-domain-stats-user ".$v_username." ".$v_domain, $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
         $v_stats_user = '';
         $v_stats_password = '';
@@ -446,11 +367,7 @@ if (!empty($_POST['save'])) {
             $v_stats_user = escapeshellarg($_POST['v_stats_user']);
             $v_stats_password = escapeshellarg($_POST['v_stats_password']);
             exec (VESTA_CMD."v-add-web-domain-stats-user ".$v_username." ".$v_domain." ".$v_stats_user." ".$v_stats_password, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $v_stats_password = "••••••••";
         }
@@ -472,11 +389,7 @@ if (!empty($_POST['save'])) {
             $v_stats_user = escapeshellarg($_POST['v_stats_user']);
             $v_stats_password = escapeshellarg($_POST['v_stats_password']);
             exec (VESTA_CMD."v-add-web-domain-stats-user ".$v_username." ".$v_domain." ".$v_stats_user." ".$v_stats_password, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $v_stats_password = "••••••••";
         }
@@ -485,11 +398,7 @@ if (!empty($_POST['save'])) {
     // Delete FTP Account
     if ((!empty($v_ftp_user)) && (empty($_POST['v_ftp'])) && (empty($_SESSION['error_msg']))) {
         exec (VESTA_CMD."v-delete-web-domain-ftp ".$v_username." ".$v_domain, $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
         unset($output);
         $v_ftp= '';
         $v_ftp_user = '';
@@ -515,11 +424,7 @@ if (!empty($_POST['save'])) {
             $v_ftp_user = escapeshellarg($v_ftp_user);
             $v_ftp_password = escapeshellarg($_POST['v_ftp_password']);
             exec (VESTA_CMD."v-add-web-domain-ftp ".$v_username." ".$v_domain." ".$v_ftp_user." ".$v_ftp_password, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            }
+            check_return_code($return_var,$output);
             unset($output);
             $v_ftp= '';
             $v_ftp_user = $user."_".preg_replace("/^".$user."_/", "", $_POST['v_ftp_user']);
@@ -546,20 +451,15 @@ if (!empty($_POST['save'])) {
             $v_ftp_user = escapeshellarg($_POST['v_ftp_user']);
             $v_ftp_password = escapeshellarg($_POST['v_ftp_password']);
             exec (VESTA_CMD."v-add-web-domain-ftp ".$v_username." ".$v_domain." ".$v_ftp_user." ".$v_ftp_password, $output, $return_var);
-            if ($return_var != 0) {
-                $error = implode('<br>', $output);
-                if (empty($error)) $error = __('Error code:',$return_var);
-                $_SESSION['error_msg'] = $error;
-            } else {
-                if (!empty($_POST['v_ftp_email'])) {
-                    $to = $_POST['v_ftp_email'];
-                    $subject = __("FTP login credentials");
-                    $hostname = exec('hostname');
-                    $from = __('MAIL_FROM',$hostname);
-                    $mailtext .= __('FTP_ACCOUNT_READY',$_GET['domain'],$user,$_POST['v_ftp_user'],$_POST['v_ftp_password']);
-                    send_email($to, $subject, $mailtext, $from);
-                    unset($v_ftp_email);
-                }
+            check_return_code($return_var,$output);
+            if ((!empty($_POST['v_ftp_email'])) && (empty($_SESSION['error_msg']))) {
+                $to = $_POST['v_ftp_email'];
+                $subject = __("FTP login credentials");
+                $hostname = exec('hostname');
+                $from = __('MAIL_FROM',$hostname);
+                $mailtext .= __('FTP_ACCOUNT_READY',$_GET['domain'],$user,$_POST['v_ftp_user'],$_POST['v_ftp_password']);
+                send_email($to, $subject, $mailtext, $from);
+                unset($v_ftp_email);
             }
             unset($output);
             $v_ftp_user =  $user."_".$_POST['v_ftp_user'];
@@ -567,25 +467,18 @@ if (!empty($_POST['save'])) {
         }
     }
 
-
     // Restart web
     if (!empty($restart_web) && (empty($_SESSION['error_msg']))) {
         exec (VESTA_CMD."v-restart-web", $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
+        unset($output);
     }
 
     // Restart dns
     if (!empty($restart_dns) && (empty($_SESSION['error_msg']))) {
         exec (VESTA_CMD."v-restart-dns", $output, $return_var);
-        if ($return_var != 0) {
-            $error = implode('<br>', $output);
-            if (empty($error)) $error = __('Error code:',$return_var);
-            $_SESSION['error_msg'] = $error;
-        }
+        check_return_code($return_var,$output);
+        unset($output);
     }
 
     if (empty($_SESSION['error_msg'])) {
@@ -600,7 +493,7 @@ if ($_SESSION['user'] == 'admin') {
 }
 unset($_SESSION['error_msg']);
 unset($_SESSION['ok_msg']);
-//}
+
 
 // Footer
 include($_SERVER['DOCUMENT_ROOT'].'/templates/footer.html');