forked from spicecrm/spicecrm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7,274 changed files
with
1,582,964 additions
and
1,632,843 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This File is part of KREST is a Restful service extension for SugarCRM | ||
* | ||
* Copyright (C) 2015 AAC SERVICES K.S., DOSTOJEVSKÉHO RAD 5, 811 09 BRATISLAVA, SLOVAKIA | ||
* | ||
* you can contat us at [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
class KRESTLogWriter | ||
{ | ||
/** | ||
* @var resource | ||
*/ | ||
protected $resource; | ||
|
||
/** | ||
* Constructor | ||
* @param resource $resource | ||
* @throws \InvalidArgumentException If invalid resource | ||
*/ | ||
public function __construct($resource) | ||
{ | ||
$this->resource = $myfile = fopen("slimlog.log", "w"); | ||
} | ||
|
||
/** | ||
* Write message | ||
* @param mixed $message | ||
* @param int $level | ||
* @return int|bool | ||
*/ | ||
public function write($message, $level = null) | ||
{ | ||
return fwrite($this->resource, (string) $message . PHP_EOL); | ||
} | ||
} | ||
<?php | ||
|
||
/* | ||
* This File is part of KREST is a Restful service extension for SugarCRM | ||
* | ||
* Copyright (C) 2015 AAC SERVICES K.S., DOSTOJEVSKÉHO RAD 5, 811 09 BRATISLAVA, SLOVAKIA | ||
* | ||
* you can contat us at [email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
class KRESTLogWriter | ||
{ | ||
/** | ||
* @var resource | ||
*/ | ||
protected $resource; | ||
|
||
/** | ||
* Constructor | ||
* @param resource $resource | ||
* @throws \InvalidArgumentException If invalid resource | ||
*/ | ||
public function __construct($resource) | ||
{ | ||
$this->resource = $myfile = fopen("slimlog.log", "w"); | ||
} | ||
|
||
/** | ||
* Write message | ||
* @param mixed $message | ||
* @param int $level | ||
* @return int|bool | ||
*/ | ||
public function write($message, $level = null) | ||
{ | ||
return fwrite($this->resource, (string) $message . PHP_EOL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,129 @@ | ||
<?php | ||
namespace CorsSlim; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS | ||
class CorsSlim extends \Slim\Middleware { | ||
protected $settings; | ||
|
||
public function __construct($settings = array()) { | ||
$this->settings = array_merge(array( | ||
'origin' => '*', // Wide Open! | ||
'allowMethods' => 'GET,HEAD,PUT,POST,DELETE' | ||
), $settings); | ||
} | ||
|
||
protected function setOrigin($req, $rsp) { | ||
$origin = $this->settings['origin']; | ||
if (is_callable($origin)) { | ||
// Call origin callback with request origin | ||
$origin = call_user_func($origin, | ||
$req->headers->get("Origin") | ||
); | ||
} | ||
|
||
// handle multiple allowed origins | ||
if(is_array($origin)) { | ||
|
||
$allowedOrigins = $origin; | ||
|
||
// default to the first allowed origin | ||
$origin = reset($allowedOrigins); | ||
|
||
// but use a specific origin if there is a match | ||
foreach($allowedOrigins as $allowedOrigin) { | ||
if($allowedOrigin === $req->headers->get("Origin")) { | ||
$origin = $allowedOrigin; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
$rsp->headers->set('Access-Control-Allow-Origin', $origin); | ||
} | ||
|
||
protected function setExposeHeaders($req, $rsp) { | ||
if (isset($this->settings['exposeHeaders'])) { | ||
$exposeHeaders = $this->settings['exposeHeaders']; | ||
if (is_array($exposeHeaders)) { | ||
$exposeHeaders = implode(", ", $exposeHeaders); | ||
} | ||
|
||
$rsp->headers->set('Access-Control-Expose-Headers', $exposeHeaders); | ||
} | ||
} | ||
|
||
protected function setMaxAge($req, $rsp) { | ||
if (isset($this->settings['maxAge'])) { | ||
$rsp->headers->set('Access-Control-Max-Age', $this->settings['maxAge']); | ||
} | ||
} | ||
|
||
protected function setAllowCredentials($req, $rsp) { | ||
if (isset($this->settings['allowCredentials']) && $this->settings['allowCredentials'] === True) { | ||
$rsp->headers->set('Access-Control-Allow-Credentials', 'true'); | ||
} | ||
} | ||
|
||
protected function setAllowMethods($req, $rsp) { | ||
if (isset($this->settings['allowMethods'])) { | ||
$allowMethods = $this->settings['allowMethods']; | ||
if (is_array($allowMethods)) { | ||
$allowMethods = implode(", ", $allowMethods); | ||
} | ||
|
||
$rsp->headers->set('Access-Control-Allow-Methods', $allowMethods); | ||
} | ||
} | ||
|
||
protected function setAllowHeaders($req, $rsp) { | ||
if (isset($this->settings['allowHeaders'])) { | ||
$allowHeaders = $this->settings['allowHeaders']; | ||
if (is_array($allowHeaders)) { | ||
$allowHeaders = implode(", ", $allowHeaders); | ||
} | ||
} | ||
else { // Otherwise, use request headers | ||
$allowHeaders = $req->headers->get("Access-Control-Request-Headers"); | ||
} | ||
|
||
if (isset($allowHeaders)) { | ||
$rsp->headers->set('Access-Control-Allow-Headers', $allowHeaders); | ||
} | ||
} | ||
|
||
protected function setCorsHeaders($app) { | ||
$req = $app->request(); | ||
$rsp = $app->response(); | ||
|
||
// http://www.html5rocks.com/static/images/cors_server_flowchart.png | ||
// Pre-flight | ||
if ($app->request->isOptions()) { | ||
$this->setOrigin($req, $rsp); | ||
$this->setMaxAge($req, $rsp); | ||
$this->setAllowCredentials($req, $rsp); | ||
$this->setAllowMethods($req, $rsp); | ||
$this->setAllowHeaders($req, $rsp); | ||
} | ||
else { | ||
$this->setOrigin($req, $rsp); | ||
$this->setExposeHeaders($req, $rsp); | ||
$this->setAllowCredentials($req, $rsp); | ||
} | ||
} | ||
|
||
public function call() { | ||
$this->setCorsHeaders($this->app); | ||
if(!$this->app->request->isOptions()) { | ||
$this->next->call(); | ||
} | ||
} | ||
|
||
public static function routeMiddleware($settings = array()) { | ||
$cors = new CorsSlim($settings); | ||
return function() use ($cors) { | ||
$app = \Slim\Slim::getInstance(); | ||
$cors->setCorsHeaders($app); | ||
}; | ||
} | ||
} | ||
?> | ||
<?php | ||
namespace CorsSlim; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS | ||
class CorsSlim extends \Slim\Middleware { | ||
protected $settings; | ||
|
||
public function __construct($settings = array()) { | ||
$this->settings = array_merge(array( | ||
'origin' => '*', // Wide Open! | ||
'allowMethods' => 'GET,HEAD,PUT,POST,DELETE' | ||
), $settings); | ||
} | ||
|
||
protected function setOrigin($req, $rsp) { | ||
$origin = $this->settings['origin']; | ||
if (is_callable($origin)) { | ||
// Call origin callback with request origin | ||
$origin = call_user_func($origin, | ||
$req->headers->get("Origin") | ||
); | ||
} | ||
|
||
// handle multiple allowed origins | ||
if(is_array($origin)) { | ||
|
||
$allowedOrigins = $origin; | ||
|
||
// default to the first allowed origin | ||
$origin = reset($allowedOrigins); | ||
|
||
// but use a specific origin if there is a match | ||
foreach($allowedOrigins as $allowedOrigin) { | ||
if($allowedOrigin === $req->headers->get("Origin")) { | ||
$origin = $allowedOrigin; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
$rsp->headers->set('Access-Control-Allow-Origin', $origin); | ||
} | ||
|
||
protected function setExposeHeaders($req, $rsp) { | ||
if (isset($this->settings['exposeHeaders'])) { | ||
$exposeHeaders = $this->settings['exposeHeaders']; | ||
if (is_array($exposeHeaders)) { | ||
$exposeHeaders = implode(", ", $exposeHeaders); | ||
} | ||
|
||
$rsp->headers->set('Access-Control-Expose-Headers', $exposeHeaders); | ||
} | ||
} | ||
|
||
protected function setMaxAge($req, $rsp) { | ||
if (isset($this->settings['maxAge'])) { | ||
$rsp->headers->set('Access-Control-Max-Age', $this->settings['maxAge']); | ||
} | ||
} | ||
|
||
protected function setAllowCredentials($req, $rsp) { | ||
if (isset($this->settings['allowCredentials']) && $this->settings['allowCredentials'] === True) { | ||
$rsp->headers->set('Access-Control-Allow-Credentials', 'true'); | ||
} | ||
} | ||
|
||
protected function setAllowMethods($req, $rsp) { | ||
if (isset($this->settings['allowMethods'])) { | ||
$allowMethods = $this->settings['allowMethods']; | ||
if (is_array($allowMethods)) { | ||
$allowMethods = implode(", ", $allowMethods); | ||
} | ||
|
||
$rsp->headers->set('Access-Control-Allow-Methods', $allowMethods); | ||
} | ||
} | ||
|
||
protected function setAllowHeaders($req, $rsp) { | ||
if (isset($this->settings['allowHeaders'])) { | ||
$allowHeaders = $this->settings['allowHeaders']; | ||
if (is_array($allowHeaders)) { | ||
$allowHeaders = implode(", ", $allowHeaders); | ||
} | ||
} | ||
else { // Otherwise, use request headers | ||
$allowHeaders = $req->headers->get("Access-Control-Request-Headers"); | ||
} | ||
|
||
if (isset($allowHeaders)) { | ||
$rsp->headers->set('Access-Control-Allow-Headers', $allowHeaders); | ||
} | ||
} | ||
|
||
protected function setCorsHeaders($app) { | ||
$req = $app->request(); | ||
$rsp = $app->response(); | ||
|
||
// http://www.html5rocks.com/static/images/cors_server_flowchart.png | ||
// Pre-flight | ||
if ($app->request->isOptions()) { | ||
$this->setOrigin($req, $rsp); | ||
$this->setMaxAge($req, $rsp); | ||
$this->setAllowCredentials($req, $rsp); | ||
$this->setAllowMethods($req, $rsp); | ||
$this->setAllowHeaders($req, $rsp); | ||
} | ||
else { | ||
$this->setOrigin($req, $rsp); | ||
$this->setExposeHeaders($req, $rsp); | ||
$this->setAllowCredentials($req, $rsp); | ||
} | ||
} | ||
|
||
public function call() { | ||
$this->setCorsHeaders($this->app); | ||
if(!$this->app->request->isOptions()) { | ||
$this->next->call(); | ||
} | ||
} | ||
|
||
public static function routeMiddleware($settings = array()) { | ||
$cors = new CorsSlim($settings); | ||
return function() use ($cors) { | ||
$app = \Slim\Slim::getInstance(); | ||
$cors->setCorsHeaders($app); | ||
}; | ||
} | ||
} | ||
?> |
Oops, something went wrong.