Commit 0ea5fc20 authored by Christian BUFFIN's avatar Christian BUFFIN

Ajout de la partie de vérification de l'application.

parent a789dd02
......@@ -81,6 +81,7 @@ Inflector::rules('plural', array(
CakePlugin::loadAll([
//['bootstrap' => false],
'AuthManager' => ['bootstrap' => true, 'routes' => false],
'Appchecks' => ['bootstrap' => false, 'routes' => false],
'Database' => ['bootstrap' => false, 'routes' => false],
'Postgres' => ['bootstrap' => false, 'routes' => false],
'Translator' => ['bootstrap' => true, 'routes' => false]
......
......@@ -24,7 +24,7 @@
* In production mode, flash messages redirect after a time interval.
* In development mode, you need to click the flash message to continue.
*/
Configure::write('debug', 0);
Configure::write('debug', 2);
/**
* Configure the Error handler used to handle errors for your application. By default
......
<?php
/**
* ChecksController
*
* web-DPO : Outil de gestion de vos traitements dans le cadre de la
* réglementation relative à la protection des données personnelles (RGPD)
*
* Copyright (c) Libriciel SCOP (https://www.libriciel.fr/)
*
* Licensed under The CeCiLL V2 License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Libriciel SCOP (https://www.libriciel.fr/)
* @link https://www.libriciel.fr/web-cil/
* @since web-DPO v1.0.0
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html CeCiLL V2 License
* @version v1.0.0
* @package App.Controller
*/
App::uses('ListeDroit', 'Model');
class ChecksController extends AppController {
public $uses = [
'WebdpoCheck'
];
public $helpers = [
'Appchecks.Checks'
];
public function index() {
if (true !== $this->Droits->authorized($this->Droits->isSu())) {
throw new ForbiddenException(__d('default', 'default.flasherrorPasDroitPage'));
}
$this->set('title', __d('checks', 'checks.titreIndex'));
$results = $this->WebdpoCheck->results();
$this->set(compact('results'));
}
}
# Locale fra
# circuit.po
#
# web-DPO : https://www.libriciel.fr/web-cil/
#
# @author Théo Guillon
# @copyright Libriciel SCOP
# @link https://www.libriciel.fr/
# @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt CeCiLL v2
#
##################### Controller/ChecksController.php #######################
msgid "checks.titreIndex"
msgstr "Vérification de l'application"
......@@ -183,6 +183,9 @@ msgstr "Gestion de tous les sous-traitants"
msgid "default.sousTitreGestionTousResponsable"
msgstr "Gestion de tous les responsables"
msgid "default.sousTitreChecksIndex"
msgstr "Vérification de l'application"
###############################################################################
......
<?php
use phpgedooo_client\GDO_PartType;
use phpgedooo_client\GDO_FusionType;
use phpgedooo_client\GDO_ContentType;
App::uses('AppModel', 'Model');
class WebdpoCheck extends AppModel
{
public $name = 'WebdpoCheck';
public $useTable = false;
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->Check = ClassRegistry::init('Appchecks.Check');
}
public function results()
{
return array_merge(
$this->environment(),
$this->php(),
$this->app(),
$this->services()
);
}
public function environment()
{
return [
'Environment' => [
'binaries' => $this->Check->binaries(
[
Configure::read('PDFTK_EXEC'),
Configure::read('PDFINFO_EXEC')
]
),
'directories' => $this->Check->directories(
array(
TMP => 'w'
),
ROOT.DS
),
'files' => $this->Check->files(
[
CONFIG.'webdpo.inc'
],
ROOT.DS
),
'cache' => $this->Check->cachePermissions(),
'cache_check' => $this->Check->cacheFilePermissions(),
'freespace' => $this->Check->freespace(
[
// 1. Répertoire temporaire de CakePHP
TMP,
// // 2. Répertoire temporaire pour les PDF.
// Configure::read( 'Cohorte.dossierTmpPdfs' ),
// // 3. Répertoire de cache des wsdl
// ini_get( 'soap.wsdl_cache_dir' ),
]
)
]
];
}
/**
* Vérifications concernant PHP:
* - la version utilisée
* - les extensions nécessaires
* - les variables du php.ini nécessaires
*
* @return array
* @access protected
*/
public function php()
{
return array(
'Php' => array(
'informations' => array(
'Version' => $this->Check->version('PHP', phpversion(), '7.0.0')
),
'extensions' => $this->Check->phpExtensions(
[
'curl',
'dom',
'mbstring',
'soap',
'xml'
]
),
// @fixme
'inis' => $this->Check->phpInis(
array(
'date.timezone',
'post_max_size',
// // Pour PHP >= 5.3.9, le passer à au moins 2500
// 'max_input_vars' => array(
// 'comparison' => array(
// 'rule' => array( 'comparison', '>=', 2500 ),
// 'allowEmpty' => false
// ),
// ),
)
),
'pear_extensions' => $this->Check->pearExtensions(
[
'xml_rpc',
'xml_rpc2'
]
)
)
);
}
public function app()
{
return [
'WebDPO' => [
'configure' => $this->Check->configure($this->configureKeys()),
'define' => $this->Check->defined($this->defineKeys())
]
];
}
public function configureKeys()
{
return [
'FusionConv.Gedooo.wsdl' => [
['rule' => 'string', 'allowEmpty' => false],
['rule' => 'url', 'allowEmpty' => false]
],
'FusionConv.method' => [
['rule' => 'string', 'allowEmpty' => false],
array( 'rule' => 'inList', ['GedoooCloudooo', 'GedoooUnoconv'] )
],
'FusionConv.cloudooo_host' => [
['rule' => 'string', 'allowEmpty' => false],
['rule' => 'url', 'allowEmpty' => false]
],
'FusionConv.cloudooo_port' => [
['rule' => 'integer', 'allowEmpty' => false]
],
'FusionConv.FusionConvConverterCloudooo.xml_rpc_class' => [
['rule' => 'integer', 'allowEmpty' => false],
['rule' => 'inList', [1, 2], 'allowEmpty' => false]
],
'FusionConv.FusionConvConverterCloudooo.server' => [
['rule' => 'string', 'allowEmpty' => false]
],
'FusionConv.FusionConvConverterCloudooo.port' => [
['rule' => 'integer', 'allowEmpty' => false]
],
'GS_RESOLUTION' => [
['rule' => 'integer', 'allowEmpty' => false],
['rule' => 'range', 50, 500, 'allowEmpty' => false],
],
'PDFTK_EXEC' => [
['rule' => 'string', 'allowEmpty' => false]
],
'PDFINFO_EXEC' => [
['rule' => 'string', 'allowEmpty' => false]
],
];
}
public function defineKeys()
{
return [
'FICHIER' => [
['rule' => 'string', 'allowEmpty' => false]
],
'PIECE_JOINT' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_PIECE_JOINT' => [
['rule' => 'string', 'allowEmpty' => false]
],
'PIECE_JOINT_TMP' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_PIECE_JOINT_TMP' => [
['rule' => 'string', 'allowEmpty' => false]
],
'MODELES' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_MODELES' => [
['rule' => 'string', 'allowEmpty' => false]
],
'EXTRAIT_REGISTRE' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_MODELES_EXTRAIT' => [
['rule' => 'string', 'allowEmpty' => false]
],
'REGISTRE' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_REGISTRE' => [
['rule' => 'string', 'allowEmpty' => false]
],
'NORMES' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_NORMES' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CONNECTEURS' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_CONNECTEURS' => [
['rule' => 'string', 'allowEmpty' => false]
],
'AUTHENTIFICATION' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_CONNECTEURS_AUTHENTIFICATION' => [
['rule' => 'string', 'allowEmpty' => false]
],
'EXPORTS' => [
['rule' => 'string', 'allowEmpty' => false]
],
'CHEMIN_EXPORTS' => [
['rule' => 'string', 'allowEmpty' => false]
],
'FORMAT_DATE' => [//@todo
['rule' => 'string', 'allowEmpty' => false]
],
'FORMAT_DATE_HEURE' => [//@todo
['rule' => 'string', 'allowEmpty' => false]
],
'REGEXP_ALPHA_FR' => [//@todo: traduction de Validate::preg_pattern
['rule' => 'string', 'allowEmpty' => false],
['rule' => 'preg_pattern', 'allowEmpty' => false]
],
'REGEXP_EMAIL_FR' => [
['rule' => 'string', 'allowEmpty' => false],
['rule' => 'preg_pattern', 'allowEmpty' => false]
]
];
}
protected function _fusion($path)
{
App::uses('FusionConvBuilder', 'FusionConv.Utility');
$MainPart = new phpgedooo_client\GDO_PartType();
$Fusion = new phpgedooo_client\GDO_FusionType(
new phpgedooo_client\GDO_ContentType(
"",
basename($path),
"application/vnd.oasis.opendocument.text",
"binary",
file_get_contents($path)
),
'application/vnd.oasis.opendocument.text',
FusionConvBuilder::main($MainPart, [], [], [])
);
$Fusion->process();
$content = $Fusion->getContent();
if ((isset($content->binary) && preg_match('/^PK/m', $content->binary) === 1) === false) {
$msgstr = 'Erreur lors de la fusion: '.isset($content->Message) ? $content->Message : 'erreur inconnue';
throw new RuntimeException($msgstr);
}
return $content->binary;
}
protected function _testFusion($path)
{
$return = [
'success' => false,
'message' => null
];
try {
$this->_fusion($path);
$return['success'] = true;
} catch(Exception $e) {
$return['success'] = false;
$return['message'] = $e->getMessage();
}
return $return;
}
protected function _testConversion($path)
{
$return = [
'success' => false,
'message' => null
];
try {
$content = $this->_fusion($path);
$pdf = null;
switch(Configure::read('FusionConv.method')) {
case 'GedoooCloudooo':
App::uses('FusionConvConverterCloudooo', 'FusionConv.Utility/Converter');
$pdf = FusionConvConverterCloudooo::convert($content);
break;
case 'GedoooUnoconv':
App::uses('FusionConvConverterUnoconv', 'FusionConv.Utility/Converter');
$pdf = FusionConvConverterUnoconv::convert($content);
break;
default:
$msgstr = 'La méthode de conversion %s n\'est pas prise en charge.';
throw new RuntimeException(sprintf($msgstr, 'FusionConv.method'));
}
if (preg_match('/^%PDF\-[0-9]/m', $pdf) === 1) {
$return['success'] = true;
} else {
$return['success'] = false;
$return['message'] = 'Erreur inconnue lors de la conversion';
}
} catch(Exception $e) {
$return['success'] = false;
$return['message'] = $e->getMessage();
}
return $return;
}
public function services()
{
$gedoooTestFile = CakePlugin::path('FusionConv').'Config'.DS.'OdtVide.odt';
return [
'Services' => [
'Gedooo' => [
'tests' => [
'Accès au WebService' => $this->Check->webservice(Configure::read('FusionConv.Gedooo.wsdl')),
'Présence du modèle de test' => $this->Check->filePermission($gedoooTestFile),
'Test de fusion' => $this->_testFusion($gedoooTestFile)
]
],
'Cloudooo' => [
'tests' => [
'Accès au serveur cloudooo de FusionConv' => $this->Check->socket(
Configure::read('FusionConv.cloudooo_host'),
Configure::read('FusionConv.cloudooo_port')
),
'Accès au serveur de FusionConv.FusionConvConverterCloudooo' => $this->Check->socket(
Configure::read('FusionConv.FusionConvConverterCloudooo.server'),
Configure::read('FusionConv.FusionConvConverterCloudooo.port')
),
'Test de conversion' => $this->_testConversion($gedoooTestFile)
]
]
]
];
}
}
\ No newline at end of file
<?php
/**
* Fonctions utilitaires pour le plugin Appchecks.
*
* PHP 5.3
*
* @package Appchecks
* @subpackage Lib
* @license CeCiLL V2 (http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html)
*/
/**
* Retourne un nombre qui sera plus grand pour une version plus élevée.
*
* @see http://az.php.net/manual/en/function.phpversion.php (Exemple 2: PHP_VERSION_ID)
*
* @param string $version La version pour laquelle obtenir l'id
* @return integer
*/
function version_id( $version ) {
$tokens = explode( '.', $version );
$multipliers = array( 0 => 1000000, 1 => 10000, 2 => 100, 3 => 1 );
$result = 0;
for( $i = 0 ; $i <= 3 ; $i++ ) {
if( isset( $tokens[$i] ) ) {
$result += $multipliers[$i] * $tokens[$i];
}
}
return $result;
}
/**
* Vérifie qu'une version donnée soit au minimum égale à une certaine version
* et soit éventuellement plus petite qu'une version maximale.
*
* @param string $actual La version à tester
* @param string $low La version minimale
* @param string $high La version maximale éventuelle
* @return boolean
*/
function version_difference( $actual, $low, $high = null ) {
$actual = version_id( $actual );
$low = version_id( $low );
$high = ( is_null( $high ) ? null : version_id( $high ) );
$success = ( $actual >= $low );
if( !is_null( $high ) ) {
$success = ( $actual < $high );
}
return $success;
}
?>
<?php
/**
* Code source de la classe Xvalidation.
*
* PHP 5.3
*
* @package Appchecks
* @subpackage Lib
* @license CeCiLL V2 (http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html)
*/
/**
* La classe Xvalidation fournit des méthodes de validation de paramètres
* simples.
*
* Cette classe est une adaptation d'une classe du coeur de 1.2.11.
*
* @package Appchecks
* @subpackage Lib
*/
class Xvalidation
{
/**
* Some complex patterns needed in multiple places
* Vient du coeur de CakePHP 1.2.11
*
* @var array
* @access private
*/
protected $__pattern = array(
'ip' => '(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])',
'hostname' => '(?:[a-z0-9][-a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,4}|museum|travel)'
);
/**
*
* @staticvar array $instance
* @return \Xvalidation
*/
public static function &getInstance() {
static $instance = array( );
if( !$instance ) {
$instance[0] = new Xvalidation();
}
return $instance[0];
}
/**
*
* @param type $check
* @return boolean
*/
public function integer( $check ) {
return is_int( $check );
}
/**
*
* @param type $check
* @return boolean
*/
public function numeric( $check ) {
return is_numeric( $check );
}
/**
*
* @param type $check
* @param type $list
* @return type
*/
public function inList( $check, $list ) {
return in_array( $check, $list );
}
/**
*
* @param type $check
* @return type
*/
public function string( $check ) {
return is_string( $check );
}
/**
*
* @param type $check
* @return type
*/
public function boolean( $check ) {
return is_bool( $check );
}
/**
*
* @param type $check
* @return type
*/
public function isarray( $check ) {
return is_array( $check );
}
/**
* Vérifie que la ou les valeurs fassent toutes partie de la liste des
* valeurs acceptées.