コード例 #1
0
ファイル: PublicSession.php プロジェクト: derekyu1437/davical
 /**
  * The constructor, which just calls the actual type configured
  */
 function PublicSession()
 {
     global $c;
     $principal = new Principal('username', 'unauthenticated');
     // Assign each field in the selected record to the object
     foreach ($principal as $k => $v) {
         $this->{$k} = $v;
     }
     $this->username = $principal->username();
     $this->user_no = $principal->user_no();
     $this->principal_id = $principal->principal_id();
     $this->email = $principal->email();
     $this->dav_name = $principal->dav_name();
     $this->principal = $principal;
     if (function_exists("awl_set_locale") && isset($this->locale) && $this->locale != "") {
         awl_set_locale($this->locale);
     }
     $this->groups = isset($c->public_groups) ? $c->public_groups : array();
     $this->roles = array('Public' => true);
     $this->logged_in = false;
 }
コード例 #2
0
 function __construct($user_no = null)
 {
     if (empty($user_no)) {
         $this->user_no = -1;
         $this->principal_id = -1;
         $this->logged_in = false;
         return;
     }
     $this->user_no = $user_no;
     $principal = new Principal('user_no', $user_no);
     // Assign each field in the selected record to the object
     foreach ($principal as $k => $v) {
         $this->{$k} = $v;
     }
     $this->username = $principal->username();
     $this->principal_id = $principal->principal_id();
     $this->email = $principal->email();
     $this->dav_name = $principal->dav_name();
     $this->principal = $principal;
     $this->logged_in = true;
 }
コード例 #3
0
/**
 * Do the scheduling adjustments for a REPLY when an ATTENDEE updates their status.
 * @param vCalendar $resource The resource that the ATTENDEE is writing to their calendar
 * @param string $organizer The property which is the event ORGANIZER.
 */
