|
@@ -1723,7 +1723,8 @@ class PHP_CRUD_API {
|
1723
|
1723
|
$request = isset($request)?$request:null;
|
1724
|
1724
|
$get = isset($get)?$get:null;
|
1725
|
1725
|
$post = isset($post)?$post:null;
|
1726
|
|
-
|
|
1726
|
+ $origin = isset($origin)?$origin:null;
|
|
1727
|
+
|
1727
|
1728
|
// defaults
|
1728
|
1729
|
if (!$dbengine) {
|
1729
|
1730
|
$dbengine = 'MySQL';
|
|
@@ -1743,6 +1744,9 @@ class PHP_CRUD_API {
|
1743
|
1744
|
if (!$post) {
|
1744
|
1745
|
$post = $this->retrievePostData();
|
1745
|
1746
|
}
|
|
1747
|
+ if (!$origin) {
|
|
1748
|
+ $origin = isset($_SERVER['HTTP_ORIGIN'])?$_SERVER['HTTP_ORIGIN']:'';
|
|
1749
|
+ }
|
1746
|
1750
|
|
1747
|
1751
|
// connect
|
1748
|
1752
|
$request = trim($request,'/');
|
|
@@ -1767,7 +1771,7 @@ class PHP_CRUD_API {
|
1767
|
1771
|
}
|
1768
|
1772
|
|
1769
|
1773
|
$this->db = $db;
|
1770
|
|
- $this->settings = compact('method', 'request', 'get', 'post', 'database', 'table_authorizer', 'record_filter', 'column_authorizer', 'tenancy_function', 'input_sanitizer', 'input_validator', 'extensions', 'auto_include', 'allow_origin');
|
|
1774
|
+ $this->settings = compact('method', 'request', 'get', 'post', 'origin', 'database', 'table_authorizer', 'record_filter', 'column_authorizer', 'tenancy_function', 'input_sanitizer', 'input_validator', 'extensions', 'auto_include', 'allow_origin');
|
1771
|
1775
|
}
|
1772
|
1776
|
|
1773
|
1777
|
public static function php_crud_api_transform(&$tables) {
|
|
@@ -2114,20 +2118,25 @@ class PHP_CRUD_API {
|
2114
|
2118
|
echo '}';
|
2115
|
2119
|
}
|
2116
|
2120
|
|
2117
|
|
- public function executeCommand() {
|
2118
|
|
- if (isset($_SERVER['REQUEST_METHOD'])) {
|
2119
|
|
- $origins = explode(',',$this->settings['allow_origin']);
|
2120
|
|
- if (count($origins)==1) {
|
2121
|
|
- header('Access-Control-Allow-Origin: '.$origins[0]);
|
2122
|
|
- } else {
|
2123
|
|
- $origins = array_map('strtolower', $origins);
|
2124
|
|
- $origins = array_map('trim', $origins);
|
2125
|
|
- $origin = strtolower($_SERVER['HTTP_ORIGIN']);
|
2126
|
|
- if (in_array($origin,$origins)) {
|
2127
|
|
- header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
|
|
2121
|
+ protected function allowOrigin($origin,$allowOrigins) {
|
|
2122
|
+ $allowedOrigins = explode(',',$allowOrigins);
|
|
2123
|
+ if ($allowedOrigins[0]=='*') {
|
|
2124
|
+ header('Access-Control-Allow-Origin: *');
|
|
2125
|
+ } else {
|
|
2126
|
+ if ($origin) foreach ($allowedOrigins as $allowedOrigin) {
|
|
2127
|
+ $allowedOrigin = str_replace('\*','.*',preg_quote(strtolower(trim($allowedOrigin))));
|
|
2128
|
+ if (preg_match('/^'.$allowedOrigin.'$/',$origin)) {
|
|
2129
|
+ header('Access-Control-Allow-Origin: '.$origin);
|
|
2130
|
+ break;
|
2128
|
2131
|
}
|
2129
|
2132
|
}
|
2130
|
2133
|
}
|
|
2134
|
+ }
|
|
2135
|
+
|
|
2136
|
+ public function executeCommand() {
|
|
2137
|
+ if (isset($_SERVER['REQUEST_METHOD'])) {
|
|
2138
|
+ $this->allowOrigin($this->settings['origin'],$this->settings['allow_origin']);
|
|
2139
|
+ }
|
2131
|
2140
|
if (!$this->settings['request']) {
|
2132
|
2141
|
$this->swagger($this->settings);
|
2133
|
2142
|
} else {
|