| 48 | | // Detect Gettext support |
|---|
| 49 | | if (!function_exists('gettext')) { |
|---|
| 50 | | /** |
|---|
| 51 | | * Load Locale class if Gettext support is not available |
|---|
| 52 | | */ |
|---|
| 53 | | require_once ('classes/Locale.php'); |
|---|
| 54 | | } |
|---|
| 55 | | |
|---|
| 56 | | require_once ('classes/Utils.php'); |
|---|
| 57 | | |
|---|
| 58 | | define('OPENID_PATH', WIFIDOG_ABS_FILE_PATH.'lib/php-openid-2.0.0-rc2/'); |
|---|
| 59 | | define('SMARTY_PATH', WIFIDOG_ABS_FILE_PATH.'lib/Smarty-2.6.18/libs/'); |
|---|
| 60 | | /** |
|---|
| 61 | | * This class checks the existence of components required by WiFiDog. |
|---|
| 62 | | * Note that it implicitely depends on the defines in include/path_defines_base.php |
|---|
| 63 | | * |
|---|
| 64 | | * @package WiFiDogAuthServer |
|---|
| 65 | | * @author Philippe April |
|---|
| 66 | | * @author Max Horváth <max.horvath@freenet.de> |
|---|
| 67 | | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| 68 | | * @copyright 2005-2007 Philippe April |
|---|
| 69 | | * @copyright 2005-2007 Max Horváth, Horvath Web Consulting |
|---|
| 70 | | * @copyright 2006-2007 Benoit Grégoire, Technologies Coeus inc. |
|---|
| 71 | | */ |
|---|
| 72 | | class Dependency |
|---|
| 73 | | { |
|---|
| 74 | | /** |
|---|
| 75 | | * An array of components used by WiFiDog |
|---|
| 76 | | * The main array key is the EXACT name name of the dependency. Do NOT translate it or blindly change it; |
|---|
| 77 | | * It is used in the code if various ways, for example to detect PHP or PEAR modules |
|---|
| 78 | | * Documentation of the various array keys: |
|---|
| 79 | | * 'mandatory' => Optional. Set to true if the dependency absolutely required for basic operation of an auth server |
|---|
| 80 | | * 'type' => Mandatory. The type of Dependency. Currently, allowed values are: |
|---|
| 81 | | * "phpExtension": Standard PHP extension |
|---|
| 82 | | * "peclStandard": Standard (in the PECL reposidory) PECL PHP module |
|---|
| 83 | | * "peclStandard": PEAR PHP module in the standard PEAR repository or in a custom channel |
|---|
| 84 | | * "pearCustom": PEAR-compatible tarball |
|---|
| 85 | | * "localLib": Custom PHP extension, to be downloaded and installed in wifidog/lib |
|---|
| 86 | | * 'detectFiles' => Mandatory for most type of dependencies, the relative path to the file that must exist for the dependency to be considered present. |
|---|
| 87 | | * The path is relative to the PHP path, or wifidog/lib depending on the type of install |
|---|
| 88 | | * 'description' => Description of the dependency, and what it's used for in wifidog |
|---|
| 89 | | * 'website' => URL to the dependency's official website |
|---|
| 90 | | * 'installSourceUrl' => For localLib and pearCustom dependency, the URL where the dependency can be downloaded. |
|---|
| 91 | | * For pearStandard, either the required alpha or beta name like "Image_Canvas-alpha" or the fulle channel URL like: "channel://pear.php.net/Image_graph-0.7.2" ( normally not used for dependencies in standard pear repositories) |
|---|
| 92 | | * 'installMethod' => For localLib, the protocol to be used to download and install the dependency. Currently, allowed values are: |
|---|
| 93 | | * 'tarball': Decompress a tarball in wifidog/lib |
|---|
| 94 | | * 'installDestination' => For localLib, the path, relative to wifidog/lib where the dependency should be installed |
|---|
| 95 | | * 'filename' => temp download filename if sourceurl does not meet preg requirements. |
|---|
| 96 | | * |
|---|
| 97 | | * @var array |
|---|
| 98 | | */ |
|---|
| 99 | | |
|---|
| 100 | | private static $_components = array( |
|---|
| 101 | | /* PHP extensions (mandatory) */ |
|---|
| | 48 | // Detect Gettext support |
|---|
| | 49 | if (!function_exists('gettext')) { |
|---|
| | 50 | /** |
|---|
| | 51 | * Load Locale class if Gettext support is not available |
|---|
| | 52 | */ |
|---|
| | 53 | require_once ('classes/Locale.php'); |
|---|
| | 54 | } |
|---|
| | 55 | |
|---|
| | 56 | require_once ('classes/Utils.php'); |
|---|
| | 57 | |
|---|
| | 58 | define('OPENID_PATH', WIFIDOG_ABS_FILE_PATH.'lib/php-openid-2.0.0-rc2/'); |
|---|
| | 59 | define('SMARTY_PATH', WIFIDOG_ABS_FILE_PATH.'lib/Smarty-2.6.18/libs/'); |
|---|
| | 60 | /** |
|---|
| | 61 | * This class checks the existence of components required by WiFiDog. |
|---|
| | 62 | * Note that it implicitely depends on the defines in include/path_defines_base.php |
|---|
| | 63 | * |
|---|
| | 64 | * @package WiFiDogAuthServer |
|---|
| | 65 | * @author Philippe April |
|---|
| | 66 | * @author Max Horváth <max.horvath@freenet.de> |
|---|
| | 67 | * @author Benoit Grégoire <bock@step.polymtl.ca> |
|---|
| | 68 | * @copyright 2005-2007 Philippe April |
|---|
| | 69 | * @copyright 2005-2007 Max Horváth, Horvath Web Consulting |
|---|
| | 70 | * @copyright 2006-2007 Benoit Grégoire, Technologies Coeus inc. |
|---|
| | 71 | */ |
|---|
| | 72 | class Dependency |
|---|
| | 73 | { |
|---|
| | 74 | /** |
|---|
| | 75 | * An array of components used by WiFiDog |
|---|
| | 76 | * The main array key is the EXACT name name of the dependency. Do NOT translate it or blindly change it; |
|---|
| | 77 | * It is used in the code if various ways, for example to detect PHP or PEAR modules |
|---|
| | 78 | * Documentation of the various array keys: |
|---|
| | 79 | * 'mandatory' => Optional. Set to true if the dependency absolutely required for basic operation of an auth server |
|---|
| | 80 | * 'type' => Mandatory. The type of Dependency. Currently, allowed values are: |
|---|
| | 81 | * "phpExtension": Standard PHP extension |
|---|
| | 82 | * "peclStandard": Standard (in the PECL reposidory) PECL PHP module |
|---|
| | 83 | * "peclStandard": PEAR PHP module in the standard PEAR repository or in a custom channel |
|---|
| | 84 | * "pearCustom": PEAR-compatible tarball |
|---|
| | 85 | * "localLib": Custom PHP extension, to be downloaded and installed in wifidog/lib |
|---|
| | 86 | * 'detectFiles' => Mandatory for most type of dependencies, the relative path to the file that must exist for the dependency to be considered present. |
|---|
| | 87 | * The path is relative to the PHP path, or wifidog/lib depending on the type of install |
|---|
| | 88 | * 'description' => Description of the dependency, and what it's used for in wifidog |
|---|
| | 89 | * 'website' => URL to the dependency's official website |
|---|
| | 90 | * 'installSourceUrl' => For localLib and pearCustom dependency, the URL where the dependency can be downloaded. |
|---|
| | 91 | * For pearStandard, either the required alpha or beta name like "Image_Canvas-alpha" or the fulle channel URL like: "channel://pear.php.net/Image_graph-0.7.2" ( normally not used for dependencies in standard pear repositories) |
|---|
| | 92 | * 'installMethod' => For localLib, the protocol to be used to download and install the dependency. Currently, allowed values are: |
|---|
| | 93 | * 'tarball': Decompress a tarball in wifidog/lib |
|---|
| | 94 | * 'installDestination' => For localLib, the path, relative to wifidog/lib where the dependency should be installed |
|---|
| | 95 | * 'filename' => temp download filename if sourceurl does not meet preg requirements. |
|---|
| | 96 | * |
|---|
| | 97 | * @var array |
|---|
| | 98 | */ |
|---|
| | 99 | |
|---|
| | 100 | private static $_components = array( |
|---|
| | 101 | /* PHP extensions (mandatory) */ |
|---|
| 298 | | private static $instanceArray = array(); |
|---|
| 299 | | |
|---|
| 300 | | private $_id; |
|---|
| 301 | | |
|---|
| 302 | | /** |
|---|
| 303 | | * Constructor |
|---|
| 304 | | */ |
|---|
| 305 | | private function __construct($component) { |
|---|
| 306 | | $this->_id = $component; |
|---|
| 307 | | } |
|---|
| 308 | | |
|---|
| 309 | | /** |
|---|
| 310 | | * Get the entire array of Dependency |
|---|
| 311 | | * |
|---|
| 312 | | * @return boolean Returns whether the file has been found or not. |
|---|
| 313 | | */ |
|---|
| 314 | | public static function getDependencies() |
|---|
| 315 | | { |
|---|
| 316 | | $retval = array(); |
|---|
| 317 | | |
|---|
| 318 | | foreach (self::$_components as $component_key=>$component_info) { |
|---|
| 319 | | $retval[] = self::getObject($component_key); |
|---|
| 320 | | } |
|---|
| 321 | | |
|---|
| 322 | | return $retval; |
|---|
| 323 | | } |
|---|
| 324 | | |
|---|
| 325 | | /** Use PHP internal functions to execute a command |
|---|
| 326 | | Â @return: Return value of the command*/ |
|---|
| 327 | | function execVerbose($command, & $output, & $return_var, &$errMsg = null) { |
|---|
| 328 | | $errMsg .= "Executing: $command <br/>"; |
|---|
| 329 | | exec($command.' 2>&1', $output, $return_var); |
|---|
| 330 | | if ($return_var != 0) |
|---|
| 331 | | $errMsg .= "<p style='color:red'><em>Error:</em> Command did not complete successfully (returned $return_var): <br/>\n"; |
|---|
| 332 | | else |
|---|
| 333 | | $errMsg .= "<p style='color:green'><em>Command completed successfully</em> (returned $return_var): <br/>\n"; |
|---|
| 334 | | |
|---|
| 335 | | if (($return_var != 0) && $output) { |
|---|
| 336 | | foreach ($output as $output_line) |
|---|
| 337 | | $errMsg .= " $output_line <br/>\n"; |
|---|
| 338 | | } |
|---|
| 339 | | $errMsg .= "</p>\n"; |
|---|
| 340 | | return $return_var; |
|---|
| 341 | | } |
|---|
| 342 | | |
|---|
| 343 | | /** |
|---|
| 344 | | * Checks if a file exists, including checking in the include path |
|---|
| 345 | | * |
|---|
| 346 | | * @param string $file Path or name of a file |
|---|
| 347 | | * |
|---|
| 348 | | * @return boolean Returns whether the file has been found or not. |
|---|
| 349 | | * |
|---|
| 350 | | * @author Aidan Lister <aidan@php.net> |
|---|
| 351 | | * @link http://aidanlister.com/repos/v/function.file_exists_incpath.php |
|---|
| 352 | | */ |
|---|
| 353 | | public static function file_exists_incpath($file) |
|---|
| 354 | | { |
|---|
| 355 | | $_paths = explode(PATH_SEPARATOR, get_include_path()); |
|---|
| 356 | | |
|---|
| 357 | | foreach ($_paths as $_path) { |
|---|
| 358 | | // Formulate the absolute path |
|---|
| 359 | | $_fullPath = $_path . DIRECTORY_SEPARATOR . $file; |
|---|
| 360 | | |
|---|
| 361 | | // Check it |
|---|
| 362 | | if (file_exists($_fullPath)) { |
|---|
| 363 | | return $_fullPath; |
|---|
| | 298 | private static $instanceArray = array(); |
|---|
| | 299 | |
|---|
| | 300 | private $_id; |
|---|
| | 301 | |
|---|
| | 302 | /** |
|---|
| | 303 | * Constructor |
|---|
| | 304 | */ |
|---|
| | 305 | private function __construct($component) { |
|---|
| | 306 | $this->_id = $component; |
|---|
| | 307 | } |
|---|
| | 308 | |
|---|
| | 309 | /** |
|---|
| | 310 | * Get the entire array of Dependency |
|---|
| | 311 | * |
|---|
| | 312 | * @return boolean Returns whether the file has been found or not. |
|---|
| | 313 | */ |
|---|
| | 314 | public static function getDependencies() |
|---|
| | 315 | { |
|---|
| | 316 | $retval = array(); |
|---|
| | 317 | |
|---|
| | 318 | foreach (self::$_components as $component_key=>$component_info) { |
|---|
| | 319 | $retval[] = self::getObject($component_key); |
|---|
| | 320 | } |
|---|
| | 321 | |
|---|
| | 322 | return $retval; |
|---|
| | 323 | } |
|---|
| | 324 | |
|---|
| | 325 | /** Use PHP internal functions to execute a command |
|---|
| | 326 | Â @return: Return value of the command*/ |
|---|
| | 327 | function execVerbose($command, & $output, & $return_var, &$errMsg = null) { |
|---|
| | 328 | $errMsg .= "Executing: $command <br/>"; |
|---|
| | 329 | exec($command.' 2>&1', $output, $return_var); |
|---|
| | 330 | if ($return_var != 0) |
|---|
| | 331 | $errMsg .= "<p style='color:red'><em>Error:</em> Command did not complete successfully (returned $return_var): <br/>\n"; |
|---|
| | 332 | else |
|---|
| | 333 | $errMsg .= "<p style='color:green'><em>Command completed successfully</em> (returned $return_var): <br/>\n"; |
|---|
| | 334 | |
|---|
| | 335 | if (($return_var != 0) && $output) { |
|---|
| | 336 | foreach ($output as $output_line) |
|---|
| | 337 | $errMsg .= " $output_line <br/>\n"; |
|---|
| | 338 | } |
|---|
| | 339 | $errMsg .= "</p>\n"; |
|---|
| | 340 | return $return_var; |
|---|
| | 341 | } |
|---|
| | 342 | |
|---|
| | 343 | /** |
|---|
| | 344 | * Checks if a file exists, including checking in the include path |
|---|
| | 345 | * |
|---|
| | 346 | * @param string $file Path or name of a file |
|---|
| | 347 | * |
|---|
| | 348 | * @return boolean Returns whether the file has been found or not. |
|---|
| | 349 | * |
|---|
| | 350 | * @author Aidan Lister <aidan@php.net> |
|---|
| | 351 | * @link http://aidanlister.com/repos/v/function.file_exists_incpath.php |
|---|
| | 352 | */ |
|---|
| | 353 | public static function file_exists_incpath($file) |
|---|
| | 354 | { |
|---|
| | 355 | $_paths = explode(PATH_SEPARATOR, get_include_path()); |
|---|
| | 356 | |
|---|
| | 357 | foreach ($_paths as $_path) { |
|---|
| | 358 | // Formulate the absolute path |
|---|
| | 359 | $_fullPath = $_path . DIRECTORY_SEPARATOR . $file; |
|---|
| | 360 | |
|---|
| | 361 | // Check it |
|---|
| | 362 | if (file_exists($_fullPath)) { |
|---|
| | 363 | return $_fullPath; |
|---|
| | 364 | } |
|---|
| | 365 | } |
|---|
| | 366 | |
|---|
| | 367 | return false; |
|---|
| | 368 | } |
|---|
| | 369 | |
|---|
| | 370 | /** |
|---|
| | 371 | * Checks if a component is available. |
|---|
| | 372 | * |
|---|
| | 373 | * This function checks, if a specific component is available to be used |
|---|
| | 374 | * by Wifidog. |
|---|
| | 375 | * |
|---|
| | 376 | * @param string $component Name of component to be checked. |
|---|
| | 377 | * @param string $errmsg Reference of a string which would contain an |
|---|
| | 378 | * error message. |
|---|
| | 379 | * |
|---|
| | 380 | * @return boolean Returns whether the component has been found or not. |
|---|
| | 381 | */ |
|---|
| | 382 | public static function check($component, &$errmsg = null) |
|---|
| | 383 | { |
|---|
| | 384 | // Init values |
|---|
| | 385 | $returnValue = false; |
|---|
| | 386 | |
|---|
| | 387 | // Check, if the requested component can be found. |
|---|
| | 388 | if (isset(self::$_components[$component])) { |
|---|
| | 389 | // What are we checking for? |
|---|
| | 390 | if (self::$_components[$component]["type"] == "phpExtension" || self::$_components[$component]["type"] == "peclStandard") { |
|---|
| | 391 | // Warning: extension_loaded(string) is case sensitive |
|---|
| | 392 | $returnValue = extension_loaded($component); |
|---|
| | 393 | } |
|---|
| | 394 | else if (self::$_components[$component]["type"] == "localLib") { |
|---|
| | 395 | if (is_array(self::$_components[$component]["detectFiles"])) { |
|---|
| | 396 | $_singleReturns = true; |
|---|
| | 397 | foreach (self::$_components[$component]["detectFiles"] as $_fileNames) { |
|---|
| | 398 | $filePath = WIFIDOG_ABS_FILE_PATH . $_fileNames; |
|---|
| | 399 | |
|---|
| | 400 | if (!file_exists($filePath)) { |
|---|
| | 401 | echo "TEST"; |
|---|
| | 402 | $_singleReturns = false; |
|---|
| | 403 | // The component has NOT been found. Return error message. |
|---|
| | 404 | $errmsg .= sprintf(_("File %s not found"), $filePath); |
|---|
| | 405 | break; |
|---|
| | 406 | } |
|---|
| | 407 | } |
|---|
| | 408 | |
|---|
| | 409 | $returnValue = $_singleReturns; |
|---|
| | 410 | } |
|---|
| | 411 | else { |
|---|
| | 412 | $filePath = WIFIDOG_ABS_FILE_PATH . self::$_components[$component]["detectFiles"]; |
|---|
| | 413 | |
|---|
| | 414 | if (file_exists($filePath)) { |
|---|
| | 415 | // The component has been found. |
|---|
| | 416 | $returnValue = true; |
|---|
| | 417 | } |
|---|
| | 418 | else { |
|---|
| | 419 | // The component has NOT been found. Return error message. |
|---|
| | 420 | $errmsg .= sprintf(_("File %s not found"), $filePath); |
|---|
| | 421 | } |
|---|
| 366 | | |
|---|
| 367 | | return false; |
|---|
| 368 | | } |
|---|
| 369 | | |
|---|
| 370 | | /** |
|---|
| 371 | | * Checks if a component is available. |
|---|
| 372 | | * |
|---|
| 373 | | * This function checks, if a specific component is available to be used |
|---|
| 374 | | * by Wifidog. |
|---|
| 375 | | * |
|---|
| 376 | | * @param string $component Name of component to be checked. |
|---|
| 377 | | * @param string $errmsg Reference of a string which would contain an |
|---|
| 378 | | * error message. |
|---|
| 379 | | * |
|---|
| 380 | | * @return boolean Returns whether the component has been found or not. |
|---|
| 381 | | */ |
|---|
| 382 | | public static function check($component, &$errmsg = null) |
|---|
| 383 | | { |
|---|
| 384 | | // Init values |
|---|
| 385 | | $returnValue = false; |
|---|
| 386 | | |
|---|
| 387 | | // Check, if the requested component can be found. |
|---|
| 388 | | if (isset(self::$_components[$component])) { |
|---|
| 389 | | // What are we checking for? |
|---|
| 390 | | if (self::$_components[$component]["type"] == "phpExtension" || self::$_components[$component]["type"] == "peclStandard") { |
|---|
| 391 | | // Warning: extension_loaded(string) is case sensitive |
|---|
| 392 | | $returnValue = extension_loaded($component); |
|---|
| 393 | | } |
|---|
| 394 | | else if (self::$_components[$component]["type"] == "localLib") { |
|---|
| 395 | | if (is_array(self::$_components[$component]["detectFiles"])) { |
|---|
| 396 | | $_singleReturns = true; |
|---|
| 397 | | foreach (self::$_components[$component]["detectFiles"] as $_fileNames) { |
|---|
| 398 | | $filePath = WIFIDOG_ABS_FILE_PATH . $_fileNames; |
|---|
| 399 | | |
|---|
| 400 | | if (!file_exists($filePath)) { |
|---|
| 401 | | echo "TEST"; |
|---|
| 402 | | $_singleReturns = false; |
|---|
| 403 | | // The component has NOT been found. Return error message. |
|---|
| 404 | | $errmsg .= sprintf(_("File %s not found"), $filePath); |
|---|
| 405 | | break; |
|---|
| 406 | | } |
|---|
| 407 | | } |
|---|
| 408 | | |
|---|
| 409 | | $returnValue = $_singleReturns; |
|---|
| 410 | | } |
|---|
| 411 | | else { |
|---|
| 412 | | $filePath = WIFIDOG_ABS_FILE_PATH . self::$_components[$component]["detectFiles"]; |
|---|
| 413 | | |
|---|
| 414 | | if (file_exists($filePath)) { |
|---|
| 415 | | // The component has been found. |
|---|
| 416 | | $returnValue = true; |
|---|
| 417 | | } |
|---|
| 418 | | else { |
|---|
| 419 | | // The component has NOT been found. Return error message. |
|---|
| 420 | | $errmsg .= sprintf(_("File %s not found"), $filePath); |
|---|
| 421 | | } |
|---|
| 422 | | } |
|---|
| 423 | | } |
|---|
| 424 | | else if (self::$_components[$component]["type"] == "pearStandard" || self::$_components[$component]["type"] == "pearCustom") { |
|---|
| 425 | | if (is_array(self::$_components[$component]["detectFiles"])) { |
|---|
| 426 | | $_singleReturns = true; |
|---|
| 427 | | |
|---|
| 428 | | foreach (self::$_components[$component]["detectFiles"] as $_fileNames) { |
|---|
| 429 | | // We need to use a custom file_exists to also check in the include path |
|---|
| 430 | | if (!self::file_exists_incpath($_fileNames)) { |
|---|
| 431 | | $_singleReturns = false; |
|---|
| 432 | | |
|---|
| 433 | | // The component has NOT been found. Return error message. |
|---|
| 434 | | $errmsg .= sprintf(_("File %s not found in %s"), $_fileNames, get_include_path()); |
|---|
| 435 | | } |
|---|
| 436 | | } |
|---|
| 437 | | |
|---|
| 438 | | $returnValue = $_singleReturns; |
|---|
| 439 | | } else { |
|---|
| 440 | | // We need to use a custom file_exists to also check in the include path |
|---|
| 441 | | if (self::file_exists_incpath(self::$_components[$component]["detectFiles"])) { |
|---|
| 442 | | // The component has been found. |
|---|
| 443 | | $returnValue = true; |
|---|
| 444 | | } |
|---|
| 445 | | else { |
|---|
| 446 | | |
|---|
| 447 | | // The component has NOT been found. Return error message. |
|---|
| 448 | | $errmsg .= sprintf(_("File %s not found in %s"), self::$_components[$component]["detectFiles"], get_include_path()); |
|---|
| 449 | | } |
|---|
| 450 | | } |
|---|
| 451 | | } |
|---|
| 452 | | else { |
|---|
| 453 | | throw new Exception(sprintf("Unknown component type: %s", self::$_components[$component]["type"])); |
|---|
| 454 | | } |
|---|
| 455 | | } else { |
|---|
| 456 | | // The requested component has not been defined in this class. |
|---|
| 457 | | throw new Exception("Component not found"); |
|---|
| 458 | | } |
|---|
| 459 | | |
|---|
| 460 | | return $returnValue; |
|---|
| 461 | | } |
|---|
| 462 | | |
|---|
| 463 | | /** |
|---|
| 464 | | * Checks if one of the mandatory components is missing. |
|---|
| 465 | | * |
|---|
| 466 | | * @param string $errmsg Reference of a string which would contain an |
|---|
| 467 | | * error message. |
|---|
| 468 | | * |
|---|
| 469 | | * @return boolean Returns false if any components are missing. |
|---|
| 470 | | */ |
|---|
| 471 | | public static function checkMandatoryComponents(&$errmsg = null) |
|---|
| 472 | | { |
|---|
| 473 | | // Init values |
|---|
| 474 | | $returnValue = true; |
|---|
| 475 | | $components = self::getDependencies(); |
|---|
| 476 | | foreach($components as $component) { |
|---|
| 477 | | if($component->isMandatory()) { |
|---|
| 478 | | $returnValue &= self::check($component->getId(), $errmsg); |
|---|
| 479 | | } |
|---|
| 480 | | } |
|---|
| 481 | | |
|---|
| 482 | | return $returnValue; |
|---|
| 483 | | } |
|---|
| | 424 | else if (self::$_components[$component]["type"] == "pearStandard" || self::$_components[$component]["type"] == "pearCustom") { |
|---|
| | 425 | if (is_array(self::$_components[$component]["detectFiles"])) { |
|---|
| | 426 | $_singleReturns = true; |
|---|
| | 427 | |
|---|
| | 428 | foreach (self::$_components[$component]["detectFiles"] as $_fileNames) { |
|---|
| | 429 | // We need to use a custom file_exists to also check in the include path |
|---|
| | 430 | if (!self::file_exists_incpath($_fileNames)) { |
|---|
| | 431 | $_singleReturns = false; |
|---|
| | 432 | |
|---|
| | 433 | // The component has NOT been found. Return error message. |
|---|
| | 434 | $errmsg .= sprintf(_("File %s not found in %s"), $_fileNames, get_include_path()); |
|---|
| | 435 | } |
|---|
| | 436 | } |
|---|
| | 437 | |
|---|
| | 438 | $returnValue = $_singleReturns; |
|---|
| | 439 | } else { |
|---|
| | 440 | // We need to use a custom file_exists to also check in the include path |
|---|
| | 441 | if (self::file_exists_incpath(self::$_components[$component]["detectFiles"])) { |
|---|
| | 442 | // The component has been found. |
|---|
| | 443 | $returnValue = true; |
|---|
| | 444 | } |
|---|
| | 445 | else { |
|---|
| | 446 | |
|---|
| | 447 | // The component has NOT been found. Return error message. |
|---|
| | 448 | $errmsg .= sprintf(_("File %s not found in %s"), self::$_components[$component]["detectFiles"], get_include_path()); |
|---|
| | 449 | } |
|---|
| | 450 | } |
|---|
| | 451 | } |
|---|
| | 452 | else { |
|---|
| | 453 | throw new Exception(sprintf("Unknown component type: %s", self::$_components[$component]["type"])); |
|---|
| | 454 | } |
|---|
| | 455 | } else { |
|---|
| | 456 | // The requested component has not been defined in this class. |
|---|
| | 457 | throw new Exception("Component not found"); |
|---|
| | 458 | } |
|---|
| | 459 | |
|---|
| | 460 | return $returnValue; |
|---|
| | 461 | } |
|---|
| | 462 | |
|---|
| | 463 | /** |
|---|
| | 464 | * Checks if one of the mandatory components is missing. |
|---|
| | 465 | * |
|---|
| | 466 | * @param string $errmsg Reference of a string which would contain an |
|---|
| | 467 | * error message. |
|---|
| | 468 | * |
|---|
| | 469 | * @return boolean Returns false if any components are missing. |
|---|
| | 470 | */ |
|---|
| | 471 | public static function checkMandatoryComponents(&$errmsg = null) |
|---|
| | 472 | { |
|---|
| | 473 | // Init values |
|---|
| | 474 | $returnValue = true; |
|---|
| | 475 | $components = self::getDependencies(); |
|---|
| | 476 | foreach($components as $component) { |
|---|
| | 477 | if($component->isMandatory()) { |
|---|
| | 478 | $returnValue &= self::check($component->getId(), $errmsg); |
|---|
| | 479 | } |
|---|
| | 480 | } |
|---|
| | 481 | |
|---|
| | 482 | return $returnValue; |
|---|
| | 483 | } |
|---|
| | 484 | |
|---|
| | 485 | /** Use PHP internal functions to download a file */ |
|---|
| | 486 | static public function downloadFile($remoteURL, $localPath) { |
|---|
| | 487 | set_time_limit(1500); // 25 minutes timeout |
|---|
| | 488 | return copy($remoteURL, $localPath); |
|---|
| | 489 | } |
|---|
| | 490 | /** |
|---|
| | 491 | * Get a UI to install the component |
|---|
| | 492 | * |
|---|
| | 493 | * @return html markup. |
|---|
| | 494 | */ |
|---|
| | 495 | public function getInstallUI() |
|---|
| | 496 | { |
|---|
| | 497 | // Init values |
|---|
| | 498 | $html = false; |
|---|
| | 499 | |
|---|
| | 500 | // Check, if the requested component can be found. |
|---|
| | 501 | if (self::check($this->getId())) { |
|---|
| | 502 | //Component already installed |
|---|
| | 503 | } |
|---|
| | 504 | else { |
|---|
| | 505 | // What are we checking for? |
|---|
| | 506 | $type = $this->getType(); |
|---|
| | 507 | switch ($type) { |
|---|
| | 508 | case "phpExtension": |
|---|
| | 509 | $html .= sprintf(_("To install this standard PHP extension, look for a package with a similar name in your distribution's package manager. Ex: For Debian based distributions, you may try 'sudo apt-get install php5-%s'"), $this->getId()); |
|---|
| | 510 | |
|---|
| | 511 | break; |
|---|
| | 512 | case "localLib": |
|---|
| | 513 | if($this->getInstallSourceUrl()) { |
|---|
| | 514 | $name = $this->getId().'_install'; |
|---|
| | 515 | $value = sprintf(_("Install %s"), $this->getId()); |
|---|
| | 516 | $html .= sprintf("<input type='submit' name='%s' value='%s'/>", $name, $value); |
|---|
| | 517 | |
|---|
| | 518 | } |
|---|
| | 519 | else { |
|---|
| | 520 | $html .= sprintf(_("Sorry, i couldn't find the source for %s in installSourceUrl"), |
|---|
| | 521 | $this->getId()); |
|---|
| | 522 | } |
|---|
| | 523 | break; |
|---|
| | 524 | |
|---|
| | 525 | |
|---|
| | 526 | case "pearStandard": |
|---|
| | 527 | if($this->getInstallSourceUrl()) { |
|---|
| | 528 | $installSource=$this->getInstallSourceUrl(); |
|---|
| | 529 | } |
|---|
| | 530 | else { |
|---|
| | 531 | $installSource=$this->getId(); |
|---|
| | 532 | } |
|---|
| | 533 | $html .= sprintf(_("To install this standard PEAR extension, try 'sudo pear install --onlyreqdeps %s'"), $installSource); |
|---|
| | 534 | break; |
|---|
| | 535 | |
|---|
| | 536 | |
|---|
| | 537 | case "peclStandard": |
|---|
| | 538 | if($this->getInstallSourceUrl()) { |
|---|
| | 539 | $installSource=$this->getInstallSourceUrl(); |
|---|
| | 540 | } |
|---|
| | 541 | else { |
|---|
| | 542 | $installSource=$this->getId(); |
|---|
| | 543 | } |
|---|
| | 544 | $html .= sprintf(_("To install this standard PEAR extension, try 'sudo pecl install %s'"), $installSource); |
|---|
| | 545 | break; |
|---|
| | 546 | |
|---|
| | 547 | |
|---|
| | 548 | case "pearCustom": |
|---|
| | 549 | if($this->getInstallSourceUrl()) { |
|---|
| | 550 | $installSource=$this->getInstallSourceUrl(); |
|---|
| | 551 | } |
|---|
| | 552 | else { |
|---|
| | 553 | $installSource=sprintf(_("url_to_the_tarball (Sorry, i couldn't find the source for %s in installSourceUrl)"), $this->getId()); |
|---|
| | 554 | } |
|---|
| | 555 | $html .= sprintf(_("To install this custom PEAR extension, use 'sudo pear install %s'"), $installSource); |
|---|
| | 556 | break; |
|---|
| | 557 | |
|---|
| | 558 | |
|---|
| | 559 | default: |
|---|
| | 560 | $html .= sprintf(_("Sorry, I don't know how to install a %s extension"), $type); |
|---|
| | 561 | } |
|---|
| | 562 | } |
|---|
| | 563 | return $html; |
|---|
| | 564 | } |
|---|
| | 565 | |
|---|
| | 566 | /** |
|---|
| | 567 | * Get a UI to install the component |
|---|
| | 568 | * |
|---|
| | 569 | * @return true if something was processed. |
|---|
| | 570 | */ |
|---|
| | 571 | public function processInstallUI(&$errMsg=null) |
|---|
| | 572 | { |
|---|
| | 573 | |
|---|
| | 574 | $retval = false; |
|---|
| | 575 | $name = $this->getId().'_install'; |
|---|
| | 576 | if(!empty($_REQUEST[$name])) |
|---|
| | 577 | { |
|---|
| | 578 | $this->install($errMsg); |
|---|
| | 579 | } |
|---|
| 485 | | /** Use PHP internal functions to download a file */ |
|---|
| 486 | | static public function downloadFile($remoteURL, $localPath) { |
|---|
| 487 | | set_time_limit(1500); // 25 minutes timeout |
|---|
| 488 | | return copy($remoteURL, $localPath); |
|---|
| 489 | | } |
|---|
| 490 | | /** |
|---|
| 491 | | * Get a UI to install the component |
|---|
| 492 | | * |
|---|
| 493 | | * @return html markup. |
|---|
| 494 | | */ |
|---|
| 495 | | public function getInstallUI() |
|---|
| 496 | | { |
|---|
| 497 | | // Init values |
|---|
| 498 | | $html = false; |
|---|
| 499 | | |
|---|
| 500 | | // Check, if the requested component can be found. |
|---|
| 501 | | if (self::check($this->getId())) { |
|---|
| 502 | | //Component already installed |
|---|
| 503 | | } |
|---|
| 504 | | else { |
|---|
| 505 | | // What are we checking for? |
|---|
| 506 | | $type = $this->getType(); |
|---|
| 507 | | switch ($type) { |
|---|
| 508 | | case "phpExtension": |
|---|
| 509 | | $html .= sprintf(_("To install this standard PHP extension, look for a package with a similar name in your distribution's package manager. Ex: For Debian based distributions, you may try 'sudo apt-get install php5-%s'"), $this->getId()); |
|---|
| 510 | | |
|---|
| 511 | | break; |
|---|
| 512 | | case "localLib": |
|---|
| 513 | | if($this->getInstallSourceUrl()) { |
|---|
| 514 | | $name = $this->getId().'_install'; |
|---|
| 515 | | $value = sprintf(_("Install %s"), $this->getId()); |
|---|
| 516 | | $html .= sprintf("<input type='submit' name='%s' value='%s'/>", $name, $value); |
|---|
| 517 | | |
|---|
| 518 | | } |
|---|
| 519 | | else { |
|---|
| 520 | | $html .= sprintf(_("Sorry, i couldn't find the source for %s in installSourceUrl"), |
|---|
| 521 | | $this->getId()); |
|---|
| 522 | | } |
|---|
| 523 | | break; |
|---|
| 524 | | |
|---|
| 525 | | |
|---|
| 526 | | case "pearStandard": |
|---|
| 527 | | if($this->getInstallSourceUrl()) { |
|---|
| 528 | | $installSource=$this->getInstallSourceUrl(); |
|---|
| 529 | | } |
|---|
| 530 | | else { |
|---|
| 531 | | $installSource=$this->getId(); |
|---|
| 532 | | } |
|---|
| 533 | | $html .= sprintf(_("To install this standard PEAR extension, try 'sudo pear install --onlyreqdeps %s'"), $installSource); |
|---|
| 534 | | break; |
|---|
| 535 | | |
|---|
| 536 | | |
|---|
| 537 | | case "peclStandard": |
|---|
| 538 | | if($this->getInstallSourceUrl()) { |
|---|
| 539 | | $installSource=$this->getInstallSourceUrl(); |
|---|
| 540 | | } |
|---|
| 541 | | else { |
|---|
| 542 | | $installSource=$this->getId(); |
|---|
| 543 | | } |
|---|
| 544 | | $html .= sprintf(_("To install this standard PEAR extension, try 'sudo pecl install %s'"), $installSource); |
|---|
| 545 | | break; |
|---|
| 546 | | |
|---|
| 547 | | |
|---|
| 548 | | case "pearCustom": |
|---|
| 549 | | if($this->getInstallSourceUrl()) { |
|---|
| 550 | | $installSource=$this->getInstallSourceUrl(); |
|---|
| 551 | | } |
|---|
| 552 | | else { |
|---|
| 553 | | $installSource=sprintf(_("url_to_the_tarball (Sorry, i couldn't find the source for %s in installSourceUrl)"), $this->getId()); |
|---|
| 554 | | } |
|---|
| 555 | | $html .= sprintf(_("To install this custom PEAR extension, use 'sudo pear install %s'"), $installSource); |
|---|
| 556 | | break; |
|---|
| 557 | | |
|---|
| 558 | | |
|---|
| 559 | | default: |
|---|
| 560 | | $html .= sprintf(_("Sorry, I don't know how to install a %s extension"), $type); |
|---|
| 561 | | } |
|---|
| 562 | | } |
|---|
| 563 | | return $html; |
|---|
| 564 | | } |
|---|
| 565 | | |
|---|
| 566 | | /** |
|---|
| 567 | | * Get a UI to install the component |
|---|
| 568 | | * |
|---|
| 569 | | * @return true if something was processed. |
|---|
| 570 | | */ |
|---|
| 571 | | public function processInstallUI(&$errMsg=null) |
|---|
| 572 | | { |
|---|
| 573 | | |
|---|
| 574 | | $retval = false; |
|---|
| 575 | | $name = $this->getId().'_install'; |
|---|
| 576 | | if(!empty($_REQUEST[$name])) |
|---|
| 577 | | { |
|---|
| 578 | | $this->install($errMsg); |
|---|
| 579 | |
|---|