From: <cl...@us...> - 2004-05-13 18:30:51
|
Update of /cvsroot/phpicalendar/phpicalendar/calendars In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10879/calendars Modified Files: publish.php Log Message: Fix for [ 904534 ] Publish.php workaround for Mozilla Calendar. Needs testing. Index: publish.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/calendars/publish.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** publish.php 23 Nov 2003 22:55:22 -0000 1.3 --- publish.php 13 May 2004 18:30:22 -0000 1.4 *************** *** 28,31 **** --- 28,47 ---- 4. Click the "Publish" button + Usage (Mozilla Calendar): + 1. Your version of php and apache MUST support $_SERVER['PATH_INFO'] + 2. You must have supplied a username and password in your config.php + 2. Create your calendar in Mozilla + 3. Add something to it (it must not be empty) + 4. Manually upload it to your calendars directory. + 5. Make sure that the webserver can write to the calendar file. + (Mozilla will not save to the remote location without first downloading a copy + from the remote location) + 6. Edit your calendar setup in mozilla + Location http://example.com/path/to/publish.php/calendarname.ics + calendarname.ics should be a unique filename and must end with .ics + 7. Username (username from config.php) + 8. Password (password from config.php) + 9. Check "publish changes automatically" + Security: The calendars directory should be configured to require authentication. This can be done via any methods *************** *** 63,150 **** } */ ! // only allow publishing if explicitly enabled ! if(PHPICALENDAR_PUBLISHING == 1) ! { // unpublishing ! if($_SERVER['REQUEST_METHOD'] == 'DELETE') ! { ! // get calendar filename ! $calendar_file = $calendar_path.substr($_SERVER['REQUEST_URI'] , ( strrpos($_SERVER['REQUEST_URI'], '/') + 1) ) ; ! ! logmsg('received request to delete '.$calendar_file); ! ! // remove calendar file ! if(!unlink($calendar_file)) ! { ! logmsg('unable to delete the calendar file'); ! } ! else ! { ! logmsg('deleted'); ! } ! return; } // publishing ! if($_SERVER['REQUEST_METHOD'] == 'PUT') ! { ! // get calendar data ! if($fp = fopen('php://input','r')) ! { ! while(!@feof($fp)) ! { ! $data .= fgets($fp,4096); ! } ! ! @fclose($fp); } ! else ! { ! logmsg('unable to read input data'); } ! if(isset($data)) ! { ! ! // get calendar name ! $cal_arr = explode("\n",$data); ! ! foreach($cal_arr as $k => $v) ! { ! if(strstr($v,'X-WR-CALNAME:')) ! { ! $arr = explode(':',$v); ! $calendar_name = trim($arr[1]); ! break; ! } ! } ! ! $calendar_name = isset($calendar_name) ? $calendar_name : 'default'; ! ! // write to file ! if($fp = fopen($calendar_path.$calendar_name.'.ics','w+')) ! { ! fputs($fp, $data, strlen($data) ); ! @fclose($fp); ! } ! else ! { ! logmsg( 'couldnt open file '.$calendar_path.$calendar_name.'.ics' ); ! } } } ! } // for logging function logmsg($str){ ! if(defined('PHPICALENDAR_LOG_PUBLISHING') && PHPICALENDAR_LOG_PUBLISHING == 1) ! { ! if($fp = fopen('publish_log.txt','a+')) ! { ! $str .= "\n"; ! fputs($fp, $str, strlen($str) ); ! fclose($fp); ! } } } ! ?> --- 79,180 ---- } */ ! if (!isset($_SERVER['PHP_AUTH_USER'])) { ! header('WWW-Authenticate: Basic realm="My Realm"'); ! header('HTTP/1.0 401 Unauthorized'); ! echo 'You must be authorized!'; ! exit; ! } else { ! // logmsg($_SERVER['PHP_AUTH_PW'] . '|' . $_SERVER['PHP_AUTH_USER']); ! if ($_SERVER['PHP_AUTH_USER'] != $auth_internal_username || $_SERVER['PHP_AUTH_PW'] != $auth_internal_password) { ! header('WWW-Authenticate: Basic realm="My Realm"'); ! header('HTTP/1.0 401 Unauthorized'); ! echo 'You must be authorized!'; ! exit; ! } ! // only allow publishing if explicitly enabled ! if(PHPICALENDAR_PUBLISHING == 1) { // unpublishing ! if($_SERVER['REQUEST_METHOD'] == 'DELETE') { ! // get calendar filename ! $calendar_file = $calendar_path.substr($_SERVER['REQUEST_URI'] , ( strrpos($_SERVER['REQUEST_URI'], '/') + 1) ) ; ! logmsg('received request to delete '.$calendar_file); ! // remove calendar file ! if(!unlink($calendar_file)) { ! logmsg('unable to delete the calendar file'); ! } else { ! logmsg('deleted'); ! } ! return; } // publishing ! if($_SERVER['REQUEST_METHOD'] == 'PUT') { ! // get calendar data ! if($fp = fopen('php://input','r')) { ! while(!@feof($fp)) { ! $data .= fgets($fp,4096); } ! ! @fclose($fp); ! } else { ! logmsg('unable to read input data'); ! } ! if(isset($data)) { ! // get calendar name ! $cal_arr = explode("\n",$data); ! ! foreach($cal_arr as $k => $v) { ! if(strstr($v,'X-WR-CALNAME:')) { ! $arr = explode(':',$v); ! $calendar_name = trim($arr[1]); ! break; ! } } ! $calendar_name = isset($calendar_name) ? $calendar_name : 'default'; ! ! if (isset($_SERVER['PATH_INFO'])) { ! preg_match("/\/([ A-Za-z0-9.]*).ics/i",$_SERVER['PATH_INFO'],$matches); ! $calendar_name = $matches[1]; } + + // write to file + if($fp = fopen($calendar_path.$calendar_name.'.ics','w+')) { + + fputs($fp, $data, strlen($data) ); + @fclose($fp); + } + else { + logmsg( 'couldnt open file '.$calendar_path.$calendar_name.'.ics' ); + } + } } ! if ($_SERVER['REQUEST_METHOD'] == 'GET') { ! if (isset($_SERVER['PATH_INFO'])) { ! preg_match("/\/([ A-Za-z0-9._]*).ics/i",$_SERVER['PATH_INFO'],$matches); ! $icsfile = $matches[1]; ! // get calendar data ! if (file_exists($calendar_path . $icsfile . '.ics') && ! is_readable($calendar_path . $icsfile . '.ics') && ! is_file($calendar_path . $icsfile . '.ics') ! ) { ! echo file_get_contents($calendar_path . $icsfile . '.ics'); ! } else { + } + } + } + } + } // for logging function logmsg($str){ ! if(defined('PHPICALENDAR_LOG_PUBLISHING') && ! PHPICALENDAR_LOG_PUBLISHING == 1) { ! if($fp = fopen('publish_log.txt','a+')) { ! $str .= "\n"; ! fputs($fp, $str, strlen($str) ); ! fclose($fp); } + } } ! ?> \ No newline at end of file |