function validate_form() { $error = array(); $NumberTickets = clean_int($_POST['numberoftickets']); $MaxMb = clean_number($_POST['MaxMb']); $Max_Mb = clean_number($_POST['Max_Mb']); $MaxTime = clean_int($_POST['MaxTime']); $Max_Time = clean_int($_POST['Max_Time']); $error[] = validate_int($NumberTickets); if (!\Grase\Validate::numericLimit($MaxMb)) { $error[] = sprintf(T_("Invalid value '%s' for Data Limit"), $MaxMb); } if (!\Grase\Validate::numericLimit($Max_Mb)) { $error[] = sprintf(T_("Invalid value '%s' for Data Limit"), $Max_Mb); } if (!\Grase\Validate::numericLimit($MaxTime)) { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $MaxTime); } if (!\Grase\Validate::numericLimit($Max_Time)) { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $Max_Time); } if ((is_numeric($Max_Mb) || $_POST['Max_Mb'] == 'inherit') && is_numeric($MaxMb)) { $error[] = T_("Only set one Data limit field"); } if ((is_numeric($Max_Time) || $_POST['Max_Time'] == 'inherit') && is_numeric($MaxTime)) { $error[] = T_("Only set one Time limit field"); } // 1000 seems like a reasonable number, if someone wants it increased we can now that we can delete batches if ($NumberTickets > 1000) { $error[] = T_("Max of 1000 tickets per batch"); } $error[] = validate_group($_POST['Group']); return array_filter($error); }
function validate_form($userDetails, $type = 'User') { $error = array(); if ($type == 'User') { if (!DatabaseFunctions::getInstance()->checkUniqueUsername($userDetails['Username'])) { $error[] = T_("Username already taken"); } if (!$userDetails['Username'] || !$userDetails['Password']) { $error[] = T_("Username and Password are both Required"); } } if ($type == 'Computer') { if (!DatabaseFunctions::getInstance()->checkUniqueUsername($userDetails['mac'])) { $error[] = T_("MAC Address already has an account"); } if (!\Grase\Validate::MACAddress($userDetails['mac'])) { $error[] = T_("MAC Address not in correct format"); } } if (!\Grase\Validate::numericLimit($userDetails['MaxMb']) && $userDetails['MaxMb'] != '') { $error[] = sprintf(T_("Invalid value '%s' for 1 Data Limit"), $userDetails['MaxMb']); } if (!\Grase\Validate::numericLimit($userDetails['Max_Mb']) && $userDetails['Max_Mb'] != 'inherit') { $error[] = sprintf(T_("Invalid value '%s' for Data Limit"), $userDetails['Max_Mb']); } if (!\Grase\Validate::numericLimit($userDetails['MaxTime']) && $userDetails['MaxTime'] != '') { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $userDetails['MaxTime']); } if (!\Grase\Validate::numericLimit($userDetails['Max_Time']) && $userDetails['Max_Time'] != 'inherit') { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $userDetails['Max_Time']); } if ((is_numeric($userDetails['Max_Mb']) || $userDetails['Max_Mb'] == 'inherit') && is_numeric($userDetails['MaxMb'])) { $error[] = T_("Only set one Data limit field"); } if ((is_numeric($userDetails['Max_Time']) || $userDetails['Max_Time'] == 'inherit') && is_numeric($userDetails['MaxTime'])) { $error[] = T_("Only set one Time limit field"); } $error[] = validate_group($userDetails['Group']); return array_filter($error); }
if (!isset($voucherprice[$key])) { $error[] = T_("Vouchers need a price"); } else { // Don't want to show both errors $error[] = @validate_num($voucherprice[$key], T_('Invalid price')); } if (!(isset($vouchermaxmb[$key]) || isset($vouchermaxtime[$key]))) { $warning[] = T_("It is not recommended having vouchers without a data or time limit"); } // validate limits //$error[] = validate_datalimit($groupdatalimit[$key]); // Silence warnings (@) as we don't care if they are set or not' if (!\Grase\Validate::numericLimit($vouchermaxtime[$key])) { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $vouchermaxtime[$key]); } if (!\Grase\Validate::numericLimit($vouchermaxmb[$key])) { $error[] = sprintf(T_("Invalid value '%s' for Data Limit"), $vouchermaxmb[$key]); } // TODO validate groupname, it already comes in in the correct format though $error = array_filter($error); $vouchersettings[\Grase\Clean::groupName($name)] = array_filter(array('VoucherName' => \Grase\Clean::groupName($name), 'VoucherLabel' => \Grase\Clean::text($name), 'VoucherPrice' => @clean_number($voucherprice[$key]), 'VoucherGroup' => $vouchergroup[$key], 'MaxMb' => @clean_number($vouchermaxmb[$key]), 'MaxTime' => @clean_int($vouchermaxtime[$key]), 'Description' => @\Grase\Clean::text($voucherdesc[$key]), 'TopupVoucher' => $vouchertopup[$key] ? TRUE : FALSE, 'InitVoucher' => $voucherinit[$key] ? TRUE : FALSE)); } if (sizeof($error) == 0) { // No errors. Save groups //$Settings->setSetting("groups", serialize($groupexpiries)); foreach ($vouchersettings as $attributes) { //$Settings->setGroup($attributes); $Settings->setVoucher($attributes); } // Delete vouchers no longer referenced foreach ($Settings->getVoucher() as $oldvoucher => $oldvouchersettings) {
} // Increase Time Limit if ($addTime) { if (!\Grase\Validate::numericLimit($addTime)) { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $addTime); } else { DatabaseFunctions::getInstance()->increaseUserTimelimit($username, $addTime); DatabaseFunctions::getInstance()->setUserExpiry($username, expiry_for_group(DatabaseFunctions::getInstance()->getUserGroup($username))); // TODO: Check return for success $success[] = T_("Time Limit Increased"); AdminLog::getInstance()->log(sprintf(T_("Time Limit increased for %s"), $username)); } } // If Time Limit is changed and Not added too, Change Time Limit if ($maxTime !== '' && !$addTime && $maxTime != $user['MaxTime']) { if (!\Grase\Validate::numericLimit($maxTime)) { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $maxTime); } else { DatabaseFunctions::getInstance()->setUserTimeLimit($username, $maxTime); DatabaseFunctions::getInstance()->setUserExpiry($username, expiry_for_group(DatabaseFunctions::getInstance()->getUserGroup($username))); // TODO: Check return for success $success[] = T_("Max Time Limit Updated"); AdminLog::getInstance()->log(sprintf(T_("Max Time Limit changed for %s"), $username)); } } } if (isset($_POST['unexpiresubmit'])) { DatabaseFunctions::getInstance()->setUserExpiry($username, expiry_for_group(DatabaseFunctions::getInstance()->getUserGroup($username))); $success[] = T_("Expiry updated"); } // Delete User
if (strtotime($groupExpireAfter[$key]) == false) { $error[] = sprintf(T_("%s: Invalid Expire After format"), $name); } elseif (strtotime($groupExpireAfter[$key]) < time()) { $error[] = sprintf(T_("%s: Expire after can not be in the past"), $name); } } if (!\Grase\Validate::numericLimit($groupTimeLimit[$key])) { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $groupTimeLimit[$key]); } if (!\Grase\Validate::numericLimit($groupRecurTimeLimit[$key])) { $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $groupRecurTimeLimit[$key]); } if (!\Grase\Validate::numericLimit($groupRecurDataLimit[$key])) { $error[] = sprintf(T_("Invalid value '%s' for Data Limit"), $groupRecurDataLimit[$key]); } if (!\Grase\Validate::numericLimit($groupIdleTimeout[$key])) { $error[] = sprintf(T_("Invalid value '%s' for Idle Timeout"), $groupIdleTimeout[$key]); } if (!\Grase\Validate::recurrenceInterval($groupRecurTime[$key], recurtimes())) { $error[] = sprintf(T_("Invalid recurrence interval '%s'"), $groupRecurTime[$key]); } if (!\Grase\Validate::recurrenceInterval($groupRecurData[$key], recurtimes())) { $error[] = sprintf(T_("Invalid recurrence interval '%s'"), $groupRecurData[$key]); } if (!\Grase\Validate::recurrenceTime($groupRecurTime[$key], $groupRecurTimeLimit[$key])) { $error[] = T_("Recurring time limit must be less than interval"); } if (!\Grase\Validate::bandwidthOptions($groupBandwidthDownLimit[$key], bandwidth_options())) { $error[] = sprintf(T_("Invalid Bandwidth Limit '%s'"), $groupBandwidthDownLimit[$key]); } if (!\Grase\Validate::bandwidthOptions($groupBandwidthUpLimit[$key], bandwidth_options())) {