function do_scheduling_reply(vCalendar $resource, vProperty $organizer)
{
    global $request;
    $organizer_email = preg_replace('/^mailto:/i', '', $organizer->Value());
    $organizer_principal = new Principal('email', $organizer_email);
    if (!$organizer_principal->Exists()) {
        dbg_error_log('PUT', 'Organizer "%s" not found - cannot perform scheduling reply.', $organizer);
        return false;
    }
    $sql = 'SELECT caldav_data.dav_name, caldav_data.caldav_data FROM caldav_data JOIN calendar_item USING(dav_id) ';
    $sql .= 'WHERE caldav_data.collection_id IN (SELECT collection_id FROM collection WHERE is_calendar AND user_no =?) ';
    $sql .= 'AND uid=? LIMIT 1';
    $uids = $resource->GetPropertiesByPath('/VCALENDAR/*/UID');
    if (count($uids) == 0) {
        dbg_error_log('PUT', 'No UID in VCALENDAR - giving up on REPLY.');
        return false;
    }
    $uid = $uids[0]->Value();
    $qry = new AwlQuery($sql, $organizer_principal->user_no(), $uid);
    if (!$qry->Exec('PUT', __LINE__, __FILE__) || $qry->rows() < 1) {
        dbg_error_log('PUT', 'Could not find original event from organizer - giving up on REPLY.');
        return false;
    }
    $row = $qry->Fetch();
    $attendees = $resource->GetAttendees();
    foreach ($attendees as $v) {
        $email = preg_replace('/^mailto:/i', '', $v->Value());
        if ($email == $request->principal->email()) {
            $attendee = $v;
        }
    }
    if (empty($attendee)) {
        dbg_error_log('PUT', 'Could not find ATTENDEE in VEVENT - giving up on REPLY.');
        return false;
    }
    $schedule_original = new vCalendar($row->caldav_data);
    $schedule_original->UpdateAttendeeStatus($request->principal->email(), clone $attendee);
    $collection_path = preg_replace('{/[^/]+$}', '/', $row->dav_name);
    $segment_name = str_replace($collection_path, '', $row->dav_name);
    $organizer_calendar = new WritableCollection(array('path' => $collection_path));
    $organizer_inbox = new WritableCollection(array('path' => $organizer_principal->internal_url('schedule-inbox')));
    $schedule_reply = clone $schedule_original;
    $schedule_reply->AddProperty('METHOD', 'REPLY');
    dbg_error_log('PUT', 'Writing scheduling REPLY from %s to %s', $request->principal->email(), $organizer_principal->email());
    $response = '3.7';
    // Organizer was not found on server.
    if (!$organizer_calendar->Exists()) {
        dbg_error_log('ERROR', 'Default calendar at "%s" does not exist for user "%s"', $organizer_calendar->dav_name(), $schedule_target->username());
        $response = '5.2';
        // No scheduling support for user
    } else {
        if (!$organizer_inbox->HavePrivilegeTo('schedule-deliver-reply')) {
            $response = '3.8';
            // No authority to deliver replies to organizer.
        } else {
            if ($organizer_inbox->WriteCalendarMember($schedule_reply, false, false, $request->principal->username() . $segment_name) !== false) {
                $response = '1.2';
                // Scheduling reply delivered successfully
                if ($organizer_calendar->WriteCalendarMember($schedule_original, false, false, $segment_name) === false) {
                    dbg_error_log('ERROR', 'Could not write updated calendar member to %s', $attendee_calendar->dav_name(), $attendee_calendar->dav_name(), $schedule_target->username());
                    trace_bug('Failed to write scheduling resource.');
                }
            }
        }
    }
    $schedule_request = clone $schedule_original;
    $schedule_request->AddProperty('METHOD', 'REQUEST');
    dbg_error_log('PUT', 'Status for organizer <%s> set to "%s"', $organizer->Value(), $response);
    $organizer->SetParameterValue('SCHEDULE-STATUS', $response);
    $resource->UpdateOrganizerStatus($organizer);
    $scheduling_actions = true;
    $calling_attendee = clone $attendee;
    $attendees = $schedule_original->GetAttendees();
    foreach ($attendees as $attendee) {
        $email = preg_replace('/^mailto:/i', '', $attendee->Value());
        if ($email == $request->principal->email() || $email == $organizer_principal->email()) {
            continue;
        }
        $agent = $attendee->GetParameterValue('SCHEDULE-AGENT');
        if ($agent && $agent != 'SERVER') {
            dbg_error_log("PUT", "not delivering to %s, schedule agent set to value other than server", $email);
            continue;
        }
        // an attendee's reply should modify only the PARTSTAT on other attendees' objects
        // other properties (that might have been adjusted individually by those other
        // attendees) should remain unmodified. Therefore, we have to make $schedule_original
        // and $schedule_request be initialized by each attendee's object here.
        $attendee_principal = new DAVPrincipal(array('email' => $email, 'options' => array('allow_by_email' => true)));
        if ($attendee_principal == false) {
            dbg_error_log('PUT', 'Could not find attendee %s', $email);
            continue;
        }
        $sql = 'SELECT caldav_data.dav_name, caldav_data.caldav_data, caldav_data.collection_id FROM caldav_data JOIN calendar_item USING(dav_id) ';
        $sql .= 'WHERE caldav_data.collection_id IN (SELECT collection_id FROM collection WHERE is_calendar AND user_no =?) ';
        $sql .= 'AND uid=? LIMIT 1';
        $qry = new AwlQuery($sql, $attendee_principal->user_no(), $uid);
        if (!$qry->Exec('PUT', __LINE__, __FILE__) || $qry->rows() < 1) {
            dbg_error_log('PUT', "Could not find attendee's event %s", $uid);
        }
        $row = $qry->Fetch();
        $schedule_original = new vCalendar($row->caldav_data);
        $schedule_original->UpdateAttendeeStatus($request->principal->email(), clone $calling_attendee);
        $schedule_request = clone $schedule_original;
        $schedule_request->AddProperty('METHOD', 'REQUEST');
        $schedule_target = new Principal('email', $email);
        $response = '3.7';
        // Attendee was not found on server.
        if ($schedule_target->Exists()) {
            // Instead of always writing to schedule-default-calendar, we first try to
            // find a calendar with an existing instance of the event in any calendar of this attendee.
            $r = new DAVResource($row);
            $attendee_calendar = new WritableCollection(array('path' => $r->parent_path()));
            if ($attendee_calendar->IsCalendar()) {
                dbg_error_log('XXX', "found the event in attendee's calendar %s", $attendee_calendar->dav_name());
            } else {
                dbg_error_log('XXX', 'could not find the event in any calendar, using schedule-default-calendar');
                $attendee_calendar = new WritableCollection(array('path' => $schedule_target->internal_url('schedule-default-calendar')));
            }
            if (!$attendee_calendar->Exists()) {
                dbg_error_log('ERROR', 'Default calendar at "%s" does not exist for user "%s"', $attendee_calendar->dav_name(), $schedule_target->username());
                $response = '5.2';
                // No scheduling support for user
            } else {
                $attendee_inbox = new WritableCollection(array('path' => $schedule_target->internal_url('schedule-inbox')));
                if (!$attendee_inbox->HavePrivilegeTo('schedule-deliver-invite')) {
                    $response = '3.8';
                    //  No authority to deliver invitations to user.
                } else {
                    if ($attendee_inbox->WriteCalendarMember($schedule_request, false) !== false) {
                        $response = '1.2';
                        // Scheduling invitation delivered successfully
                        if ($attendee_calendar->WriteCalendarMember($schedule_original, false) === false) {
                            dbg_error_log('ERROR', 'Could not write updated calendar member to %s', $attendee_calendar->dav_name(), $attendee_calendar->dav_name(), $schedule_target->username());
                            trace_bug('Failed to write scheduling resource.');
                        }
                    }
                }
            }
        }
        dbg_error_log('PUT', 'Status for attendee <%s> set to "%s"', $attendee->Value(), $response);
        $attendee->SetParameterValue('SCHEDULE-STATUS', $response);
        $scheduling_actions = true;
        $resource->UpdateAttendeeStatus($email, clone $attendee);
    }
    return $scheduling_actions;
}
コード例 #4
0
/**
 * Does the actual processing of the iTIP CANCEL message on behalf of an ATTENDEE,
 * which generally means writing it into the ATTENDEE's default calendar.
 * 
 * @param vCalendar $vcal The message.
 * @param vProperty $attendee
 * @param WritableCollection $attendee_calendar
 */
