From 928320b34b790eb2bbce1da8b6e72692b4fe62b8 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:04:49 +0530 Subject: [PATCH 01/34] Jitsi calendar --- lib/Dav/BeforeCreateFilePlugin.php | 101 +++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 lib/Dav/BeforeCreateFilePlugin.php diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php new file mode 100644 index 000000000..4669ee018 --- /dev/null +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -0,0 +1,101 @@ + + * + * @author John Molakvoæ (skjnldsv) + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Calendar\Dav; + +use Sabre\DAV\Server; +use Sabre\DAV\ServerPlugin; + +class BeforeCreateFilePlugin extends ServerPlugin { + public const METHOD_REPLACE = 0; + public const METHOD_APPEND = 1; + + /** @var Server */ + protected $server; + + /** + * Initializes the plugin and registers event handlers + * + * @param Server $server + * @return void + */ + + public function initialize(Server $server) { + \OC::$server->getLogger()->error("ABC"); + $this->server = $server; + //$server->on('beforeCreateFile', [$this, 'beforeCreateFile']); + } + + /** + * This method is invoked if some subsystem creates a new file. + * + * This is used to deal with HTTP LOCK requests which create a new + * file. + * + * @param string $uri + * @param resource $data + * @param bool $modified should be set to true, if this event handler + * changed &$data + * + * @return bool + */ + public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { + \OC::$server->getLogger()->error("ecloud theme helper new"); + \OC::$server->getLogger()->error(print_r($data, true)); + + return; + } + + /** + * Returns a plugin name. + * + * Using this name other plugins will be able to access other plugins + * using \Sabre\DAV\Server::getPlugin + * + * @return string + */ + public function getPluginName() { + return 'vcard-patch'; + } + + /** + * Returns a bunch of meta-data about the plugin. + * + * Providing this information is optional, and is mainly displayed by the + * Browser plugin. + * + * The description key in the returned array may contain html and will not + * be sanitized. + * + * @return array + */ + public function getPluginInfo() { + return [ + 'name' => $this->getPluginName(), + 'description' => 'Allow to patch unique properties.' + ]; + } +} \ No newline at end of file -- GitLab From bbd4043e8f9e6ea3ea57ab57a4303bb60b5e0836 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:12:25 +0530 Subject: [PATCH 02/34] Jitsi calendar --- lib/AppInfo/Application.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 39c29d82f..eed141796 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -45,6 +45,7 @@ use OCP\L10N\IFactory as L10NFactory; use OCP\Mail\IMailer; use OCP\User\Events\UserDeletedEvent; use function method_exists; +use OCA\Calendar\Dav\BeforeCreateFilePlugin; class Application extends App implements IBootstrap { /** @var string */ @@ -126,5 +127,17 @@ class Application extends App implements IBootstrap { // executed in the order that it is registered $containerinvite->registerMiddleware("InvitationMiddleware"); + + + $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); + $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) { + $eventServer = $event->getServer(); + + if ($eventServer !== null) { + $plugin = $context->getAppContainer()->get(BeforeCreateFilePlugin::class); + $eventServer->addPlugin($plugin); + } + }); + } } -- GitLab From a00f0d67c4096bafcb8ddc6996495e8eca47ebb1 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:14:45 +0530 Subject: [PATCH 03/34] Jitsi calendar --- lib/Dav/BeforeCreateFilePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 4669ee018..49341fd7c 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -63,7 +63,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { * @return bool */ public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { - \OC::$server->getLogger()->error("ecloud theme helper new"); + \OC::$server->getLogger()->error("jiti called"); \OC::$server->getLogger()->error(print_r($data, true)); return; -- GitLab From 8ebf325609a0ffe4edeee3eeb48ab3343d6612df Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:16:12 +0530 Subject: [PATCH 04/34] Jitsi calendar --- lib/Dav/BeforeCreateFilePlugin.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 49341fd7c..4a37a71a4 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -65,6 +65,24 @@ class BeforeCreateFilePlugin extends ServerPlugin { public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { \OC::$server->getLogger()->error("jiti called"); \OC::$server->getLogger()->error(print_r($data, true)); + // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' + if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { + // Set the base URL for the meeting + $baseURL = 'https://meet.jit.si/'; + + // Generate a random alphanumeric string of length 8 + $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; + $randomString = substr(str_shuffle($chars), 0, 8); + + // Append the current date to the random string + $randomString .= date('dmy'); + + // Create the complete meeting URL + $meetingURL = $baseURL . $randomString; + + // Replace the first occurrence of 'SUMMARY:' with 'SUMMARY:' followed by 'LOCATION:' + $data = preg_replace('/(SUMMARY:[^\r\n]*)/', "$1\nLOCATION: $meetingURL", $data); + } return; } -- GitLab From b9139a802b5b747a72ad75979b36dfcbc7e69427 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:19:08 +0530 Subject: [PATCH 05/34] Jitsi calendar --- lib/Dav/BeforeCreateFilePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 4a37a71a4..0d69fbe84 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -46,7 +46,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { public function initialize(Server $server) { \OC::$server->getLogger()->error("ABC"); $this->server = $server; - //$server->on('beforeCreateFile', [$this, 'beforeCreateFile']); + $this->server->on('beforeCreateFile', [$this, 'beforeCreateFile']); } /** -- GitLab From 1ef990ae48b093a3d7fff5d6c0d8d5a1ffdefda1 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:20:03 +0530 Subject: [PATCH 06/34] Jitsi calendar --- lib/AppInfo/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index eed141796..a36de91fd 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -46,6 +46,7 @@ use OCP\Mail\IMailer; use OCP\User\Events\UserDeletedEvent; use function method_exists; use OCA\Calendar\Dav\BeforeCreateFilePlugin; +use OCP\EventDispatcher\IEventDispatcher; class Application extends App implements IBootstrap { /** @var string */ -- GitLab From e911a8b2bf8df39eb4668e36f7a9cd47df8c3790 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:20:43 +0530 Subject: [PATCH 07/34] Jitsi calendar --- lib/AppInfo/Application.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a36de91fd..f807dc788 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -47,6 +47,8 @@ use OCP\User\Events\UserDeletedEvent; use function method_exists; use OCA\Calendar\Dav\BeforeCreateFilePlugin; use OCP\EventDispatcher\IEventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App implements IBootstrap { /** @var string */ -- GitLab From ee54cc52a3985a4f26942cd032295a9b02b8bb93 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:26:05 +0530 Subject: [PATCH 08/34] Jitsi calendar --- lib/AppInfo/Application.php | 6 +- lib/Dav/BeforeCreateFilePlugin.php | 174 ++++++++++++++--------------- 2 files changed, 89 insertions(+), 91 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f807dc788..16572a614 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OCA\Calendar\AppInfo; use OCA\Calendar\Dashboard\CalendarWidget; +use OCA\Calendar\Dav\BeforeCreateFilePlugin; use OCA\Calendar\Listener\UserDeletedListener; use OCA\Calendar\Middleware\InvitationMiddleware; use OCA\Calendar\Notification\Notifier; @@ -35,6 +36,7 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\BackgroundJob\IJobList; use OCP\Calendar\IManager; use OCP\Defaults; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; @@ -45,10 +47,6 @@ use OCP\L10N\IFactory as L10NFactory; use OCP\Mail\IMailer; use OCP\User\Events\UserDeletedEvent; use function method_exists; -use OCA\Calendar\Dav\BeforeCreateFilePlugin; -use OCP\EventDispatcher\IEventDispatcher; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App implements IBootstrap { /** @var string */ diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 0d69fbe84..693077e74 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -30,90 +30,90 @@ use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; class BeforeCreateFilePlugin extends ServerPlugin { - public const METHOD_REPLACE = 0; - public const METHOD_APPEND = 1; - - /** @var Server */ - protected $server; - - /** - * Initializes the plugin and registers event handlers - * - * @param Server $server - * @return void - */ - - public function initialize(Server $server) { - \OC::$server->getLogger()->error("ABC"); - $this->server = $server; - $this->server->on('beforeCreateFile', [$this, 'beforeCreateFile']); - } - - /** - * This method is invoked if some subsystem creates a new file. - * - * This is used to deal with HTTP LOCK requests which create a new - * file. - * - * @param string $uri - * @param resource $data - * @param bool $modified should be set to true, if this event handler - * changed &$data - * - * @return bool - */ - public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { - \OC::$server->getLogger()->error("jiti called"); - \OC::$server->getLogger()->error(print_r($data, true)); - // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' - if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { - // Set the base URL for the meeting - $baseURL = 'https://meet.jit.si/'; - - // Generate a random alphanumeric string of length 8 - $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; - $randomString = substr(str_shuffle($chars), 0, 8); - - // Append the current date to the random string - $randomString .= date('dmy'); - - // Create the complete meeting URL - $meetingURL = $baseURL . $randomString; - - // Replace the first occurrence of 'SUMMARY:' with 'SUMMARY:' followed by 'LOCATION:' - $data = preg_replace('/(SUMMARY:[^\r\n]*)/', "$1\nLOCATION: $meetingURL", $data); - } - - return; - } - - /** - * Returns a plugin name. - * - * Using this name other plugins will be able to access other plugins - * using \Sabre\DAV\Server::getPlugin - * - * @return string - */ - public function getPluginName() { - return 'vcard-patch'; - } - - /** - * Returns a bunch of meta-data about the plugin. - * - * Providing this information is optional, and is mainly displayed by the - * Browser plugin. - * - * The description key in the returned array may contain html and will not - * be sanitized. - * - * @return array - */ - public function getPluginInfo() { - return [ - 'name' => $this->getPluginName(), - 'description' => 'Allow to patch unique properties.' - ]; - } -} \ No newline at end of file + public const METHOD_REPLACE = 0; + public const METHOD_APPEND = 1; + + /** @var Server */ + protected $server; + + /** + * Initializes the plugin and registers event handlers + * + * @param Server $server + * @return void + */ + + public function initialize(Server $server) { + \OC::$server->getLogger()->error("ABC"); + $this->server = $server; + $this->server->on('beforeCreateFile', [$this, 'beforeCreateFile']); + } + + /** + * This method is invoked if some subsystem creates a new file. + * + * This is used to deal with HTTP LOCK requests which create a new + * file. + * + * @param string $uri + * @param resource $data + * @param bool $modified should be set to true, if this event handler + * changed &$data + * + * @return bool + */ + public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { + \OC::$server->getLogger()->error("jiti called"); + \OC::$server->getLogger()->error(print_r($data, true)); + // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' + if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { + // Set the base URL for the meeting + $baseURL = 'https://meet.jit.si/'; + + // Generate a random alphanumeric string of length 8 + $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; + $randomString = substr(str_shuffle($chars), 0, 8); + + // Append the current date to the random string + $randomString .= date('dmy'); + + // Create the complete meeting URL + $meetingURL = $baseURL . $randomString; + + // Replace the first occurrence of 'SUMMARY:' with 'SUMMARY:' followed by 'LOCATION:' + $data = preg_replace('/(SUMMARY:[^\r\n]*)/', "$1\nLOCATION: $meetingURL", $data); + } + + return; + } + + /** + * Returns a plugin name. + * + * Using this name other plugins will be able to access other plugins + * using \Sabre\DAV\Server::getPlugin + * + * @return string + */ + public function getPluginName() { + return 'vcard-patch'; + } + + /** + * Returns a bunch of meta-data about the plugin. + * + * Providing this information is optional, and is mainly displayed by the + * Browser plugin. + * + * The description key in the returned array may contain html and will not + * be sanitized. + * + * @return array + */ + public function getPluginInfo() { + return [ + 'name' => $this->getPluginName(), + 'description' => 'Allow to patch unique properties.' + ]; + } +} -- GitLab From 8b5357d3a096f4b446cb9947ebe12b07c7c5960f Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 12:33:27 +0530 Subject: [PATCH 09/34] Jitsi calendar --- lib/AppInfo/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 16572a614..1bd048a4f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -45,6 +45,7 @@ use OCP\IRequest; use OCP\IUserManager; use OCP\L10N\IFactory as L10NFactory; use OCP\Mail\IMailer; +use OCP\SabrePluginEvent; use OCP\User\Events\UserDeletedEvent; use function method_exists; -- GitLab From 69444d59c5247007916588f00b8c880eda18882a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 13:20:13 +0530 Subject: [PATCH 10/34] Jitsi calendar --- lib/AppInfo/Application.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1bd048a4f..f7413f819 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -47,6 +47,7 @@ use OCP\L10N\IFactory as L10NFactory; use OCP\Mail\IMailer; use OCP\SabrePluginEvent; use OCP\User\Events\UserDeletedEvent; +use Sabre\DAV\Server; use function method_exists; class Application extends App implements IBootstrap { @@ -130,7 +131,7 @@ class Application extends App implements IBootstrap { // executed in the order that it is registered $containerinvite->registerMiddleware("InvitationMiddleware"); - + /* $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) { $eventServer = $event->getServer(); @@ -139,7 +140,14 @@ class Application extends App implements IBootstrap { $plugin = $context->getAppContainer()->get(BeforeCreateFilePlugin::class); $eventServer->addPlugin($plugin); } - }); + });*/ + + $server = $this->getContainer()->query(Server::class); + $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); + $eventDispatcher->addListener( + 'beforeCreateFile', + [new BeforeCreateFilePlugin, 'beforeCreateFile'] + ); } } -- GitLab From f3d497a02e162845f18d915e18e31e11390a7fa4 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 14:13:47 +0530 Subject: [PATCH 11/34] Jitsi calendar --- lib/AppInfo/Application.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f7413f819..83e814a7b 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -140,7 +140,9 @@ class Application extends App implements IBootstrap { $plugin = $context->getAppContainer()->get(BeforeCreateFilePlugin::class); $eventServer->addPlugin($plugin); } - });*/ + }); + + */ $server = $this->getContainer()->query(Server::class); $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); -- GitLab From 37bc022ede9f6577ecddda28c90c2af07640a1c3 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 15:45:22 +0530 Subject: [PATCH 12/34] add plugin --- lib/AppInfo/Application.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 83e814a7b..43e7708e8 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -75,6 +75,10 @@ class Application extends App implements IBootstrap { $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerNotifierService(Notifier::class); + $context->registerEventListener( + 'OCA\DAV\Connector\Sabre::addPlugin', + 'OCA\Calendar\Dav\BeforeCreateFilePlugin' + ); } /** @@ -143,13 +147,14 @@ class Application extends App implements IBootstrap { }); */ - + /* $server = $this->getContainer()->query(Server::class); $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); $eventDispatcher->addListener( 'beforeCreateFile', [new BeforeCreateFilePlugin, 'beforeCreateFile'] ); + */ } } -- GitLab From e3fb90f4c5a98504d4d966bbd987da6431c5d980 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 18:04:05 +0530 Subject: [PATCH 13/34] add plugin --- lib/Dav/BeforeCreateFilePlugin.php | 159 +++++++++++++---------------- 1 file changed, 73 insertions(+), 86 deletions(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 693077e74..a028440b0 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -2,118 +2,105 @@ declare(strict_types=1); -/** Dav/BeforeFilePlugin.php /** - * @copyright Copyright (c) 2020 John Molakvoæ - * - * @author John Molakvoæ (skjnldsv) +namespace Sabre\DAV; + +/** + * Temporary File Filter Plugin. * - * @license GNU AGPL version 3 or any later version + * The purpose of this filter is to intercept some of the garbage files + * operation systems and applications tend to generate when mounting + * a WebDAV share as a disk. * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * It will intercept these files and place them in a separate directory. + * these files are not deleted automatically, so it is advisable to + * delete these after they are not accessed for 24 hours. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. + * Currently it supports: + * * OS/X style resource forks and .DS_Store + * * desktop.ini and Thumbs.db (windows) + * * .*.swp (vim temporary files) + * * .dat.* (smultron temporary files) * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * Additional patterns can be added, by adding on to the + * temporaryFilePatterns property. * + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) + * @author Evert Pot (http://evertpot.com/) + * @license http://sabre.io/license/ Modified BSD License */ - -namespace OCA\Calendar\Dav; - -use Sabre\DAV\Server; -use Sabre\DAV\ServerPlugin; - class BeforeCreateFilePlugin extends ServerPlugin { - public const METHOD_REPLACE = 0; - public const METHOD_APPEND = 1; - /** @var Server */ + /** + * A reference to the main Server class. + * + * @var \Sabre\DAV\Server + */ protected $server; /** - * Initializes the plugin and registers event handlers + * This is the directory where this plugin + * will store it's files. * - * @param Server $server - * @return void + * @var string */ + private $dataDir; - public function initialize(Server $server) { - \OC::$server->getLogger()->error("ABC"); - $this->server = $server; - $this->server->on('beforeCreateFile', [$this, 'beforeCreateFile']); - } - - /** - * This method is invoked if some subsystem creates a new file. - * - * This is used to deal with HTTP LOCK requests which create a new - * file. - * - * @param string $uri - * @param resource $data - * @param bool $modified should be set to true, if this event handler - * changed &$data - * - * @return bool - */ - public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { - \OC::$server->getLogger()->error("jiti called"); - \OC::$server->getLogger()->error(print_r($data, true)); - // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' - if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { - // Set the base URL for the meeting - $baseURL = 'https://meet.jit.si/'; - - // Generate a random alphanumeric string of length 8 - $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; - $randomString = substr(str_shuffle($chars), 0, 8); - - // Append the current date to the random string - $randomString .= date('dmy'); - - // Create the complete meeting URL - $meetingURL = $baseURL . $randomString; - - // Replace the first occurrence of 'SUMMARY:' with 'SUMMARY:' followed by 'LOCATION:' - $data = preg_replace('/(SUMMARY:[^\r\n]*)/', "$1\nLOCATION: $meetingURL", $data); + /** + * Creates the plugin. + * + * Make sure you specify a directory for your files. If you don't, we + * will use PHP's directory for session-storage instead, and you might + * not want that. + * + * @param string|null $dataDir + */ + public function __construct($dataDir = null) { + if (!$dataDir) { + $dataDir = ini_get('session.save_path').'/sabredav/'; } - - return; + if (!is_dir($dataDir)) { + mkdir($dataDir); + } + $this->dataDir = $dataDir; } /** - * Returns a plugin name. - * - * Using this name other plugins will be able to access other plugins - * using \Sabre\DAV\Server::getPlugin + * Initialize the plugin. * - * @return string + * This is called automatically be the Server class after this plugin is + * added with Sabre\DAV\Server::addPlugin() */ - public function getPluginName() { - return 'vcard-patch'; + public function initialize(Server $server) { + $this->server = $server; + $server->on('beforeCreateFile', [$this, 'beforeCreateFile']); } + + /** - * Returns a bunch of meta-data about the plugin. + * This method is invoked if some subsystem creates a new file. * - * Providing this information is optional, and is mainly displayed by the - * Browser plugin. + * This is used to deal with HTTP LOCK requests which create a new + * file. * - * The description key in the returned array may contain html and will not - * be sanitized. + * @param string $uri + * @param resource $data + * @param bool $modified should be set to true, if this event handler + * changed &$data * - * @return array + * @return bool */ - public function getPluginInfo() { - return [ - 'name' => $this->getPluginName(), - 'description' => 'Allow to patch unique properties.' - ]; + public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { + if ($tempPath = $this->isTempFile($uri)) { + $hR = $this->server->httpResponse; + $hR->setHeader('X-Sabre-Temp', 'true'); + file_put_contents($tempPath, $data); + + return false; + } + + return; } + + } -- GitLab From c51d4b5460107a30ddfaba047b6cfd9fd76ddbb6 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 19:19:44 +0530 Subject: [PATCH 14/34] add plugin --- lib/Dav/BeforeCreateFilePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index a028440b0..a264c32a6 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Sabre\DAV; +namespace OCA\Calendar\Dav; /** * Temporary File Filter Plugin. -- GitLab From 19ac74d239830d67186ed4a242eb7ada56a0e1df Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 28 Jul 2023 19:47:29 +0530 Subject: [PATCH 15/34] add plugin --- lib/AppInfo/Application.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 43e7708e8..5b23d6360 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -75,10 +75,10 @@ class Application extends App implements IBootstrap { $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerNotifierService(Notifier::class); - $context->registerEventListener( + /*$context->registerEventListener( 'OCA\DAV\Connector\Sabre::addPlugin', 'OCA\Calendar\Dav\BeforeCreateFilePlugin' - ); + );*/ } /** @@ -135,7 +135,7 @@ class Application extends App implements IBootstrap { // executed in the order that it is registered $containerinvite->registerMiddleware("InvitationMiddleware"); - /* + $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) { $eventServer = $event->getServer(); @@ -146,7 +146,7 @@ class Application extends App implements IBootstrap { } }); - */ + /* $server = $this->getContainer()->query(Server::class); $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); -- GitLab From 13f6403c1a270782745eb84edb70c917b7440c2f Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sun, 30 Jul 2023 19:39:40 +0530 Subject: [PATCH 16/34] jitsi fix --- lib/AppInfo/Application.php | 16 ++------- lib/Dav/BeforeCreateFilePlugin.php | 55 ++++++++++++------------------ 2 files changed, 25 insertions(+), 46 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 5b23d6360..8ba5fa415 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -47,7 +47,6 @@ use OCP\L10N\IFactory as L10NFactory; use OCP\Mail\IMailer; use OCP\SabrePluginEvent; use OCP\User\Events\UserDeletedEvent; -use Sabre\DAV\Server; use function method_exists; class Application extends App implements IBootstrap { @@ -135,26 +134,17 @@ class Application extends App implements IBootstrap { // executed in the order that it is registered $containerinvite->registerMiddleware("InvitationMiddleware"); - - $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); + $eventDispatcher = $serverContainer->get(IEventDispatcher::class); $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) { + \OC::$server->getLogger()->error("calendar111"); $eventServer = $event->getServer(); if ($eventServer !== null) { + \OC::$server->getLogger()->error("calendar111 if"); $plugin = $context->getAppContainer()->get(BeforeCreateFilePlugin::class); $eventServer->addPlugin($plugin); } }); - - /* - $server = $this->getContainer()->query(Server::class); - $eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class); - $eventDispatcher->addListener( - 'beforeCreateFile', - [new BeforeCreateFilePlugin, 'beforeCreateFile'] - ); - */ - } } diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index a264c32a6..6806c9d3b 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace OCA\Calendar\Dav; +use Sabre\DAV\Server; +use Sabre\DAV\ServerPlugin; + /** * Temporary File Filter Plugin. * @@ -37,33 +40,6 @@ class BeforeCreateFilePlugin extends ServerPlugin { */ protected $server; - /** - * This is the directory where this plugin - * will store it's files. - * - * @var string - */ - private $dataDir; - - /** - * Creates the plugin. - * - * Make sure you specify a directory for your files. If you don't, we - * will use PHP's directory for session-storage instead, and you might - * not want that. - * - * @param string|null $dataDir - */ - public function __construct($dataDir = null) { - if (!$dataDir) { - $dataDir = ini_get('session.save_path').'/sabredav/'; - } - if (!is_dir($dataDir)) { - mkdir($dataDir); - } - $this->dataDir = $dataDir; - } - /** * Initialize the plugin. * @@ -91,15 +67,28 @@ class BeforeCreateFilePlugin extends ServerPlugin { * @return bool */ public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { - if ($tempPath = $this->isTempFile($uri)) { - $hR = $this->server->httpResponse; - $hR->setHeader('X-Sabre-Temp', 'true'); - file_put_contents($tempPath, $data); + if (is_resource($data)) { + $data = stream_get_contents($data); + } + // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' + if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { + // Set the base URL for the meeting + $baseURL = 'https://meet.jit.si/'; + + // Generate a random alphanumeric string of length 8 + $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; + $randomString = substr(str_shuffle($chars), 0, 8); + + // Append the current date to the random string + $randomString .= date('dmy'); + + // Create the complete meeting URL + $meetingURL = $baseURL . $randomString; - return false; + // Replace the first occurrence of 'SUMMARY:' with 'SUMMARY:' followed by 'LOCATION:' + $data = preg_replace('/(SUMMARY:[^\r\n]*)/', "$1\nLOCATION: $meetingURL", $data); } - return; } -- GitLab From 84b2c436b956c51acef793f4e89313c3aa74ba56 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sun, 30 Jul 2023 19:58:41 +0530 Subject: [PATCH 17/34] jitsi fix --- lib/AppInfo/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 8ba5fa415..f67c1da59 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -133,7 +133,8 @@ class Application extends App implements IBootstrap { // executed in the order that it is registered $containerinvite->registerMiddleware("InvitationMiddleware"); - + $appContainer = $context->getAppContainer(); + $serverContainer = $context->getServerContainer(); $eventDispatcher = $serverContainer->get(IEventDispatcher::class); $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) { \OC::$server->getLogger()->error("calendar111"); -- GitLab From 7453de3ce5488e327ecf034a28ec0fafe7a85436 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sun, 30 Jul 2023 20:52:21 +0530 Subject: [PATCH 18/34] jitsi fix --- appinfo/info.xml | 3 +++ lib/AppInfo/Application.php | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 449f49c5d..3f09c08ae 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -20,6 +20,9 @@ Anna Larch Nextcloud Groupware Team Calendar + + + https://docs.nextcloud.com/server/latest/user_manual/en/groupware/calendar.html https://docs.nextcloud.com/server/latest/admin_manual/groupware/calendar.html diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index f67c1da59..aeeadc10f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -133,15 +133,12 @@ class Application extends App implements IBootstrap { // executed in the order that it is registered $containerinvite->registerMiddleware("InvitationMiddleware"); - $appContainer = $context->getAppContainer(); + $serverContainer = $context->getServerContainer(); $eventDispatcher = $serverContainer->get(IEventDispatcher::class); $eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) { - \OC::$server->getLogger()->error("calendar111"); $eventServer = $event->getServer(); - if ($eventServer !== null) { - \OC::$server->getLogger()->error("calendar111 if"); $plugin = $context->getAppContainer()->get(BeforeCreateFilePlugin::class); $eventServer->addPlugin($plugin); } -- GitLab From 8953763a74694377ec20013ce156818f3d795ae7 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sun, 30 Jul 2023 20:56:25 +0530 Subject: [PATCH 19/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 6806c9d3b..7c45586a4 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -66,7 +66,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { * * @return bool */ - public function beforeCreateFile($uri, $data, ICollection $parent, $modified) { + public function beforeCreateFile($uri, &$data, ICollection $parent, $modified) { if (is_resource($data)) { $data = stream_get_contents($data); } -- GitLab From 993c5a56bc022729c1c9da8e544b4e43a0884306 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sun, 30 Jul 2023 20:57:35 +0530 Subject: [PATCH 20/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 7c45586a4..5c95aaa90 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -66,7 +66,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { * * @return bool */ - public function beforeCreateFile($uri, &$data, ICollection $parent, $modified) { + public function beforeCreateFile($uri, &$data, DAV\ICollection $parentNode, &$modified) { if (is_resource($data)) { $data = stream_get_contents($data); } -- GitLab From 7d5ebc924dc9a5d5e3e669127b72b6be62eb58b2 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sun, 30 Jul 2023 20:58:31 +0530 Subject: [PATCH 21/34] jitsi fix --- lib/AppInfo/Application.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index aeeadc10f..3156b97c2 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -74,10 +74,6 @@ class Application extends App implements IBootstrap { $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerNotifierService(Notifier::class); - /*$context->registerEventListener( - 'OCA\DAV\Connector\Sabre::addPlugin', - 'OCA\Calendar\Dav\BeforeCreateFilePlugin' - );*/ } /** -- GitLab From 014de3d0cd25e7b39e483edcd178a13ad36e06d2 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Sun, 30 Jul 2023 21:07:58 +0530 Subject: [PATCH 22/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 5c95aaa90..3644bf469 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace OCA\Calendar\Dav; +use Sabre\DAV\INode; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; @@ -66,7 +67,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { * * @return bool */ - public function beforeCreateFile($uri, &$data, DAV\ICollection $parentNode, &$modified) { + public function beforeCreateFile($uri, &$data, INode $parent, &$modified) { if (is_resource($data)) { $data = stream_get_contents($data); } -- GitLab From fbcd10c948ec90679f3728a210356c662749b5d0 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 31 Jul 2023 10:18:00 +0530 Subject: [PATCH 23/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 3644bf469..b7f055f1e 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -8,30 +8,6 @@ use Sabre\DAV\INode; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; -/** - * Temporary File Filter Plugin. - * - * The purpose of this filter is to intercept some of the garbage files - * operation systems and applications tend to generate when mounting - * a WebDAV share as a disk. - * - * It will intercept these files and place them in a separate directory. - * these files are not deleted automatically, so it is advisable to - * delete these after they are not accessed for 24 hours. - * - * Currently it supports: - * * OS/X style resource forks and .DS_Store - * * desktop.ini and Thumbs.db (windows) - * * .*.swp (vim temporary files) - * * .dat.* (smultron temporary files) - * - * Additional patterns can be added, by adding on to the - * temporaryFilePatterns property. - * - * @copyright Copyright (C) fruux GmbH (https://fruux.com/) - * @author Evert Pot (http://evertpot.com/) - * @license http://sabre.io/license/ Modified BSD License - */ class BeforeCreateFilePlugin extends ServerPlugin { /** -- GitLab From a0c882a52c8a0f9f9ab704f9dbeaeb075dce1199 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 31 Jul 2023 10:20:54 +0530 Subject: [PATCH 24/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index b7f055f1e..c3effa811 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -31,18 +31,14 @@ class BeforeCreateFilePlugin extends ServerPlugin { /** - * This method is invoked if some subsystem creates a new file. + * Assign jitsi link to location * - * This is used to deal with HTTP LOCK requests which create a new - * file. - * - * @param string $uri - * @param resource $data - * @param bool $modified should be set to true, if this event handler - * changed &$data - * - * @return bool + * @param string $uri target file URI + * @param resource $data data + * @param INode $parent Sabre Node + * @param bool $modified modified */ + public function beforeCreateFile($uri, &$data, INode $parent, &$modified) { if (is_resource($data)) { $data = stream_get_contents($data); -- GitLab From 3c64837d71deb87dede0bb6a185bc26d3bf2f720 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 31 Jul 2023 10:25:49 +0530 Subject: [PATCH 25/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index c3effa811..5435be3a8 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -63,6 +63,6 @@ class BeforeCreateFilePlugin extends ServerPlugin { } } - + return true; } -- GitLab From 1db98fd071f6271b1e6c928e13509255804d68e7 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 31 Jul 2023 10:26:27 +0530 Subject: [PATCH 26/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 5435be3a8..cc80942d1 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -61,8 +61,9 @@ class BeforeCreateFilePlugin extends ServerPlugin { // Replace the first occurrence of 'SUMMARY:' with 'SUMMARY:' followed by 'LOCATION:' $data = preg_replace('/(SUMMARY:[^\r\n]*)/', "$1\nLOCATION: $meetingURL", $data); } + return true; } - return true; + } -- GitLab From 28ec6debc7d49597a358d9c8f69f202a195bbabf Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Mon, 31 Jul 2023 10:32:25 +0530 Subject: [PATCH 27/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index cc80942d1..483767a3d 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -37,6 +37,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { * @param resource $data data * @param INode $parent Sabre Node * @param bool $modified modified + * @return bool */ public function beforeCreateFile($uri, &$data, INode $parent, &$modified) { -- GitLab From c9927ec2c785734d86ff01d99af735d7dae02a36 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 1 Aug 2023 14:07:49 +0530 Subject: [PATCH 28/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 483767a3d..9ac0e062c 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -7,6 +7,7 @@ namespace OCA\Calendar\Dav; use Sabre\DAV\INode; use Sabre\DAV\Server; use Sabre\DAV\ServerPlugin; +use Sabre\VObject\Reader; class BeforeCreateFilePlugin extends ServerPlugin { @@ -44,6 +45,13 @@ class BeforeCreateFilePlugin extends ServerPlugin { if (is_resource($data)) { $data = stream_get_contents($data); } + // Parse the data as a vCalendar object using Sabre\VObject. + try { + $vCalendar = Reader::read($data); + } catch (\Exception $e) { + // The data is not a valid vCalendar object. + return false; + } // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { // Set the base URL for the meeting -- GitLab From fcb94254d242c976d5f018615c867377a237e9e3 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 1 Aug 2023 15:24:04 +0530 Subject: [PATCH 29/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 9ac0e062c..1d316fb78 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -67,8 +67,8 @@ class BeforeCreateFilePlugin extends ServerPlugin { // Create the complete meeting URL $meetingURL = $baseURL . $randomString; - // Replace the first occurrence of 'SUMMARY:' with 'SUMMARY:' followed by 'LOCATION:' - $data = preg_replace('/(SUMMARY:[^\r\n]*)/', "$1\nLOCATION: $meetingURL", $data); + // Replace the BEGIN:VEVENT/ with 'BEGIN:VEVENT' followed by 'LOCATION:' + $data = preg_replace('/BEGIN:VEVENT/', "BEGIN:VEVENT\nLOCATION:$meetingURL", $data); } return true; -- GitLab From ebdeeff63e0329b56e84cd37c8363b85a6bc2472 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 1 Aug 2023 19:04:07 +0530 Subject: [PATCH 30/34] jitsi fix --- lib/Dav/BeforeCreateFilePlugin.php | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 1d316fb78..480b836d1 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -27,6 +27,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { public function initialize(Server $server) { $this->server = $server; $server->on('beforeCreateFile', [$this, 'beforeCreateFile']); + $server->on('beforeWriteContent', [$this, 'beforeWriteContent']); } @@ -74,5 +75,48 @@ class BeforeCreateFilePlugin extends ServerPlugin { } + /** + * Assign jitsi link to location + * + * @param string $uri target file URI + * @param INode $parent Sabre Node + * @param resource $data data + * @param bool $modified modified + * @return bool + */ + + public function beforeWriteContent($uri, INode $parent, &$data, &$modified) { + if (is_resource($data)) { + $data = stream_get_contents($data); + } + // Parse the data as a vCalendar object using Sabre\VObject. + try { + $vCalendar = Reader::read($data); + } catch (\Exception $e) { + // The data is not a valid vCalendar object. + return false; + } + // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' + if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { + // Set the base URL for the meeting + $baseURL = 'https://meet.jit.si/'; + + // Generate a random alphanumeric string of length 8 + $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; + $randomString = substr(str_shuffle($chars), 0, 8); + + // Append the current date to the random string + $randomString .= date('dmy'); + + // Create the complete meeting URL + $meetingURL = $baseURL . $randomString; + + // Replace the BEGIN:VEVENT/ with 'BEGIN:VEVENT' followed by 'LOCATION:' + $data = preg_replace('/BEGIN:VEVENT/', "BEGIN:VEVENT\nLOCATION:$meetingURL", $data); + } + return true; + + } + } -- GitLab From 7ed4a2efe8f276764d776fbc7a28382cdfffc06a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 2 Aug 2023 15:23:33 +0530 Subject: [PATCH 31/34] code refactoring --- lib/Dav/BeforeCreateFilePlugin.php | 36 +++++++++++------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 480b836d1..0b31e8840 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -53,24 +53,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { // The data is not a valid vCalendar object. return false; } - // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' - if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { - // Set the base URL for the meeting - $baseURL = 'https://meet.jit.si/'; - - // Generate a random alphanumeric string of length 8 - $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; - $randomString = substr(str_shuffle($chars), 0, 8); - - // Append the current date to the random string - $randomString .= date('dmy'); - - // Create the complete meeting URL - $meetingURL = $baseURL . $randomString; - - // Replace the BEGIN:VEVENT/ with 'BEGIN:VEVENT' followed by 'LOCATION:' - $data = preg_replace('/BEGIN:VEVENT/', "BEGIN:VEVENT\nLOCATION:$meetingURL", $data); - } + $this->processEventData($data); return true; } @@ -96,6 +79,17 @@ class BeforeCreateFilePlugin extends ServerPlugin { // The data is not a valid vCalendar object. return false; } + $this->processEventData($data); + return true; + + } + + /** + * Process event data and assign a Jitsi link to the event location. + * + * @param string $data Data + */ + private function processEventData(&$data) { // Check if the data contains 'ATTENDEE;' but not 'LOCATION:' if (strpos($data, 'ATTENDEE;') !== false && strpos($data, 'LOCATION:') === false) { // Set the base URL for the meeting @@ -111,12 +105,8 @@ class BeforeCreateFilePlugin extends ServerPlugin { // Create the complete meeting URL $meetingURL = $baseURL . $randomString; - // Replace the BEGIN:VEVENT/ with 'BEGIN:VEVENT' followed by 'LOCATION:' + // Replace the BEGIN:VEVENT/ with 'BEGIN:VEVENT' followed by 'LOCATION:' $data = preg_replace('/BEGIN:VEVENT/', "BEGIN:VEVENT\nLOCATION:$meetingURL", $data); } - return true; - } - - } -- GitLab From 0abeea72f83c2780a20caa0589dd37b830273404 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 2 Aug 2023 15:35:04 +0530 Subject: [PATCH 32/34] code refactoring --- lib/Dav/BeforeCreateFilePlugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 0b31e8840..05d6a867f 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -54,7 +54,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { return false; } $this->processEventData($data); - return true; + return; } @@ -80,7 +80,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { return false; } $this->processEventData($data); - return true; + return; } -- GitLab From b03ef67c00d64f9dfa5408000585f970d98e71da Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 2 Aug 2023 15:35:49 +0530 Subject: [PATCH 33/34] code refactoring --- lib/Dav/BeforeCreateFilePlugin.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index 05d6a867f..e84988014 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -39,7 +39,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { * @param resource $data data * @param INode $parent Sabre Node * @param bool $modified modified - * @return bool + * @return */ public function beforeCreateFile($uri, &$data, INode $parent, &$modified) { @@ -51,7 +51,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { $vCalendar = Reader::read($data); } catch (\Exception $e) { // The data is not a valid vCalendar object. - return false; + return; } $this->processEventData($data); return; @@ -65,7 +65,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { * @param INode $parent Sabre Node * @param resource $data data * @param bool $modified modified - * @return bool + * @return */ public function beforeWriteContent($uri, INode $parent, &$data, &$modified) { @@ -77,7 +77,7 @@ class BeforeCreateFilePlugin extends ServerPlugin { $vCalendar = Reader::read($data); } catch (\Exception $e) { // The data is not a valid vCalendar object. - return false; + return; } $this->processEventData($data); return; -- GitLab From 142b1391d5b513728a817390afd4779b94c09d34 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 2 Aug 2023 15:52:44 +0530 Subject: [PATCH 34/34] code refactoring --- lib/Dav/BeforeCreateFilePlugin.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Dav/BeforeCreateFilePlugin.php b/lib/Dav/BeforeCreateFilePlugin.php index e84988014..373fa13f3 100644 --- a/lib/Dav/BeforeCreateFilePlugin.php +++ b/lib/Dav/BeforeCreateFilePlugin.php @@ -54,7 +54,6 @@ class BeforeCreateFilePlugin extends ServerPlugin { return; } $this->processEventData($data); - return; } @@ -80,8 +79,6 @@ class BeforeCreateFilePlugin extends ServerPlugin { return; } $this->processEventData($data); - return; - } /** -- GitLab