| 69 |
aurelien |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PHP Version 5
|
|
|
4 |
*
|
|
|
5 |
* @category PHP
|
|
|
6 |
* @package jrest
|
|
|
7 |
* @author aurelien <aurelien@tela-botanica.org>
|
|
|
8 |
* @copyright 2009 Tela-Botanica
|
|
|
9 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
10 |
* @version $$id$$
|
|
|
11 |
* @link /doc/jrest/
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class JrestService {
|
|
|
15 |
|
|
|
16 |
protected $config;
|
|
|
17 |
protected $script_time;
|
|
|
18 |
protected $max_exec_time;
|
|
|
19 |
|
|
|
20 |
public function JrestService($config) {
|
|
|
21 |
$this->config = config;
|
|
|
22 |
$this->script_time = microtime(true);
|
|
|
23 |
$this->max_exec_time = ini_get('max_execution_time');
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public function isAdmin($id) {
|
|
|
27 |
$admins = $this->config['jrest_admin']['admin'];
|
|
|
28 |
$admin_tab = split(',',$admins);
|
|
|
29 |
|
|
|
30 |
if (in_array($id,$admin_tab)) {
|
|
|
31 |
return true;
|
|
|
32 |
} else {
|
|
|
33 |
return false;
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public function controleUtilisateur($id) {
|
|
|
38 |
if ($_SESSION['user']['name'] == '') {
|
|
|
39 |
//cas de la session temporaire, on ne fait rien de particulier
|
|
|
40 |
} else {
|
|
|
41 |
if (!$this->isAdmin($_SESSION['user']['name']) && $_SESSION['user']['name'] != $id) {
|
|
|
42 |
// cas d'usurpation d'identité
|
|
|
43 |
print 'Accès interdit';
|
|
|
44 |
exit();
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public function logger($index,$chaine) {
|
|
|
50 |
if(!class_exists('Log')) {
|
|
|
51 |
include_once('Log.php');
|
|
|
52 |
Log::getInstance();
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
Log::setCheminLog($this->config['log']['cheminlog']);
|
|
|
56 |
Log::setTimeZone($this->config['log']['timezone']);
|
|
|
57 |
Log::setTailleMax($this->config['log']['taillemax']);
|
|
|
58 |
|
|
|
59 |
Log::ajouterEntree($index,$chaine);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function verifierOuRelancerExecution() {
|
|
|
63 |
|
|
|
64 |
if((microtime(true) - $this->script_time) > ($this->max_exec_time - 5)*100) {
|
|
|
65 |
set_time_limit(2);
|
|
|
66 |
$this->logger('JRestService','Durée du script augmentée :'.microtime(true).' - '.$this->script_time.'.) > ('.$this->max_exec_time.' - 5)*1000000');
|
|
|
67 |
return true;
|
|
|
68 |
}
|
|
|
69 |
return false;
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
?>
|