Subversion Repositories Applications.annuaire

Rev

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

Rev 430 Rev 473
Line 127... Line 127...
127
		header('Content-type: text/plain; charset=UTF-8');
127
		header('Content-type: text/plain; charset=UTF-8');
128
		print $message_echec;
128
		print $message_echec;
129
		exit(0);
129
		exit(0);
130
	}
130
	}
Line -... Line 131...
-
 
131
 
-
 
132
	protected function envoyerMessageErreur($msg, $code) {
-
 
133
		$textHttp = $this->getCodeHttpText($code);
-
 
134
		header("HTTP/1.0 $code $textHttp");
-
 
135
		header("Content-Type: text/plain; charset=utf-8");
-
 
136
		die($msg);
-
 
137
	}
-
 
138
 
-
 
139
	private function getCodeHttpText($code) {
-
 
140
		$text = '';
-
 
141
		switch ($code) {
-
 
142
			case 100: $text = 'Continue'; break;
-
 
143
			case 101: $text = 'Switching Protocols'; break;
-
 
144
			case 200: $text = 'OK'; break;
-
 
145
			case 201: $text = 'Created'; break;
-
 
146
			case 202: $text = 'Accepted'; break;
-
 
147
			case 203: $text = 'Non-Authoritative Information'; break;
-
 
148
			case 204: $text = 'No Content'; break;
-
 
149
			case 205: $text = 'Reset Content'; break;
-
 
150
			case 206: $text = 'Partial Content'; break;
-
 
151
			case 300: $text = 'Multiple Choices'; break;
-
 
152
			case 301: $text = 'Moved Permanently'; break;
-
 
153
			case 302: $text = 'Moved Temporarily'; break;
-
 
154
			case 303: $text = 'See Other'; break;
-
 
155
			case 304: $text = 'Not Modified'; break;
-
 
156
			case 305: $text = 'Use Proxy'; break;
-
 
157
			case 400: $text = 'Bad Request'; break;
-
 
158
			case 401: $text = 'Unauthorized'; break;
-
 
159
			case 402: $text = 'Payment Required'; break;
-
 
160
			case 403: $text = 'Forbidden'; break;
-
 
161
			case 404: $text = 'Not Found'; break;
-
 
162
			case 405: $text = 'Method Not Allowed'; break;
-
 
163
			case 406: $text = 'Not Acceptable'; break;
-
 
164
			case 407: $text = 'Proxy Authentication Required'; break;
-
 
165
			case 408: $text = 'Request Time-out'; break;
-
 
166
			case 409: $text = 'Conflict'; break;
-
 
167
			case 410: $text = 'Gone'; break;
-
 
168
			case 411: $text = 'Length Required'; break;
-
 
169
			case 412: $text = 'Precondition Failed'; break;
-
 
170
			case 413: $text = 'Request Entity Too Large'; break;
-
 
171
			case 414: $text = 'Request-URI Too Large'; break;
-
 
172
			case 415: $text = 'Unsupported Media Type'; break;
-
 
173
			case 500: $text = 'Internal Server Error'; break;
-
 
174
			case 501: $text = 'Not Implemented'; break;
-
 
175
			case 502: $text = 'Bad Gateway'; break;
-
 
176
			case 503: $text = 'Service Unavailable'; break;
-
 
177
			case 504: $text = 'Gateway Time-out'; break;
-
 
178
			case 505: $text = 'HTTP Version not supported'; break;
-
 
179
			default:
-
 
180
				exit('Unknown http status code "' . htmlentities($code) . '"');
-
 
181
			break;
-
 
182
		}
-
 
183
		return $text;
-
 
184
	}
131
 
185
 
132
	//+----------------------------------------------------------------------------------------------------------------+
186
	//+----------------------------------------------------------------------------------------------------------------+
Line 133... Line 187...
133
	// GESTION de la BASE de DONNÉES
187
	// GESTION de la BASE de DONNÉES
134
 
188
 
135
	private function connecterPDO($config, $base = 'database') {
189
	private function connecterPDO($config, $base = 'database') {
136
  		$cfg = $config[$base];
190
  		$cfg = $config[$base];
137
        // ATTENTION : la connexin à la bdd peut échouer si l'host vaut localhost. Utiliser 127.0.0.1 à la place.
191
		// ATTENTION : la connexin à la bdd peut échouer si l'host vaut localhost. Utiliser 127.0.0.1 à la place.
138
		$dsn = $cfg['phptype'].':dbname='.$cfg['database'].';host='.$cfg['hostspec'];
192
		$dsn = $cfg['phptype'].':dbname='.$cfg['database'].';host='.$cfg['hostspec'];
139
		try {
193
		try {
140
    		// Création de la connexion en UTF-8 à la BDD
194
		// Création de la connexion en UTF-8 à la BDD
141
			$PDO = new PDO($dsn, $cfg['username'], $cfg['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
195
			$PDO = new PDO($dsn, $cfg['username'], $cfg['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
142
		} catch (PDOException $e) {
196
		} catch (PDOException $e) {
143
    		echo 'La connexion à la base de donnée via PDO a échouée : ' .$dsn. $e->getMessage();
197
			echo 'La connexion à la base de donnée via PDO a échouée : ' .$dsn. $e->getMessage();
144
		}
198
		}
145
		// Affiche les erreurs détectées par PDO (sinon mode silencieux => aucune erreur affiché)
199
		// Affiche les erreurs détectées par PDO (sinon mode silencieux => aucune erreur affiché)
146
		$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
200
		$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Line 147... Line 201...
147
        return $PDO;
201
		return $PDO;
148
	}
202
	}
149
 
203
 
Line 199... Line 253...
199
	}
253
	}
Line 200... Line 254...
200
 
254
 
201
	//+----------------------------------------------------------------------------------------------------------------+
255
	//+----------------------------------------------------------------------------------------------------------------+
Line -... Line 256...
-
 
256
	// GESTION DE L'IDENTIFICATION
-
 
257
 
-
 
258
	public function controlerIpAutorisees() {
-
 
259
		$ipsAutorisees = $this->config['jrest_admin']['ip_autorisees'];
-
 
260
 
-
 
261
		$remoteIp = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
-
 
262
		$serverIp = filter_input(INPUT_SERVER, 'SERVER_ADDR', FILTER_VALIDATE_IP);
-
 
263
		if (in_array($remoteIp, $ipsAutorisees) == false) {
-
 
264
			if ($remoteIp != $serverIp) {// ATTENTION : maintenir ce test à l'intérieur du précédent
-
 
265
				$message = "Accès interdit. \n".
-
 
266
					"Vous n'êtes pas autorisé à accéder à ce service depuis '$remoteIp' !\n";
-
 
267
				$this->envoyerMessageErreur($message, 401);
-
 
268
			}
-
 
269
		}
-
 
270
		return true;
202
	// GESTION DE L'IDENTIFICATION
271
	}
203
 
272
 
204
	protected function getIdentification(&$params) {
273
	protected function getIdentification(&$params) {
Line 205... Line 274...
205
		// Initialisation des variables
274
		// Initialisation des variables