@@ -286,7 +286,7 @@ public function __construct()
286
286
$ this ->auth_override = $ this ->_auth_override_check ();
287
287
288
288
// Checking for keys? GET TO WorK!
289
- // Skip keys test for $config['auth_override_class_method']['class'['method'] = 'none'
289
+ // Skip keys test for $config['auth_override_class_method']['class'['method'] = 'none'
290
290
if (config_item ('rest_enable_keys ' ) and $ this ->auth_override !== true ) {
291
291
$ this ->_allow = $ this ->_detect_api_key ();
292
292
}
@@ -444,8 +444,6 @@ protected function _fire_method($method, $args)
444
444
*/
445
445
public function response ($ data = null , $ http_code = null , $ continue = false )
446
446
{
447
- global $ CFG ;
448
-
449
447
// If data is null and not code provide, error and bail
450
448
if ($ data === null && $ http_code === null ) {
451
449
$ http_code = 404 ;
@@ -462,7 +460,7 @@ public function response($data = null, $http_code = null, $continue = false)
462
460
// Otherwise (if no data but 200 provided) or some data, carry on camping!
463
461
else {
464
462
// Is compression requested?
465
- if ($ CFG ->item ('compress_output ' ) === true && $ this ->_zlib_oc == false ) {
463
+ if ($ this -> config ->item ('compress_output ' ) === true && $ this ->_zlib_oc == false ) {
466
464
if (extension_loaded ('zlib ' )) {
467
465
if (isset ($ _SERVER ['HTTP_ACCEPT_ENCODING ' ]) and strpos ($ _SERVER ['HTTP_ACCEPT_ENCODING ' ], 'gzip ' ) !== false ) {
468
466
ob_start ('ob_gzhandler ' );
@@ -501,7 +499,7 @@ public function response($data = null, $http_code = null, $continue = false)
501
499
// but it will not modify the content-length header to compensate for
502
500
// the reduction, causing the browser to hang waiting for more data.
503
501
// We'll just skip content-length in those cases.
504
- if ( ! $ this ->_zlib_oc && ! $ CFG ->item ('compress_output ' )) {
502
+ if ( ! $ this ->_zlib_oc && ! $ this -> config ->item ('compress_output ' )) {
505
503
header ('Content-Length: ' . strlen ($ output ));
506
504
}
507
505
@@ -794,8 +792,8 @@ protected function _check_limit($controller_method)
794
792
->get (config_item ('rest_limits_table ' ))
795
793
->row ();
796
794
797
- // No calls yet, or been an hour since they called
798
- if ( ! $ result or $ result -> hour_started < time () - ( 60 * 60 ) ) {
795
+ // No calls yet for this key
796
+ if ( ! $ result ) {
799
797
// Right, set one up from scratch
800
798
$ this ->rest ->db ->insert (config_item ('rest_limits_table ' ), array (
801
799
'uri ' => $ this ->uri ->uri_string (),
@@ -810,7 +808,7 @@ protected function _check_limit($controller_method)
810
808
// Reset the started period
811
809
$ this ->rest ->db
812
810
->where ('uri ' , $ this ->uri ->uri_string ())
813
- ->where ('api_key_id ' , $ this ->rest ->key_id )
811
+ ->where ('api_key ' , isset ( $ this ->rest ->key ) ? $ this -> rest -> key : '' )
814
812
->set ('hour_started ' , time ())
815
813
->set ('count ' , 1 )
816
814
->update (config_item ('rest_limits_table ' ));
@@ -1303,13 +1301,19 @@ protected function _check_login($username = '', $password = false)
1303
1301
if (empty ($ username )) {
1304
1302
return false ;
1305
1303
}
1304
+
1305
+ $ auth_source = strtolower ($ this ->config ->item ('auth_source ' ));
1306
+ $ rest_auth = strtolower ($ this ->config ->item ('rest_auth ' ));
1307
+ $ valid_logins = $ this ->config ->item ('rest_valid_logins ' );
1308
+
1309
+ if (!$ this ->config ->item ('auth_source ' ) && $ rest_auth == 'digest ' ) { // for digest we do not have a password passed as argument
1310
+ return md5 ($ username .': ' .$ this ->config ->item ('rest_realm ' ).': ' .(isset ($ valid_logins [$ username ])?$ valid_logins [$ username ]:'' ));
1311
+ }
1306
1312
1307
1313
if ($ password === false ) {
1308
1314
return false ;
1309
1315
}
1310
1316
1311
- $ auth_source = strtolower ($ this ->config ->item ('auth_source ' ));
1312
-
1313
1317
if ($ auth_source == 'ldap ' ) {
1314
1318
log_message ('debug ' , 'performing LDAP authentication for $username ' );
1315
1319
@@ -1322,8 +1326,6 @@ protected function _check_login($username = '', $password = false)
1322
1326
return $ this ->_perform_library_auth ($ username , $ password );
1323
1327
}
1324
1328
1325
- $ valid_logins = $ this ->config ->item ('rest_valid_logins ' );
1326
-
1327
1329
if (!array_key_exists ($ username , $ valid_logins )) {
1328
1330
return false ;
1329
1331
}
@@ -1410,18 +1412,11 @@ protected function _prepare_digest_auth()
1410
1412
$ digest = (empty ($ matches [1 ]) || empty ($ matches [2 ])) ? array () : array_combine ($ matches [1 ], $ matches [2 ]);
1411
1413
1412
1414
// For digest authentication the library function should return already stored md5(username:restrealm:password) for that username @see rest.php::auth_library_function config
1413
- if ( ! array_key_exists ('username ' , $ digest ) or ! ($ A1 = $ this ->_check_login ($ digest ['username ' ])) ) {
1415
+ $ A1 = $ this ->_check_login ($ digest ['username ' ], true );
1416
+ if ( ! array_key_exists ('username ' , $ digest ) or ! $ A1 ) {
1414
1417
$ this ->_force_login ($ uniqid );
1415
1418
}
1416
1419
1417
- // If the auth_source is not selected use the rest.php configuration valid logins
1418
- if ( ! $ this ->config ->item ('auth_source ' ) ) {
1419
- $ valid_logins = $ this ->config ->item ('rest_valid_logins ' );
1420
- $ valid_pass = $ valid_logins [$ digest ['username ' ]];
1421
-
1422
- // This is the valid response expected
1423
- $ A1 = md5 ($ digest ['username ' ].': ' .$ this ->config ->item ('rest_realm ' ).': ' .$ valid_pass );
1424
- }
1425
1420
$ A2 = md5 (strtoupper ($ this ->request ->method ).': ' .$ digest ['uri ' ]);
1426
1421
$ valid_response = md5 ($ A1 .': ' .$ digest ['nonce ' ].': ' .$ digest ['nc ' ].': ' .$ digest ['cnonce ' ].': ' .$ digest ['qop ' ].': ' .$ A2 );
1427
1422
0 commit comments