import caldav

This commit is contained in:
afornerot 2019-04-26 15:03:19 +02:00
parent f664bc3b2a
commit 7ec1602335
7 changed files with 456 additions and 119 deletions

View File

@ -38,6 +38,7 @@
"symfony/swiftmailer-bundle": "^2.6.4", "symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*", "symfony/symfony": "3.4.*",
"tetranz/select2entity-bundle": "2.*", "tetranz/select2entity-bundle": "2.*",
"thecsea/simple-caldav-client": "^0.1.10",
"twig/twig": "^1.0||^2.0" "twig/twig": "^1.0||^2.0"
}, },
"require-dev": { "require-dev": {

View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "2a3f597051554e40aa4b6ba10405d656", "hash": "8ad66c1cc79500add7118e829f63f6a9",
"content-hash": "04339c394373f4030131258933c232ea", "content-hash": "15efa0e4514b73fe595c60779f3eec40",
"packages": [ "packages": [
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",
@ -65,16 +65,16 @@
}, },
{ {
"name": "debril/feed-io", "name": "debril/feed-io",
"version": "v3.1.3", "version": "v3.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/alexdebril/feed-io.git", "url": "https://github.com/alexdebril/feed-io.git",
"reference": "a0035d9bfe7c9ac1333242447fab781ae89fe8af" "reference": "a8ae664c948f0ca926150cc4597f343af797b4b0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/alexdebril/feed-io/zipball/a0035d9bfe7c9ac1333242447fab781ae89fe8af", "url": "https://api.github.com/repos/alexdebril/feed-io/zipball/a8ae664c948f0ca926150cc4597f343af797b4b0",
"reference": "a0035d9bfe7c9ac1333242447fab781ae89fe8af", "reference": "a8ae664c948f0ca926150cc4597f343af797b4b0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -121,7 +121,7 @@
"news", "news",
"rss" "rss"
], ],
"time": "2019-03-11 15:08:14" "time": "2019-04-12 11:48:51"
}, },
{ {
"name": "debril/rss-atom-bundle", "name": "debril/rss-atom-bundle",
@ -1725,16 +1725,16 @@
}, },
{ {
"name": "jasig/phpcas", "name": "jasig/phpcas",
"version": "1.3.6", "version": "1.3.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/apereo/phpCAS.git", "url": "https://github.com/apereo/phpCAS.git",
"reference": "7972833e84f6ee5fa41f1479eab5d855109627f5" "reference": "b5b29102c3a42f570c4a3e852f3cf67cae6d6082"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/apereo/phpCAS/zipball/7972833e84f6ee5fa41f1479eab5d855109627f5", "url": "https://api.github.com/repos/apereo/phpCAS/zipball/b5b29102c3a42f570c4a3e852f3cf67cae6d6082",
"reference": "7972833e84f6ee5fa41f1479eab5d855109627f5", "reference": "b5b29102c3a42f570c4a3e852f3cf67cae6d6082",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1776,7 +1776,7 @@
"cas", "cas",
"jasig" "jasig"
], ],
"time": "2018-10-25 20:22:09" "time": "2019-04-22 19:48:16"
}, },
{ {
"name": "jdorn/sql-formatter", "name": "jdorn/sql-formatter",
@ -3679,16 +3679,16 @@
}, },
{ {
"name": "symfony/symfony", "name": "symfony/symfony",
"version": "v3.4.23", "version": "v3.4.26",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/symfony.git", "url": "https://github.com/symfony/symfony.git",
"reference": "336cf12e5e82d71874e8522e0879794340351b56" "reference": "1b89e7baec9891c323bbf1ec81af77d901fc60c9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/symfony/zipball/336cf12e5e82d71874e8522e0879794340351b56", "url": "https://api.github.com/repos/symfony/symfony/zipball/1b89e7baec9891c323bbf1ec81af77d901fc60c9",
"reference": "336cf12e5e82d71874e8522e0879794340351b56", "reference": "1b89e7baec9891c323bbf1ec81af77d901fc60c9",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3830,7 +3830,7 @@
"keywords": [ "keywords": [
"framework" "framework"
], ],
"time": "2019-03-03 18:52:48" "time": "2019-04-17 15:57:27"
}, },
{ {
"name": "tetranz/select2entity-bundle", "name": "tetranz/select2entity-bundle",
@ -3880,17 +3880,60 @@
"time": "2018-03-05 02:52:46" "time": "2018-03-05 02:52:46"
}, },
{ {
"name": "twig/twig", "name": "thecsea/simple-caldav-client",
"version": "v2.7.4", "version": "v0.1.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/thecsea/simpleCalDAV.git",
"reference": "ed9c49220e09bfaeb1ba4d48077c08a7b09908dd" "reference": "dae70da0dacd0c8a1e184fbc91ecbe6f7fa5dea9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/ed9c49220e09bfaeb1ba4d48077c08a7b09908dd", "url": "https://api.github.com/repos/thecsea/simpleCalDAV/zipball/dae70da0dacd0c8a1e184fbc91ecbe6f7fa5dea9",
"reference": "ed9c49220e09bfaeb1ba4d48077c08a7b09908dd", "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": "" "shasum": ""
}, },
"require": { "require": {
@ -3906,7 +3949,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.7-dev" "dev-master": "2.8-dev"
} }
}, },
"autoload": { "autoload": {
@ -3944,7 +3987,7 @@
"keywords": [ "keywords": [
"templating" "templating"
], ],
"time": "2019-03-23 14:28:58" "time": "2019-04-16 17:14:24"
}, },
{ {
"name": "zendframework/zend-code", "name": "zendframework/zend-code",
@ -4162,16 +4205,16 @@
}, },
{ {
"name": "symfony/maker-bundle", "name": "symfony/maker-bundle",
"version": "v1.11.5", "version": "v1.11.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/maker-bundle.git", "url": "https://github.com/symfony/maker-bundle.git",
"reference": "186ffc80b8f363e04ea3c2ebf49e1263a84b4e39" "reference": "d262c2cace4d9bca99137a84f6fc6ba909a17e02"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/maker-bundle/zipball/186ffc80b8f363e04ea3c2ebf49e1263a84b4e39", "url": "https://api.github.com/repos/symfony/maker-bundle/zipball/d262c2cace4d9bca99137a84f6fc6ba909a17e02",
"reference": "186ffc80b8f363e04ea3c2ebf49e1263a84b4e39", "reference": "d262c2cace4d9bca99137a84f6fc6ba909a17e02",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4224,20 +4267,20 @@
"scaffold", "scaffold",
"scaffolding" "scaffolding"
], ],
"time": "2019-03-11 15:55:09" "time": "2019-04-19 17:26:45"
}, },
{ {
"name": "symfony/phpunit-bridge", "name": "symfony/phpunit-bridge",
"version": "v3.4.23", "version": "v3.4.26",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/phpunit-bridge.git", "url": "https://github.com/symfony/phpunit-bridge.git",
"reference": "b539f37134c10edbf85dc0567be4151c56870f5e" "reference": "a43a2f6c465a2d99635fea0addbebddc3864ad97"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/b539f37134c10edbf85dc0567be4151c56870f5e", "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/a43a2f6c465a2d99635fea0addbebddc3864ad97",
"reference": "b539f37134c10edbf85dc0567be4151c56870f5e", "reference": "a43a2f6c465a2d99635fea0addbebddc3864ad97",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4289,7 +4332,7 @@
], ],
"description": "Symfony PHPUnit Bridge", "description": "Symfony PHPUnit Bridge",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2019-02-16 18:50:26" "time": "2019-04-16 09:03:16"
} }
], ],
"aliases": [], "aliases": [],

