Cleanup #14987: Spelling mistakes in cli_dispatch.phpsh
[Packages/TYPO3.CMS.git] / typo3 / cli_dispatch.phpsh
1 #! /usr/bin/php -q
2 <?php
3 /***************************************************************
4 * Copyright notice
5 *
6 * (c) 2005-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Command Line Interface module dispatcher
31 *
32 * $Id$
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 *
36 * This script takes a "cliKey" as first argument and uses that to look up the path of the script to include in the end.
37 * See configuration of this feature in $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'].
38 * The point is to have only ONE script dealing with the environment initialization while the actual processing is all a developer should care for.
39 *
40 */
41
42 if (substr(php_sapi_name(), 0, 3) == 'cgi') {
43 // sanity check: ensure that we're running in a shell or cronjob (and NOT via HTTP)
44 $checkEnvVars = array('HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_NAME', 'REMOTE_ADDR', 'REMOTE_PORT', 'SERVER_PROTOCOL');
45 foreach ($checkEnvVars as $var) {
46 if (array_key_exists($var, $_SERVER)) {
47 echo 'SECURITY CHECK FAILED! This script cannot be used within your browser!' . chr(10);
48 echo 'If you are sure that we run in a shell or cronjob, please unset' . chr(10);
49 echo 'environment variable ' . $var . ' (usually using \'unset ' . $var . '\')' . chr(10);
50 echo 'before starting this script.' . chr(10);
51 exit;
52 }
53 }
54 unset($checkEnvVars);
55
56 // mimic CLI API in CGI API (you must use the -C/-no-chdir and the -q/--no-header switches!)
57 ini_set('html_errors', 0);
58 ini_set('implicit_flush', 1);
59 ini_set('max_execution_time', 0);
60 if (!ini_get('register_argc_argv')) {
61 $argv = $_SERVER['argv'];
62 $argc = $_SERVER['argc'];
63 }
64 define(STDIN, fopen('php://stdin', 'r'));
65 define(STDOUT, fopen('php://stdout', 'w'));
66 define(STDERR, fopen('php://stderr', 'w'));
67 } elseif (php_sapi_name() != 'cli') {
68 die('Not called from a command line interface (e.g. a shell or scheduler).' . chr(10));
69 }
70
71 // Defining circumstances for CLI mode:
72 define('TYPO3_cliMode', TRUE);
73
74 // Get path to this script
75 $temp_PATH_thisScript = isset($_SERVER['argv'][0]) ? $_SERVER['argv'][0] : (isset($_ENV['_']) ? $_ENV['_'] : $_SERVER['_']);
76
77 // Figure out if the path is relative
78 $relativePath = FALSE;
79 if (stristr(PHP_OS,'win') && !stristr(PHP_OS,'darwin')) {
80 // Windows
81 if (!preg_match('/^([A-Z]:)?\\\/', $temp_PATH_thisScript)) {
82 $relativePath = TRUE;
83 }
84 } else {
85 // *nix, et al
86 if ($temp_PATH_thisScript{0} != '/') {
87 $relativePath = TRUE;
88 }
89 }
90
91 // Resolve path
92 if ($relativePath) {
93 $workingDirectory = $_SERVER['PWD'] ? $_SERVER['PWD'] : getcwd();
94 if ($workingDirectory) {
95 $temp_PATH_thisScript =
96 $workingDirectory.'/'.preg_replace('/\.\//','',$temp_PATH_thisScript);
97 if (!@is_file($temp_PATH_thisScript)) {
98 die('Relative path found, but an error occurred while resolving the absolute path: ' . $temp_PATH_thisScript . chr(10));
99 }
100 } else {
101 die ('Relative path found, but resolving absolute path is not supported on this platform.'.chr(10));
102 }
103 }
104
105 // Define absolute path to this script
106 define('PATH_thisScript',$temp_PATH_thisScript);
107
108 if (!isset($_SERVER['argv'][1])) {
109 die ('The first argument must be a valid key.'.chr(10));
110 }
111
112 // First argument is a key that points to the script configuration
113 define('TYPO3_cliKey', $_SERVER['argv'][1]);
114
115 // Include init file:
116 require(dirname(PATH_thisScript).'/init.php');
117
118 // Make sure output is not buffered,
119 // so that command-line output and interaction can take place
120 t3lib_div::flushOutputBuffers();
121
122 if (defined('TYPO3_cliInclude')) {
123 include(TYPO3_cliInclude);
124 } else {
125 die('No include file configured for key "'.TYPO3_cliKey.'".'.chr(10));
126 }
127
128 ?>