Skip to content

Commit

Permalink
Implements a more permissive way of detecting command-line execution.
Browse files Browse the repository at this point in the history
Change /api/task/* -> /api/tasks/*
  • Loading branch information
protich committed Mar 6, 2013
1 parent 0812887 commit ba72326
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
7 changes: 5 additions & 2 deletions api/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion api/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

$dispatcher = patterns('',
url_post("^/tickets\.(?P<format>xml|json|email)$", array('api.tickets.php:TicketApiController','create')),
url('^/task/', patterns('',
url('^/tasks/', patterns('',
url_post("^cron$", array('api.cron.php:CronApiController', 'execute'))
))
);
Expand Down
8 changes: 4 additions & 4 deletions api/pipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
?>
4 changes: 2 additions & 2 deletions include/class.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 7 additions & 0 deletions include/class.osticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}

?>

0 comments on commit ba72326

Please sign in to comment.