00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00085 class t3lib_exec {
00086
00095 function checkCommand($cmd, $handler='') {
00096 global $T3_VAR;
00097
00098 if (!t3lib_exec::_init()) {
00099 return false;
00100 }
00101
00102
00103 if ($handler && !t3lib_exec::checkCommand($handler)) {
00104 return -1;
00105 }
00106
00107 if ($T3_VAR['t3lib_exec']['apps'][$cmd]['valid']) {
00108 return true;
00109 }
00110
00111 if (isset($T3_VAR['t3lib_exec']['apps'][$cmd]['valid'])) {
00112 return false;
00113 }
00114
00115 foreach($T3_VAR['t3lib_exec']['paths'] as $path => $validPath) {
00116
00117 if ($validPath) {
00118 if (TYPO3_OS=='WIN') {
00119 if (@is_file($path.$cmd)) {
00120 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00121 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path;
00122 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true;
00123 return true;
00124 }
00125 if (@is_file($path.$cmd.'.exe')) {
00126 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd.'.exe';
00127 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path;
00128 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true;
00129 return true;
00130 }
00131 } else {
00132 if (@is_executable($path.$cmd)) {
00133 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00134 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = $path;
00135 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true;
00136 return true;
00137 }
00138 }
00139 }
00140 }
00141
00142
00143 if (TYPO3_OS!='WIN') {
00144 $cmd = @exec ('which '.$cmd);
00145
00146 if (@is_executable($cmd)) {
00147 $T3_VAR['t3lib_exec']['apps'][$cmd]['app'] = $cmd;
00148 $T3_VAR['t3lib_exec']['apps'][$cmd]['path'] = dirname($cmd).'/';
00149 $T3_VAR['t3lib_exec']['apps'][$cmd]['valid'] = true;
00150 return true;
00151 }
00152 }
00153
00154 return false;
00155 }
00156
00157
00166 function getCommand($cmd, $handler='', $handlerOpt='') {
00167 global $T3_VAR;
00168
00169 if (!t3lib_exec::_init()) {
00170 return false;
00171 }
00172
00173
00174 if ($handler) {
00175 $handler = t3lib_exec::getCommand($handler);
00176
00177 if (!$handler) {
00178 return -1;
00179 }
00180 $handler .= ' '.$handlerOpt.' ';
00181 }
00182
00183
00184 if (!t3lib_exec::checkCommand($cmd)) {
00185 return false;
00186 }
00187 $cmd = $T3_VAR['t3lib_exec']['apps'][$cmd]['path'].$T3_VAR['t3lib_exec']['apps'][$cmd]['app'].' ';
00188
00189 return trim($handler.$cmd);
00190 }
00191
00192
00199 function addPaths($paths) {
00200 t3lib_exec::_initPaths($paths);
00201 }
00202
00203
00204
00211 function getPaths($addInvalid=false) {
00212 global $T3_VAR;
00213
00214 if (!t3lib_exec::_init()) {
00215 return array();
00216 }
00217
00218 $paths = $T3_VAR['t3lib_exec']['paths'];
00219 if(!$addInvalid) {
00220
00221 foreach($paths as $path => $validPath) {
00222 if(!$validPath) {
00223 unset($paths);
00224 }
00225 }
00226 }
00227 return $paths;
00228 }
00229
00230
00237 function _init() {
00238 global $T3_VAR, $TYPO3_CONF_VARS;
00239
00240 if ($TYPO3_CONF_VARS['BE']['disable_exec_function']) {
00241 return false;
00242 }
00243 if (!$T3_VAR['t3lib_exec']['init']) {
00244 t3lib_exec::_initPaths();
00245 $T3_VAR['t3lib_exec']['apps'] = t3lib_exec::_getConfiguredApps();;
00246 $T3_VAR['t3lib_exec']['init'] = true;
00247 }
00248 return true;
00249 }
00250
00251
00259 function _initPaths($paths='') {
00260 global $T3_VAR;
00261
00262 $doCeck=false;
00263
00264
00265 if (!is_array($T3_VAR['t3lib_exec']['paths'])) {
00266 $T3_VAR['t3lib_exec']['paths'] = t3lib_exec::_getPaths();
00267 $doCeck=true;
00268 }
00269
00270 if ($paths) {
00271 $paths = t3lib_div::trimExplode(',',$paths,1);
00272 if (is_array($paths)) {
00273 foreach($paths as $path) {
00274
00275 if (!preg_match('#^/#',$path)) {
00276 $path = PATH_site.$path;
00277 }
00278 if (!isset($T3_VAR['t3lib_exec']['paths'][$path])) {
00279 if (@is_dir($path)) {
00280 $T3_VAR['t3lib_exec']['paths'][$path] = $path;
00281 $T3_VAR['t3lib_exec']['allPaths'].=','.$path;
00282
00283 } else {
00284 $T3_VAR['t3lib_exec']['paths'][$path] = false;
00285 }
00286 }
00287 }
00288 }
00289 }
00290
00291 if ($doCeck) {
00292 $T3_VAR['t3lib_exec']['allPaths']='';
00293 foreach($T3_VAR['t3lib_exec']['paths'] as $path => $valid) {
00294
00295 if ($valid AND !@is_dir($path)) {
00296 $T3_VAR['t3lib_exec']['paths'][$path] = false;
00297 }
00298 if ($path = $T3_VAR['t3lib_exec']['paths'][$path]) {
00299 $T3_VAR['t3lib_exec']['allPaths'].=','.$path;
00300 }
00301 }
00302 }
00303 }
00304
00305
00312 function _getConfiguredApps() {
00313 global $TYPO3_CONF_VARS;
00314
00315 $cmdArr = array();
00316
00317 if ($TYPO3_CONF_VARS['SYS']['binSetup']) {
00318 $pathSetup = implode("\n", t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['SYS']['binSetup'],1));
00319 $pathSetup = t3lib_div::trimExplode("\n",$pathSetup,1);
00320 foreach($pathSetup as $val) {
00321 list($cmd, $cmdPath) = t3lib_div::trimExplode('=',$val,1);
00322
00323 $cmdArr[$cmd]['app'] = basename($cmdPath);
00324 $cmdArr[$cmd]['path'] = dirname($cmdPath).'/';
00325 $cmdArr[$cmd]['valid'] = true;
00326 }
00327 }
00328
00329 return $cmdArr;
00330 }
00331
00332
00339 function _getPaths() {
00340 global $T3_VAR, $TYPO3_CONF_VARS;
00341
00342 $pathsArr = array();
00343 $sysPathArr = array();
00344
00345
00346
00347 if ($imPath = ($TYPO3_CONF_VARS['GFX']['im_path_lzw'] ? $TYPO3_CONF_VARS['GFX']['im_path_lzw'] : $TYPO3_CONF_VARS['GFX']['im_path'])) {
00348 $imPath = t3lib_exec::_fixPath($imPath);
00349 $pathsArr[$imPath] = $imPath;
00350 }
00351
00352
00353 if ($TYPO3_CONF_VARS['SYS']['binPath']) {
00354 $sysPath = t3lib_div::trimExplode(',',$TYPO3_CONF_VARS['SYS']['binPath'],1);
00355 foreach($sysPath as $val) {
00356 $val = t3lib_exec::_fixPath($val);
00357 $sysPathArr[$val]=$val;
00358 }
00359 }
00360
00361
00362
00363
00364 if ($GLOBALS['_SERVER']['PATH']) {
00365 $sep = (TYPO3_OS=='WIN') ? ';' : ':';
00366 $envPath = t3lib_div::trimExplode($sep,$GLOBALS['_SERVER']['PATH'],1);
00367 foreach($envPath as $val) {
00368 $val = t3lib_exec::_fixPath($val);
00369 $sysPathArr[$val]=$val;
00370 }
00371 }
00372
00373 if (TYPO3_OS=='WIN') {
00374
00375 $sysPathArr = array_merge($sysPathArr, array (
00376 '/usr/bin/' => '/usr/bin/',
00377 '/perl/bin/' => '/perl/bin/',
00378 ));
00379 } else {
00380 $sysPathArr = array_merge($sysPathArr, array (
00381 '/usr/bin/' => '/usr/bin/',
00382 '/usr/local/bin/' => '/usr/local/bin/',
00383 ));
00384 }
00385
00386
00387 $pathsArr = array_merge($pathsArr, $sysPathArr);
00388
00389 return $pathsArr;
00390 }
00391
00392
00400 function _fixPath($path) {
00401 return str_replace ('
00402 }
00403 }
00404
00405 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_exec.php']) {
00406 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_exec.php']);
00407 }
00408 ?>