Subversion Repositories Applications.annuaire

Rev

Rev 412 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 412 Rev 561
Line 21... Line 21...
21
	private $resource = NULL;
21
	private $resource = NULL;
Line 22... Line 22...
22
 
22
 
23
	/** Identifiant unique resource. */
23
	/** Identifiant unique resource. */
Line -... Line 24...
-
 
24
	private $uid = NULL;
-
 
25
 
-
 
26
	/** True si le type d'api est CGI / FastCGI, false si on a un module Apache... ou autre ? */
24
	private $uid = NULL;
27
	public static $cgi;
25
 
28
 
26
	/**
29
	/**
27
	 * Constructor. Parses the configuration file "JRest.ini", grabs any request data sent, records the HTTP
30
	 * Constructor. Parses the configuration file "JRest.ini", grabs any request data sent, records the HTTP
28
	 * request method used and parses the request URL to find out the requested resource
31
	 * request method used and parses the request URL to find out the requested resource
Line 61... Line 64...
61
						$this->uid[] = urldecode($uid);
64
						$this->uid[] = urldecode($uid);
62
					}
65
					}
63
				}
66
				}
64
			}
67
			}
Line -... Line 68...
-
 
68
 
-
 
69
			// détection du type d'API : CGI ou module Apache - le CGI ne permet pas
-
 
70
			// d'utiliser l'authentification HTTP Basic :-(
-
 
71
			self::$cgi = substr(php_sapi_name(), 0, 3) == 'cgi';
65
 
72
 
66
			$this->method = $_SERVER['REQUEST_METHOD'];
73
			$this->method = $_SERVER['REQUEST_METHOD'];
67
		} else {
74
		} else {
68
			trigger_error('I require the server variables REQUEST_URI, REQUEST_METHOD and QUERY_STRING to work.', E_USER_ERROR);
75
			trigger_error('I require the server variables REQUEST_URI, REQUEST_METHOD and QUERY_STRING to work.', E_USER_ERROR);
69
		}
76
		}
Line 259... Line 266...
259
 
266
 
260
	/**
267
	/**
261
	 * Send a HTTP 401 response header.
268
	 * Send a HTTP 401 response header.
262
	 */
269
	 */
-
 
270
	private function unauthorized($realm = 'JRest') {
263
	private function unauthorized($realm = 'JRest') {
271
		if (self::$cgi === false) { // si on est en CGI, accès libre pour tous (pas trouvé mieux)
264
		if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
272
			if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
-
 
273
				header('WWW-Authenticate: Basic realm="'.$realm.'"');
-
 
274
			}
265
			header('WWW-Authenticate: Basic realm="'.$realm.'"');
275
			header('HTTP/1.0 401 Unauthorized');
266
		}
-
 
267
		header('HTTP/1.0 401 Unauthorized');
276
		}
Line 268... Line 277...
268
	}
277
	}
269
 
278
 
270
	/**
279
	/**