From 67c2baf157c50ae1b545f36bcf6afee6cdf6f67c Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 14 Dec 2015 23:18:15 +0545 Subject: Coe style firewall * --- src/usr/local/www/firewall_schedule_edit.php | 249 ++++++++++++--------------- 1 file changed, 112 insertions(+), 137 deletions(-) (limited to 'src/usr/local/www/firewall_schedule_edit.php') diff --git a/src/usr/local/www/firewall_schedule_edit.php b/src/usr/local/www/firewall_schedule_edit.php index 0621591..14cab5a 100644 --- a/src/usr/local/www/firewall_schedule_edit.php +++ b/src/usr/local/www/firewall_schedule_edit.php @@ -73,8 +73,9 @@ function schedulecmp($a, $b) { function schedule_sort() { global $g, $config; - if (!is_array($config['schedules']['schedule'])) + if (!is_array($config['schedules']['schedule'])) { return; + } usort($config['schedules']['schedule'], "schedulecmp"); } @@ -91,16 +92,19 @@ $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firew $dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun')); $monthArray = array (gettext('January'), gettext('February'), gettext('March'), gettext('April'), gettext('May'), gettext('June'), gettext('July'), gettext('August'), gettext('September'), gettext('October'), gettext('November'), gettext('December')); -if (!is_array($config['schedules']['schedule'])) +if (!is_array($config['schedules']['schedule'])) { $config['schedules']['schedule'] = array(); +} $a_schedules = &$config['schedules']['schedule']; -if (is_numericint($_GET['id'])) +if (is_numericint($_GET['id'])) { $id = $_GET['id']; +} -if (isset($_POST['id']) && is_numericint($_POST['id'])) +if (isset($_POST['id']) && is_numericint($_POST['id'])) { $id = $_POST['id']; +} if (isset($id) && $a_schedules[$id]) { $pconfig['name'] = $a_schedules[$id]['name']; @@ -112,27 +116,32 @@ if (isset($id) && $a_schedules[$id]) { if ($_POST) { - if (strtolower($_POST['name']) == "lan") + if (strtolower($_POST['name']) == "lan") { $input_errors[] = gettext("Schedule may not be named LAN."); + } - if (strtolower($_POST['name']) == "wan") + if (strtolower($_POST['name']) == "wan") { $input_errors[] = gettext("Schedule may not be named WAN."); + } - if (strtolower($_POST['name']) == "") + if (strtolower($_POST['name']) == "") { $input_errors[] = gettext("Schedule name cannot be blank."); + } $x = is_validaliasname($_POST['name']); if (!isset($x)) { $input_errors[] = gettext("Reserved word used for schedule name."); } else { - if (is_validaliasname($_POST['name']) == false) + if (is_validaliasname($_POST['name']) == false) { $input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9"); + } } /* check for name conflicts */ foreach ($a_schedules as $schedule) { - if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule)) + if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule)) { continue; + } if ($schedule['name'] == $_POST['name']) { $input_errors[] = gettext("A Schedule with this name already exists."); @@ -169,21 +178,16 @@ if ($_POST) { $timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8'); $dashpos = strpos($timestr, '-'); - if ($dashpos === false) - { + if ($dashpos === false) { $timeparts['position'] = $timestr; - } - else - { + } else { $tempindarray = array(); $monthstr = ""; $daystr = ""; $tempindarray = explode(",", $timestr); - foreach ($tempindarray as $currentselection) - { + foreach ($tempindarray as $currentselection) { if ($currentselection) { - if ($firstprint) - { + if ($firstprint) { $monthstr .= ","; $daystr .= ","; } @@ -206,39 +210,41 @@ if ($_POST) { } } - if (!$timerangeFound) + if (!$timerangeFound) { $input_errors[] = gettext("The schedule must have at least one time range configured."); + } if (!$input_errors) { - if (!empty($pconfig['schedlabel'])) + if (!empty($pconfig['schedlabel'])) { $schedule['schedlabel'] = $pconfig['schedlabel']; - else + } else { $schedule['schedlabel'] = uniqid(); + } if (isset($id) && $a_schedules[$id]) { $a_schedules[$id] = $schedule; - } - else { + } else { $a_schedules[] = $schedule; } schedule_sort(); - if (write_config()) + if (write_config()) { filter_configure(); + } header("Location: firewall_schedule.php"); exit; } //we received input errors, copy data to prevent retype - else - { - if (!$_POST['schedule0']) + else { + if (!$_POST['schedule0']) { $getSchedule = false; - else + } else { $getSchedule = true; + } $pconfig['name'] = $schedule['name']; $pconfig['descr'] = $schedule['descr']; @@ -260,8 +266,9 @@ function build_date_table() { for ($k = 0; $k < 12; $k++) { $firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter))); - if ($firstdayofmonth == 0) + if ($firstdayofmonth == 0) { $firstdayofmonth = 7; + } $daycounter = 1; //number of day in month @@ -273,10 +280,11 @@ function build_date_table() { $mostr = '
' . $daycounter . "\r\n"; $daycounter++; $mostr .= ""; - } - else - { + } else { $mostr .= ''; } if ($positioncounter == 7 || $daycounter > $numberofdays) { $positioncounter = 1; $mostr .= ""; - } - else { + } else { $positioncounter++; } @@ -338,13 +341,10 @@ function build_date_table() { $mostr .= gettext('Click individual date to select that date only. Click the appropriate weekday Header to select all occurrences of that weekday. '); $mostr .= '
'; - if ($monthcounter == 12) - { + if ($monthcounter == 12) { $monthcounter = 1; $yearcounter++; - } - else - { + } else { $monthcounter++; } @@ -368,9 +368,7 @@ function build_month_list() { if ($monthcounter == 12) { $monthcounter = 1; $yearcounter++; - } - else - { + } else { $monthcounter++; } } @@ -378,8 +376,9 @@ function build_month_list() { return($list); } -if ($input_errors) +if ($input_errors) { print_input_errors($input_errors); +} $form = new Form(); @@ -395,8 +394,9 @@ $input = new Form_Input( $input->setHelp((is_schedule_inuse($pconfig['name']) != true) ? 'The name of the alias may only consist of the characters a-z, A-Z and 0-9': 'This schedule is in use so the name may not be modified!'); -if (is_schedule_inuse($pconfig['name']) == true) +if (is_schedule_inuse($pconfig['name']) == true) { $input->setReadonly(); +} $section->addInput($input); @@ -529,16 +529,14 @@ if ($getSchedule) { $weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y"))); $weeknumber = ltrim($weeknumber, "0"); - if ($firstPrint) - { + if ($firstPrint) { $tempID .= ","; } $tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day; $firstPrint = true; - if (!$firstDayFound) - { + if (!$firstDayFound) { $firstDay = $day; $firstmonth = $month; $firstDayFound = true; @@ -548,15 +546,17 @@ if ($getSchedule) { $nextDay = $tempdayarray[$arraycounter+1]; $currentDay++; if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) { - if ($firstprint2) + if ($firstprint2) { $tempFriendlyTime .= ", "; + } $currentDay--; - if ($currentDay != $firstDay) + if ($currentDay != $firstDay) { $tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ; - else + } else { $tempFriendlyTime .= $monthArray[$month-1] . " " . $day; + } $firstDayFound = false; $firstprint2 = true; @@ -564,9 +564,7 @@ if ($getSchedule) { $arraycounter++; } - } - else - { + } else { $dayFriendly = $timerange['position']; $tempID = $dayFriendly; } @@ -586,8 +584,7 @@ if ($getSchedule) { if (!$timerange['month']) { foreach ($tempFriendlyDayArray as $day) { if ($day != "") { - if (!$firstDayFound) - { + if (!$firstDayFound) { $firstDay = $tempFriendlyDayArray[$i]; $firstDayFound = true; } @@ -598,15 +595,17 @@ if ($getSchedule) { $currentDay++; if ($currentDay != $nextDay) { - if ($firstprint) + if ($firstprint) { $tempFriendlyTime .= ", "; + } $currentDay--; - if ($currentDay != $firstDay) + if ($currentDay != $firstDay) { $tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1]; - else + } else { $tempFriendlyTime .= $dayArray[$firstDay-1]; + } $firstDayFound = false; $firstprint = true; @@ -679,7 +678,7 @@ print($form);