441,4 → 441,75 |
$disabled = explode(', ', ini_get('disable_functions')); |
return !in_array('exec', $disabled); |
} |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// GESTION DU CLIENT REST |
|
protected function getRestClient() { |
if (! isset($this->restClient)) { |
$this->restClient = new RestClient(); |
} |
return $this->restClient; |
} |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// GESTION DE L'IDENTIFICATION |
|
protected function getAuthIdentifiant() { |
$id = (isset($_SERVER['PHP_AUTH_USER'])) ? $_SERVER['PHP_AUTH_USER'] : null; |
return $id; |
} |
|
protected function getAuthMotDePasse() { |
$mdp = (isset($_SERVER['PHP_AUTH_PW'])) ? $_SERVER['PHP_AUTH_PW'] : null; |
return $mdp; |
} |
|
public function authentifierCoordinateur() { |
$message_accueil = "Veuillez vous identifier avec votre compte Tela Botanica."; |
$message_echec = "Accès limité aux coordinateurs du projet.\n". |
"Votre tentative d'identification a échoué.\n". |
"Actualiser la page pour essayer à nouveau si vous êtes bien inscrit comme coordinateur."; |
return $this->authentifier($message_accueil, $message_echec); |
} |
|
private function authentifier($message_accueil, $message_echec) { |
$id = $this->getAuthIdentifiant(); |
if (!isset($id)) { |
$this->envoyerAuth($message_accueil, $message_echec); |
} else { |
$autorisation = $this->etreCoordinateurAutorise(); |
if ($autorisation == false) { |
$this->envoyerAuth($message_accueil, $message_echec); |
} |
} |
return true; |
} |
|
public function etreCoordinateurAutorise($identifiant) { |
$identifiant = $this->getAuthIdentifiant(); |
$mdp = md5($this->getAuthMotDePasse()); |
$url = sprintf(Config::get('authentification.serviceUrlTpl'), $identifiant, $mdp); |
$json = $this->getRestClient()->envoyerRequeteConsultation($url); |
$existe = json_decode($json); |
$admin = $this->etreCoordinateur($identifiant) ? true : false; |
$autorisation = ($existe && $admin) ? true : false; |
return $autorisation; |
} |
|
public function etreCoordinateur($courriel) { |
$coordinateurs = Config::get('authentification.coordinateurs'); |
$courriels_autorises = explode(',', $coordinateurs); |
|
$autorisation = (in_array($courriel, $courriels_autorises)) ? true : false ; |
return $autorisation; |
} |
|
private function envoyerAuth($message_accueil, $message_echec) { |
header('HTTP/1.0 401 Unauthorized'); |
header('WWW-Authenticate: Basic realm="'.mb_convert_encoding($message_accueil, 'ISO-8859-1', 'UTF-8').'"'); |
header('Content-type: text/plain; charset=UTF-8'); |
print $message_echec; |
exit(0); |
} |
} |