From: <jo...@us...> - 2003-11-24 04:05:40
|
Update of /cvsroot/phpicalendar/phpicalendar/functions In directory sc8-pr-cvs1:/tmp/cvs-serv30895/functions Modified Files: calendar_functions.php init.inc.php list_icals.php Log Message: Added HTTP authentication support. Modifications to non-HTTP authentication login so that the two are mutually exclusive. Moved calendar <option> listing into calendar_functions.php so it can be shared by the navigation (via list_icals.php) and also by the preferences.php file. Fixed typo of $show_login to $allow_login. Added E_ERROR to the debug error level, so fatal errors are logged. Index: calendar_functions.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/functions/calendar_functions.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** calendar_functions.php 22 Nov 2003 21:16:10 -0000 1.1 --- calendar_functions.php 24 Nov 2003 04:05:37 -0000 1.2 *************** *** 15,23 **** function availableCalendars($username, $password, $cal_filename, $admin = false) { // Import globals. ! global $calendar_path, $blacklisted_cals, $list_webcals, $locked_cals, $locked_map, $error_path_lang, $error_restrictedcal_lang, $ALL_CALENDARS_COMBINED; // Create the list of available calendars. $calendars = array(); // Grab the list of unlocked calendars. $unlocked_cals = array(); --- 15,29 ---- function availableCalendars($username, $password, $cal_filename, $admin = false) { // Import globals. ! global $calendar_path, $blacklisted_cals, $list_webcals, $locked_cals, $locked_map, $apache_map, $error_path_lang, $error_restrictedcal_lang, $error_invalidcal_lang, $ALL_CALENDARS_COMBINED, $_SERVER; // Create the list of available calendars. $calendars = array(); + // Grab any HTTP authentication. + unset($http_user); + if (isset($_SERVER['PHP_AUTH_USER'])) { + $http_user = $_SERVER['PHP_AUTH_USER']; + } + // Grab the list of unlocked calendars. $unlocked_cals = array(); *************** *** 38,44 **** $cal_name = substr($file, 0, -4); if (in_array($cal_name, $blacklisted_cals)) continue; ! // Exclude locked calendars. ! if (!$admin && in_array($cal_name, $locked_cals) && !in_array($cal_name, $unlocked_cals)) --- 44,56 ---- $cal_name = substr($file, 0, -4); if (in_array($cal_name, $blacklisted_cals)) continue; + + // If HTTP authenticated, make sure this calendar is available + // to the user. + if (isset($http_user)) { + if (!in_array($cal_name, $apache_map[$http_user])) continue; + } ! // Otherwise exclude locked calendars. ! else if (!$admin && in_array($cal_name, $locked_cals) && !in_array($cal_name, $unlocked_cals)) *************** *** 52,56 **** // Add web calendars. ! if (!$admin) { foreach ($list_webcals as $file) { // Make sure the URL ends with .ics. --- 64,68 ---- // Add web calendars. ! if (!isset($http_user) && !$admin) { foreach ($list_webcals as $file) { // Make sure the URL ends with .ics. *************** *** 70,76 **** if (in_array($cal_filename, $blacklisted_cals)) exit(error($error_restrictedcal_lang, $cal_filename)); ! // Make sure this calendar is not locked. ! if (in_array($cal_filename, $locked_cals) && !in_array($cal_filename, $unlocked_cals)) { --- 82,98 ---- if (in_array($cal_filename, $blacklisted_cals)) exit(error($error_restrictedcal_lang, $cal_filename)); + + // If HTTP authenticated, make sure this calendar is available + // to the user. + if (isset($http_user)) { + if (!in_array($cal_filename, $apache_map[$http_user])) { + // Use the invalid calendar message so that the user is + // not made aware of locked calendars. + exit(error($error_invalidcal_lang, $cal_filename)); + } + } ! // Otherwise make sure this calendar is not locked. ! else if (in_array($cal_filename, $locked_cals) && !in_array($cal_filename, $unlocked_cals)) { *************** *** 112,113 **** --- 134,194 ---- return $calendars; } + + // This function prints out the calendars available to the user, for + // selection. Should be enclosed within a <select>...</select>, which + // is not printed out by this function. + // + // $cals = The calendars (entire path, e.g. from availableCalendars). + function display_ical_list($cals) { + global $cal, $ALL_CALENDARS_COMBINED, $current_view, $getdate, $calendar_lang, $all_cal_comb_lang; + + // Print each calendar option. + foreach ($cals as $cal_tmp) { + // Format the calendar path for display. + // + // Only display the calendar name, replace all instances of "32" with " ", + // and remove the .ics suffix. + $cal_displayname_tmp = basename($cal_tmp); + $cal_displayname_tmp = str_replace("32", " ", $cal_displayname_tmp); + $cal_displayname_tmp = substr($cal_displayname_tmp, 0, -4); + + // If this is a webcal, add 'Webcal' to the display name. + if (preg_match("/^(https?|webcal):\/\//i", $cal_tmp)) { + $cal_displayname_tmp .= " Webcal"; + } + + // Otherwise, remove all the path information, since that should + // not be used to identify local calendars. Also add the calendar + // label to the display name. + else { + // Strip path and .ics suffix. + $cal_tmp = basename($cal_tmp); + $cal_tmp = substr($cal_tmp, 0, -4); + + // Add calendar label. + $cal_displayname_tmp .= " $calendar_lang"; + } + + // Encode the calendar path. + $cal_encoded_tmp = urlencode($cal_tmp); + + // Display the option. + // + // The submitted calendar will be encoded, and always use http:// + // if it is a webcal. So that is how we perform the comparison when + // trying to figure out if this is the selected calendar. + $cal_httpPrefix_tmp = str_replace('webcal://', 'http://', $cal_tmp); + if ($cal_httpPrefix_tmp == urldecode($cal)) { + print "<option value=\"$current_view.php?cal=$cal_encoded_tmp&getdate=$getdate\" selected>$cal_displayname_tmp</option>"; + } else { + print "<option value=\"$current_view.php?cal=$cal_encoded_tmp&getdate=$getdate\">$cal_displayname_tmp</option>"; + } + } + + // option to open all (non-web) calenders together + if ($cal == $ALL_CALENDARS_COMBINED) { + print "<option value=\"$current_view.php?cal=$ALL_CALENDARS_COMBINED&getdate=$getdate\" selected>$all_cal_comb_lang</option>"; + } else { + print "<option value=\"$current_view.php?cal=$ALL_CALENDARS_COMBINED&getdate=$getdate\">$all_cal_comb_lang</option>"; + } + } \ No newline at end of file Index: init.inc.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/functions/init.inc.php,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** init.inc.php 24 Nov 2003 02:17:58 -0000 1.47 --- init.inc.php 24 Nov 2003 04:05:37 -0000 1.48 *************** *** 7,13 **** // uncomment when developing, comment for shipping version ! error_reporting (E_WARNING); $ALL_CALENDARS_COMBINED = 'all_calendars_combined971'; if (!defined('BASE')) define('BASE', './'); include(BASE.'config.inc.php'); --- 7,21 ---- // uncomment when developing, comment for shipping version ! error_reporting (E_ERROR | E_WARNING); ! ! // Older versions of PHP do not define $_SERVER. Define it here instead. ! if (!isset($_SERVER) && isset($HTTP_SERVER_VARS)) { ! $_SERVER = &$HTTP_SERVER_VARS; ! } + // Define some magic strings. $ALL_CALENDARS_COMBINED = 'all_calendars_combined971'; + + // Pull in the configuration and some functions. if (!defined('BASE')) define('BASE', './'); include(BASE.'config.inc.php'); *************** *** 24,54 **** } if ($cookie_uri == '') { $cookie_uri = $HTTP_SERVER_VARS['SERVER_NAME'].substr($HTTP_SERVER_VARS['PHP_SELF'],0,strpos($HTTP_SERVER_VARS['PHP_SELF'], '/')); } ! // Look for a login cookie. ! unset($username, $password); ! if (isset($HTTP_COOKIE_VARS['phpicalendar_login'])) { ! $login_cookie = unserialize(stripslashes($HTTP_COOKIE_VARS['phpicalendar_login'])); ! if (isset($login_cookie['username'])) $username = $login_cookie['username']; ! if (isset($login_cookie['password'])) $password = $login_cookie['password']; ! } ! ! // Look for a new username and password. ! if (isset($HTTP_GET_VARS['username'])) $username = $HTTP_GET_VARS['username']; ! else if (isset($HTTP_POST_VARS['username'])) $username = $HTTP_POST_VARS['username']; ! if (isset($HTTP_GET_VARS['password'])) $password = $HTTP_GET_VARS['password']; ! else if (isset($HTTP_POST_VARS['password'])) $password = $HTTP_POST_VARS['password']; ! // Set the login cookie if logging in. Clear it if logging out. ! $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : ''; ! if ($action == 'login') { ! $the_cookie = serialize(array('username' => $username, 'password' => $password)); ! setcookie('phpicalendar_login', $the_cookie, time()+(60*60*24*7*12*10), '/', $cookie_uri, 0); ! } else if ($action == 'logout') { ! setcookie('phpicalendar_login', '', time()-(60*60*24*7), '/', $cookie_uri, 0); ! unset($username, $password); } --- 32,65 ---- } + // Set the cookie URI. if ($cookie_uri == '') { $cookie_uri = $HTTP_SERVER_VARS['SERVER_NAME'].substr($HTTP_SERVER_VARS['PHP_SELF'],0,strpos($HTTP_SERVER_VARS['PHP_SELF'], '/')); } ! // If not HTTP authenticated, try login via cookies or the web page. ! $username = ''; $password = ''; ! if (!isset($_SERVER['PHP_AUTH_USER'])) { ! // Look for a login cookie. ! if (isset($HTTP_COOKIE_VARS['phpicalendar_login'])) { ! $login_cookie = unserialize(stripslashes($HTTP_COOKIE_VARS['phpicalendar_login'])); ! if (isset($login_cookie['username'])) $username = $login_cookie['username']; ! if (isset($login_cookie['password'])) $password = $login_cookie['password']; ! } ! // Look for a new username and password. ! if (isset($HTTP_GET_VARS['username'])) $username = $HTTP_GET_VARS['username']; ! else if (isset($HTTP_POST_VARS['username'])) $username = $HTTP_POST_VARS['username']; ! if (isset($HTTP_GET_VARS['password'])) $password = $HTTP_GET_VARS['password']; ! else if (isset($HTTP_POST_VARS['password'])) $password = $HTTP_POST_VARS['password']; ! // Set the login cookie if logging in. Clear it if logging out. ! $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : ''; ! if ($action == 'login') { ! $the_cookie = serialize(array('username' => $username, 'password' => $password)); ! setcookie('phpicalendar_login', $the_cookie, time()+(60*60*24*7*12*10), '/', $cookie_uri, 0); ! } else if ($action == 'logout') { ! setcookie('phpicalendar_login', '', time()-(60*60*24*7), '/', $cookie_uri, 0); ! $username = ''; $password = ''; ! } } Index: list_icals.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/functions/list_icals.php,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** list_icals.php 23 Nov 2003 19:53:29 -0000 1.22 --- list_icals.php 24 Nov 2003 04:05:37 -0000 1.23 *************** *** 4,34 **** if (isset($query)) echo $query; echo "');\">"; ! ! $all_cals = availableCalendars($username, $password, $ALL_CALENDARS_COMBINED); ! foreach ($all_cals as $cal_tmp) { ! $cal_displayname_tmp = basename($cal_tmp); ! $cal_displayname_tmp = str_replace("32", " ", $cal_displayname_tmp); ! $cal_displayname_tmp = substr($cal_displayname_tmp, 0, -4); ! ! if (preg_match("/^(https?|webcal):\/\//i", $cal_tmp)) { ! $cal_displayname_tmp .= " Webcal"; ! } else { ! $cal_tmp = basename($cal_tmp); ! $cal_tmp = substr($cal_tmp, 0, -4); ! $cal_displayname_tmp .= " $calendar_lang"; ! } ! $cal_encoded_tmp = urlencode($cal_tmp); ! $cal_httpPrefix_tmp = str_replace('webcal://', 'http://', $cal_tmp); ! if ($cal_httpPrefix_tmp == urldecode($cal)) { ! print "<option value=\"$current_view.php?cal=$cal_encoded_tmp&getdate=$getdate\" selected>$cal_displayname_tmp</option>"; ! } else { ! print "<option value=\"$current_view.php?cal=$cal_encoded_tmp&getdate=$getdate\">$cal_displayname_tmp</option>"; ! } ! } ! if ($cal == $ALL_CALENDARS_COMBINED) { ! print "<option value=\"$current_view.php?cal=$ALL_CALENDARS_COMBINED&getdate=$getdate\" selected>$all_cal_comb_lang</option>"; ! } else { ! print "<option value=\"$current_view.php?cal=$ALL_CALENDARS_COMBINED&getdate=$getdate\">$all_cal_comb_lang</option>"; ! } print "</select>"; --- 4,10 ---- if (isset($query)) echo $query; echo "');\">"; ! ! // List the calendars. ! display_ical_list(availableCalendars($username, $password, $ALL_CALENDARS_COMBINED)); print "</select>"; |