Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1814 Rev 1869
Line 119... Line 119...
119
	}
119
	}
Line 120... Line 120...
120
 
120
 
121
 
121
 
122
	protected function verifierSecuriteParametreUrl($param) {
122
	protected function verifierSecuriteParametreUrl($param) {
123
		//$verifier = array('NULL', "\n", "\r", "\\", "'", '"', "\x00", "\x1a", ';');
-
 
124
		if (!is_string($param)) return $param;
-
 
125
 
-
 
126
		$param = strip_tags($param);
123
		//$verifier = array('NULL', "\n", "\r", "\\", "'", '"', "\x00", "\x1a", ';');
Line 127... Line 124...
127
		return $param;
124
		return is_string($param) ? strip_tags($param) : $param;
128
	}
125
	}
129
 
126
 
Line 217... Line 214...
217
			header("Content-Type: $mime");
214
			header("Content-Type: $mime");
218
		}
215
		}
219
		print $contenu;
216
		print $contenu;
220
	}
217
	}
Line 221... Line 218...
221
 
218
 
222
	private function envoyerAuth($message_accueil, $message_echec) {
219
	static function envoyerAuth($message_accueil, $message_echec) {
223
		header('HTTP/1.0 401 Unauthorized');
220
		header('HTTP/1.0 401 Unauthorized');
224
		header('WWW-Authenticate: Basic realm="'.mb_convert_encoding($message_accueil, 'ISO-8859-1', 'UTF-8').'"');
221
		header('WWW-Authenticate: Basic realm="'.mb_convert_encoding($message_accueil, 'ISO-8859-1', 'UTF-8').'"');
225
		header('Content-type: text/plain; charset=UTF-8');
222
		header('Content-type: text/plain; charset=UTF-8');
226
		print $message_echec;
223
		print $message_echec;
227
		exit(0);
224
		exit;
Line 228... Line 225...
228
	}
225
	}
229
 
226
 
Line 238... Line 235...
238
	}
235
	}
Line 239... Line 236...
239
 
236
 
240
	//+----------------------------------------------------------------------------------------------------------------+
237
	//+----------------------------------------------------------------------------------------------------------------+
Line 241... Line 238...
241
	// GESTION DE L'IDENTIFICATION
238
	// GESTION DE L'IDENTIFICATION
242
	
239
	
243
	protected function getAuthIdentifiant() {
-
 
244
		$id = (isset($_SERVER['PHP_AUTH_USER'])) ? $_SERVER['PHP_AUTH_USER'] : null;
240
	static function getAuthIdentifiant() {
Line 245... Line 241...
245
		return $id;
241
		return isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null;
246
	}
242
	}
247
 
-
 
248
	protected function getAuthMotDePasse() {
243
 
Line 249... Line 244...
249
		$mdp = (isset($_SERVER['PHP_AUTH_PW'])) ? $_SERVER['PHP_AUTH_PW'] : null;
244
	static function getAuthMotDePasse() {
250
		return $mdp;
245
		return isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null;
251
	}
246
	}
Line 266... Line 261...
266
			"Actualiser la page pour essayer à nouveau si vous êtes déjà inscrit ou contacter 'accueil@tela-botanica.org'.";
261
			"Actualiser la page pour essayer à nouveau si vous êtes déjà inscrit ou contacter 'accueil@tela-botanica.org'.";
267
		return $this->authentifier($message_accueil, $message_echec, 'Utilisateur');
262
		return $this->authentifier($message_accueil, $message_echec, 'Utilisateur');
268
	}
263
	}
Line 269... Line 264...
269
 
264
 
270
	public function isAdmin($id) {
265
	public function isAdmin($id) {
271
		$admins = $this->config['jrest_admin']['admin'];
-
 
272
		$admin_tab = explode(',',$admins);
-
 
273
 
-
 
274
		if (in_array($id,$admin_tab)) {
-
 
275
			return true;
-
 
276
		} else {
-
 
277
			return false;
-
 
278
		}
266
		return in_array($id, explode(',', $this->config['jrest_admin']['admin']));
Line 279... Line 267...
279
	}
267
	}
280
 
-
 
281
	public function controleUtilisateur($id) {
268
 
282
 
269
	public function controleUtilisateur($id) {
283
		if (isset($_SESSION['user']) && isset($_SESSION['user']['name']) && $_SESSION['user']['name'] == '') {
270
		if (@array_key_exists('name', $_SESSION['user']) && empty($_SESSION['user']['name'])) {
284
			//cas de la session temporaire, on ne fait rien de particulier
271
			//cas de la session temporaire, on ne fait rien de particulier
285
		} else {
272
		} else {
286
			if (isset($_SESSION['user']) && isset($_SESSION['user']['name']) && !$this->isAdmin($_SESSION['user']['name']) && $_SESSION['user']['name'] != $id) {
273
			if (isset($_SESSION['user']) && isset($_SESSION['user']['name']) && !$this->isAdmin($_SESSION['user']['name']) && $_SESSION['user']['name'] != $id) {
Line 290... Line 277...
290
			}
277
			}
291
		}
278
		}
292
	}
279
	}
Line 293... Line 280...
293
	
280
	