function processItipCancel(vCalendar $vcal, vProperty $attendee, WritableCollection $attendee_calendar, Principal $attendee_principal)
{
    global $request;
    dbg_error_log('schedule', 'Processing iTIP CANCEL to %s', $attendee->Value());
    header("Debug: Could maybe do the iMIP message dance for attendee " . $attendee->Value());
    if (!$attendee_calendar->Exists()) {
        if (doImipMessage('CANCEL', $attendee_principal->email(), $vcal)) {
            return '1.1';
            // Scheduling whoosit 'Sent'
        } else {
            dbg_error_log('ERROR', 'Default calendar at "%s" does not exist for attendee "%s"', $attendee_calendar->dav_name(), $attendee->Value());
            return '5.2';
            // No scheduling support for user
        }
    }
    $sql = 'SELECT caldav_data.dav_name FROM caldav_data JOIN calendar_item USING(dav_id) ';
    $sql .= 'WHERE caldav_data.collection_id IN (SELECT collection_id FROM collection WHERE is_calendar AND user_no =?) ';
    $sql .= 'AND uid=? LIMIT 1';
    $uids = $vcal->GetPropertiesByPath('/VCALENDAR/*/UID');
    if (count($uids) == 0) {
        dbg_error_log('schedule', 'No UID in VCALENDAR - giving up on CANCEL processing.');
        return '3.8';
    }
    $uid = $uids[0]->Value();
    $qry = new AwlQuery($sql, $attendee_principal->user_no(), $uid);
    if (!$qry->Exec('schedule', __LINE__, __FILE__) || $qry->rows() < 1) {
        dbg_error_log('schedule', 'Could not find ATTENDEE copy of original event - not trying to DELETE it!');
        return '1.2';
    }
    $row = $qry->Fetch();
    if ($attendee_calendar->actualDeleteCalendarMember($row->dav_name) === false) {
        dbg_error_log('ERROR', 'Could not delete calendar member %s for %s', $row->dav_name(), $attendee->Value());
        trace_bug('Failed to write scheduling resource.');
        return '5.2';
    }
    return '1.2';
    // Scheduling invitation delivered successfully
}