function Process_stat_tab($tab_changed, $profile_changed) { // the default display page - the profile stats $_SESSION['display'] = 'default'; // if it's a new profile, only admin tasks make sense // no refresh if ($_SESSION['profileinfo']['status'] == 'new') { $_SESSION['tablock'] = "A new profile needs to be completed first."; } else { unset($_SESSION['tablock']); } if (isset($_COOKIE['extended_channellist'])) { $_POST['extended_channellist'] = $_COOKIE['extended_channellist']; } $parse_opts = array("extended_channellist" => array("required" => 0, "default" => 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL)); list($form_data, $has_errors) = ParseForm($parse_opts); $_COOKIE['extended_channellist'] = $form_data['extended_channellist']; // just display profile status if ($tab_changed || $profile_changed) { unset($_SESSION['form_data']); return; } // Delete this profile - process confirmed action if (array_key_exists('deleteprofile_x', $_POST)) { $parse_opts = array("switch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 1)); list($form_data, $has_errors) = ParseForm($parse_opts); if ($has_errors > 0) { return; } if ($form_data['switch'] != $_SESSION['profileswitch']) { SetMessage('error', "Profile to delete is not current profile"); return; } // Do the work $cmd_opts['profile'] = $_SESSION['profileswitch']; if (array_key_exists('pid', $_SESSION)) { $cmd_opts['pid'] = $_SESSION['pid']; } $cmd_out = nfsend_query("delete-profile", $cmd_opts, 0); if (is_array($cmd_out)) { SetMessage('info', "Profile '" . $cmd_opts['profile'] . "' deleted"); unset($_SESSION['ProfileList']); $profiles = GetProfiles(); // as current profile no longer exists, switch to 'live' $_SESSION['profile'] = 'live'; $_SESSION['profilegroup'] = '.'; $_SESSION['profileswitch'] = './live'; $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; } // else errors are displayed anyway - nothing to do return; } // Cancel building the profile if (array_key_exists('cancelbuild_x', $_POST)) { $parse_opts = array("switch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 1)); list($form_data, $has_errors) = ParseForm($parse_opts); if ($has_errors > 0) { return; } if ($form_data['switch'] != $_SESSION['profileswitch']) { SetMessage('error', "Profile to delete is not current profile"); return; } // Do the work $cmd_opts['profile'] = $_SESSION['profileswitch']; $cmd_out = nfsend_query("cancel-profile", $cmd_opts, 0); if (is_array($cmd_out)) { SetMessage('info', "Building profile '" . $cmd_opts['profile'] . "' canceled"); $profiles = GetProfiles(); $_SESSION['cancel-inprogress'] = 1; } // else errors are displayed anyway - nothing to do $_SESSION['refresh'] = 5; return; } // put profile into another group? if (array_key_exists('regroup', $_POST)) { if (!array_key_exists('groupselect', $_POST) || !array_key_exists('profilegroup', $_POST)) { SetMessage('error', "Missing parameters"); return; } $_group = Util::htmlentities($_POST['groupselect']); if ($_group == '(nogroup)') { $_group = '.'; } else { if ($_group == 'New group ...') { $_group = Util::htmlentities($_POST['profilegroup']); } } if ($_group != '.' && !preg_match("/^[A-Za-z0-9][A-Za-z0-9\\-+_]+\$/", $_group)) { SetMessage('error', "Illegal characters in group name '{$_group}'"); return; } else { $cmd_opts['profile'] = $_SESSION['profile']; $cmd_opts['profilegroup'] = $_SESSION['profilegroup']; $cmd_opts['newgroup'] = $_group; } if ($cmd_opts['profilegroup'] == $cmd_opts['newgroup']) { // nothing changed return; } // Do the work $cmd_out = nfsend_query("modify-profile", $cmd_opts, 0); if (is_array($cmd_out)) { // update new info in SESSION $_SESSION['profilegroup'] = $cmd_opts['newgroup']; $_SESSION['profileswitch'] = $cmd_opts['newgroup'] . '/' . $_SESSION['profile']; $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; unset($_SESSION['ProfileList']); $profiles = GetProfiles(); } // else errors are displayed anyway - nothing to do return; } // Edit a profile if (array_key_exists('edit', $_POST)) { $cmd_opts = array(); if (array_key_exists('profile_maxsize', $_POST)) { $_tmp = ParseMaxSize($_POST['profile_maxsize']); if (strlen($_tmp) > 0) { $cmd_opts['maxsize'] = $_tmp; } else { SetMessage('warning', "Invalid value for maxsize"); } } if (array_key_exists('profile_expire', $_POST)) { $_tmp = ParseExpire($_POST['profile_expire']); if ($_tmp >= 0) { $cmd_opts['expire'] = $_tmp; } else { SetMessage('warning', "Invalid value for expire"); } } if (array_key_exists('description', $_POST)) { $_tmp = preg_replace("/\r/", '', $_POST['description']); if (!get_magic_quotes_gpc()) { $description = addslashes($_tmp); } else { $description = $_tmp; } $cmd_opts['description'] = explode("\n", $description); } if (array_key_exists('profile_type', $_POST)) { $_tmp = $_POST['profile_type']; if (!is_numeric($_tmp) || $_tmp > 6) { SetMessage('warning', "Invalid value for profile_type"); } else { if ($_SESSION['profileinfo']['type'] != $_tmp) { $cmd_opts['profile_type'] = $_tmp; } } } if (count(array_keys($cmd_opts)) > 0) { $cmd_opts['profile'] = $_SESSION['profileswitch']; // Do the work $cmd_out = nfsend_query("modify-profile", $cmd_opts, 0); if (is_array($cmd_out)) { $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; } } return; } // Cancel an edit or add a channel dialog if (array_key_exists('edit_channel_cancel', $_POST) || array_key_exists('add_channel_cancel', $_POST)) { // nothing to do - default will do return; } // Add a new channel - provide add dialog if (array_key_exists('add_channel_x', $_POST)) { $_POST['add_channel'] = $_POST['add_channel_x']; } if (array_key_exists('add_channel', $_POST)) { $_SESSION['display'] = 'add_channel'; $_SESSION['refresh'] = 0; return; } // edit a channel - provide edit dialog if (array_key_exists('edit_channel', $_POST)) { $parse_opts = array("edit_channel" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9][A-Za-z0-9\\-+_]+\$/", "validate" => NULL)); list($form_data, $has_errors) = ParseForm($parse_opts); $form_data['profileswitch'] = $_SESSION['profileswitch']; if ($has_errors > 0) { return; } $_channel = $form_data['edit_channel']; if (!array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) { SetMessage('error', "Channel '{$_channel}' does not exists in profile '" . $form_data['profile'] . "'"); return; } $_SESSION['form_data'] = $form_data; $_SESSION['refresh'] = 0; $_SESSION['display'] = 'edit_channel'; return; } // edit or add a channel? - process commited form entries if (array_key_exists('edit_channel_commit', $_POST) || array_key_exists('add_channel_commit', $_POST)) { if (array_key_exists('edit_channel_commit', $_POST)) { $_display = "edit_channel"; } else { $_display = "add_channel"; } $_SESSION['refresh'] = 0; $parse_opts = array("name" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9][A-Za-z0-9\\-+_]*\$/", "validate" => NULL), "colour" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^#[0-9a-f]{6}/i", "validate" => NULL), "sign" => array("required" => 1, "default" => '+', "allow_null" => 0, "match" => array('+', '-'), "validate" => NULL), "order" => array("required" => 1, "default" => 1, "allow_null" => 0, "match" => "/^[0-9]{1,2}/", "validate" => NULL), "filter" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'filter_validate'), "configured" => array("required" => 1, "default" => array(), "allow_null" => 0, "match" => NULL, "validate" => 'channel_validate')); list($form_data, $has_errors) = ParseForm($parse_opts); $form_data['profile'] = $_SESSION['profile']; $form_data['profilegroup'] = $_SESSION['profilegroup']; // additional checks if (!is_null($form_data['name'])) { $_channel = $form_data['name']; if ($_display == "edit_channel") { // verify channel in existing profile if (!array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) { SetMessage('error', "Channel '{$_channel}' does not exist in profile '{$profile}'"); $has_errors = 1; } } else { // verify channel name for new channel if (array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) { SetMessage('error', "Channel '{$_channel}' already exist in profile '" . $_SESSION['profile'] . "'"); $has_errors = 1; } } } // else error already reported by ParseForm // must not change the sourcelist or the filter of a channel in profile 'live' if ($form_data['profile'] == 'live') { unset($form_data['sourcelist']); unset($form_data['filter']); } else { $form_data['sourcelist'] = implode('|', $form_data['configured']); } unset($form_data['configured']); $_SESSION['form_data'] = $form_data; if ($has_errors > 0) { $_SESSION['display'] = $_display; return; } // Do the work $command = $_display == 'add_channel' ? 'add-channel' : 'modify-channel'; // make sure parameters match for nfsend $form_data['channel'] = $form_data['name']; unset($form_data['name']); $cmd_out = nfsend_query($command, $form_data, 0); if (is_array($cmd_out)) { $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; unset($_SESSION['form_data']); } else { // fishy something went wrong $_SESSION['display'] = $_display; } return; } // delete a channel if (array_key_exists('delete_channel_commit_x', $_POST)) { if (!array_key_exists('name', $_POST)) { SetMessage('error', "Missing channel name"); return; } $profile = $_SESSION['profile']; $_channelname = $_POST['name']; if (!array_key_exists($_channelname, $_SESSION['profileinfo']['channel'])) { SetMessage('error', "Channel '{$_tmp}' does not exist in profile '{$profile}'"); return; } // do the work $cmd_opts['profile'] = $_SESSION['profileswitch']; $cmd_opts['channel'] = $_channelname; $cmd_out = nfsend_query("delete-channel", $cmd_opts, 0); if (is_array($cmd_out)) { $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; } return; } // Cancel a new profile dialog if (array_key_exists('new_profile_cancel', $_POST)) { if (array_key_exists("new_profile", $_SESSION)) { unset($_SESSION['new_profile']); } // default will do return; } // create a new profile - provide the new profile dialog // this input comes directly from the profile select menu if (array_key_exists('new_profile', $_SESSION)) { unset($_SESSION['new_profile']); $_SESSION['display'] = 'new_profile'; return; } // create a new profile - process commited form if (array_key_exists('new_profile_commit', $_POST)) { $parse_opts = array("newprofileswitch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 0), "tstart" => array("required" => 1, "default" => NULL, "allow_null" => 1, "match" => "/^[0-9]+[0-9\\-]+[0-9]+\$/", "validate" => "date_time_validate"), "tend" => array("required" => 1, "default" => NULL, "allow_null" => 1, "match" => "/^[0-9]+[0-9\\-]+[0-9]+\$/", "validate" => "date_time_validate"), "channel_wizard" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => array('classic', 'individual'), "validate" => NULL), "expire" => array("required" => 0, "default" => 0, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'expire_validate'), "maxsize" => array("required" => 0, "default" => 0, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'maxsize_validate'), "description" => array("required" => 0, "default" => NULL, "allow_null" => 1, "match" => "/^[\\s!-~]+\$/", "validate" => 'description_validate'), "filter" => array("required" => 0, "default" => NULL, "allow_null" => 1, "match" => "/^[\\s!-~]+\$/", "validate" => 'filter_validate'), "channel" => array("required" => 0, "default" => array(), "allow_null" => 1, "match" => NULL, "validate" => 'channel_validate'), "shadow" => array("required" => 1, "default" => 1, "allow_null" => 1, "match" => array(0, 1), "validate" => NULL), "num_channels" => array("required" => 0, "default" => 0, "allow_null" => 1, "match" => "/^[0-9]{1,3}\$/", "validate" => NULL)); list($form_data, $has_errors) = ParseForm($parse_opts); if (preg_match("/^(.+)\\/(.+)/", $form_data['newprofileswitch'], $matches)) { $_profilegroup = $matches[1]; $_profilename = $matches[2]; $form_data['profileswitch'] = $form_data['newprofileswitch']; $form_data['profile'] = $_profilename; $form_data['profilegroup'] = $_profilegroup; unset($form_data['newprofileswitch']); } else { $has_errors = 1; } // additional checks if (!is_null($form_data['tend']) && !is_null($form_data['tstart']) && $form_data['tend'] < $form_data['tstart']) { $ts = UNIX2DISPLAY($form_data['tstart']); $te = UNIX2DISPLAY($form_data['tend']); $form_data['tstart'] = NULL; $form_data['tend'] = NULL; SetMessage('error', "Profile end time '{$te}' earlier then Start time '{$ts}'"); $has_errors = 1; } if (!is_null($form_data['tend']) && is_null($form_data['tstart'])) { $te = UNIX2DISPLAY($form_data['tend']); SetMessage('error', "Profile has end time '{$te}', but no start time set"); $has_errors = 1; } if ($form_data['channel_wizard'] == 'classic') { if (is_null($form_data['filter']) || count($form_data['channel']) == 0) { SetMessage('error', "A classic profile needs a valid filter and at least one selected channel"); $has_errors = 1; } } if ($has_errors > 0) { $_SESSION['form_data'] = $form_data; $_SESSION['display'] = 'new_profile'; $_SESSION['refresh'] = 0; return; } // do the work if (array_key_exists('channel_wizard', $form_data)) { $type = $form_data['channel_wizard']; if (NewProfileCreate($form_data, $type) == TRUE) { // update NfSen to include the new profile unset($_SESSION['ProfileList']); $profiles = GetProfiles(); // switch to new profile $_SESSION['profileswitch'] = $form_data['profileswitch']; $_SESSION['profile'] = $form_data['profile']; $_SESSION['profilegroup'] = $form_data['profilegroup']; $_SESSION['profileinfo'] = ReadProfile($_SESSION['profileswitch']); SetMessage('info', "Profile '" . $form_data['profile'] . "' created"); // if ( $_SESSION['profileinfo']['type'] == 1 && $_SESSION['profileinfo']['status'] != 'new' ) if ($_SESSION['profileinfo']['tstart'] < $_SESSION['profileinfo']['tend']) { $_SESSION['refresh'] = 5; } } else { $_SESSION['form_data'] = $form_data; $_SESSION['display'] = 'new_profile'; } } return; } if (array_key_exists('commit_profile_x', $_POST)) { if ($_SESSION['profileinfo']['status'] != 'new' && $_SESSION['profileinfo']['status'] != 'stalled') { SetMessage('error', "Can not commit a profile, not in status 'new or stalled'"); return; } // Do the work // if it fails, the default will do if (NewProfileCommit($_SESSION['profileswitch'])) { $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; unset($_SESSION['tablock']); if ($_SESSION['profileinfo']['tstart'] < $_SESSION['profileinfo']['tend']) { $_SESSION['refresh'] = 5; } } return; } // refresh time if profile building in progress if (preg_match("/built/", $_SESSION['profileinfo']['status'])) { $_SESSION['refresh'] = 5; } }
function expire_validate(&$expire, $opts) { $str = ParseExpire($expire); if (!is_null($str)) { $expire = $str; return 0; } else { SetMessage('error', "Invalid expire time: '{$expire}'"); return 1; } }