294
	public function controleAppelIpAutorisee() {
281
	public function controleAppelIpAutorisee() {
295
		$ips_autorisees = explode(',', $this->config['jrest_admin']['ip_autorisees']);
-
 
296
		$ip_appelante = $_SERVER['REMOTE_ADDR'];
282
		$ips_autorisees = explode(',', @$this->config['jrest_admin']['ip_autorisees']);
297
		if(!in_array($ip_appelante, $ips_autorisees) && $ip_appelante != $_SERVER['SERVER_ADDR']) {
283
		if(!in_array($_SERVER['REMOTE_ADDR'], $ips_autorisees) && $_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) {
298
			header('HTTP/1.0 401 Unauthorized');
284
			header('HTTP/1.0 401 Unauthorized');
299
			echo 'Accès interdit';
-
 
300
			exit(0);
285
			exit('Accès interdit');
301
		}
286
		}
302
		return true;
287
		return true;
Line 303... Line 288...
303
	}
288
	}
Line 313... Line 298...
313
 
298
 
314
		Log::ajouterEntree($index,$chaine);
299
		Log::ajouterEntree($index,$chaine);
Line 315... Line 300...
315
	}
300
	}
316
 
-
 
317
	private function authentifier($message_accueil, $message_echec, $type) {
301
 
318
		$id = $this->getAuthIdentifiant();
302
	private function authentifier($message_accueil, $message_echec, $type) {
-
 
303
		if (!isset($_SERVER['PHP_AUTH_USER'])) {
-
 
304
			self::envoyerAuth($message_accueil, $message_echec); // exit
-
 
305
		}
-
 
306
 
319
		if (!isset($id)) {
307
		if ($type == 'Utilisateur' && self::getAuthMotDePasse() == 'debug') {
320
			$this->envoyerAuth($message_accueil, $message_echec);
-
 
321
		} else {
-
 
322
			if ($type == 'Utilisateur' && $this->getAuthMotDePasse() == 'debug') {
-
 
323
				$autorisation = true;
308
			$autorisation = true;
324
			} else {
309
		} else {
325
				$methodeAutorisation = "etre{$type}Autorise";
-
 
326
				$autorisation = $this->$methodeAutorisation();
-
 
327
			}
-
 
328
			if ($autorisation == false) {
-
 
329
				$this->envoyerAuth($message_accueil, $message_echec);
310
			$methodeAutorisation = "etre{$type}Autorise";
-
 
311
			$autorisation = $this->$methodeAutorisation();
-
 
312
		}
-
 
313
		if ($autorisation == false) {
-
 
314
			self::envoyerAuth($message_accueil, $message_echec);
330
			}
315
		}
331
		}
316
 
Line 332... Line 317...
332
		return true;
317
		return true;
333
	}
318
	}
334
 
319
 
335
	public function etreUtilisateurAutorise() {
320
	public function etreUtilisateurAutorise() {
336
		$identifiant = $this->getAuthIdentifiant();
321
		$identifiant = self::getAuthIdentifiant();
337
		$mdp = md5($this->getAuthMotDePasse());
322
		$mdp = md5(self::getAuthMotDePasse());
338
		$service = "TestLoginMdp/$identifiant/$mdp";
323
		$service = "TestLoginMdp/$identifiant/$mdp";
Line 339... Line 324...
339
		$url = sprintf($this->config['settings']['baseURLServicesAnnuaireTpl'], $service);
324
		$url = sprintf($this->config['settings']['baseURLServicesAnnuaireTpl'], $service);
340
		$json = $this->getRestClient()->consulter($url);
325
		$json = $this->getRestClient()->consulter($url);
341
		$existe = json_decode($json);
326
		$existe = json_decode($json);
Line 342... Line 327...
342
 
327
 
343
		$autorisation = (isset($existe) && $existe) ? true :false;
328
		$autorisation = (isset($existe) && $existe) ? true :false;
344
		return $autorisation;
329
		return $autorisation;
345
	}
330
	}
346
 
331
 
Line 347... Line 332...
347
	public function etreAdminAutorise() {
332
	public function etreAdminAutorise() {
348
		$identifiant = $this->getAuthIdentifiant();
-
 
349
		$autorisation = ($this->etreUtilisateurAutorise() && $this->etreAdminCel($identifiant)) ? true : false;
333
		$identifiant = self::getAuthIdentifiant();
350
		return $autorisation;
-
 
351
	}
334
		$autorisation = ($this->etreUtilisateurAutorise() && $this->etreAdminCel($identifiant)) ? true : false;
352
 
-
 
353
	public function etreAdminCel($courriel) {
335
		return $autorisation;
Line 354... Line 336...
354
		$admins = $this->config['jrest_admin']['admin'];
336
	}
Line 355... Line 337...
355
		$courriels_autorises = explode(',', $admins);
337
 
Line 454... Line 436...
454
		}
436
		}
455
		return $noms;
437
		return $noms;
456
	}
438
	}
Line 457... Line 439...
457
 
439
 
458
	protected function tronquerCourriel($courriel) {
440
	protected function tronquerCourriel($courriel) {
459
		$courriel = preg_replace('/[^@]+$/i', '...', $courriel);
-
 
460
		return $courriel;
441
		return preg_replace('/[^@]+$/i', '...', $courriel);
Line 461... Line 442...
461
	}
442
	}
462
 
443
 
463
	protected function nettoyerTableau(Array $tableau) {
444
	protected function nettoyerTableau(Array $tableau) {
Line 716... Line 697...
716
		// Ajout systématique d'un point virgule avant la fermeture php
697
		// Ajout systématique d'un point virgule avant la fermeture php
717
		$contenu = preg_replace("/;*\s*\?>/", "; ?>", $contenu);
698
		$contenu = preg_replace("/;*\s*\?>/", "; ?>", $contenu);
718
		return $contenu;
699
		return $contenu;
719
	}
700
	}
720
}
701
}
721
 
-
 
722
?>
-
 
723
702