@@ -60,6 +60,13 @@ abstract class REST_Controller extends CI_Controller
6060 */
6161 protected $ rest = NULL ;
6262
63+ /**
64+ * Object to store data about the client sending the request
65+ *
66+ * @var object
67+ */
68+ protected $ client = NULL ;
69+
6370 /**
6471 * The arguments for the GET request method
6572 *
@@ -145,8 +152,13 @@ public function __construct()
145152 // Lets grab the config and get ready to party
146153 $ this ->load ->config ('rest ' );
147154
148- // How is this request being made? POST, DELETE, GET, PUT?
155+ // let's learn about the request
149156 $ this ->request = new stdClass ();
157+
158+ // Is it over SSL?
159+ $ this ->request ->ssl = $ this ->_detect_ssl ();
160+
161+ // How is this request being made? POST, DELETE, GET, PUT?
150162 $ this ->request ->method = $ this ->_detect_method ();
151163
152164 // Create argument container, if nonexistent
@@ -250,6 +262,12 @@ public function __construct()
250262 */
251263 public function _remap ($ object_called , $ arguments )
252264 {
265+ // Should we answer if not over SSL?
266+ if (config_item ('force_https ' ) AND !$ this ->_detect_ssl ())
267+ {
268+ $ this ->response (array ('status ' => false , 'error ' => 'Unsupported protocol ' ), 403 );
269+ }
270+
253271 $ pattern = '/^(.*)\.( ' .implode ('| ' , array_keys ($ this ->_supported_formats )).')$/ ' ;
254272 if (preg_match ($ pattern , $ object_called , $ matches ))
255273 {
@@ -407,6 +425,17 @@ public function response($data = array(), $http_code = null)
407425 exit ($ output );
408426 }
409427
428+ /*
429+ * Detect SSL use
430+ *
431+ * Detect whether SSL is being used or not
432+ */
433+ protected function _detect_ssl ()
434+ {
435+ return (isset ($ _SERVER ['HTTPS ' ]) && $ _SERVER ['HTTPS ' ] == "on " ));
436+ }
437+
438+
410439 /*
411440 * Detect input format
412441 *
@@ -569,18 +598,20 @@ protected function _detect_api_key()
569598 // Find the key from server or arguments
570599 if (($ key = isset ($ this ->_args [$ api_key_variable ]) ? $ this ->_args [$ api_key_variable ] : $ this ->input ->server ($ key_name )))
571600 {
572- if ( ! ($ row = $ this ->rest ->db ->where (' key ' , $ key )->get (config_item ('rest_keys_table ' ))->row ()))
601+ if ( ! ($ this -> client = $ this ->rest ->db ->where (config_item ( ' rest_key_column ' ) , $ key )->get (config_item ('rest_keys_table ' ))->row ()))
573602 {
574603 return FALSE ;
575604 }
576605
577- $ this ->rest ->key = $ row -> key ;
606+ $ this ->rest ->key = $ this -> client ->{ config_item ( ' rest_key_column ' )} ;
578607
608+ /*
579609 isset($row->user_id) AND $this->rest->user_id = $row->user_id;
580610 isset($row->level) AND $this->rest->level = $row->level;
581611 isset($row->ignore_limits) AND $this->rest->ignore_limits = $row->ignore_limits;
612+ */
582613
583- return TRUE ;
614+ return $ this -> client ;
584615 }
585616
586617 // No key has been sent
0 commit comments