function DisplayAdminPage() { // include all required javascript for this page ?> <script language="Javascript" src="js/profileadmin.js" type="text/javascript"> </script> <?php switch ($_SESSION['display']) { case "add_channel": $num_pos = 0; $num_neg = 0; foreach ($_SESSION['profileinfo']['channel'] as $_chan) { if ($_chan['sign'] == '+') { $num_pos++; } if ($_chan['sign'] == '-') { $num_neg++; } } $liveprofile = ReadProfile('./live'); $is_live_profile = 0; $is_new_channel = 1; // setup channel defaults if (array_key_exists('form_data', $_SESSION)) { // add channel contained errors - interate ones more $channel_defaults = $_SESSION['form_data']; unset($_SESSION['form_data']); if ($channel_defaults['sign'] == '+') { $num_pos++; } else { if ($channel_defaults['sign'] == '-') { $num_neg++; } } } else { // initial dialog $channel_defaults = array(); $channel_defaults['name'] = ''; $channel_defaults['sign'] = '+'; $num_pos++; $channel_defaults['colour'] = '#abcdef'; $channel_defaults['order'] = $num_pos; $channel_defaults['sourcelist'] = NULL; } EditChannel($is_live_profile, $is_new_channel, $channel_defaults, $liveprofile, $num_pos, $num_neg); break; case 'edit_channel': $channelinfo = $_SESSION['form_data']; $profileswitch = $channelinfo['profileswitch']; $num_pos = 0; $num_neg = 0; foreach ($_SESSION['profileinfo']['channel'] as $_chan) { if ($_chan['sign'] == '+') { $num_pos++; } if ($_chan['sign'] == '-') { $num_neg++; } } $liveprofile = ReadProfile('./live'); $is_live_profile = $profileswitch == './live'; $is_new_channel = 0; // if edit icon was clicked, load channel data if (array_key_exists('edit_channel', $channelinfo)) { $channel = $channelinfo['edit_channel']; $channelinfo = $_SESSION['profileinfo']['channel'][$channel]; $_opts['profile'] = $profileswitch; $_opts['channel'] = $channel; $_filter = nfsend_query("get-channelfilter", $_opts, 0); if (!is_array($_filter)) { $channelinfo['filter'] = array('Unable to get channel filter'); } $channelinfo['filter'] = $_filter['filter']; } EditChannel($is_live_profile, $is_new_channel, $channelinfo, $liveprofile, $num_pos, $num_neg); unset($_SESSION['form_data']); break; case "new_profile": if (array_key_exists('form_data', $_SESSION)) { $form_data = $_SESSION['form_data']; unset($_SESSION['form_data']); } else { $form_data = array(); $form_data['profile'] = NULL; $form_data['profilegroup'] = NULL; $form_data['tstart'] = NULL; $form_data['tend'] = NULL; $form_data['channel_wizard'] = 'classic'; $form_data['expire'] = '1440'; $form_data['maxsize'] = '10G'; $form_data['shadow'] = 0; $form_data['description'] = NULL; $form_data['filter'] = NULL; $form_data['channel'] = NULL; $form_data['num_channels'] = 1; } NewProfileDialog($form_data); break; case 'default': default: ProfileDialog(); } unset($_SESSION['display']); /* print "<pre>"; print_r($_SESSION); print_r($_POST); print "</pre>"; */ }
function ParseInput() { global $TabList; global $BookmarkVars; global $GraphTabs; global $Refresh; // Preset refresh value. Any Input pasring routing may reset refresh to 0, to disable refresh $_SESSION['refresh'] = $Refresh; /* * user input may come from forms or links (POST or GET data) due to normal * form processing. If a bookmark is specified in the URL, this overwrites other * input data. To simplify data input checks, the bookmark is handled as any other post request */ ReportLog("ParseInput:"); if (isset($_GET['bookmark'])) { // process bookmarkstring $_bookmark = Util::htmlentities(base64_decode(urldecode($_GET['bookmark']))); ReportLog("Bookmark: '{$_bookmark}'"); $_vars = explode('|', $_bookmark); if (count($BookmarkVars) == count($_vars)) { for ($i = 0; $i < count($BookmarkVars); $i++) { if ($_vars[$i] != '-') { $_varpath = explode('/', $BookmarkVars[$i]); $_varname = count($_varpath) == 2 ? $_varpath[1] : $_varpath[0]; ReportLog("Bookmark: Set {$_varname}"); $_POST[$_varname] = $_vars[$i]; } } } else { SetMessage('warning', "Bookmark processing error"); } } // process tab if (!array_key_exists('tab', $_SESSION)) { // first time in this session // initialize some more vars in the SESSION var InitSession(count($BookmarkVars)); } else { $_tab = $_SESSION['tab']; } // click on tab list if (array_key_exists('tab', $_GET)) { $_tab = $_GET['tab']; } // tab from bookmark overwrites other entries if (array_key_exists('tab', $_POST)) { $_tab = $_POST['tab']; } $tab_changed = 0; if ($_tab != $_SESSION['tab'] || $_SESSION['tab'] == NULL) { // _tab changed since last cycle if (array_key_exists('tablock', $_SESSION)) { // must not change tab right now SetMessage('error', $_SESSION['tablock']); } else { // Verify new tab if (!is_numeric($_tab) || ($_tab > count($TabList) || $_tab < 0)) { SetMessage('warning', "Requested Tab not available. Set default tab to " . $TabList[0]); $_tab = 0; } $_tab = (int) $_tab; $_SESSION['tab'] = $_tab; if (!isset($_GET['bookmark'])) { $tab_changed = 1; } ReportLog("Tab: Set tab to {$_tab}: " . $TabList[$_tab]); } } // rebuild profile list if ($tab_changed && $_SESSION['tab'] == 4) { unset($_SESSION['ProfileList']); unset($_SESSION['PluginList']); $profiles = GetProfiles(); GetPlugins(); } // process sub tab $_tab = -1; if (array_key_exists('sub_tab', $_GET)) { $_tab = strip_tags($_GET['sub_tab']); } if (array_key_exists('sub_tab', $_POST)) { $_tab = strip_tags($_POST['sub_tab']); } if ($_tab >= 0) { if (!is_numeric($_tab) || $_tab < 0) { $_tab = 0; } $_SESSION['sub_tab'] = $_tab; ReportLog("Subtab: Set tab to {$_tab}: " . $GraphTabs[$_tab]); } // process profileswitch if (!array_key_exists('profileswitch', $_SESSION)) { // this is fishy - InitSession should have set this SetMessage('error', "Missing session parameter 'profileswitch'"); $_SESSION['refresh'] = 0; return array(FALSE, 0, 0); } else { $_profileswitch = $_SESSION['profileswitch']; } if (array_key_exists('profileswitch', $_POST)) { $_profileswitch = Util::htmlentities($_POST['profileswitch']); } // the alerting module only accepts profile live for now if ($_SESSION['tab'] == 3) { $_profileswitch = './live'; } $profile_changed = 0; if ($_profileswitch != $_SESSION['profileswitch']) { if ($_profileswitch == "New Profile ...") { // make sure the profile admin page gets this request; $_SESSION['tab'] = 4; $_SESSION['new_profile'] = TRUE; $_SESSION['refresh'] = 0; } else { // process new profileswitch if (preg_match("/^(.+)\\/(.+)/", $_profileswitch, $matches)) { $_profilegroup = $matches[1]; $_profilename = $matches[2]; // Check if profilegroup/profilename exists $_found = FALSE; foreach ($_SESSION['ProfileList'] as $p) { if ($p == $_profileswitch) { $_found = TRUE; } } if (!$_found) { SetMessage('error', "Profile '{$_profilename}' does not exists in profile group '{$_profilegroup}'"); SetMessage('warning', "Fall back to profile live"); $_profilegroup = '.'; $_profilename = 'live'; } } else { SetMessage('error', "Can not parse profileswitch"); SetMessage('warning', "Fall back to profile live"); $_profilegroup = '.'; $_profilename = 'live'; } $profile_changed = 1; $_SESSION['profile'] = $_profilename; $_SESSION['profilegroup'] = $_profilegroup; $_SESSION['profileswitch'] = $_profileswitch; } } $profileinfo = ReadProfile($_SESSION['profileswitch']); if ($profileinfo == FALSE) { SetMessage('warning', "Fall back to profile live"); unset($_SESSION['ProfileList']); $profiles = GetProfiles(); $_SESSION['profileswitch'] = './live'; $_SESSION['profile'] = 'live'; $_SESSION['profilegroup'] = '.'; $profileinfo = ReadProfile('./live'); if ($profileinfo == FALSE) { // double failure SetMessage('error', "Can't read profile 'live'"); $_SESSION['refresh'] = 0; return array(FALSE, 0, 0); } } if ($profileinfo['status'] == 'new') { $_SESSION['tab'] = 4; $_SESSION['refresh'] = 0; $_SESSION['tablock'] = "A new profile needs to be completed first."; } else { unset($_SESSION['tablock']); } $_SESSION['profileinfo'] = $profileinfo; // no refresh for history profiles if (($profileinfo['type'] & 3) == 1) { $_SESSION['refresh'] = 0; } return array(TRUE, $tab_changed, $profile_changed); }