From 83ecd7336cb787f10d8da9eb306b0d8880552da5 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Sat, 19 Oct 2013 03:42:54 +0000 Subject: [PATCH] Fix NOTICE errors from cli cron Fix PHP NOTICE level errors for cron jobs executed from the command line Fixes #4 --- api/cron.php | 2 -- bootstrap.php | 3 +++ include/class.osticket.php | 6 ++++-- main.inc.php | 4 +++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/api/cron.php b/api/cron.php index 0ca641b52..f5d47e43e 100644 --- a/api/cron.php +++ b/api/cron.php @@ -19,8 +19,6 @@ 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'); require_once(INCLUDE_DIR.'api.cron.php'); LocalCronApiController::call(); ?> diff --git a/bootstrap.php b/bootstrap.php index e99b1e339..d050960ed 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -43,6 +43,9 @@ class Bootstrap { ini_set('date.timezone', 'America/New_York'); } } + + if (!isset($_SERVER['REMOTE_ADDR'])) + $_SERVER['REMOTE_ADDR'] = ''; } function https() { diff --git a/include/class.osticket.php b/include/class.osticket.php index 467831d5b..10f16bf95 100644 --- a/include/class.osticket.php +++ b/include/class.osticket.php @@ -367,7 +367,7 @@ class osTicket { * Secondly, if the directory of main.inc.php is the same as the * document root, the the ROOT path truly is '/' */ - if(!$_SERVER['DOCUMENT_ROOT'] + if(!isset($_SERVER['DOCUMENT_ROOT']) || !strcasecmp($_SERVER['DOCUMENT_ROOT'], $dir)) return '/'; @@ -411,7 +411,9 @@ class osTicket { /* returns true if script is being executed via commandline */ 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 + || (!isset($_SERVER['REQUEST_METHOD']) && + !isset($_SERVER['HTTP_HOST'])) + //Fallback when php-cgi binary is used via cli ); } diff --git a/main.inc.php b/main.inc.php index 56da2cb71..e62d6e5e4 100644 --- a/main.inc.php +++ b/main.inc.php @@ -16,7 +16,9 @@ vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ #Disable direct access. -if(!strcasecmp(basename($_SERVER['SCRIPT_NAME']),basename(__FILE__))) die('kwaheri rafiki!'); +if(isset($_SERVER['SCRIPT_NAME']) + && !strcasecmp(basename($_SERVER['SCRIPT_NAME']),basename(__FILE__))) + die('kwaheri rafiki!'); require('bootstrap.php'); Bootstrap::loadConfig(); -- GitLab