From 534d907b48df77f9d6e9eebbd33917a1938d8660 Mon Sep 17 00:00:00 2001
From: xdrm-brackets CRAP
-
-
+
+
@@ -77,13 +77,13 @@
- 47
+ 52
-
-
+
+
@@ -179,13 +179,13 @@
@@ -374,48 +374,52 @@
- 25.11
+ 30
-
-
+
+ * */
- public static function check($type, $value){
+ $checker = !is_null($value); $checker = !is_null($value); switch($type){
- /* (1) Global */
+ case 'auto_increment_id': case 'auto_increment_id': return $checker && is_numeric($value) && $value <= 2147483647 && $value >= -2147483647; break;
- /* (2) Utilisateur */
- case 'user.code':
+ case 'machine.code':
+ case 'user.code': case 'machine.code': return $checker && is_string($value) && preg_match('/^[\dA-F]{2}(\-[\dA-F]{2}){3,5}$/i', $value); break;
-
- case 'user.username':
- case 'machine.name':
+ case 'group.name':
+ case 'user.username':
+ case 'machine.name': case 'group.name': return $checker && is_string($value) && preg_match('/^[\w-]{1,30}$/i', $value); break;
-
- case 'user.firstname':
+ case 'user.lastname':
+ case 'user.firstname': case 'user.lastname': return $checker && is_string($value) && preg_match('/^[a-z -]{3,30}$/i', $value); break;
-
+ case 'user.mail': case 'user.mail': return $checker && is_string($value) && strlen($value) <= 50 && preg_match('/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i', $value); break;
-
+ case 'user.password': case 'user.password': return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value); break;
-
- }
-
+ return $checker;
+ case 'user.status':
+ return $checker && is_numeric($value) && floor($value) == $value && $value >= 0 && $value <= 100; break;
-
+ } }
-
-
- }
+ ?>
+ return $checker;
+
+ }
+
+
+ }
@@ -427,7 +431,7 @@
Dead Code
?>
- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 22:01:41 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:21:09 CET 2016.
diff --git a/phpunit/coverage/ManagerError.php.html b/phpunit/coverage/ManagerError.php.html index eb5c9be..32bc08c 100644 --- a/phpunit/coverage/ManagerError.php.html +++ b/phpunit/coverage/ManagerError.php.html @@ -203,7 +203,7 @@ Dead Code- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 22:01:41 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:21:09 CET 2016.
diff --git a/phpunit/coverage/ResourceDispatcher.php.html b/phpunit/coverage/ResourceDispatcher.php.html index c2500a2..5cb940c 100644 --- a/phpunit/coverage/ResourceDispatcher.php.html +++ b/phpunit/coverage/ResourceDispatcher.php.html @@ -450,7 +450,7 @@ Dead Code- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 22:01:41 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:21:09 CET 2016.
diff --git a/phpunit/coverage/autoloader.php.html b/phpunit/coverage/autoloader.php.html index 39c0b9f..1e5c090 100755 --- a/phpunit/coverage/autoloader.php.html +++ b/phpunit/coverage/autoloader.php.html @@ -58,7 +58,7 @@- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 22:01:41 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:21:09 CET 2016.
diff --git a/phpunit/coverage/index.dashboard.html b/phpunit/coverage/index.dashboard.html index 9e06cbb..4f9b37f 100755 --- a/phpunit/coverage/index.dashboard.html +++ b/phpunit/coverage/index.dashboard.html @@ -41,7 +41,8 @@- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 22:01:41 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Fri Feb 12 23:21:09 CET 2016.
diff --git a/phpunit/coverage/sessionManager.php.html b/phpunit/coverage/sessionManager.php.html new file mode 100644 index 0000000..695f607 --- /dev/null +++ b/phpunit/coverage/sessionManager.php.html @@ -0,0 +1,295 @@ + + + + ++ | Code Coverage |
+ |||||||||
+ | Classes and Traits |
+ Functions and Methods |
+ Lines |
+ |||||||
Total | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 25.00% |
+ 1 / 4 |
+ CRAP | +
+
+
+ |
+ 3.33% |
+ 1 / 30 |
+
sessionManager | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+
+
+
+ |
+ 25.00% |
+ 1 / 4 |
+ 120.30 | +
+
+
+ |
+ 3.33% |
+ 1 / 30 |
+
secure_sha1($data) | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ 1 | +
+
+
+ |
+ 100.00% |
+ 1 / 1 |
+ |||
reset_session($session_id=null) | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+ 6 | +
+
+
+ |
+ 0.00% |
+ 0 / 8 |
+ |||
update_token() | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+ 2 | +
+
+
+ |
+ 0.00% |
+ 0 / 5 |
+ |||
session_start() | +
+
+
+ |
+ 0.00% |
+ 0 / 1 |
+ 56 | +
+
+
+ |
+ 0.00% |
+ 0 / 16 |
+
<?php | |
namespace manager; | |
class sessionManager{ | |
private static $prefix; | |
/*************************/ | |
/* SECURE SHA1 ALGORITHM */ | |
/*************************/ | |
public static function secure_sha1($data){ | |
return sha1( '">\[..|{@#))'.sha1($data.'_)Q@#((%*_$%(@#') ); | |
} | |
/*****************************/ | |
/* INITIALISATION DE SESSION */ | |
/*****************************/ | |
private static function reset_session($session_id=null){ | |
// On ferme la session | |
session_destroy(); | |
// On definit l'id session si donne en argument | |
if( $session_id != null ) | |
session_id( $session_id ); | |
// Precaution: on met a jour le cookie | |
setcookie('PHPSESSID', session_id(), time()+60*30 ); | |
// On redemarre la session avec le bon id session | |
\session_start(); | |
// On met a jour le token | |
self::update_token(); | |
header('Refresh: 0'); | |
} | |
/*******************/ | |
/* GENERE UN TOKEN */ | |
/*******************/ | |
private static function update_token(){ | |
$token = self::$prefix.self::secure_sha1(uniqid()); | |
// On definit le token en session | |
$_SESSION['session_token'] = $token; | |
// On definit le token en cookie | |
$_COOKIE['session_token'] = $_SESSION['session_token']; | |
setcookie('session_token', $_COOKIE['session_token'], time()+60*30 ); | |
} | |
/************/ | |
/* AMORCEUR */ | |
/************/ | |
public static function session_start(){ | |
/* [1] Génération et Gestion des donnees a utiliser | |
==============================================================*/ | |
// On genere le hash a partir des donnees personnelles | |
self::$prefix = self::secure_sha1( $_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'] ); | |
// On cree un id session associe a ces donnees personnelles | |
$sessid = substr(self::$prefix,0,5) . substr(self::secure_sha1(uniqid()),0,24); | |
// On genere un token pour l'execution suivante | |
$token = self::$prefix.self::secure_sha1(uniqid()); | |
// On definit/recupere le token | |
$session_token = (isset($_COOKIE['session_token'])) ? $_COOKIE['session_token'] : null; | |
/* [2] Verification de l'id session | |
==============================================================*/ | |
\session_start(); | |
// On verifie l'id session (5 premiers chars du hash des donnees perso) | |
$valid_sessid = strpos( session_id(), substr(self::$prefix,0,5) ) === 0; | |
// Si id session incorrect ou pas de token | |
if( !$valid_sessid ) | |
self::reset_session( $sessid ); // On initialise la session (bon id session) | |
// si id session invalide | |
/* [3] Verification du token | |
==============================================================*/ | |
// On verifie que le token est valide | |
$valid_token = $session_token != null; // verification de l'existence du cookie | |
$valid_token = $valid_token && strpos($session_token, self::$prefix) === 0; // verification des donnes personnelles | |
$valid_token = $valid_token && isset($_SESSION['session_token']); // verification que la variable session associee existe | |
$valid_token = $valid_token && $_SESSION['session_token'] == $_COOKIE['session_token']; // verification que la session est coherente | |
/* [4] Si token inexistant | |
==============================================================*/ | |
if( !$valid_token ) | |
self::reset_session($sessid); // On initialise la session | |
else | |
self::update_token(); // Dans tous les cas, on cree un nouveau token | |
} | |
} | |
?> |