diff --git a/api/cron.php b/api/cron.php index 43ff2b28..0ca641b5 100644 --- a/api/cron.php +++ b/api/cron.php @@ -13,8 +13,11 @@ vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ -if (substr(php_sapi_name(), 0, 3) != 'cli') - die('cron.php only supports local cron jobs - use http -> api/task/cron'); +@chdir(realpath(dirname(__FILE__)).'/'); //Change dir. +require('api.inc.php'); + +if (!osTicket::is_cli()) + die('cron.php only supports local cron calls - use http -> api/tasks/cron'); @chdir(realpath(dirname(__FILE__)).'/'); //Change dir. require('api.inc.php'); diff --git a/api/http.php b/api/http.php index 985d8e49..0fc32444 100644 --- a/api/http.php +++ b/api/http.php @@ -20,7 +20,7 @@ $dispatcher = patterns('', url_post("^/tickets\.(?Pxml|json|email)$", array('api.tickets.php:TicketApiController','create')), - url('^/task/', patterns('', + url('^/tasks/', patterns('', url_post("^cron$", array('api.cron.php:CronApiController', 'execute')) )) ); diff --git a/api/pipe.php b/api/pipe.php index aa35f898..7cf1ad1b 100644 --- a/api/pipe.php +++ b/api/pipe.php @@ -14,14 +14,14 @@ vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ +ini_set('memory_limit', '256M'); //The concern here is having enough mem for emails with attachments. +@chdir(realpath(dirname(__FILE__)).'/'); //Change dir. +require('api.inc.php'); //Only local piping supported via pipe.php -if (substr(php_sapi_name(), 0, 3) != 'cli') +if (!osTicket::is_cli()) die('pipe.php only supports local piping - use http -> api/tickets.email'); -ini_set('memory_limit', '256M'); //The concern here is having enough mem for emails with attachments. -@chdir(realpath(dirname(__FILE__)).'/'); //Change dir. -require('api.inc.php'); require_once(INCLUDE_DIR.'api.tickets.php'); PipeApiController::process(); ?> diff --git a/include/class.api.php b/include/class.api.php index 6403222c..9185093b 100644 --- a/include/class.api.php +++ b/include/class.api.php @@ -193,8 +193,8 @@ function getApiKey() { */ function getRequest($format) { global $ost; - - $input = (substr(php_sapi_name(), 0, 3) == 'cli')?'php://stdin':'php://input'; + + $input = $ost->is_cli()?'php://stdin':'php://input'; if (!($stream = @fopen($input, 'r'))) $this->exerr(400, "Unable to read request body"); diff --git a/include/class.osticket.php b/include/class.osticket.php index 4445aca6..4891b8d5 100644 --- a/include/class.osticket.php +++ b/include/class.osticket.php @@ -338,6 +338,13 @@ function start($configId) { return $ost; } + + /* is_cli */ + function is_cli() { + return (!strcasecmp(substr(php_sapi_name(), 0, 3), 'cli') + || (!$_SERVER['REQUEST_METHOD'] && !$_SERVER['HTTP_HOST']) //Fallback when php-cgi binary is used via cli + ); + } } ?>