View File

@ -12,6 +12,7 @@ use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\DBAL\Connection as DBALConnection; use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Constraints\DateTime;
use it\thecsea\simple_caldav_client\SimpleCalDAVClient;
use Cadoles\PortalBundle\Entity\Calendarevent; use Cadoles\PortalBundle\Entity\Calendarevent;
@ -399,7 +400,8 @@ class SynchroICSCommand extends Command
->setDescription('Synchronize external ICS URL') ->setDescription('Synchronize external ICS URL')
->setHelp('Synchronize external ICS URL') ->setHelp('Synchronize external ICS URL')
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job') ->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/"; $this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
$alias = $this->container->getParameter('alias'); $alias = $this->container->getParameter('alias');
$idcalendar = $input->getArgument('idcalendar');
$PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYactivate"])->getValue(); $PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYactivate"])->getValue();
$PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYserver"])->getValue(); $PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYserver"])->getValue();
$PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYport"])->getValue(); $PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->findOneBy(["id"=>"PROXYport"])->getValue();
@ -423,94 +428,196 @@ class SynchroICSCommand extends Command
$now=new \DateTime('now'); $now=new \DateTime('now');
$fgdebug = false; $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) { foreach($calendars as $calendar) {
$this->writeln($calendar->getUrl());
$client = new CalFileParser();
try { switch($calendar->getType()) {
if($PROXYactivate) // ICS
$cal = $client->parse($calendar->getUrl(), '', array("proxy"=>$PROXYserver.":".$PROXYport)); case 1:
else $this->writeln($calendar->getId()." = ICS = ".$calendar->getUrl());
$cal = $client->parse($calendar->getUrl()); $client = new CalFileParser();
$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"]!="") { try {
// On sauvegarde l'uid if($PROXYactivate)
array_push($tbuid,$event["UID"]); $cal = $client->parse($calendar->getUrl(), '', array("proxy"=>$PROXYserver.":".$PROXYport));
else
// Allday ? $cal = $client->parse($calendar->getUrl());
$allday=0;
if($event["ALLDAY"]==1||$event["SEQUENCE"]>=1) $tbuid=array();
$allday=1;
foreach($cal as $event) {
// Cas particulier $event["SUMMARY"] = (isset($event["SUMMARY"])?$event["SUMMARY"]:"");
if($allday==0&&$event["SEQUENCE"]==0) { $event["DESCRIPTION"] = (isset($event["DESCRIPTION"])?$event["DESCRIPTION"]:"");
if($event["DTSTART"]->format('H:i:s')=='00:00:00'&&$event["DTEND"]->format('H:i:s')=='00:00:00') $event["DTSTART"] = (isset($event["DTSTART"])?$event["DTSTART"]:"");
$allday=1; $event["DTEND"] = (isset($event["DTEND"])?$event["DTEND"]:"");
} $event["ALLDAY"] = (isset($event["ALLDAY"])?$event["ALLDAY"]:"");
$event["SEQUENCE"] = (isset($event["SEQUENCE"])?$event["SEQUENCE"]:"");
// On recherche l'uid dans le calendrier $event["UID"] = (isset($event["UID"])?$event["UID"]:"");
$toset=false;
$calendarevent=$this->em->getRepository("CadolesPortalBundle:Calendarevent")->findOneBy(["uid"=>$event["UID"]]); if($fgdebug) {
if($calendarevent) { echo "<br>";
if($event["SUMMARY"]!=$calendarevent->getName()||$event["DESCRIPTION"]!=$calendarevent->getDescription()||$event["DTSTART"]!=$calendarevent->getStart()||$event["DTEND"]!=$calendarevent->getEnd()||$allday!=$calendarevent->getAllday()) { echo "<br>SUMMARY = ".$event["SUMMARY"];
$toset=true; 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; // Purge des évènements plus présent
$calendarevent=new Calendarevent(); $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) { // CalDav
$calendarevent->setName($event["SUMMARY"]); case 2:
$calendarevent->setDescription($event["DESCRIPTION"]); $this->writeln($calendar->getId()." = CalDAV = ".$calendar->getUrl());
$calendarevent->setStart($event["DTSTART"]);
$calendarevent->setEnd($event["DTEND"]); $client = new SimpleCalDAVClient();
$calendarevent->setAllday($allday); try {
$calendarevent->setUid($event["UID"]); if($PROXYactivate)
$calendarevent->setCalendar($calendar); $client->connect($calendar->getUrl(), $calendar->getLogin(), $calendar->getPasswordDecrypt(),['proxy_host'=>$PROXYserver.":".$PROXYport,'timeout'=>5]);
else
$this->em->persist($calendarevent); $client->connect($calendar->getUrl(), $calendar->getLogin(), $calendar->getPasswordDecrypt(),['timeout'=>5]);
$this->em->flush();
}
} }
} catch (Exception $e) {
dump($e->__toString());
// Purge des évènements plus présent continue;
$calendarevents=$this->em->getRepository("CadolesPortalBundle:Calendarevent")->findBy(["calendar"=>$calendar]); }
foreach($calendarevents as $calendarevent) {
if(!in_array($calendarevent->getUid(),$tbuid)) { $this->writeln("connected");
$this->em->remove($calendarevent); $this->writeln("");
$this->em->flush(); $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();
}
}
} }
}
} break;
catch (Exception $e) {
$this->writelnred($e->__toString());
} }
} }
@ -518,6 +625,31 @@ class SynchroICSCommand extends Command
return 1; 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) { private function writelnred($string) {
$this->output->writeln('<fg=red>'.$string.'</>'); $this->output->writeln('<fg=red>'.$string.'</>');
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n"); $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");

View File

@ -188,7 +188,8 @@ class CalendarController extends Controller
$em->getRepository($this->labelentity)->getPermission($this->getUser(),$entity,$cansee,$canupdate); $em->getRepository($this->labelentity)->getPermission($this->getUser(),$entity,$cansee,$canupdate);
if(!$canupdate) throw $this->createNotFoundException('Permission denied'); if(!$canupdate) throw $this->createNotFoundException('Permission denied');
} }
$oldpassword=$entity->getPasswordDecrypt();
// Création du formulaire // Création du formulaire
$form = $this->entityForm($entity,$access); $form = $this->entityForm($entity,$access);
$form->handleRequest($request); $form->handleRequest($request);
@ -198,6 +199,17 @@ class CalendarController extends Controller
if ($form->isValid()) { if ($form->isValid()) {
$em = $this->getDoctrine()->getManager(); $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->persist($entity);
$em->flush(); $em->flush();

View File

@ -60,6 +60,29 @@ class Calendar
*/ */
private $url; 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 * @var string
* *
@ -103,6 +126,57 @@ class Calendar
return $this; 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 * Constructor
*/ */
@ -242,6 +316,56 @@ class Calendar
return $this->url; 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 * Set roles
* *

View File

@ -9,6 +9,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
@ -38,6 +39,7 @@ class CalendarType extends AbstractType
"choices" => [ "choices" => [
"Interne" => '0', "Interne" => '0',
"iCalendar (ICS)" => '1', "iCalendar (ICS)" => '1',
"CalDAV" => '2',
], ],
"disabled" => ($options["mode"]=="delete"?true:false), "disabled" => ($options["mode"]=="delete"?true:false),
]) ])
@ -45,6 +47,16 @@ class CalendarType extends AbstractType
->add('url', TextType::class, [ ->add('url', TextType::class, [
'label' => "URL", 'label' => "URL",
'required' => false, 'required' => false,
])
->add('login', TextType::class, [
'label' => "Login",
'required' => false,
])
->add('password', PasswordType::class, [
'label' => "Password",
'required' => false,
]); ]);
if($options["access"]=="config") { if($options["access"]=="config") {

View File

@ -57,6 +57,11 @@
<div id="url" style="display:none"> <div id="url" style="display:none">
{{ form_row(form.url) }} {{ form_row(form.url) }}
</div> </div>
<div id="login" style="display:none">
{{ form_row(form.login) }}
{{ form_row(form.password) }}
</div>
</div> </div>
{% if form.roles is defined %} {% if form.roles is defined %}
@ -84,9 +89,17 @@
function showhide() { function showhide() {
console.log($("#calendar_type").val()); console.log($("#calendar_type").val());
if($("#calendar_type").val()==1) if($("#calendar_type").val()==1) {
$("#url").show(); $("#url").show();
else $("#login").hide();
}
else if($("#calendar_type").val()==2) {
$("#url").show();
$("#login").show();
}
else {
$("#url").hide(); $("#url").hide();
$("#login").hide();
}
} }
{% endblock %} {% endblock %}