limesurvey

This commit is contained in:
root 2019-06-04 15:05:41 +02:00
parent baac78e631
commit eee28b7c2c
7 changed files with 542 additions and 39 deletions

View File

@ -8,7 +8,7 @@ twig:
cron_activate: %cron_activate%
portal_activate: %portal_activate%
portal_item_activate: %portal_item_activate%
item_activate: %item_activate%
eportail_sync: %eportail_sync%
moderegistration: %moderegistration%

View File

@ -5,10 +5,11 @@ SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES
(-100, 'transnum', '0000000A');
(-100, 'DRAAF', '130007107');
INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES
(-100, -100, 'admin', 'Administrateur', 'transnum', 'PWD_CAS', 'admin@transnum.cadol.es', 'admin.jpg', 'ROLE_ADMIN', '0000000A', 'simple');
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}fb3ceUoJ3JONkQV2fav0CuKOAZb9h9vO
', 'admin@transnum.cadol.es', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple');

View File

@ -60,8 +60,17 @@
else $roles=$curentuser->getRoles();
// App activate
$portal_activate =$this->container->getParameter('portal_activate');
$cron_activate =$this->container->getParameter('cron_activate');
$app=[];
$app["portal_activate"] =$this->container->getParameter('portal_activate');
$app["cron_activate"] =$this->container->getParameter('cron_activate');
$app["module_activate"] =$this->container->getParameter('module_activate');
$app["page_activate"] =$this->container->getParameter('page_activate');
$app["item_activate"] =$this->container->getParameter('item_activate');
$app["alert_activate"] =$this->container->getParameter('alert_activate');
$app["calendar_activate"] =$this->container->getParameter('calendar_activate');
$app["blog_activate"] =$this->container->getParameter('blog_activate');
$app["flux_activate"] =$this->container->getParameter('flux_activate');
$app["notice_activate"] =$this->container->getParameter('notice_activate');
// Masteridentity
$masteridentity =$this->container->getParameter('masteridentity');
@ -97,12 +106,7 @@
"path" => $nv1->getPath(),
);
if($nv1->getAppactivate()=="portal_activate"&&!$portal_activate) {
unset($sidebar[$nv1->getRoworder()]);
continue;
}
if($nv1->getAppactivate()=="cron_activate"&&!$cron_activate) {
if($nv1->getAppactivate()!=""&&!$app[$nv1->getAppactivate()]) {
unset($sidebar[$nv1->getRoworder()]);
continue;
}
@ -136,6 +140,8 @@
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["label"]=$labelsniveau01;
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["fonticon"]=$iconniveau01;
}
if($nv2->getPath()=="cadoles_core_config_niveau02") {
if(!$viewniveau02)
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
@ -153,6 +159,10 @@
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
}
if($nv2->getAppactivate()!=""&&!$app[$nv2->getAppactivate()]) {
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
}
foreach($nv2->getChilds() as $nv3) {
if($this->haveRole($roles,$nv3->getPermission())) {
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()] = array (
@ -190,7 +200,7 @@
}
$session->set('sidebar', $sidebar);
if($portal_activate) {
if($app["portal_activate"]) {
$session->set('cancreatepage',false);
$session->set('cancreatecalendar',false);
$session->set('cancreateblog',false);

View File

@ -92,8 +92,8 @@ class CronCommand extends ContainerAwareCommand
// Date prochaine execution
if($cron->getrepeatinterval()>=0) {
// Si interval par jour
if(fmod($cron->getRepeatinterval(),86400)==0)
// Si interval par heure
if(fmod($cron->getRepeatinterval(),3600)==0)
$next=clone $cron->getNextexecdate();
else
$next=new \DateTime();

View File

@ -94,23 +94,6 @@ class InitDataCommand extends ContainerAwareCommand
$this->entityManager->persist($entity);
}
// Job purge des registrations obsolètes
// Toute les 5mn
$entity = $this->entityManager->getRepository('CadolesCronBundle:Cron')->find(120);
if(!$entity) {
$entity = new Cron;
$entity->setCommand("Portal:SynchroICS");
$entity->setDescription("Synchronisation des Calendriers Utilisateurs liés à une URL ICS");
$entity->setId(120);
$entity->setStatut(2);
$entity->setRepeatcall(0);
$entity->setRepeatexec(0);
$entity->setRepeatinterval(600);
$entity->setNextexecdate($entity->getSubmitdate());
$this->entityManager->persist($entity);
}
// Job de purge des fichiers obsolète
// Toute les 24h à 3h00
$entity = $this->entityManager->getRepository('CadolesCronBundle:Cron')->find(200);
@ -129,6 +112,50 @@ class InitDataCommand extends ContainerAwareCommand
$this->entityManager->persist($entity);
}
// CRON PORTAIL
// Job purge des registrations obsolètes
// Toute les 5mn
$portal_activate = $this->getContainer()->getParameter('portal_activate');
$calendar_activate = $this->getContainer()->getParameter('calendar_activate');
$entity = $this->entityManager->getRepository('CadolesCronBundle:Cron')->find(1000);
if(!$entity&&($portal_activate||$calendar_activate)) {
$entity = new Cron;
$entity->setCommand("Portal:SynchroICS");
$entity->setDescription("Synchronisation des Calendriers Utilisateurs liés à une URL ICS");
$entity->setId(1000);
$entity->setStatut(2);
$entity->setRepeatcall(0);
$entity->setRepeatexec(0);
$entity->setRepeatinterval(600);
$entity->setNextexecdate($entity->getSubmitdate());
$this->entityManager->persist($entity);
}
elseif($entity) {
$this->entityManager->remove($entity);
}
// Job de récupération des sondages Limesurvey
// Toute les 6h
$activate_widlimesurvey = $this->getContainer()->getParameter('activate_widlimesurvey');
$entity = $this->entityManager->getRepository('CadolesCronBundle:Cron')->find(1010);
if(!$entity&&$activate_widlimesurvey) {
$entity = new Cron;
$nextdate=$entity->getSubmitdate();
$nextdate->setTime(1,0);
$entity->setCommand("Portal:GetLimesurvey");
$entity->setDescription("Récupération des sondages Limesurvey ");
$entity->setId(1010);
$entity->setStatut(2);
$entity->setRepeatcall(0);
$entity->setRepeatexec(0);
$entity->setRepeatinterval(21600);
$entity->setNextexecdate($nextdate);
$this->entityManager->persist($entity);
}
elseif($entity) {
$this->entityManager->remove($entity);
}
// afin de forcer les ID sur certaines entités
$metadata = $this->entityManager->getClassMetaData(get_class($entity));
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);

View File

@ -0,0 +1,405 @@
<?php
namespace Cadoles\PortalBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Validator\Constraints\DateTime;
class jsonRPCClient
{
protected $url = null, $is_debug = false, $parameters_structure = 'array';
/**
* Default options for curl
*
* @var array
*/
protected $curl_options = array(
CURLOPT_CONNECTTIMEOUT => 8,
CURLOPT_TIMEOUT => 8
);
/**
* Http error statuses
*
* Source: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
*
* @var array
*/
private $httpErrors = array(
400 => '400 Bad Request',
401 => '401 Unauthorized',
403 => '403 Forbidden',
404 => '404 Not Found',
405 => '405 Method Not Allowed',
406 => '406 Not Acceptable',
408 => '408 Request Timeout',
500 => '500 Internal Server Error',
502 => '502 Bad Gateway',
503 => '503 Service Unavailable'
);
/**
* Takes the connection parameter and checks for extentions
*
* @param string $pUrl - url name like http://example.com/
*/
public function __construct($pUrl)
{
$this->validate(false === extension_loaded('curl'), 'The curl extension must be loaded for using this class!');
$this->validate(false === extension_loaded('json'), 'The json extension must be loaded for using this class!');
// set an url to connect to
$this->url = $pUrl;
}
/**
* Return http error message
*
* @param $pErrorNumber
*
* @return string|null
*/
private function getHttpErrorMessage($pErrorNumber)
{
return isset($this->httpErrors[$pErrorNumber]) ? $this->httpErrors[$pErrorNumber] : null;
}
/**
* Set debug mode
*
* @param boolean $pIsDebug
*
* @return jsonRPCClient
*/
public function setDebug($pIsDebug)
{
$this->is_debug = !empty($pIsDebug);
return $this;
}
/**
* Set structure to use for parameters
*
* @param string $pParametersStructure 'array' or 'object'
*
* @throws UnexpectedValueException
* @return jsonRPCClient
*/
public function setParametersStructure($pParametersStructure)
{
if (in_array($pParametersStructure, array('array', 'object')))
{
$this->parameters_structure = $pParametersStructure;
}
else
{
throw new UnexpectedValueException('Invalid parameters structure type.');
}
return $this;
}
/**
* Set extra options for curl connection
*
* @param array $pOptionsArray
*
* @throws InvalidArgumentException
* @return jsonRPCClient
*/
public function setCurlOptions($pOptionsArray)
{
if (is_array($pOptionsArray))
{
$this->curl_options = $pOptionsArray + $this->curl_options;
}
else
{
throw new InvalidArgumentException('Invalid options type.');
}
return $this;
}
/**
* Performs a request and gets the results
*
* @param string $pMethod - A String containing the name of the method to be invoked.
* @param array $pParams - An Array of objects to pass as arguments to the method.
*
* @throws RuntimeException
* @return array
*/
public function __call($pMethod, $pParams)
{
static $requestId = 0;
// generating uniuqe id per process
$requestId++;
// check if given params are correct
$this->validate(false === is_scalar($pMethod), 'Method name has no scalar value');
$this->validate(false === is_array($pParams), 'Params must be given as array');
// send params as an object or an array
$pParams = ($this->parameters_structure == 'object') ? $pParams[0] : array_values($pParams);
// Request (method invocation)
$request = json_encode(array('jsonrpc' => '2.0', 'method' => $pMethod, 'params' => $pParams, 'id' => $requestId));
// if is_debug mode is true then add url and request to is_debug
$this->debug('Url: ' . $this->url . "\r\n", false);
$this->debug('Request: ' . $request . "\r\n", false);
$responseMessage = $this->getResponse($request);
// if is_debug mode is true then add response to is_debug and display it
$this->debug('Response: ' . $responseMessage . "\r\n", true);
// decode and create array ( can be object, just set to false )
$responseDecoded = json_decode($responseMessage, true);
// check if decoding json generated any errors
$jsonErrorMsg = $this->getJsonLastErrorMsg();
$this->validate( !is_null($jsonErrorMsg), $jsonErrorMsg . ': ' . $responseMessage);
// check if response is correct
$this->validate(empty($responseDecoded['id']), 'Invalid response data structure: ' . $responseMessage);
$this->validate($responseDecoded['id'] != $requestId, 'Request id: ' . $requestId . ' is different from Response id: ' . $responseDecoded['id']);
if (isset($responseDecoded['error']))
{
$errorMessage = 'Request have return error: ' . $responseDecoded['error']['message'] . '; ' . "\n" .
'Request: ' . $request . '; ';
if (isset($responseDecoded['error']['data']))
{
$errorMessage .= "\n" . 'Error data: ' . $responseDecoded['error']['data'];
}
$this->validate( !is_null($responseDecoded['error']), $errorMessage);
}
return $responseDecoded['result'];
}
/**
* When the method invocation completes, the service must reply with a response.
* The response is a single object serialized using JSON
*
* @param string $pRequest
*
* @throws RuntimeException
* @return string
*/
protected function & getResponse(&$pRequest)
{
// do the actual connection
$ch = curl_init();
if ( !$ch)
{
throw new \RuntimeException('Could\'t initialize a cURL session');
}
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pRequest);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ( !curl_setopt_array($ch, $this->curl_options))
{
throw new \RuntimeException('Error while setting curl options');
}
// send the request
$response = curl_exec($ch);
// check http status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (isset($this->httpErrors[$httpCode]))
{
throw new \RuntimeException('Response Http Error - ' . $this->httpErrors[$httpCode]);
}
// check for curl error
if (0 < curl_errno($ch))
{
throw new \RuntimeException('Unable to connect to '.$this->url . ' Error: ' . curl_error($ch));
}
// close the connection
curl_close($ch);
return $response;
}
/**
* Throws exception if validation is failed
*
* @param bool $pFailed
* @param string $pErrMsg
*
* @throws RuntimeException
*/
protected function validate($pFailed, $pErrMsg)
{
if ($pFailed)
{
throw new \RuntimeException($pErrMsg);
}
}
/**
* For is_debug and performance stats
*
* @param string $pAdd
* @param bool $pShow
*/
protected function debug($pAdd, $pShow = false)
{
static $debug, $startTime;
// is_debug off return
if (false === $this->is_debug)
{
return;
}
// add
$debug .= $pAdd;
// get starttime
$startTime = empty($startTime) ? array_sum(explode(' ', microtime())) : $startTime;
if (true === $pShow and !empty($debug))
{
// get endtime
$endTime = array_sum(explode(' ', microtime()));
// performance summary
$debug .= 'Request time: ' . round($endTime - $startTime, 3) . ' s Memory usage: ' . round(memory_get_usage() / 1024) . " kb\r\n";
echo nl2br($debug);
// send output imidiately
flush();
// clean static
$debug = $startTime = null;
}
}
/**
* Getting JSON last error message
* Function json_last_error_msg exists from PHP 5.5
*
* @return string
*/
function getJsonLastErrorMsg()
{
if (!function_exists('json_last_error_msg'))
{
function json_last_error_msg()
{
static $errors = array(
JSON_ERROR_NONE => 'No error',
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
JSON_ERROR_SYNTAX => 'Syntax error',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
);
$error = json_last_error();
return array_key_exists($error, $errors) ? $errors[$error] : 'Unknown error (' . $error . ')';
}
}
// Fix PHP 5.2 error caused by missing json_last_error function
if (function_exists('json_last_error'))
{
return json_last_error() ? json_last_error_msg() : null;
}
else
{
return null;
}
}
}
class GetLimesurveyCommand extends Command
{
private $container;
private $em;
private $output;
private $filesystem;
private $rootlog;
protected function configure()
{
$this
->setName('Portal:GetLimesurvey')
->setDescription('Get Datas from Limesurvey')
->setHelp('Synchronize Limesurvey')
->addArgument('cronid', InputArgument::OPTIONAL, 'ID Cron Job')
->addArgument('lastchance', InputArgument::OPTIONAL, 'Lastchance to run the cron')
->addArgument('idcalendar', InputArgument::OPTIONAL, 'ID Calendar to synchronize')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->container = $this->getApplication()->getKernel()->getContainer();
$this->em = $this->container->get('doctrine')->getEntityManager();
$this->output = $output;
$this->filesystem = new Filesystem();
$this->rootlog = $this->container->get('kernel')->getRootDir()."/../var/logs/";
$alias = $this->container->getParameter('alias');
$activate_widlimesurvey = $this->container->getParameter('activate_widlimesurvey');
if(!$activate_widlimesurvey) {
$this->writeln('Widget Limesurvey désactivé');
return 1;
}
$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();
$this->writelnred('');
$this->writelnred('== Portal:GetLimesurvey');
$this->writelnred('==========================================================================================================');
$now=new \DateTime('now');
$fgdebug = false;
// Instance Limesurvey
$widlimesurvey_url = $this->container->getParameter('widlimesurvey_url');
if(stripos($widlimesurvey_url,"/limesurvey")==0) {
$weburl=$this->container->getParameter('weburl');
$widlimesurvey_url="https://".$weburl.$widlimesurvey_url;
}
echo $widlimesurvey_url;
$widlimesurvey_apiuser = $this->container->getParameter('widlimesurvey_apiuser');
$widlimesurvey_apikey = $this->container->getParameter('widlimesurvey_apikey');
$myJSONRPCClient = new JsonRPCClient( $widlimesurvey_url.'/admin/remotecontrol' );
// Connection Limesurvey
$sessionKey= $myJSONRPCClient->get_session_key( $widlimesurvey_apiuser, $widlimesurvey_apikey );
$this->writeln('');
return 1;
}
private function writelnred($string) {
$this->output->writeln('<fg=red>'.$string.'</>');
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
private function writeln($string) {
$this->output->writeln($string);
$this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
}
}

View File

@ -26,21 +26,61 @@ parameters:
%end if
# Activation module
portal_module_activate: false
cron_activate: true
%if %%getVar("ninegate_activate_portal", 'non') == "oui"
portal_activate: true
portal_item_activate: false
module_activate: false
page_activate: false
item_activate: false
alert_activate: false
calendar_activate: false
blog_activate: false
flux_activate: false
notice_activate: false
%else
portal_activate: false
%if %%getVar("ninegate_activate_item", 'non') == "oui"
portal_module_activate: true
portal_item_activate: true
%if %%getVar("ninegate_activate_page", 'non') == "oui"
module_activate: true
page_activate: true
%else
portal_item_activate: false
page_activate: false
%end if
%if %%getVar("ninegate_activate_item", 'non') == "oui"
module_activate: true
item_activate: true
%else
item_activate: false
%end if
%if %%getVar("ninegate_activate_alert", 'non') == "oui"
module_activate: true
alert_activate: true
%else
alert_activate: false
%end if
%if %%getVar("ninegate_activate_calendar", 'non') == "oui"
module_activate: true
calendar_activate: true
%else
calendar_activate: false
%end if
%if %%getVar("ninegate_activate_blog", 'non') == "oui"
module_activate: true
blog_activate: true
%else
blog_activate: false
%end if
%if %%getVar("ninegate_activate_flux", 'non') == "oui"
module_activate: true
flux_activate: true
%else
flux_activate: false
%end if
%if %%getVar("ninegate_activate_notice", 'non') == "oui"
module_activate: true
notice_activate: true
%else
notice_activate: false
%end if
%end if
# Information de base de l'annuaire
@ -56,6 +96,7 @@ parameters:
ldap_basedn: o=gouv,c=fr
# Mise en page
weburl: %%web_url
alias: ninegate
libelle_etab: %%libelle_etab
numero_etab: %%numero_etab
@ -114,6 +155,25 @@ parameters:
ldap_email: mail
ldap_usersadmin: [admin,prof.6a]
# Activation Widget
%if %%getVar("ninegate_activate_widmoodle", 'non') == "oui"
activate_widmoodle: true
widmoodle_url: %%ninegate_widmoodle_url
widmoodle_apikey: %%ninegate_widmoodle_apikey
%else
activate_widmoodle: false
%end if
%if %%getVar("ninegate_activate_widlimesurvey", 'non') == "oui"
activate_widlimesurvey: true
widlimesurvey_url: %%ninegate_widlimesurvey_url
widlimesurvey_apiuser: %%ninegate_widlimesurvey_apiuser
widlimesurvey_apikey: %%ninegate_widlimesurvey_apikey
%else
activate_widlimesurvey: false
%end if
# Synchrinisation eportail
%if %%getVar("ninegate_synceportail", 'non') == "oui"
eportail_sync: true
eportail_url: /eportail