// Show freebusy info in a format that Apple ical understands if ($_SERVER['SERVER_PORT'] == "443") { if (!isset($_REQUEST['user'])) { $argv = $_SERVER['argv']; $query = strip_tags($argv[0]); print "
Login to retrieve calendar $query:
"; print "
"; exit; } else { $user = strip_tags($_REQUEST['user']); // password could be anything, but we don't display it so don't need to strip $pass = $_REQUEST['pass']; $fp = fopen("/tmp/ical.log", "a"); if ($fp) { fwrite($fp,"$user\n"); fclose($fp); } $ds=ldap_connect("127.0.0.1","389"); // must be a valid LDAP server! if (!$ds) { print "Can't connect to LDAP server
"; exit; } $rr=ldap_bind($ds,"uid=$user,ou=people,o=rutgers.edu,o=rulink-top", $pass); if (!$rr) { print "
Login failed
"; exit; } $fh = fsockopen ('rulink.rutgers.edu', 81, &$errorNumber, &$errorString, 10); if (!$fh) { print "
Unable to connect to calendar server
"; exit; } //tell server what document we want fputs ($fh, "GET /login.wcap?user=" . urlencode($user) . "&password=" . urlencode($pass) . " HTTP/1.0"); fputs ($fh, "\r\n\r\n"); $id = ""; while (!feof($fh)) { $currentLine = fgets ($fh, 128); if ( ereg("^X-NSCP-WCAP-SESSION-ID:([a-z0-9]*)", $currentLine, $regs) ) { $id = $regs[1]; } } if ($id == "") { print "Login failed
"; exit; } } } // user's argument. Should be a calendarid. $argv = $_SERVER['argv']; $query = strip_tags($argv[0]); //$query=$argv[0]; if ($i = strrchr($query, "&")) { $query = substr($i,1); } $s = strpos($query, ".ics"); if ($s > 0) $query = substr($query, 0, $s); if (!(strstr($query,"@"))) { $query = "$query@rutgers.edu"; } $query = urlencode($query); $today = getdate(); $month = $today['mon']; $day = $today['mday']; $year = $today['year']; // echo "$month/$day/$year"; // Generate start and end arguments in GMT. Go from midnight local time // for 2 months. $start = gmstrftime("%Y%m%dT%H%M%SZ",mktime(0, 0, 0, $month-1, $day, $year)); if (!isset($months)) { $months = 3; } $end = gmstrftime("%Y%m%dT%H%M%SZ",mktime(0, 0, 0, $month+$months, $day, $year)); // Obviously you should use your own iplanet calendar server here $connection = fsockopen ('rulink.rutgers.edu', 81, &$errorNumber, &$errorString, 10); if ($connection) { //tell server what document we want if ($id) { fputs ($connection, "GET /fetchcomponents_by_range.wcap?id=$id&calid=$query&dtstart=$start&dtend=$end&fmt-out=text/calendar HTTP/1.0"); } else { fputs ($connection, "GET /fetchcomponents_by_range.wcap?calid=$query&dtstart=$start&dtend=$end&fmt-out=text/calendar HTTP/1.0"); } // fputs ($connection, "GET /fetchcomponents_by_range.wcap?calid=$query&dtstart=0&dtend=0&fmt-out=text/calendar HTTP/1.0"); fputs ($connection, "\r\n\r\n"); $show = 0; // should we try to disable caching? Presumably Outlook doesn't cache this. // Now display the results of the query. Outlook doesn't process the // FBTYPE's, so we have to omit the ones showing FREE, or Outlook will // think we're always busy. We're going to see a whole HTTP output including // headers. Start output after the header. (In ics 5.1 there's an option // busyonly=1 for the query. Not sure that we want to make this script // version-specific.) Also filter out iplanet-specific lines (start with // X-NSCP-, as those contain access-control info that might be helpful to // an attacker. $inhead = 1; $readdone = 0; while (!feof($connection)) { if ($readdone) $readdone = 0; else $currentLine = fgets ($connection, 128); if ($inhead && $currentLine == "\r\n") { $inhead = 0; continue; } if ($inhead) { header(trim($currentLine)); } else if ( ereg("^X-NSCP-", $currentLine) ) { continue; } else if ( ereg("^ ;X-NSCP-", $currentLine) ) { continue; // tiger seems to get confused by recurrence. Have to remove recurrence-id // but append it to uid, otherwise the uid won't be unique. } else if ( ereg("^RECURRENCE-ID:", $currentLine) ) { $rec = substr(trim($currentLine),14); continue; } else if ( ereg("^UID:", $currentLine) ) { $uid = substr(trim($currentLine),4); continue; // print uid now, at the end, so we can append recurrence if there is one } else if ( ereg("^END:", $currentLine) ) { if ($uid) { if ($rec) print "UID:$uid.$rec\r\n"; else print "UID:$uid\r\n"; $rec = ""; $uid = ""; } print $currentLine; } else if ( ereg("^ORGANIZER", $currentLine) ) { // skip organizer and all continuation lines // isync seeems to get confused by it, and apple/palm software doesn't use it $currentLine = " "; while (ereg("^ ", $currentLine)) { $currentLine = fgets ($connection, 128); } $readdone = 1; } else { print $currentLine; } } } ?>