From cdc4a9366f2e153e9eb7307cb1d2ccd1324a8e83 Mon Sep 17 00:00:00 2001 From: Giam Teck Choon Date: Tue, 27 Aug 2024 22:02:24 +0800 Subject: [PATCH 9/9] perform.php - Add in conditional check for $_POST['form'] is set. This is needed to fix the following error: PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in perform.php:65 Signed-off-by: Giam Teck Choon --- perform.php | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/perform.php b/perform.php index faca18f..5237f5a 100644 --- a/perform.php +++ b/perform.php @@ -6,7 +6,7 @@ * Authors: * Daniel Lorch * - */ + */ include "auth.php"; @@ -34,7 +34,7 @@ if(isset($_POST['key'])) { } } } - + /* Create error page and halt further execution*/ function raise_error($string) { @@ -44,7 +44,7 @@ function raise_error($string) { 'title' => $language['error']['title'], 'character' => $language['language']['encoding'] )); - + echo template_replace($parts['error_header'], array( 'header' => $language['error']['header'] )); @@ -53,7 +53,7 @@ function raise_error($string) { 'message' => $string, 'back' => $language['error']['back'] )); - + echo $parts['error_footer']; echo $parts['footer']; @@ -62,7 +62,7 @@ function raise_error($string) { /* Clean up form data */ -if(count($_POST['form']) > 0) { +if(isset($_POST['form']) && count($_POST['form']) > 0) { foreach($_POST['form'] as $name => $value) { if(ini_get("magic_quotes_gpc")) { @@ -76,7 +76,7 @@ if(count($_POST['form']) > 0) { break; case 'forwards': - $_POST['form'][$name] = preg_split("/\s+/", $_POST['form'][$name]); + $_POST['form'][$name] = preg_split("/\s+/", $_POST['form'][$name]); break; case 'softquota': @@ -104,7 +104,7 @@ if(count($_POST['form']) > 0) { $_POST['form'][$name] = $matches[0]; } break; - + case 'expiry_month': case 'expiry_day': if(preg_match("/\d{2}/", $value, $matches)) { @@ -182,7 +182,7 @@ switch($action) { if(!$account_exists) { $vm->delete_user($_POST['form']['username']); } - + raise_error($error); } break; @@ -191,7 +191,7 @@ switch($action) { /* this is explained at 'add_account' */ $account_exists = ($vm->user_info($_POST['form']['username']) !== false); - + if(trim($_POST['form']['username'] == '')) raise_error($language['error']['no_username']); else if($_POST['form']['password'] != $_POST['form']['password_repeat']) @@ -208,7 +208,7 @@ switch($action) { if(!$account_exists) { $vm->delete_user($_POST['form']['username']); } - + raise_error($error); } @@ -226,13 +226,13 @@ switch($action) { raise_error($vm->last_response()); } } - + if(!($vm->set_personal($_POST['form']['username'], $_POST['form']['personal']) && $vm->set_expiry($_POST['form']['username'], $_POST['form']['expiry']) && $vm->set_enabled($_POST['form']['username'], $_POST['form']['account_enabled']) && $vm->set_forwards($_POST['form']['username'], $_POST['form']['forwards']) )) { - + raise_error($vm->last_response()); } break; @@ -249,7 +249,7 @@ switch($action) { raise_error($vm->last_response()); } } - + if(!($vm->set_personal($_POST['form']['username'], $_POST['form']['personal']) && $vm->set_softquota($_POST['form']['username'], $_POST['form']['softquota']) && $vm->set_hardquota($_POST['form']['username'], $_POST['form']['hardquota']) @@ -261,7 +261,7 @@ switch($action) { && $vm->autoresponse_set($_POST['form']['username'], 'Subject: ' . $_POST['form']['autoresponse_subject'] . "\nAuto-Submitted: auto-generated\nFrom: " . $_POST['form']['username'] . "@" . $_SESSION['domain'] . "\n\n" . $_POST['form']['autoresponse_text']) && $vm->autoresponse_set_enabled($_POST['form']['username'], $_POST['form']['autoresponse_enabled'] != '') )) { - + raise_error($vm->last_response()); } break; @@ -275,7 +275,7 @@ switch($action) { case 'catchall': if(!$vm->set_catchall($_POST['form']['catchall'])) { raise_error($vm->last_response()); - } + } break; case 'user_alias': @@ -287,7 +287,7 @@ switch($action) { else if(is_password_secure($_POST['form']['password']) == false) raise_error($language['error']['password_insecure']); else { - + if($vm->set_password($_SESSION['user'], $_POST['form']['password'])) { $vm->pass = $_POST['form']['password']; $_SESSION['password'] = rc4_encrypt($salt, $_POST['form']['password']); @@ -295,13 +295,13 @@ switch($action) { else { raise_error($vm->last_response()); } - + } } if(!($vm->set_forwards($_SESSION['user'], $_POST['form']['forwards']) )) { - + raise_error($vm->last_response()); } @@ -312,7 +312,7 @@ switch($action) { Header('Location: user.php?key=' . $_POST['key'] . '&' . SID); exit; - + break; case 'user_account': @@ -324,7 +324,7 @@ switch($action) { else if(is_password_secure($_POST['form']['password']) == false) raise_error($language['error']['password_insecure']); else { - + if($vm->set_password($_SESSION['user'], $_POST['form']['password'])) { $vm->pass = $_POST['form']['password']; $_SESSION['password'] = rc4_encrypt($salt, $_POST['form']['password']); @@ -332,7 +332,7 @@ switch($action) { else { raise_error($vm->last_response()); } - + } } @@ -340,7 +340,7 @@ switch($action) { && $vm->autoresponse_set($_SESSION['user'], 'Subject: ' . $_POST['form']['autoresponse_subject'] . "\nFrom: " . $_SESSION['user'] . "@" . $_SESSION['domain'] . "\n\n" . $_POST['form']['autoresponse_text']) && $vm->autoresponse_set_enabled($_SESSION['user'], $_POST['form']['autoresponse_enabled'] != '') )) { - + raise_error($vm->last_response()); } @@ -351,21 +351,21 @@ switch($action) { Header('Location: user.php?key=' . $_POST['key'] . '&' . SID); exit; - + break; case 'settings': $form = $_POST['form']; $form['forwards'] = @join("\n", $form['forwards']); - + if($form['softquota'] != '') $form['softquota'] /= BYTE_UNIT; if($form['hardquota'] != '') $form['softquota'] /= BYTE_UNIT; if($form['messagesize'] != '') $form['softquota'] /= BYTE_UNIT; setcookie("form", serialize($form)); break; -} +} /* action successful - we don't need this anymore */ if(isset($_POST['key'])) { -- 2.34.1