| 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 | | } |
| 580 | | |
| 581 | | return $retval; |
| 582 | | } |
| 583 | | /** |
| 584 | | * Retreives the id of the object |
| 585 | | * |
| 586 | | * @return The id, a string |
| 587 | | */ |
| 588 | | public function getId() { |
| 589 | | return $this->_id; |
| | 581 | return $retval; |
| | 582 | } |
| | 583 | /** |
| | 584 | * Retreives the id of the object |
| | 585 | * |
| | 586 | * @return The id, a string |
| | 587 | */ |
| | 588 | public function getId() { |
| | 589 | return $this->_id; |
| | 590 | } |
| | 591 | |
| | 592 | /** |
| | 593 | * Get an instance of the object |
| | 594 | * |
| | 595 | * @param string $id The object id |
| | 596 | * |
| | 597 | * @return mixed The Content object, or null if there was an error |
| | 598 | * (an exception is also thrown) |
| | 599 | * |
| | 600 | * @see GenericObject |
| | 601 | * @static |
| | 602 | * @access public |
| | 603 | */ |
| | 604 | public static function &getObject($id) |
| | 605 | { |
| | 606 | if(!isset(self::$instanceArray[$id])) { |
| | 607 | self::$instanceArray[$id] = new self($id); |
| | 608 | } |
| | 609 | |
| | 610 | return self::$instanceArray[$id]; |
| | 611 | } |
| | 612 | |
| | 613 | /** |
| | 614 | * Get website URL for the dependency (if available) |
| | 615 | * |
| | 616 | * @return URL or null |
| | 617 | */ |
| | 618 | public function getWebsiteURL() |
| | 619 | { |
| | 620 | $retval = null; |
| | 621 | |
| | 622 | if(self::$_components[$this->_id]["type"] == "phpExtension") { |
| | 623 | $retval = "http://www.php.net/" . $this->_id . "/"; |
| | 624 | } else if(self::$_components[$this->_id]["type"] == "pearStandard") { |
| | 625 | $retval = "http://pear.php.net/package/" . $this->_id . "/"; |
| | 626 | } else if(self::$_components[$this->_id]["type"] == "peclStandard") { |
| | 627 | $retval = "http://pecl.php.net/package/" . $this->_id . "/"; |
| | 628 | } else { |
| | 629 | if(!empty(self::$_components[$this->_id]['website'])) { |
| | 630 | $retval = self::$_components[$this->_id]['website']; |
| 591 | | |
| 592 | | /** |
| 593 | | * Get an instance of the object |
| 594 | | * |
| 595 | | * @param string $id The object id |
| 596 | | * |
| 597 | | * @return mixed The Content object, or null if there was an error |
| 598 | | * (an exception is also thrown) |
| 599 | | * |
| 600 | | * @see GenericObject |
| 601 | | * @static |
| 602 | | * @access public |
| 603 | | */ |
| 604 | | public static function &getObject($id) |
| 605 | | { |
| 606 | | if(!isset(self::$instanceArray[$id])) { |
| 607 | | self::$instanceArray[$id] = new self($id); |
| 608 | | } |
| 609 | | |
| 610 | | return self::$instanceArray[$id]; |
| 611 | | } |
| 612 | | |
| 613 | | /** |
| 614 | | * Get website URL for the dependency (if available) |
| 615 | | * |
| 616 | | * @return URL or null |
| 617 | | */ |
| 618 | | public function getWebsiteURL() |
| 619 | | { |
| 620 | | $retval = null; |
| 621 | | |
| 622 | | if(self::$_components[$this->_id]["type"] == "phpExtension") { |
| 623 | | $retval = "http://www.php.net/" . $this->_id . "/"; |
| 624 | | } else if(self::$_components[$this->_id]["type"] == "pearStandard") { |
| 625 | | $retval = "http://pear.php.net/package/" . $this->_id . "/"; |
| 626 | | } else if(self::$_components[$this->_id]["type"] == "peclStandard") { |
| 627 | | $retval = "http://pecl.php.net/package/" . $this->_id . "/"; |
| 628 | | } else { |
| 629 | | if(!empty(self::$_components[$this->_id]['website'])) { |
| 630 | | $retval = self::$_components[$this->_id]['website']; |
| 631 | | } |
| 632 | | } |
| 633 | | |
| 634 | | return $retval; |
| 635 | | } |
| 636 | | |
| 637 | | /** |
| 638 | | * Get the description of the dependency (if available) |
| 639 | | * |
| 640 | | * @return String or null |
| 641 | | */ |
| 642 | | public function getDescription() |
| 643 | | { |
| 644 | | $retval = null; |
| 645 | | |
| 646 | | if(!empty(self::$_components[$this->_id]['description'])) { |
| 647 | | $retval = self::$_components[$this->_id]['description']; |
| 648 | | } |
| 649 | | |
| 650 | | return $retval; |
| 651 | | } |
| 652 | | |
| 653 | | |
| 654 | | /** |
| 655 | | * Get the source URL where the package can be downloaded. It's meaning depends on the install method (for example, it may be a svn source) |
| 656 | | * |
| 657 | | * @return String or null |
| 658 | | */ |
| 659 | | public function getInstallSourceUrl() |
| 660 | | { |
| 661 | | $retval = null; |
| 662 | | if(!empty(self::$_components[$this->_id]['installSourceUrl'])) { |
| 663 | | $retval = self::$_components[$this->_id]['installSourceUrl']; |
| 664 | | } |
| 665 | | return $retval; |
| 666 | | } |
| 667 | | /** |
| 668 | | * Get the install method for this dependency (only for those that can be directly installed by the auth server) * |
| 669 | | * @return String or null |
| 670 | | */ |
| 671 | | public function getInstallMethod() |
| 672 | | { |
| 673 | | $retval = null; |
| 674 | | if(!empty(self::$_components[$this->_id]['installMethod'])) { |
| 675 | | $retval = self::$_components[$this->_id]['installMethod']; |
| 676 | | } |
| 677 | | return $retval; |
| 678 | | } |
| 679 | | |
| 680 | | /** |
| 681 | | * Get the install destination. Interpretation depends on the install method. Usisally the parameter to be passed to tar or SVN * |
| 682 | | * @return String or null |
| 683 | | */ |
| 684 | | public function getInstallDestination() |
| 685 | | { |
| 686 | | $retval = null; |
| 687 | | if(!empty(self::$_components[$this->_id]['installDestination'])) { |
| 688 | | $retval = self::$_components[$this->_id]['installDestination']; |
| 689 | | } |
| 690 | | return $retval; |
| 691 | | } |
| 692 | | /** |
| 693 | | * Get the type of the dependency |
| 694 | | * |
| 695 | | * @return String |
| 696 | | */ |
| 697 | | public function getType() |
| 698 | | { |
| 699 | | return self::$_components[$this->_id]['type']; |
| 700 | | } |
| 701 | | |
| 702 | | /** |
| 703 | | * Get the type of the dependency |
| 704 | | * |
| 705 | | * @return String |
| 706 | | */ |
| 707 | | public function isMandatory() |
| 708 | | { |
| 709 | | $retval = null; |
| 710 | | |
| 711 | | if(!empty(self::$_components[$this->_id]['mandatory'])) { |
| 712 | | $retval = true; |
| 713 | | } |
| 714 | | |
| 715 | | return $retval; |
| 716 | | } |
| 717 | | |
| 718 | | public function install(&$errorMsg = null){ |
| 719 | | $installSourceUrl = $this->getInstallSourceUrl(); |
| 720 | | $installDestinationPathOrig = $this->getInstallDestination(); |
| 721 | | if(!$installSourceUrl || !$installDestinationPathOrig) { |
| 722 | | $errorMsg .= "<em style=\"color:red\">Error:</em>Either the install source or destination path is missing<br/>\n"; |
| | 632 | } |
| | 633 | |
| | 634 | return $retval; |
| | 635 | } |
| | 636 | |
| | 637 | /** |
| | 638 | * Get the description of the dependency (if available) |
| | 639 | * |
| | 640 | * @return String or null |
| | 641 | */ |
| | 642 | public function getDescription() |
| | 643 | { |
| | 644 | $retval = null; |
| | 645 | |
| | 646 | if(!empty(self::$_components[$this->_id]['description'])) { |
| | 647 | $retval = self::$_components[$this->_id]['description']; |
| | 648 | } |
| | 649 | |
| | 650 | return $retval; |
| | 651 | } |
| | 652 | |
| | 653 | |
| | 654 | /** |
| | 655 | * Get the source URL where the package can be downloaded. It's meaning depends on the install method (for example, it may be a svn source) |
| | 656 | * |
| | 657 | * @return String or null |
| | 658 | */ |
| | 659 | public function getInstallSourceUrl() |
| | 660 | { |
| | 661 | $retval = null; |
| | 662 | if(!empty(self::$_components[$this->_id]['installSourceUrl'])) { |
| | 663 | $retval = self::$_components[$this->_id]['installSourceUrl']; |
| | 664 | } |
| | 665 | return $retval; |
| | 666 | } |
| | 667 | /** |
| | 668 | * Get the install method for this dependency (only for those that can be directly installed by the auth server) * |
| | 669 | * @return String or null |
| | 670 | */ |
| | 671 | public function getInstallMethod() |
| | 672 | { |
| | 673 | $retval = null; |
| | 674 | if(!empty(self::$_components[$this->_id]['installMethod'])) { |
| | 675 | $retval = self::$_components[$this->_id]['installMethod']; |
| | 676 | } |
| | 677 | return $retval; |
| | 678 | } |
| | 679 | |
| | 680 | /** |
| | 681 | * Get the install destination. Interpretation depends on the install method. Usisally the parameter to be passed to tar or SVN * |
| | 682 | * @return String or null |
| | 683 | */ |
| | 684 | public function getInstallDestination() |
| | 685 | { |
| | 686 | $retval = null; |
| | 687 | if(!empty(self::$_components[$this->_id]['installDestination'])) { |
| | 688 | $retval = self::$_components[$this->_id]['installDestination']; |
| | 689 | } |
| | 690 | return $retval; |
| | 691 | } |
| | 692 | /** |
| | 693 | * Get the type of the dependency |
| | 694 | * |
| | 695 | * @return String |
| | 696 | */ |
| | 697 | public function getType() |
| | 698 | { |
| | 699 | return self::$_components[$this->_id]['type']; |
| | 700 | } |
| | 701 | |
| | 702 | /** |
| | 703 | * Get the type of the dependency |
| | 704 | * |
| | 705 | * @return String |
| | 706 | */ |
| | 707 | public function isMandatory() |
| | 708 | { |
| | 709 | $retval = null; |
| | 710 | |
| | 711 | if(!empty(self::$_components[$this->_id]['mandatory'])) { |
| | 712 | $retval = true; |
| | 713 | } |
| | 714 | |
| | 715 | return $retval; |
| | 716 | } |
| | 717 | |
| | 718 | public function install(&$errorMsg = null){ |
| | 719 | $installSourceUrl = $this->getInstallSourceUrl(); |
| | 720 | $installDestinationPathOrig = $this->getInstallDestination(); |
| | 721 | if(!$installSourceUrl || !$installDestinationPathOrig) { |
| | 722 | $errorMsg .= "<em style=\"color:red\">Error:</em>Either the install source or destination path is missing<br/>\n"; |
| | 723 | } |
| | 724 | else { |
| | 725 | $installDestinationPath = WIFIDOG_ABS_FILE_PATH . "lib/" .$installDestinationPathOrig; |
| | 726 | $installMethod = $this->getInstallMethod(); |
| | 727 | switch($installMethod) { |
| | 728 | case "svn": |
| | 729 | self::execVerbose("svn co ".escapeshellarg($installSourceUrl)." ".escapeshellarg ($installDestinationPath), $output, $return, $errorMsg); |
| | 730 | |
| | 731 | |
| | 732 | break; |
| | 733 | |
| | 734 | case "tarball": |
| | 735 | $downloadPath = WIFIDOG_ABS_FILE_PATH . "tmp/"; |
| | 736 | chdir($downloadPath); |
| | 737 | if(!empty(self::$_components[$this->_id]['filename'])) { |
| | 738 | $filename = self::$_components[$this->_id]['filename']; |
| | 739 | } |
| | 740 | else { |
| | 741 | $filename_array = preg_split("/\//", $installSourceUrl); |
| | 742 | $filename = array_pop($filename_array); |
| | 743 | } |
| | 744 | |
| | 745 | |
| | 746 | if (!file_exists($downloadPath . $filename)){ |
| | 747 | $errorMsg .= "Downloading tarball ($installSourceUrl) : "; |
| | 748 | //execVerbose("wget \"$phlickr_full_url\" 2>&1", $output, $return); |
| | 749 | self::downloadFile($installSourceUrl, $downloadPath . $filename); |
| | 750 | |
| | 751 | if (!file_exists($downloadPath . $filename)) { # Error occured, print output of wget |
| | 752 | $errorMsg .= sprintf("<em style=\"color:red\">Error:</em> Unable to download $installSourceUrl to $destinationPath<br/>\n"); |
| | 753 | return false; |
| 725 | | $installDestinationPath = WIFIDOG_ABS_FILE_PATH . "lib/" .$installDestinationPathOrig; |
| 726 | | $installMethod = $this->getInstallMethod(); |
| 727 | | switch($installMethod) { |
| 728 | | case "svn": |
| 729 | | self::execVerbose("svn co ".escapeshellarg($installSourceUrl)." ".escapeshellarg ($installDestinationPath), $output, $return, $errorMsg); |
| 730 | | |
| 731 | | |
| 732 | | break; |
| 733 | | |
| 734 | | case "tarball": |
| 735 | | $downloadPath = WIFIDOG_ABS_FILE_PATH . "tmp/"; |
| 736 | | chdir($downloadPath); |
| 737 | | if(!empty(self::$_components[$this->_id]['filename'])) { |
| 738 | | $filename = self::$_components[$this->_id]['filename']; |
| 739 | | } |
| 740 | | else { |
| 741 | | $filename_array = preg_split("/\//", $installSourceUrl); |
| 742 | | $filename = array_pop($filename_array); |
| 743 | | } |
| 744 | | |
| 745 | | |
| 746 | | if (!file_exists($downloadPath . $filename)){ |
| 747 | | $errorMsg .= "Downloading tarball ($installSourceUrl) : "; |
| 748 | | //execVerbose("wget \"$phlickr_full_url\" 2>&1", $output, $return); |
| 749 | | self::downloadFile($installSourceUrl, $downloadPath . $filename); |
| 750 | | |
| 751 | | if (!file_exists($downloadPath . $filename)) { # Error occured, print output of wget |
| 752 | | $errorMsg .= sprintf("<em style=\"color:red\">Error:</em> Unable to download $installSourceUrl to $destinationPath<br/>\n"); |
| 753 | | return false; |
| 754 | | } |
| 755 | | else { |
| 756 | | $errorMsg .= "OK<br/>"; |
| 757 | | } |
| 758 | | } |
| 759 | | else { |
| 760 | | $errorMsg .= "Tarball $filename already present<br/>\n"; |
| 761 | | } |
| 762 | | chdir($installDestinationPath); |
| 763 | | //pretty_print_r($installDestinationPath); |
| 764 | | if(preg_match("/(.tgz$)|(.tar.gz$)/",$filename)) { |
| 765 | | $errorMsg .= "Archive is in gzip format<br/>"; |
| 766 | | $params = "-zxf"; |
| 767 | | } |
| 768 | | else if(preg_match("/\.bz2$/",$filename)) { |
| 769 | | $errorMsg .= "Archive is in bz2 format<br/>"; |
| 770 | | $params = "-jxf"; |
| 771 | | } |
| 772 | | else { |
| 773 | | $errorMsg .= "Unable to determine the archive format from the filemname<br/>"; |
| 774 | | return; |
| 775 | | } |
| 776 | | $errorMsg .= "Uncompressing : "; |
| 777 | | $execRetval = self::execVerbose("tar $params ".$downloadPath . $filename, $output, $return, $errorMsg); |
| 778 | | if($execRetval==0) { |
| 779 | | $errorMsg .= "OK<br/>"; |
| 780 | | } |
| 781 | | else { |
| 782 | | $errorMsg .= "<em style=\"color:red\">Decompression failed</em><br/>"; |
| 783 | | return; |
| 784 | | } |
| 785 | | break; |
| 786 | | default: |
| 787 | | $errorMsg .= "Unknown install method $installMethod<br/>"; |
| 788 | | }//End switch |
| | 756 | $errorMsg .= "OK<br/>"; |