. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* pfSense_MODULE: schedules */ ##|+PRIV ##|*IDENT=page-firewall-schedules-edit ##|*NAME=Firewall: Schedules: Edit page ##|*DESCR=Allow access to the 'Firewall: Schedules: Edit' page. ##|*MATCH=firewall_schedule_edit.php* ##|-PRIV function schedulecmp($a, $b) { return strcmp($a['name'], $b['name']); } function schedule_sort() { global $g, $config; if (!is_array($config['schedules']['schedule'])) { return; } usort($config['schedules']['schedule'], "schedulecmp"); } require("guiconfig.inc"); require_once("functions.inc"); require_once("filter.inc"); require_once("shaper.inc"); $pgtitle = array(gettext("Firewall"), gettext("Schedules"), gettext("Edit")); $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_schedule.php'); $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'])) { $config['schedules']['schedule'] = array(); } $a_schedules = &$config['schedules']['schedule']; if (is_numericint($_GET['id'])) { $id = $_GET['id']; } if (isset($_POST['id']) && is_numericint($_POST['id'])) { $id = $_POST['id']; } if (isset($id) && $a_schedules[$id]) { $pconfig['name'] = $a_schedules[$id]['name']; $pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']); $pconfig['timerange'] = $a_schedules[$id]['timerange']; $pconfig['schedlabel'] = $a_schedules[$id]['schedlabel']; $getSchedule = true; } if ($_POST) { if (strtolower($_POST['name']) == "lan") { $input_errors[] = gettext("Schedule may not be named LAN."); } if (strtolower($_POST['name']) == "wan") { $input_errors[] = gettext("Schedule may not be named WAN."); } 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) { $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)) { continue; } if ($schedule['name'] == $_POST['name']) { $input_errors[] = gettext("A Schedule with this name already exists."); break; } } $schedule = array(); $schedule['name'] = $_POST['name']; $schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8'); $timerangeFound = false; for ($x = 0; $x < 99; $x++) { if ($_POST['schedule' . $x]) { if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['starttime' . $x])) { $input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $_POST['starttime' . $x]); continue; } if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['stoptime' . $x])) { $input_errors[] = sprintf(gettext("Invalid stop time - '%s'"), $_POST['stoptime' . $x]); continue; } $timerangeFound = true; $timeparts = array(); $firstprint = false; $timestr = $_POST['schedule' . $x]; $timehourstr = $_POST['starttime' . $x]; $timehourstr .= "-"; $timehourstr .= $_POST['stoptime' . $x]; $timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8'); $dashpos = strpos($timestr, '-'); if ($dashpos === false) { $timeparts['position'] = $timestr; } else { $tempindarray = array(); $monthstr = ""; $daystr = ""; $tempindarray = explode(",", $timestr); foreach ($tempindarray as $currentselection) { if ($currentselection) { if ($firstprint) { $monthstr .= ","; $daystr .= ","; } $tempstr = ""; $monthpos = strpos($currentselection, "m"); $daypos = strpos($currentselection, "d"); $monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1); $daystr .= substr($currentselection, $daypos+1); $firstprint = true; } } $timeparts['month'] = $monthstr; $timeparts['day'] = $daystr; } $timeparts['hour'] = $timehourstr; $timeparts['rangedescr'] = $timedescrstr; $schedule['timerange'][$x] = $timeparts; } } if (!$timerangeFound) { $input_errors[] = gettext("The schedule must have at least one time range configured."); } if (!$input_errors) { if (!empty($pconfig['schedlabel'])) { $schedule['schedlabel'] = $pconfig['schedlabel']; } else { $schedule['schedlabel'] = uniqid(); } if (isset($id) && $a_schedules[$id]) { $a_schedules[$id] = $schedule; } else { $a_schedules[] = $schedule; } schedule_sort(); if (write_config()) { filter_configure(); } header("Location: firewall_schedule.php"); exit; } else { //we received input errors, copy data to prevent retype if (!$_POST['schedule0']) { $getSchedule = false; } else { $getSchedule = true; } $pconfig['name'] = $schedule['name']; $pconfig['descr'] = $schedule['descr']; $pconfig['timerange'] = $schedule['timerange']; } } include("head.inc"); /* put your custom HTML head content here */ /* using some of the $pfSenseHead function calls */ $jscriptstr = << // stoptimehour) { errors = "Error: Start Hour cannot be greater than Stop Hour."; passedValidiation = false; } else if (starttimehour == stoptimehour) { if (starttimemin > stoptimemin) { errors = "Error: Start Minute cannot be greater than Stop Minute."; passedValidiation = false; } } if (passedValidiation) { addTimeRange(); } else { if (errors != "") { alert(errors); } } } function addTimeRange() { var tempdayarray = daysSelected.split(","); var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = ""; var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = ""; rtempFriendlyTime = ""; nrtempFriendlyTime = ""; nrtempID = ""; rtempID = ""; nrtempTime = ""; rtempTime = ""; tempdayarray.sort(); rtempFriendlyDay = ""; monthstr = ""; daystr = ""; //check for existing entries var findCurrentCounter; for (u = 0; u < 99; u++) { findCurrentCounter = document.getElementById("schedule" + u); if (!findCurrentCounter) { schCounter = u; break; } } if (daysSelected != "") { //get days selected for (i = 0; i < tempdayarray.length; i++) { tempstr = tempdayarray[i]; if (tempstr != "") { tempstrdaypos = tempstr.search("p"); week = tempstr.substring(1, tempstrdaypos); week = parseInt(week); dashpos = tempstr.search("-"); if (dashpos != "-1") { var nonrepeatingfound = true; daypos = tempstr.substring(tempstrdaypos+1, dashpos); daypos = parseInt(daypos); monthpos = tempstr.search("m"); tempstrdaypos = tempstr.search("d"); month = tempstr.substring(monthpos+1, tempstrdaypos); month = parseInt(month); day = tempstr.substring(tempstrdaypos+1); day = parseInt(day); monthstr += month + ","; daystr += day + ","; nrtempID += tempstr + ","; } else { var repeatingfound = true; daypos = tempstr.substr(tempstrdaypos+1); daypos = parseInt(daypos); rtempFriendlyDay += daypos + ","; rtempID += daypos + ","; } } } //code below spits out friendly look format for nonrepeating schedules var foundEnd = false; var firstDayFound = false; var firstprint = false; var tempFriendlyMonthArray = monthstr.split(","); var tempFriendlyDayArray = daystr.split(","); var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = ""; for (k = 0; k < tempFriendlyMonthArray.length; k++) { tempstr = tempFriendlyMonthArray[k]; if (tempstr != "") { if (!firstDayFound) { firstDay = tempFriendlyDayArray[k]; firstDay = parseInt(firstDay); firstMonth = tempFriendlyMonthArray[k]; firstMonth = parseInt(firstMonth); firstDayFound = true; } currentDay = tempFriendlyDayArray[k]; currentDay = parseInt(currentDay); //get next day nextDay = tempFriendlyDayArray[k+1]; nextDay = parseInt(nextDay); //get next month currentDay++; if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])) { if (firstprint) { nrtempFriendlyTime += ", "; } currentDay--; if (currentDay != firstDay) { nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay; } else { nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay; } firstDayFound = false; firstprint = true; } } } //code below spits out friendly look format for repeating schedules foundEnd = false; firstDayFound = false; firstprint = false; tempFriendlyDayArray = rtempFriendlyDay.split(","); tempFriendlyDayArray.sort(); currentDay, firstDay, nextDay = ""; for (k = 0; k < tempFriendlyDayArray.length; k++) { tempstr = tempFriendlyDayArray[k]; if (tempstr != "") { if (!firstDayFound) { firstDay = tempFriendlyDayArray[k]; firstDay = parseInt(firstDay); firstDayFound = true; } currentDay = tempFriendlyDayArray[k]; currentDay = parseInt(currentDay); //get next day nextDay = tempFriendlyDayArray[k+1]; nextDay = parseInt(nextDay); currentDay++; if (currentDay != nextDay) { if (firstprint) { rtempFriendlyTime += ", "; } currentDay--; if (currentDay != firstDay) { rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1]; } else { rtempFriendlyTime += day_array[firstDay-1]; } firstDayFound = false; firstprint = true; } } } //sort the tempID var tempsortArray = rtempID.split(","); var isFirstdone = false; tempsortArray.sort(); //clear tempID rtempID = ""; for (t = 0; t < tempsortArray.length; t++) { if (tempsortArray[t] != "") { if (!isFirstdone) { rtempID += tempsortArray[t]; isFirstdone = true; } else { rtempID += "," + tempsortArray[t]; } } } //get time specified starttimehour = document.getElementById("starttimehour").value starttimemin = document.getElementById("starttimemin").value; stoptimehour = document.getElementById("stoptimehour").value; stoptimemin = document.getElementById("stoptimemin").value; timeRange = "||" + starttimehour + ":"; timeRange += starttimemin + "-"; timeRange += stoptimehour + ":"; timeRange += stoptimemin; //get description for time range var tempdescr = document.getElementById("timerangedescr").value if (nonrepeatingfound) { nrtempTime += nrtempID; //add time ranges nrtempTime += timeRange; //add description nrtempTime += "||" + tempdescr; insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID); } if (repeatingfound) { rtempTime += rtempID; //add time ranges rtempTime += timeRange; //add description rtempTime += "||" + tempdescr; insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID); } } else { //no days were selected, alert user alert ("You must select at least 1 day before adding time"); } } function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID) { //add it to the schedule list d = document; tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0); tr = d.createElement("tr"); td = d.createElement("td"); td.innerHTML= "" + tempFriendlyTime + "<\/span>"; tr.appendChild(td); td = d.createElement("td"); td.innerHTML=""; tr.appendChild(td); td = d.createElement("td"); td.innerHTML=""; tr.appendChild(td); td = d.createElement("td"); td.innerHTML=""; tr.appendChild(td); td = d.createElement("td"); td.innerHTML = "edit"; tr.appendChild(td); td = d.createElement("td"); td.innerHTML = "remove"; tr.appendChild(td); td = d.createElement("td"); td.innerHTML=""; tr.appendChild(td); tbody.appendChild(tr); schCounter++; //reset calendar and time and descr clearCalendar(); clearTime(); clearDescr(); } function clearCalendar() { var tempstr, daycell = ""; //clear days selected daysSelected = ""; //loop through all 52 weeks for (j=1; j<=53; j++) { //loop through all 7 days for (k=1; k<8; k++) { tempstr = 'w' + j + 'p' + k; daycell = eval('document.getElementById(tempstr)'); if (daycell != null) { daycell.style.backgroundColor = "#FFFFFF"; // white } } } } function clearTime() { document.getElementById("starttimehour").value = "0"; document.getElementById("starttimemin").value = "00"; document.getElementById("stoptimehour").value = "23"; document.getElementById("stoptimemin").value = "59"; } function clearDescr() { document.getElementById("timerangedescr").value = ""; } function editRow(incTime, el) { var check = checkForRanges(); if (check) { //reset calendar and time clearCalendar(); clearTime(); var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = ""; tempArray = incTime.split ("||"); days = tempArray[0]; hours = tempArray[1]; descr = tempArray[2]; var tempdayArray = days.split(","); var temphourArray = hours.split("-"); tempstr = temphourArray[0]; var temphourArray2 = tempstr.split(":"); document.getElementById("starttimehour").value = temphourArray2[0]; document.getElementById("starttimemin").value = temphourArray2[1]; tempstr = temphourArray[1]; temphourArray2 = tempstr.split(":"); document.getElementById("stoptimehour").value = temphourArray2[0]; document.getElementById("stoptimemin").value = temphourArray2[1]; document.getElementById("timerangedescr").value = descr; //toggle the appropriate days for (i = 0; i < tempdayArray.length; i++) { if (tempdayArray[i]) { var tempweekstr = tempdayArray[i]; dashpos = tempweekstr.search("-"); if (dashpos == "-1") { tempstr = "w2p" + tempdayArray[i]; } else { tempstr = tempdayArray[i]; } daytoggle(tempstr); } } removeRownoprompt(el); } } function removeRownoprompt(el) { var cel; while (el && el.nodeName.toLowerCase() != "tr") { el = el.parentNode; } if (el && el.parentNode) { cel = el.getElementsByTagName("td").item(0); el.parentNode.removeChild(el); } } function removeRow(el) { var check = confirm ("Do you really want to delete this time range?"); if (check) { var cel; while (el && el.nodeName.toLowerCase() != "tr") { el = el.parentNode; } if (el && el.parentNode) { cel = el.getElementsByTagName("td").item(0); el.parentNode.removeChild(el); } } } //]]> EOD; ?> ">





" style=" position:relative; display:"> "; } if ($firstdayofmonth == $positioncounter) { ?> "; } if ($positioncounter == 7 || $daycounter > $numberofdays) { $positioncounter = 1; echo ""; } else { $positioncounter++; } } //end while loop ?>
"; } elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays) { ?> "; } else { echo "

           


  " class="formbtn" onclick="javascript:processEntries();" />    " class="formbtn" onclick="javascript:clearCalendar(); clearTime(); clearDescr();" />
/images/icons/icon_e.gif' alt='edit' /> /images/icons/icon_x.gif' alt='remove' />
  " /> " onclick="window.location.href=''" />