Subversion Repositories Applications.referentiel

Rev

Rev 118 | Rev 134 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 118 Rev 120
Line 439... Line 439...
439
	
439
	
440
	private function verifierAccesFonctionExec() {
440
	private function verifierAccesFonctionExec() {
441
		$disabled = explode(', ', ini_get('disable_functions'));
441
		$disabled = explode(', ', ini_get('disable_functions'));
442
		return !in_array('exec', $disabled);
442
		return !in_array('exec', $disabled);
-
 
443
	}
-
 
444
	
-
 
445
	//+----------------------------------------------------------------------------------------------------------------+
-
 
446
	// GESTION DU CLIENT REST
-
 
447
	
-
 
448
	protected function getRestClient() {
-
 
449
		if (! isset($this->restClient)) {
-
 
450
			$this->restClient = new RestClient();
-
 
451
		}
-
 
452
		return $this->restClient;
-
 
453
	}
-
 
454
	
-
 
455
	//+----------------------------------------------------------------------------------------------------------------+
-
 
456
	// GESTION DE L'IDENTIFICATION
-
 
457
	
-
 
458
	protected function getAuthIdentifiant() {
-
 
459
		$id = (isset($_SERVER['PHP_AUTH_USER'])) ? $_SERVER['PHP_AUTH_USER'] : null;
-
 
460
		return $id;
-
 
461
	}
-
 
462
	
-
 
463
	protected function getAuthMotDePasse() {
-
 
464
		$mdp = (isset($_SERVER['PHP_AUTH_PW'])) ? $_SERVER['PHP_AUTH_PW'] : null;
-
 
465
		return $mdp;
-
 
466
	}
-
 
467
	
-
 
468
	public function authentifierCoordinateur() { 
-
 
469
		$message_accueil = "Veuillez vous identifier avec votre compte Tela Botanica.";
-
 
470
		$message_echec = "Accès limité aux coordinateurs du projet.\n".
-
 
471
			"Votre tentative d'identification a échoué.\n".
-
 
472
			"Actualiser la page pour essayer à nouveau si vous êtes bien inscrit comme coordinateur.";
-
 
473
		return $this->authentifier($message_accueil, $message_echec);
-
 
474
	}
-
 
475
	
-
 
476
	private function authentifier($message_accueil, $message_echec) {
-
 
477
		$id = $this->getAuthIdentifiant();
-
 
478
		if (!isset($id)) {
-
 
479
			$this->envoyerAuth($message_accueil, $message_echec);
-
 
480
		} else {
-
 
481
			$autorisation = $this->etreCoordinateurAutorise();
-
 
482
			if ($autorisation == false) {
-
 
483
				$this->envoyerAuth($message_accueil, $message_echec);
-
 
484
			}
-
 
485
		}
-
 
486
		return true;
-
 
487
	} 
-
 
488
	
-
 
489
	public function etreCoordinateurAutorise($identifiant) {
-
 
490
		$identifiant = $this->getAuthIdentifiant();
-
 
491
		$mdp = md5($this->getAuthMotDePasse());
-
 
492
		$url = sprintf(Config::get('authentification.serviceUrlTpl'), $identifiant, $mdp);
-
 
493
		$json = $this->getRestClient()->envoyerRequeteConsultation($url);
-
 
494
		$existe = json_decode($json);
-
 
495
		$admin = $this->etreCoordinateur($identifiant) ? true : false;
-
 
496
		$autorisation = ($existe && $admin) ? true : false;
-
 
497
		return $autorisation;
-
 
498
	}
-
 
499
	
-
 
500
	public function etreCoordinateur($courriel) {
-
 
501
		$coordinateurs = Config::get('authentification.coordinateurs');
-
 
502
		$courriels_autorises = explode(',', $coordinateurs);
-
 
503
 
-
 
504
		$autorisation = (in_array($courriel, $courriels_autorises)) ? true : false ;
-
 
505
		return $autorisation;
-
 
506
	}
-
 
507
	
-
 
508
	private function envoyerAuth($message_accueil, $message_echec) {
-
 
509
		header('HTTP/1.0 401 Unauthorized');
-
 
510
		header('WWW-Authenticate: Basic realm="'.mb_convert_encoding($message_accueil, 'ISO-8859-1', 'UTF-8').'"');
-
 
511
		header('Content-type: text/plain; charset=UTF-8');
-
 
512
		print $message_echec;
-
 
513
		exit(0);
443
	}
514
	}
444
}
515
}