TYPO3 CMS  TYPO3_6-2
CliBootstrap.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Core;
3 
25 class CliBootstrap {
26 
33  static public function checkEnvironmentOrDie() {
34  if (substr(php_sapi_name(), 0, 3) === 'cgi') {
35  self::initializeCgiCompatibilityLayerOrDie();
36  } elseif (php_sapi_name() !== 'cli') {
37  die('Not called from a command line interface (e.g. a shell or scheduler).' . chr(10));
38  }
39  }
40 
49  static public function initializeCliKeyOrDie() {
50  if (!isset($_SERVER['argv'][1]) || !is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'][$_SERVER['argv'][1]])) {
51  if (!isset($_SERVER['argv'][1])) {
52  $message = 'This script must have a \'cliKey\' as first argument.';
53  } else {
54  $message = 'The supplied \'cliKey\' is not valid.';
55  }
56  $message .= ' Valid keys are:
57 
58 ';
59  $cliKeys = array_keys($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']);
60  asort($cliKeys);
61  foreach ($cliKeys as $key => $value) {
62  $message .= ' ' . $value . LF;
63  }
64  fwrite(STDERR, $message . LF);
65  die(1);
66  }
67  define('TYPO3_cliKey', $_SERVER['argv'][1]);
68  define('TYPO3_cliInclude', \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'][TYPO3_cliKey][0]));
69  $GLOBALS['MCONF']['name'] = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'][TYPO3_cliKey][1];
70  // This is a compatibility layer: Some cli scripts rely on this, like ext:phpunit cli
71  $GLOBALS['temp_cliScriptPath'] = array_shift($_SERVER['argv']);
72  $GLOBALS['temp_cliKey'] = array_shift($_SERVER['argv']);
73  array_unshift($_SERVER['argv'], $GLOBALS['temp_cliScriptPath']);
74  }
75 
82  static protected function initializeCgiCompatibilityLayerOrDie() {
83  // Sanity check: Ensure we're running in a shell or cronjob (and NOT via HTTP)
84  $checkEnvVars = array('HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_NAME', 'REMOTE_ADDR', 'REMOTE_PORT', 'SERVER_PROTOCOL');
85  foreach ($checkEnvVars as $var) {
86  if (array_key_exists($var, $_SERVER)) {
87  echo 'SECURITY CHECK FAILED! This script cannot be used within your browser!' . chr(10);
88  echo 'If you are sure that we run in a shell or cronjob, please unset' . chr(10);
89  echo 'environment variable ' . $var . ' (usually using \'unset ' . $var . '\')' . chr(10);
90  echo 'before starting this script.' . chr(10);
91  die;
92  }
93  }
94  // Mimic CLI API in CGI API (you must use the -C/-no-chdir and the -q/--no-header switches!)
95  ini_set('html_errors', 0);
96  ini_set('implicit_flush', 1);
97  ini_set('max_execution_time', 0);
98  define('STDIN', fopen('php://stdin', 'r'));
99  define('STDOUT', fopen('php://stdout', 'w'));
100  define('STDERR', fopen('php://stderr', 'w'));
101  }
102 
103 }
die
Definition: index.php:6
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)