diff --git a/config/dispatcher-tree.json b/config/dispatcher-tree.json index a99e550..6e7558d 100755 --- a/config/dispatcher-tree.json +++ b/config/dispatcher-tree.json @@ -9,9 +9,6 @@ "css" : "/css", "js" : "/js", - "highcharts": "/js/lib/highcharts", - "sigma": "/js/lib/sigma", - - "cssview" : "/view/css", - "jsview" : "/view/js" -} \ No newline at end of file + "highcharts": "/js/lib/highcharts", + "sigma": "/js/lib/sigma" +} diff --git a/config/modules.json b/config/modules.json index 6c390b0..c341857 100755 --- a/config/modules.json +++ b/config/modules.json @@ -1,4 +1,26 @@ { + "module": { + "method": { + "description": "Test de l'API", + "permissions": [], + "parameters": {} + }, + + "phpunitParams": { + "description": "Méthode utile à phpunit pour le test des paramètres.", + "permissions": [], + "parameters": { + "p1": { "description": "Texte", "type": "text" }, + "p2": { "description": "Entier positif", "type": "id" } + } + }, + + "phpunitPermissions": { + "description": "Méthode utile à phpunit pour le test des permissions.", + "permissions": ["a", "b"], + "parameters": {} + } + }, "user": { "login": { diff --git a/js/action-script.js b/js/action-script.js index 9f038b3..c12ba0f 100755 --- a/js/action-script.js +++ b/js/action-script.js @@ -28,7 +28,7 @@ function navSubMenu(subsection){ var target = null; // si @subsection est un element, on le prends - target = (subsection instanceof Element) ? subsection : null; + target = (subsection instanceof Element) ? subsection : null; // Si string, on trouve l'element correspondant target = (typeof subsection == 'string') ? document.querySelector('#MENU-SIDE > span[data-link='+pageManager.page+'] + div.sub > span[data-sublink="'+subsection+'"]') : target; @@ -44,7 +44,7 @@ function navSubMenu(subsection){ // On desactive l'element courant if( current != null ) current.remClass('active'); - + // On cache les sections visibles var visibleSections = document.querySelectorAll('#CONTAINER > section[data-sublink].active'); for( var i = 0 ; i < visibleSections.length ; i++ ) @@ -84,7 +84,7 @@ function navSubMenu(subsection){ /* [4 Toggle du side-menu <-> navigation ===========================================*/ function navMenu(section){ - + /* [1] Format du param ------------------------------------------------*/ // Contient l'element courant @@ -94,7 +94,7 @@ function navMenu(section){ var target = null; // si @section est un element, on le prends - target = (section instanceof Element) ? section : null; + target = (section instanceof Element) ? section : null; // Si string, on trouve l'element correspondant target = (typeof section == 'string') ? document.querySelector('#WRAPPER > #MENU-SIDE > span[data-link="'+section+'"]') : target; @@ -190,22 +190,22 @@ DOM.MENUSIDE.addEventListener('click', function(e){ /* [6] Gestion du rechargement de page -=========================================================*/ +=========================================================*/ function reload(){ navMenu( pageManager.page ); } -/* [7] Gestion du toggle de la page de login -=========================================================*/ -var LOGIN = { - show: document.getElementById('user-data'), - hide: document.getElementById('login-close'), - page: document.getElementById('LOGIN') -}; +/* [7] Gestion du toggle de la page de login +=========================================================*/ +var LOGIN = { + show: document.getElementById('user-data'), + hide: document.getElementById('login-close'), + page: document.getElementById('LOGIN') +}; -/* (1) Gestion de l'affichage de la page de login */ -LOGIN.show.addEventListener('click', function(e){ LOGIN.page.className = 'active'; }, false); +/* (1) Gestion de l'affichage de la page de login */ +LOGIN.show.addEventListener('click', function(e){ LOGIN.page.className = 'active'; }, false); -/* (2) Gestion de la fermeture de la page de login */ -LOGIN.hide.addEventListener('click', function(e){ LOGIN.page.className = ''; }, false); +/* (2) Gestion de la fermeture de la page de login */ +LOGIN.hide.addEventListener('click', function(e){ LOGIN.page.className = ''; }, false); @@ -229,4 +229,4 @@ pageManagerClass.prototype.ajax('/f/json/menu/conf', function(pagelistSerialized /* (2) On charge la premiere page */ navMenu(pageManager.page); -}, 'GET'); \ No newline at end of file +}, 'GET'); diff --git a/js/includes/test.js b/js/includes/test.js new file mode 100644 index 0000000..84d02ea --- /dev/null +++ b/js/includes/test.js @@ -0,0 +1 @@ +var a = 'Hello World!'; diff --git a/js/lib/reset.js b/js/lib/reset.js index b3c32a4..25be8eb 100755 --- a/js/lib/reset.js +++ b/js/lib/reset.js @@ -105,9 +105,21 @@ Element.prototype.anim = function(className, timeout){ } +// INCLUSION D'UN SCRIPT JAVASCRIPT +function include(jsResource, callback){ + var tag = document.createElement('script'); + tag.type = 'text/javascript'; + tag.src = jsResource; + + document.head.appendChild( tag ); + + tag.onload = callback; +} + + /* DEFINITION DES FORMATS UTILES POUR INPUT-CHECKER * */ -var format_code = new formatChecker(null, 'HH-HH-HH-HH', { 'H' : '[0-9A-F]'} ) \ No newline at end of file +var format_code = new formatChecker(null, 'HH-HH-HH-HH', { 'H' : '[0-9A-F]'} ) diff --git a/manager/ManagerError.php b/manager/ManagerError.php index d724603..509fa59 100755 --- a/manager/ManagerError.php +++ b/manager/ManagerError.php @@ -1,6 +1,6 @@ \ No newline at end of file +?> diff --git a/manager/ModuleRequest.php b/manager/ModuleRequest.php index d7e38fd..9a93ed4 100755 --- a/manager/ModuleRequest.php +++ b/manager/ModuleRequest.php @@ -1,4 +1,4 @@ -modules = json_decode( ResourceDispatcher::getResource(self::$config_path), true ); - + // Gestion de l'erreur de parsage if( $this->modules == null ){ $this->error = ManagerError::ParsingFailed; @@ -63,7 +62,7 @@ } // Type de @data (optionnel) - $params = (is_array($params)) ? $params : array(); + $params = (is_array($params)) ? $params : array(); /* [2] Verification du chemin (existence module+methode) @@ -72,14 +71,11 @@ return false; + /* [3] Verification des droits =========================================================*/ - if( !$this->checkPermission($token) ){ // Si on a pas les droits - - // Si on a un token -> erreur de token, sinon erreur de permission - $this->error = ($token===null) ? ManagerError::PermissionError : ManagerError::TokenError; + if( !$this->checkPermission($token) ) // Si on a pas les droits return false; - } /* [4] Verification des parametres (si @type est defini) @@ -159,7 +155,7 @@ // On definit $params au cas ou il soit vide $params = $json; // On retire le @path de @params - unset($params['path']); + unset($params['path']); return new ModuleRequest($json['path'], $params); } @@ -192,7 +188,7 @@ =========================================================*/ // Si variable n'existe pas, on cree un tableau vide $params = $post; - + // On retire le @path de @params unset($params['path']); @@ -226,6 +222,7 @@ $module = $matches[1]; $method = $matches[2]; + /* [2] Verification de l'existence du module (conf) =========================================================*/ if( !array_key_exists($module, $this->modules) ){ // Si le module n'est pas specifie dans la conf @@ -239,7 +236,7 @@ $this->error = ManagerError::UnknownMethod; return false; // On retourne FALSE, si erreur } - + /* [4] Enregistrement du chemin et renvoi de SUCCESS @@ -283,9 +280,12 @@ $checkToken = new Repo('token/check', array($token) ); $token_permissions = $checkToken->answer(); - // Si le token est invalide, on retourne FAUX - if( $token_permissions === false ) return false; - + // Si le token est invalide, on retourne une erreur -> FAUX + if( $token_permissions === false ){ + $this->error = ManagerError::TokenError; + return false; + } + $local_permissions = $token_permissions; @@ -310,6 +310,7 @@ /* [5] On retourne FAUX si aucun droit n'a ete trouve =========================================================*/ + $this->error = ManagerError::PermissionError; return false; } @@ -344,7 +345,7 @@ // Si le type n'est pas defini, on reboucle if( !isset($paramsdata['type']) ) continue; - + // Si la verification est fausse, on retourne faux if( !Database::check($paramsdata['type'], $params[$name]) ) return false; } @@ -370,4 +371,4 @@ } -?> \ No newline at end of file +?> diff --git a/manager/module/module.php b/manager/module/module.php new file mode 100644 index 0000000..3c2e195 --- /dev/null +++ b/manager/module/module.php @@ -0,0 +1,25 @@ + ManagerError::Success, + 'ReceivedArguments' => $arguments + ); + + } + + + + + } + + +?> diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index bdac929..5eb0795 100755 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -5,8 +5,12 @@ $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0'; + + $_SESSION = array(); + $_SESSION['permission'] = array('phpunit'); + require_once __ROOT__.'/manager/autoloader.php'; -?> \ No newline at end of file +?> diff --git a/phpunit/coverage/Database.php.html b/phpunit/coverage/Database.php.html index 63205f8..491f6fb 100755 --- a/phpunit/coverage/Database.php.html +++ b/phpunit/coverage/Database.php.html @@ -297,7 +297,7 @@
- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/coverage/ManagerError.php.html b/phpunit/coverage/ManagerError.php.html index 51d9c4c..3951256 100755 --- a/phpunit/coverage/ManagerError.php.html +++ b/phpunit/coverage/ManagerError.php.html @@ -126,7 +126,7 @@- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/coverage/ResourceDispatcher.php.html b/phpunit/coverage/ResourceDispatcher.php.html index 0fd0aff..03af216 100755 --- a/phpunit/coverage/ResourceDispatcher.php.html +++ b/phpunit/coverage/ResourceDispatcher.php.html @@ -262,49 +262,49 @@- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/coverage/autoloader.php.html b/phpunit/coverage/autoloader.php.html index edb67cf..074336c 100755 --- a/phpunit/coverage/autoloader.php.html +++ b/phpunit/coverage/autoloader.php.html @@ -167,19 +167,19 @@- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/coverage/index.html b/phpunit/coverage/index.html index 0c88c4e..ebe8e60 100755 --- a/phpunit/coverage/index.html +++ b/phpunit/coverage/index.html @@ -43,29 +43,57 @@- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
- Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 6:41:06 UTC 2016. + Generated by PHP_CodeCoverage 2.1.7 using PHP 5.6.11-1ubuntu3.1 and PHPUnit 4.7.6 at Mon Apr 18 8:26:51 UTC 2016.
diff --git a/phpunit/phpunit.xml b/phpunit/phpunit.xml index 2b70fd8..676aac4 100755 --- a/phpunit/phpunit.xml +++ b/phpunit/phpunit.xml @@ -1,19 +1,23 @@