From ab88aa25e6d76bb56ea43a798768e966d29bef46 Mon Sep 17 00:00:00 2001 From: Wesley Miaw Date: Mon, 24 Nov 2003 04:05:37 +0000 Subject: Added HTTP authentication support. Modifications to non-HTTP authentication login so that the two are mutually exclusive. Moved calendar "; + } else { + print ""; + } + } + + // option to open all (non-web) calenders together + if ($cal == $ALL_CALENDARS_COMBINED) { + print ""; + } else { + print ""; + } +} \ No newline at end of file diff --git a/functions/init.inc.php b/functions/init.inc.php index 46f5bcc..7adb4e5 100644 --- a/functions/init.inc.php +++ b/functions/init.inc.php @@ -6,9 +6,17 @@ //chmod(BASE.'calendars/School.ics',0666); // uncomment when developing, comment for shipping version -error_reporting (E_WARNING); +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'); include(BASE.'functions/error.php'); @@ -23,33 +31,36 @@ if (isset($HTTP_COOKIE_VARS['phpicalendar'])) { if (isset($phpicalendar['cookie_time'])) $day_start = $phpicalendar['cookie_time']; } +// 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'], '/')); } -// 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']; -} +// 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']; -// 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); + // 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 = ''; + } } // language support diff --git a/functions/list_icals.php b/functions/list_icals.php index c4d5211..81984f7 100644 --- a/functions/list_icals.php +++ b/functions/list_icals.php @@ -3,33 +3,9 @@ if ($display_ical_list == "yes") { echo ""; } diff --git a/includes/calendar_nav.php b/includes/calendar_nav.php index fc82742..f4e7285 100644 --- a/includes/calendar_nav.php +++ b/includes/calendar_nav.php @@ -150,7 +150,7 @@ echo "$goprint_lang
\n"; if ($allow_preferences != 'no') echo "$preferences_lang
\n"; if ($cal != $ALL_CALENDARS_COMBINED && $subscribe_path != '' && $download_filename != '') echo "$subscribe_lang | $download_lang\n"; - if (isset($username)) { + if ($username != '') { $querys = preg_replace("/action=[^&]+/", "action=logout", $QUERY_STRING); if ($querys == $QUERY_STRING) $querys .= "&action=logout"; $querys = preg_replace("/(username|password)=[^&]+/", "", $querys); diff --git a/includes/login.php b/includes/login.php index f374c31..06b7381 100644 --- a/includes/login.php +++ b/includes/login.php @@ -1,6 +1,7 @@ < echo "$goprint_lang
\n"; if ($allow_preferences != 'no') echo "$preferences_lang
\n"; if ($cal != $ALL_CALENDARS_COMBINED && $subscribe_path != '' && $download_filename != '') echo "$subscribe_lang | $download_lang\n"; - if (isset($username)) { + if ($username != '') { $querys = preg_replace("/action=[^&]+/", "action=logout", $QUERY_STRING); if ($querys == $QUERY_STRING) $querys .= '&action=logout'; $querys = preg_replace("/(username|password)=[^&]+/", "", $querys); diff --git a/preferences.php b/preferences.php index 7c67ec7..2aa7ba0 100644 --- a/preferences.php +++ b/preferences.php @@ -2,7 +2,6 @@ define('BASE','./'); include(BASE.'functions/ical_parser.php'); -include(BASE.'functions/calendar_functions.php'); $display_date = $preferences_lang; if ($cookie_uri == '') { @@ -158,41 +157,7 @@ include (BASE.'includes/header.inc.php'); // Begin Calendar Selection // print "\n"; ?> -- cgit v1.2.3