addRoute("/calendar/calendarStream", "calendarStream", "GET"); $this->addRoute("/calendar/calendarNotify", "calendarNotify", "POST"); $this->addRoute("/calendar/calendarUserSubscriptions", "getcalendarUserSubscriptions", "GET"); $this->addRoute("/calendar/calendarUserSubscriptions", "updatecalendarUserSubscriptions", "POST"); $this->addRoute("/calendar/calendarUsers", "getcalendarUsers", "GET"); } protected function calendarNotify() { $myfile = fopen(__DIR__ . "/../../../var/log/microsoft_notify_log.txt", "a") or die("Unable to open file!"); $get = json_encode($_GET); fwrite($myfile, "\nGET: " . $get); $post = serialize($_POST); fwrite($myfile, "\nPOST: " . $post); if ($_GET['validationToken']) { echo $_GET['validationToken']; die(); } $input = file_get_contents('php://input'); fwrite($myfile, "\nINPUT: " . $input); $result = 'ok'; CalendarModel::insertMicrosoftCalendarEvent($input); die(); } protected function getcalendarUsers() { $users = UserModel::search(['employee' => 'true']); $json['data'] = $users; $json['status'] = "success"; $result = json_encode($json); echo $result; die(); } protected function getcalendarUserSubscriptions() { if ($_GET['onlymsuser']) { $userSubscriptions = CalendarModel::search(array("checkSubscriptions" => 1)); } else { $userSubscriptions = CalendarModel::getAll(); } $json['data'] = $userSubscriptions; $json['status'] = "success"; $result = json_encode($json); echo $result; die(); } protected function updatecalendarUserSubscriptions() { $id = $this->post['id']; $user_id = $this->post['user_id']; $go_calendar_id = $this->post['go_calendar_id']; $microsoft_id = $this->post['microsoft_id']; $subscription_id = $this->post['subscription_id']; $expirationDateTime = $this->post['expirationDateTime']; $Calendar = new Calendar($id); if (!($Calendar->id) || $Calendar->id != $id) { $mode = "add"; } else { $mode = "update"; } $data = []; if ($user_id) { $data['user_id'] = $user_id; } if ($go_calendar_id) { $data['go_calendar_id'] = $go_calendar_id; } if ($microsoft_id) { $data['microsoft_id'] = $microsoft_id; } if ($subscription_id) { $data['subscription_id'] = $subscription_id; } if ($expirationDateTime) { $data['expirationDateTime'] = $expirationDateTime; } if ($mode == "add") { $data['create_by'] = '154'; } $data['edit_by'] = '154'; $Calendar->update($data); $Calendar->save(); $json['status'] = "success"; $result = json_encode($json); echo $result; die(); } protected function decryptString($cipherText, $password, $salt) { // Definiere den Algorithmus und die Länge des Initialisierungsvektors $cipher = "aes-256-cbc"; $ivlen = openssl_cipher_iv_length($cipher); // Dekodiere den verschlüsselten Text von base64 $cipherText = base64_decode($cipherText); // Extrahiere den Initialisierungsvektor und den verschlüsselten Text $iv = substr($cipherText, 0, $ivlen); $cipherText = substr($cipherText, $ivlen); // Erzeuge einen Schlüssel aus dem Passwort und dem Salt $key = hash_pbkdf2("sha256", $password, $salt, 1000, 32, true); // Entschlüssele den Text $plainText = openssl_decrypt($cipherText, $cipher, $key, 0, $iv); return $plainText; } protected function calendarStream() { $decstring = $this->decryptString($_GET['user'], "testpw", "testsalt"); date_default_timezone_set('Europe/Berlin'); header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); header('Connection: keep-alive'); $timestamp = time(); $Calendar = CalendarModel::search(array("user_id" => $decstring)); $rights = json_decode($Calendar[0]->rights, true); if (!$Calendar[0]->rights) { $allowedCalendar[] = $Calendar[0]->calendar_id; } else { foreach (json_decode($Calendar[0]->rights, true) as $key => $value) { $allowedCalendar[] = $key; } } if ($Calendar[0]->colors) { $calendarColors = json_decode($Calendar[0]->colors, true); } $redis = new Redis(); //Connecting to Redis $redis->connect('172.16.5.5', '6379'); //$redis->auth('password'); $oldoutput = ""; $now = floor(microtime(true) * 1000); $timenow = time(); while (true) { $colors = $redis->get('thetool_calendar_usercolors_' . $decstring); if ($colors) { $calendarColors = json_decode($colors, true); } $output = $redis->get('thetool_calendar_event_tigger'); $json = json_decode($output, true); $message[0] = $json; if ($json['time'] > $now && $output !== $oldoutput) { $timenow = time(); // $Calendar=CalendarModel::getCalendarEvents($decstring, $json['cal_events_id']); $Calendarevent = json_decode(CalendarModel::getCalendarEvents($decstring, $json['cal_events_id']), true); if ($json['all_day_event'] == 1) { $message[0]['start_time'] = date('Y-m-d', $json['start_time']); $message[0]['end_time'] = date('Y-m-d', $json['end_time']); } else { $message[0]['start_time'] = date('Y-m-d H:i', $json['start_time']); $message[0]['end_time'] = date('Y-m-d H:i', $json['end_time']); } $message[0]['name']= $Calendarevent['data'][0]['category']['category']; $message[0]['description'] = $Calendarevent['data'][0]['description']['description']; $message[0]['location'] = $Calendarevent['data'][0]['location']['location']; $message[0]['event_type'] = $Calendarevent['data'][0]['event_type']['event_type']; $message[0]['attachment'] = $Calendarevent['data'][0]['attachment']['attachment']; $message[0]['attachments'] = $Calendarevent['data'][0]['attachments']['attachments']; $message[0]['calendar_name'] = $Calendarevent['data'][0]['calendar_name']['calendar_name']; $message[0]['isorganizer'] = $Calendarevent['data'][0]['isorganizer']['isorganizer']; $message[0]['privateflag'] = $Calendarevent['data'][0]['privateflag']['privateflag']; $message[0]['rrule'] = $Calendarevent['data'][0]['rrule']['rrule']; $message[0]['duration'] = $Calendarevent['data'][0]['duration']['duration']; $message[0]['mtime'] = $Calendarevent['data'][0]['mtime']['mtime']; $message[0]['mname'] = $Calendarevent['data'][0]['mname']['mname']; $message[0]['ctime'] = $Calendarevent['data'][0]['ctime']['ctime']; $message[0]['cname'] = $Calendarevent['data'][0]['cname']['cname']; $message[0]['busy'] = $Calendarevent['data'][0]['busy']['busy']; $message[0]['calendar_id_check'] = array('calendar_id' => $json['calendar_id'], 'order' => $json['calendar_id']);; $message[0]['userr'] = $Calendar[0]->calendar_id; $message[0]['bgColor'] = $calendarColors[$json['calendar_id']]['bgcolor']; $message[0]['txtColor'] = $calendarColors[$json['calendar_id']]['txtcolor']; $message[0]['rights'] = $rights[$json['calendar_id']]; $message[0]['me'] = $decstring; $result = json_encode($message); if (in_array($message[0]['calendar_id'], $allowedCalendar)) { echo "data: " . ($result) . "\n\n"; } unset($Array); $now = floor(microtime(true) * 1000);; } if (ob_get_level() > 0) { ob_flush(); } if ($timenow + 300 < time()) { die(); } flush(); if (connection_aborted()) die(); usleep(100000); $oldoutput = $output;; } die(); } }