// 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 BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. include_once 'db.inc.php'; include_once 'swreg/swreg.inc.php'; require_once 'Log.php'; require_once 'functions.php'; $logger = Log::singleton('file', LOGFILE, TOOL_NAME . ' : Port Profile Preview'); if ($logger === false) { die("Failed to open logfile.\n"); } $mask = Log::MAX(LOG_LEVEL); $logger->setMask($mask); $base = get_base($_SERVER['SCRIPT_NAME']); $pname = $_REQUEST['pname']; $pid = $_REQUEST['pid']; if (!isset($pname) || !isset($pid) || $pname == '') { echo "You must specify a name and a PID\n"; exit(1); } $vlans = $_REQUEST['vlan']; $start_ports = $_REQUEST['start_port']; $end_ports = $_REQUEST['end_port']; $profile = ''; $errors = array(); $seen_sports = array(); $seen_eports = array(); $max_port = 0; for ($i = 0; $i < count($start_ports); ++$i) { $vlan = $vlans[$i]; $start_port = $start_ports[$i]; $end_port = $end_ports[$i]; $row = $i + 1; if ($vlan == '__BOGUS__') { continue; } if ($start_port == '__BOGUS__' || $end_port == '__BOGUS__') { array_push($errors, "You must select a starting and ending port at row $row"); continue; } if ($pid != '__ANY__') { preg_match("/\/(\d+)$/", $start_port, $sm); if ($sm[1] > $end_port) { array_push($errors, "Starting port must be less than equal to the ending port at row $row"); continue; } } elseif ($vlan == 'DYNAMIC') { array_push($errors, "In order to make ports dynamic, you must choose an explicit PID at row $row"); continue; } if (isset($seen_sports[$start_port])) { array_push($errors, "Starting port $start_port was already used at row {$seen_sports[$start_port]}"); continue; } $seen_sports[$start_port] = $row; if (isset($seen_eports[$end_port])) { array_push($errors, "Ending port $end_port was already used at row {$seen_eports[$end_port]}"); continue; } $seen_eports[$end_port] = $row; $profile .= generate_port_profile($start_port, $end_port, $vlan, $pid); $profile .= "!\n"; if ($pid != '__ANY__' && $end_port > $max_port) { $max_port = $end_port; } } if ($profile == '') { array_push($errors, 'No profile ranges specified'); } if (!preg_match("/^[\w\d\-_]+$/", $pname)) { array_push($errors, 'Profile name can only contain letters, numbers, hyphens, and underscores'); } if ($pid != '__ANY__') { $ports = 8; foreach ($PID_PORTS as $pp => $np) { if ($pid == $pp) { $ports = $np; break; } } if ($max_port != $ports) { array_push($errors, 'All ports must be specified for a port profile'); } } $profile = preg_replace('/"/', '\\"', $profile); $profile = preg_replace("/\r\n/", '\\n', $profile); $profile = preg_replace("/\n/", '\\\\n', $profile); ?> Port Profile Preview :: <?= $pname ?>
0) { foreach ($errors as $error) { ?>