import caldav
This commit is contained in:
parent
f664bc3b2a
commit
7ec1602335
@ -38,6 +38,7 @@
|
||||
"symfony/swiftmailer-bundle": "^2.6.4",
|
||||
"symfony/symfony": "3.4.*",
|
||||
"tetranz/select2entity-bundle": "2.*",
|
||||
"thecsea/simple-caldav-client": "^0.1.10",
|
||||
"twig/twig": "^1.0||^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
|
113
src/ninegate-1.0/composer.lock
generated
113
src/ninegate-1.0/composer.lock
generated
@ -4,8 +4,8 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "2a3f597051554e40aa4b6ba10405d656",
|
||||
"content-hash": "04339c394373f4030131258933c232ea",
|
||||
"hash": "8ad66c1cc79500add7118e829f63f6a9",
|
||||
"content-hash": "15efa0e4514b73fe595c60779f3eec40",
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/ca-bundle",
|
||||
@ -65,16 +65,16 @@
|
||||
},
|
||||
{
|
||||
"name": "debril/feed-io",
|
||||
"version": "v3.1.3",
|
||||
"version": "v3.1.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alexdebril/feed-io.git",
|
||||
"reference": "a0035d9bfe7c9ac1333242447fab781ae89fe8af"
|
||||
"reference": "a8ae664c948f0ca926150cc4597f343af797b4b0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/alexdebril/feed-io/zipball/a0035d9bfe7c9ac1333242447fab781ae89fe8af",
|
||||
"reference": "a0035d9bfe7c9ac1333242447fab781ae89fe8af",
|
||||
"url": "https://api.github.com/repos/alexdebril/feed-io/zipball/a8ae664c948f0ca926150cc4597f343af797b4b0",
|
||||
"reference": "a8ae664c948f0ca926150cc4597f343af797b4b0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -121,7 +121,7 @@
|
||||
"news",
|
||||
"rss"
|
||||
],
|
||||
"time": "2019-03-11 15:08:14"
|
||||
"time": "2019-04-12 11:48:51"
|
||||
},
|
||||
{
|
||||
"name": "debril/rss-atom-bundle",
|
||||
@ -1725,16 +1725,16 @@
|
||||
},
|
||||
{
|
||||
"name": "jasig/phpcas",
|
||||
"version": "1.3.6",
|
||||
"version": "1.3.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/apereo/phpCAS.git",
|
||||
"reference": "7972833e84f6ee5fa41f1479eab5d855109627f5"
|
||||
"reference": "b5b29102c3a42f570c4a3e852f3cf67cae6d6082"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/apereo/phpCAS/zipball/7972833e84f6ee5fa41f1479eab5d855109627f5",
|
||||
"reference": "7972833e84f6ee5fa41f1479eab5d855109627f5",
|
||||
"url": "https://api.github.com/repos/apereo/phpCAS/zipball/b5b29102c3a42f570c4a3e852f3cf67cae6d6082",
|
||||
"reference": "b5b29102c3a42f570c4a3e852f3cf67cae6d6082",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1776,7 +1776,7 @@
|
||||
"cas",
|
||||
"jasig"
|
||||
],
|
||||
"time": "2018-10-25 20:22:09"
|
||||
"time": "2019-04-22 19:48:16"
|
||||
},
|
||||
{
|
||||
"name": "jdorn/sql-formatter",
|
||||
@ -3679,16 +3679,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/symfony",
|
||||
"version": "v3.4.23",
|
||||
"version": "v3.4.26",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/symfony.git",
|
||||
"reference": "336cf12e5e82d71874e8522e0879794340351b56"
|
||||
"reference": "1b89e7baec9891c323bbf1ec81af77d901fc60c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/symfony/zipball/336cf12e5e82d71874e8522e0879794340351b56",
|
||||
"reference": "336cf12e5e82d71874e8522e0879794340351b56",
|
||||
"url": "https://api.github.com/repos/symfony/symfony/zipball/1b89e7baec9891c323bbf1ec81af77d901fc60c9",
|
||||
"reference": "1b89e7baec9891c323bbf1ec81af77d901fc60c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -3830,7 +3830,7 @@
|
||||
"keywords": [
|
||||
"framework"
|
||||
],
|
||||
"time": "2019-03-03 18:52:48"
|
||||
"time": "2019-04-17 15:57:27"
|
||||
},
|
||||
{
|
||||
"name": "tetranz/select2entity-bundle",
|
||||
@ -3880,17 +3880,60 @@
|
||||
"time": "2018-03-05 02:52:46"
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v2.7.4",
|
||||
"name": "thecsea/simple-caldav-client",
|
||||
"version": "v0.1.10",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "ed9c49220e09bfaeb1ba4d48077c08a7b09908dd"
|
||||
"url": "https://github.com/thecsea/simpleCalDAV.git",
|
||||
"reference": "dae70da0dacd0c8a1e184fbc91ecbe6f7fa5dea9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/ed9c49220e09bfaeb1ba4d48077c08a7b09908dd",
|
||||
"reference": "ed9c49220e09bfaeb1ba4d48077c08a7b09908dd",
|
||||
"url": "https://api.github.com/repos/thecsea/simpleCalDAV/zipball/dae70da0dacd0c8a1e184fbc91ecbe6f7fa5dea9",
|
||||
"reference": "dae70da0dacd0c8a1e184fbc91ecbe6f7fa5dea9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"it\\thecsea\\simple_caldav_client\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPL-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "claudio cardinale",
|
||||
"email": "cardi@thecsea.it",
|
||||
"homepage": "http://thecsea.it"
|
||||
}
|
||||
],
|
||||
"description": "A simple and complete php caldav client",
|
||||
"homepage": "http://www.thecsea.it",
|
||||
"keywords": [
|
||||
"CalDAV",
|
||||
"Simple",
|
||||
"client"
|
||||
],
|
||||
"time": "2019-04-25 19:55:16"
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v2.8.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "91cc2594d3143761ce0399c1caffd0b500ffe5b9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/91cc2594d3143761ce0399c1caffd0b500ffe5b9",
|
||||
"reference": "91cc2594d3143761ce0399c1caffd0b500ffe5b9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -3906,7 +3949,7 @@
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.7-dev"
|
||||
"dev-master": "2.8-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@ -3944,7 +3987,7 @@
|
||||
"keywords": [
|
||||
"templating"
|
||||
],
|
||||
"time": "2019-03-23 14:28:58"
|
||||
"time": "2019-04-16 17:14:24"
|
||||
},
|
||||
{
|
||||
"name": "zendframework/zend-code",
|
||||
@ -4162,16 +4205,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/maker-bundle",
|
||||
"version": "v1.11.5",
|
||||
"version": "v1.11.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/maker-bundle.git",
|
||||
"reference": "186ffc80b8f363e04ea3c2ebf49e1263a84b4e39"
|
||||
"reference": "d262c2cace4d9bca99137a84f6fc6ba909a17e02"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/maker-bundle/zipball/186ffc80b8f363e04ea3c2ebf49e1263a84b4e39",
|
||||
"reference": "186ffc80b8f363e04ea3c2ebf49e1263a84b4e39",
|
||||
"url": "https://api.github.com/repos/symfony/maker-bundle/zipball/d262c2cace4d9bca99137a84f6fc6ba909a17e02",
|
||||
"reference": "d262c2cace4d9bca99137a84f6fc6ba909a17e02",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -4224,20 +4267,20 @@
|
||||
"scaffold",
|
||||
"scaffolding"
|
||||
],
|
||||
"time": "2019-03-11 15:55:09"
|
||||
"time": "2019-04-19 17:26:45"
|
||||
},
|
||||
{
|
||||
"name": "symfony/phpunit-bridge",
|
||||
"version": "v3.4.23",
|
||||
"version": "v3.4.26",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/phpunit-bridge.git",
|
||||
"reference": "b539f37134c10edbf85dc0567be4151c56870f5e"
|
||||
"reference": "a43a2f6c465a2d99635fea0addbebddc3864ad97"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/b539f37134c10edbf85dc0567be4151c56870f5e",
|
||||
"reference": "b539f37134c10edbf85dc0567be4151c56870f5e",
|
||||
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/a43a2f6c465a2d99635fea0addbebddc3864ad97",
|
||||
"reference": "a43a2f6c465a2d99635fea0addbebddc3864ad97",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -4289,7 +4332,7 @@
|
||||
],
|
||||
"description": "Symfony PHPUnit Bridge",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2019-02-16 18:50:26"
|
||||
"time": "2019-04-16 09:03:16"
|
||||
}
|
||||
],
|
||||
"aliases": [],
|
||||
|
@ -12,6 +12,7 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Doctrine\DBAL\Connection as DBALConnection;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\Validator\Constraints\DateTime;
|
||||
use it\thecsea\simple_caldav_client\SimpleCalDAVClient;
|
||||
|
||||
use Cadoles\PortalBundle\Entity\Calendarevent;
|
||||
|
||||
@ -399,7 +400,8 @@ class SynchroICSCommand extends Command
|
||||
->setDescription('Synchronize external ICS URL')
|
||||
->setHelp('Synchronize external ICS URL')
|
||||
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
|
||||
->addArgument('idcalendar', InputArgument::OPTIONAL, 'ID Calendar to synchronize')
|
||||
;
|
||||
}
|
||||
|
||||
@ -412,6 +414,9 @@ class SynchroICSCommand extends Command
|
||||
$this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
|
||||
$alias = $this->container->getParameter('alias');
|
||||
|
||||
$idcalendar = $input->getArgument('idcalendar');
|
||||
|
||||
|
||||
$PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYactivate"])->getValue();
|
||||
$PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYserver"])->getValue();
|
||||
$PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYport"])->getValue();
|
||||
@ -423,94 +428,196 @@ class SynchroICSCommand extends Command
|
||||
$now=new \DateTime('now');
|
||||
$fgdebug = false;
|
||||
|
||||
$calendars=$this->em->getRepository("CadolesPortalBundle:Calendar")->findBy(["type"=>1]);
|
||||
|
||||
if($idcalendar=="")
|
||||
$calendars=$this->em->getRepository("CadolesPortalBundle:Calendar")->findAll();
|
||||
else
|
||||
$calendars=$this->em->getRepository("CadolesPortalBundle:Calendar")->findBy(["id"=>$idcalendar]);
|
||||
|
||||
foreach($calendars as $calendar) {
|
||||
$this->writeln($calendar->getUrl());
|
||||
$client = new CalFileParser();
|
||||
|
||||
try {
|
||||
if($PROXYactivate)
|
||||
$cal = $client->parse($calendar->getUrl(), '', array("proxy"=>$PROXYserver.":".$PROXYport));
|
||||
else
|
||||
$cal = $client->parse($calendar->getUrl());
|
||||
|
||||
$tbuid=array();
|
||||
|
||||
foreach($cal as $event) {
|
||||
$event["SUMMARY"] = (isset($event["SUMMARY"])?$event["SUMMARY"]:"");
|
||||
$event["DESCRIPTION"] = (isset($event["DESCRIPTION"])?$event["DESCRIPTION"]:"");
|
||||
$event["DTSTART"] = (isset($event["DTSTART"])?$event["DTSTART"]:"");
|
||||
$event["DTEND"] = (isset($event["DTEND"])?$event["DTEND"]:"");
|
||||
$event["ALLDAY"] = (isset($event["ALLDAY"])?$event["ALLDAY"]:"");
|
||||
$event["SEQUENCE"] = (isset($event["SEQUENCE"])?$event["SEQUENCE"]:"");
|
||||
$event["UID"] = (isset($event["UID"])?$event["UID"]:"");
|
||||
|
||||
if($fgdebug) {
|
||||
echo "<br>";
|
||||
echo "<br>SUMMARY = ".$event["SUMMARY"];
|
||||
echo "<br>DESCRIPTION = ".$event["DESCRIPTION"];
|
||||
echo "<br>DTSTART = ".$event["DTSTART"]->format('d/m/Y H:i:s');
|
||||
echo "<br>DTEND = ".$event["DTEND"]->format('d/m/Y H:i:s');
|
||||
echo "<br>ALLDAY = ".$event["ALLDAY"];
|
||||
echo "<br>SEQUENCE = ".$event["SEQUENCE"];
|
||||
echo "<br>UID = ".$event["UID"];
|
||||
}
|
||||
switch($calendar->getType()) {
|
||||
// ICS
|
||||
case 1:
|
||||
$this->writeln($calendar->getId()." = ICS = ".$calendar->getUrl());
|
||||
$client = new CalFileParser();
|
||||
|
||||
if($event["UID"]!="") {
|
||||
// On sauvegarde l'uid
|
||||
array_push($tbuid,$event["UID"]);
|
||||
|
||||
// Allday ?
|
||||
$allday=0;
|
||||
if($event["ALLDAY"]==1||$event["SEQUENCE"]>=1)
|
||||
$allday=1;
|
||||
|
||||
// Cas particulier
|
||||
if($allday==0&&$event["SEQUENCE"]==0) {
|
||||
if($event["DTSTART"]->format('H:i:s')=='00:00:00'&&$event["DTEND"]->format('H:i:s')=='00:00:00')
|
||||
$allday=1;
|
||||
}
|
||||
|
||||
// On recherche l'uid dans le calendrier
|
||||
$toset=false;
|
||||
$calendarevent=$this->em->getRepository("CadolesPortalBundle:Calendarevent")->findOneBy(["uid"=>$event["UID"]]);
|
||||
if($calendarevent) {
|
||||
if($event["SUMMARY"]!=$calendarevent->getName()||$event["DESCRIPTION"]!=$calendarevent->getDescription()||$event["DTSTART"]!=$calendarevent->getStart()||$event["DTEND"]!=$calendarevent->getEnd()||$allday!=$calendarevent->getAllday()) {
|
||||
$toset=true;
|
||||
try {
|
||||
if($PROXYactivate)
|
||||
$cal = $client->parse($calendar->getUrl(), '', array("proxy"=>$PROXYserver.":".$PROXYport));
|
||||
else
|
||||
$cal = $client->parse($calendar->getUrl());
|
||||
|
||||
$tbuid=array();
|
||||
|
||||
foreach($cal as $event) {
|
||||
$event["SUMMARY"] = (isset($event["SUMMARY"])?$event["SUMMARY"]:"");
|
||||
$event["DESCRIPTION"] = (isset($event["DESCRIPTION"])?$event["DESCRIPTION"]:"");
|
||||
$event["DTSTART"] = (isset($event["DTSTART"])?$event["DTSTART"]:"");
|
||||
$event["DTEND"] = (isset($event["DTEND"])?$event["DTEND"]:"");
|
||||
$event["ALLDAY"] = (isset($event["ALLDAY"])?$event["ALLDAY"]:"");
|
||||
$event["SEQUENCE"] = (isset($event["SEQUENCE"])?$event["SEQUENCE"]:"");
|
||||
$event["UID"] = (isset($event["UID"])?$event["UID"]:"");
|
||||
|
||||
if($fgdebug) {
|
||||
echo "<br>";
|
||||
echo "<br>SUMMARY = ".$event["SUMMARY"];
|
||||
echo "<br>DESCRIPTION = ".$event["DESCRIPTION"];
|
||||
echo "<br>DTSTART = ".$event["DTSTART"]->format('d/m/Y H:i:s');
|
||||
echo "<br>DTEND = ".$event["DTEND"]->format('d/m/Y H:i:s');
|
||||
echo "<br>ALLDAY = ".$event["ALLDAY"];
|
||||
echo "<br>SEQUENCE = ".$event["SEQUENCE"];
|
||||
echo "<br>UID = ".$event["UID"];
|
||||
}
|
||||
|
||||
if($event["UID"]!="") {
|
||||
// On sauvegarde l'uid
|
||||
array_push($tbuid,$event["UID"]);
|
||||
|
||||
// Allday ?
|
||||
$allday=0;
|
||||
if($event["ALLDAY"]==1||$event["SEQUENCE"]>=1)
|
||||
$allday=1;
|
||||
|
||||
// Cas particulier
|
||||
if($allday==0&&$event["SEQUENCE"]==0) {
|
||||
if($event["DTSTART"]->format('H:i:s')=='00:00:00'&&$event["DTEND"]->format('H:i:s')=='00:00:00')
|
||||
$allday=1;
|
||||
}
|
||||
|
||||
// On recherche l'uid dans le calendrier
|
||||
$toset=false;
|
||||
$calendarevent=$this->em->getRepository("CadolesPortalBundle:Calendarevent")->findOneBy(["uid"=>$event["UID"]]);
|
||||
if($calendarevent) {
|
||||
if($event["SUMMARY"]!=$calendarevent->getName()||$event["DESCRIPTION"]!=$calendarevent->getDescription()||$event["DTSTART"]!=$calendarevent->getStart()||$event["DTEND"]!=$calendarevent->getEnd()||$allday!=$calendarevent->getAllday()) {
|
||||
$toset=true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$toset=true;
|
||||
$calendarevent=new Calendarevent();
|
||||
}
|
||||
|
||||
if($toset) {
|
||||
$calendarevent->setName($event["SUMMARY"]);
|
||||
$calendarevent->setDescription($event["DESCRIPTION"]);
|
||||
$calendarevent->setStart($event["DTSTART"]);
|
||||
$calendarevent->setEnd($event["DTEND"]);
|
||||
$calendarevent->setAllday($allday);
|
||||
$calendarevent->setUid($event["UID"]);
|
||||
$calendarevent->setCalendar($calendar);
|
||||
|
||||
$this->em->persist($calendarevent);
|
||||
$this->em->flush();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$toset=true;
|
||||
$calendarevent=new Calendarevent();
|
||||
}
|
||||
|
||||
// Purge des évènements plus présent
|
||||
$calendarevents=$this->em->getRepository("CadolesPortalBundle:Calendarevent")->findBy(["calendar"=>$calendar]);
|
||||
foreach($calendarevents as $calendarevent) {
|
||||
if(!in_array($calendarevent->getUid(),$tbuid)) {
|
||||
$this->em->remove($calendarevent);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->writelnred($e->__toString());
|
||||
}
|
||||
break;
|
||||
|
||||
if($toset) {
|
||||
$calendarevent->setName($event["SUMMARY"]);
|
||||
$calendarevent->setDescription($event["DESCRIPTION"]);
|
||||
$calendarevent->setStart($event["DTSTART"]);
|
||||
$calendarevent->setEnd($event["DTEND"]);
|
||||
$calendarevent->setAllday($allday);
|
||||
$calendarevent->setUid($event["UID"]);
|
||||
$calendarevent->setCalendar($calendar);
|
||||
|
||||
$this->em->persist($calendarevent);
|
||||
$this->em->flush();
|
||||
|
||||
}
|
||||
// CalDav
|
||||
case 2:
|
||||
$this->writeln($calendar->getId()." = CalDAV = ".$calendar->getUrl());
|
||||
|
||||
$client = new SimpleCalDAVClient();
|
||||
try {
|
||||
if($PROXYactivate)
|
||||
$client->connect($calendar->getUrl(), $calendar->getLogin(), $calendar->getPasswordDecrypt(),['proxy_host'=>$PROXYserver.":".$PROXYport,'timeout'=>5]);
|
||||
else
|
||||
$client->connect($calendar->getUrl(), $calendar->getLogin(), $calendar->getPasswordDecrypt(),['timeout'=>5]);
|
||||
}
|
||||
}
|
||||
|
||||
// Purge des évènements plus présent
|
||||
$calendarevents=$this->em->getRepository("CadolesPortalBundle:Calendarevent")->findBy(["calendar"=>$calendar]);
|
||||
foreach($calendarevents as $calendarevent) {
|
||||
if(!in_array($calendarevent->getUid(),$tbuid)) {
|
||||
$this->em->remove($calendarevent);
|
||||
$this->em->flush();
|
||||
catch (Exception $e) {
|
||||
dump($e->__toString());
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->writeln("connected");
|
||||
$this->writeln("");
|
||||
$tbuid=array();
|
||||
$arrayOfCalendars = $client->findCalendars();
|
||||
foreach($arrayOfCalendars as $calcalendar) {
|
||||
$client->setCalendar($calcalendar);
|
||||
$events = $client->getEvents();
|
||||
|
||||
foreach ($events as $calevent) {
|
||||
$event=$this->icsToArray($calevent->getData())[2];
|
||||
|
||||
$event["SUMMARY"] = (isset($event["SUMMARY"])?$event["SUMMARY"]:"");
|
||||
$event["DESCRIPTION"] = (isset($event["DESCRIPTION"])?$event["DESCRIPTION"]:"");
|
||||
$event["DTSTART"] = (isset($event["DTSTART;VALUE=DATE"])?new \datetime($event["DTSTART;VALUE=DATE"]):"");
|
||||
$event["DTEND"] = (isset($event["DTEND;VALUE=DATE"])?new \datetime($event["DTEND;VALUE=DATE"]):"");
|
||||
$event["ALLDAY"] = (isset($event["ALLDAY"])?$event["ALLDAY"]:"");
|
||||
$event["SEQUENCE"] = (isset($event["SEQUENCE"])?$event["SEQUENCE"]:"");
|
||||
$event["UID"] = (isset($event["UID"])?$event["UID"]:"");
|
||||
|
||||
if($event["UID"]!="") {
|
||||
// On sauvegarde l'uid
|
||||
array_push($tbuid,$event["UID"]);
|
||||
|
||||
// Allday ?
|
||||
$allday=0;
|
||||
if($event["ALLDAY"]==1||$event["SEQUENCE"]>=1)
|
||||
$allday=1;
|
||||
|
||||
// Cas particulier
|
||||
if($allday==0&&$event["SEQUENCE"]==0) {
|
||||
if($event["DTSTART"]->format('H:i:s')=='00:00:00'&&$event["DTEND"]->format('H:i:s')=='00:00:00')
|
||||
$allday=1;
|
||||
}
|
||||
|
||||
// On recherche l'uid dans le calendrier
|
||||
$toset=false;
|
||||
$calendarevent=$this->em->getRepository("CadolesPortalBundle:Calendarevent")->findOneBy(["uid"=>$event["UID"]]);
|
||||
if($calendarevent) {
|
||||
if($event["SUMMARY"]!=$calendarevent->getName()||$event["DESCRIPTION"]!=$calendarevent->getDescription()||$event["DTSTART"]!=$calendarevent->getStart()||$event["DTEND"]!=$calendarevent->getEnd()||$allday!=$calendarevent->getAllday()) {
|
||||
$toset=true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$toset=true;
|
||||
$calendarevent=new Calendarevent();
|
||||
}
|
||||
|
||||
if($toset) {
|
||||
$calendarevent->setName($event["SUMMARY"]);
|
||||
$calendarevent->setDescription($event["DESCRIPTION"]);
|
||||
$calendarevent->setStart($event["DTSTART"]);
|
||||
$calendarevent->setEnd($event["DTEND"]);
|
||||
$calendarevent->setAllday($allday);
|
||||
$calendarevent->setUid($event["UID"]);
|
||||
$calendarevent->setCalendar($calendar);
|
||||
|
||||
$this->em->persist($calendarevent);
|
||||
$this->em->flush();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Purge des évènements plus présent
|
||||
$calendarevents=$this->em->getRepository("CadolesPortalBundle:Calendarevent")->findBy(["calendar"=>$calendar]);
|
||||
foreach($calendarevents as $calendarevent) {
|
||||
if(!in_array($calendarevent->getUid(),$tbuid)) {
|
||||
$this->em->remove($calendarevent);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->writelnred($e->__toString());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -518,6 +625,31 @@ class SynchroICSCommand extends Command
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function icsToArray($icsFile) {
|
||||
$icsData = explode("BEGIN:", $icsFile);
|
||||
|
||||
foreach($icsData as $key => $value) {
|
||||
$icsDatesMeta[$key] = explode("\n", $value);
|
||||
}
|
||||
|
||||
foreach($icsDatesMeta as $key => $value) {
|
||||
foreach($value as $subKey => $subValue) {
|
||||
if ($subValue != "") {
|
||||
if ($key != 0 && $subKey == 0) {
|
||||
$icsDates[$key]["BEGIN"] = $subValue;
|
||||
} else {
|
||||
//dump($subValue);
|
||||
$subValueArr = explode(":", $subValue, 2);
|
||||
//dump($subValueArr);
|
||||
$icsDates[$key][$subValueArr[0]] = $subValueArr[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $icsDates;
|
||||
}
|
||||
|
||||
private function writelnred($string) {
|
||||
$this->output->writeln('<fg=red>'.$string.'</>');
|
||||
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
|
||||
|
@ -188,7 +188,8 @@ class CalendarController extends Controller
|
||||
$em->getRepository($this->labelentity)->getPermission($this->getUser(),$entity,$cansee,$canupdate);
|
||||
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
|
||||
}
|
||||
|
||||
$oldpassword=$entity->getPasswordDecrypt();
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->entityForm($entity,$access);
|
||||
$form->handleRequest($request);
|
||||
@ -198,6 +199,17 @@ class CalendarController extends Controller
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$entity = $form->getData();
|
||||
|
||||
// Si pas de changement de password on replace l'ancien
|
||||
if($entity->getPasswordDecrypt()=="") {
|
||||
$entity->setPassword($oldpassword);
|
||||
}
|
||||
// Sinon on encode le nouveau
|
||||
else {
|
||||
$entity->setPasswordDirect($entity->getPassword());
|
||||
}
|
||||
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
|
@ -60,6 +60,29 @@ class Calendar
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="login", type="string", nullable=true)
|
||||
*/
|
||||
private $login;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="password", type="string", nullable=true)
|
||||
*/
|
||||
private $password;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="salt", type="string", nullable=true)
|
||||
*/
|
||||
private $salt;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
@ -103,6 +126,57 @@ class Calendar
|
||||
return $this;
|
||||
}
|
||||
|
||||
/* Password User */
|
||||
public function setPassword($password)
|
||||
{
|
||||
$length = 8;
|
||||
$cstrong = true;
|
||||
$cipher = 'aes-128-cbc';
|
||||
|
||||
if (in_array($cipher, openssl_get_cipher_methods()))
|
||||
{
|
||||
$ivlen = openssl_cipher_iv_length($cipher);
|
||||
$iv = openssl_random_pseudo_bytes($ivlen);
|
||||
$this->salt = uniqid(mt_rand(), true);
|
||||
|
||||
$ciphertext_raw = openssl_encrypt($password, $cipher, $this->salt, $options=OPENSSL_RAW_DATA, $iv);
|
||||
$hmac = hash_hmac('sha256', $ciphertext_raw, $this->salt, $as_binary=true);
|
||||
|
||||
$this->password = base64_encode( $iv.$hmac.$ciphertext_raw );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPasswordDirect($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function getPasswordDecrypt()
|
||||
{
|
||||
$c = base64_decode($this->password);
|
||||
$cipher = 'aes-128-cbc';
|
||||
|
||||
if (in_array($cipher, openssl_get_cipher_methods()))
|
||||
{
|
||||
$ivlen = openssl_cipher_iv_length($cipher);
|
||||
$iv = substr($c, 0, $ivlen);
|
||||
$hmac = substr($c, $ivlen, $sha2len=32);
|
||||
$ivlenSha2len = $ivlen+$sha2len;
|
||||
$ciphertext_raw = substr($c, $ivlen+$sha2len);
|
||||
$plainText = openssl_decrypt($ciphertext_raw, $cipher, $this->salt, $options=OPENSSL_RAW_DATA, $iv);
|
||||
}
|
||||
|
||||
return $plainText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@ -242,6 +316,56 @@ class Calendar
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set login
|
||||
*
|
||||
* @param string $login
|
||||
*
|
||||
* @return Calendar
|
||||
*/
|
||||
public function setLogin($login)
|
||||
{
|
||||
$this->login = $login;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get login
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLogin()
|
||||
{
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set salt
|
||||
*
|
||||
* @param string $salt
|
||||
*
|
||||
* @return Calendar
|
||||
*/
|
||||
public function setSalt($salt)
|
||||
{
|
||||
$this->salt = $salt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get salt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSalt()
|
||||
{
|
||||
return $this->salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set roles
|
||||
*
|
||||
|
@ -9,6 +9,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -38,6 +39,7 @@ class CalendarType extends AbstractType
|
||||
"choices" => [
|
||||
"Interne" => '0',
|
||||
"iCalendar (ICS)" => '1',
|
||||
"CalDAV" => '2',
|
||||
],
|
||||
"disabled" => ($options["mode"]=="delete"?true:false),
|
||||
])
|
||||
@ -45,6 +47,16 @@ class CalendarType extends AbstractType
|
||||
->add('url', TextType::class, [
|
||||
'label' => "URL",
|
||||
'required' => false,
|
||||
])
|
||||
|
||||
->add('login', TextType::class, [
|
||||
'label' => "Login",
|
||||
'required' => false,
|
||||
])
|
||||
|
||||
->add('password', PasswordType::class, [
|
||||
'label' => "Password",
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
if($options["access"]=="config") {
|
||||
|
@ -57,6 +57,11 @@
|
||||
<div id="url" style="display:none">
|
||||
{{ form_row(form.url) }}
|
||||
</div>
|
||||
<div id="login" style="display:none">
|
||||
{{ form_row(form.login) }}
|
||||
{{ form_row(form.password) }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{% if form.roles is defined %}
|
||||
@ -84,9 +89,17 @@
|
||||
|
||||
function showhide() {
|
||||
console.log($("#calendar_type").val());
|
||||
if($("#calendar_type").val()==1)
|
||||
if($("#calendar_type").val()==1) {
|
||||
$("#url").show();
|
||||
else
|
||||
$("#login").hide();
|
||||
}
|
||||
else if($("#calendar_type").val()==2) {
|
||||
$("#url").show();
|
||||
$("#login").show();
|
||||
}
|
||||
else {
|
||||
$("#url").hide();
|
||||
$("#login").hide();
|
||||
}
|
||||
}
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user