root/trunk/wifidog-auth/wifidog/classes/Dependency.php @ 1313

Revision 1313, 36.7 KB (checked in by benoitg, 5 years ago)
  • install.php, Dependency.php: Commit install script improvements by Robin Jones
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[734]1<?php
[747]2
[866]3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
[747]4
[866]5// +-------------------------------------------------------------------+
6// | WiFiDog Authentication Server                                     |
7// | =============================                                     |
8// |                                                                   |
9// | The WiFiDog Authentication Server is part of the WiFiDog captive  |
10// | portal suite.                                                     |
11// +-------------------------------------------------------------------+
12// | PHP version 5 required.                                           |
13// +-------------------------------------------------------------------+
14// | Homepage:     http://www.wifidog.org/                             |
15// | Source Forge: http://sourceforge.net/projects/wifidog/            |
16// +-------------------------------------------------------------------+
17// | This program is free software; you can redistribute it and/or     |
18// | modify it under the terms of the GNU General Public License as    |
19// | published by the Free Software Foundation; either version 2 of    |
20// | the License, or (at your option) any later version.               |
21// |                                                                   |
22// | This program is distributed in the hope that it will be useful,   |
23// | but WITHOUT ANY WARRANTY; without even the implied warranty of    |
24// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     |
25// | GNU General Public License for more details.                      |
26// |                                                                   |
27// | You should have received a copy of the GNU General Public License |
28// | along with this program; if not, contact:                         |
29// |                                                                   |
30// | Free Software Foundation           Voice:  +1-617-542-5942        |
31// | 59 Temple Place - Suite 330        Fax:    +1-617-542-2652        |
32// | Boston, MA  02111-1307,  USA       gnu@gnu.org                    |
33// |                                                                   |
34// +-------------------------------------------------------------------+
35
[857]36/**
[866]37 * @package    WiFiDogAuthServer
38 * @author     Philippe April
[1306]39 * @author     Max Horváth <max.horvath@freenet.de>
40 * @author     Benoit Grégoire <bock@step.polymtl.ca>
[1185]41 * @copyright  2005-2007 Philippe April
[1306]42 * @copyright  2005-2007 Max Horváth, Horvath Web Consulting
43 * @copyright  2006-2007 Benoit Grégoire, Technologies Coeus inc.
[915]44 * @version    Subversion $Id$
45 * @link       http://www.wifidog.org/
[734]46 */
[1082]47
[1287]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 }
[1185]55
[1287]56 require_once ('classes/Utils.php');
[1294]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/');       
[1287]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
[1306]66  * @author     Max Horváth <max.horvath@freenet.de>
67  * @author     Benoit Grégoire <bock@step.polymtl.ca>
[1287]68  * @copyright  2005-2007 Philippe April
[1306]69  * @copyright  2005-2007 Max Horváth, Horvath Web Consulting
70  * @copyright  2006-2007 Benoit Grégoire, Technologies Coeus inc.
[1287]71  */
72  class Dependency
73  {
74      /**
[1294]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
[1313]83           *    "peclStandard":  PEAR PHP module in the standard PEAR repository or in a custom channel
[1294]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.
[1313]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)
[1294]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
[1313]95       * 'filename' => temp download filename if sourceurl does not meet preg requirements.
[1294]96       *
[1287]97       * @var array
98       */
[1082]99
[1287]100       private static $_components = array(
101       /* PHP extensions (mandatory) */
102       'mbstring' => array (
[1294]103       'mandatory' => true,
[1287]104       "type" => "phpExtension",
105       'description' => 'Required for core auth-server and RSS support'
106       ),
107       'session' => array (
[1294]108       'mandatory' => true,
[1287]109       "type" => "phpExtension",
110       'description' => 'Required for core auth-server'
111       ),
112       'pgsql' => array (
[1294]113       'mandatory' => true,
[1287]114       "type" => "phpExtension",
115       'description' => 'Required for auth-server to connect to Postgresql database'
116       ),
[1294]117       "Smarty" => array (
118       'mandatory' => true,
119       "type" => "localLib",
120       "detectFiles" => "lib/Smarty-2.6.18/libs/Smarty.class.php",
121       'description' => "Required for all parts of wifidog",
122       'website' => "http://smarty.php.net/",
123       'installSourceUrl' => "http://smarty.php.net/do_download.php?download_file=Smarty-2.6.18.tar.gz",
124       'installMethod' => "tarball",
125       'installDestination' => "/"
126       ),
[1306]127     
[1287]128       /* PHP extensions (optional) */
[1306]129       "simplepie" => array (
130       "type" => "localLib",
131       "detectFiles" => "lib/simplepie/simplepie.inc",
132       'description' => "SimplePie is a dependency that provides an RSS parser in PHP. It is required for RssPressReview.  It is is recommended to install it, if you do not, RSS feed options will be disabled.",
133       'website' => "http://simplepie.org/",
134       'installSourceUrl' => "http://svn.simplepie.org/simplepie/branches/1.0/",
135       'installMethod' => "svn",
136       'installDestination' => "simplepie"
137       ),
138       'jpgraph' => array (
139       "type" => "localLib",
140       "detectFiles" => "lib/jpgraph-1.22/src/jpgraph.php",
141       'description' => "JpGraph is a Object-Oriented Graph creating library for PHP.
142JpGraph is not currently used by Wifidog (it will be use for statistic graphs in a later version). You can skip this installation if your not a developper.",
143       'website' => "http://www.aditus.nu/jpgraph/",
144       'installSourceUrl' => "http://hem.bredband.net/jpgraph/jpgraph-1.22.tar.gz",
145       'installMethod' => "tarball",
146       'installDestination' => "/"
147        ),
148       'feedpressreview' => array (
149       "type" => "localLib",
150       "detectFiles" => "lib/feedpressreview/FeedPressReview.inc",
151       'description' => "Feed Press Review allows your athentication server to produce RSS Feeds.  It is recommended that it is installed.  If it is not installed, the RSS feed options will be disabled.",
152       'website' => "http://projects.coeus.ca/feedpressreview/",
153       'installSourceUrl' => "http://projects.coeus.ca/svn/feedpressreview/trunk/",
154       'installMethod' => "svn",
155       'installDestination' => "feedpressreview"
156        ),
[1287]157       'gettext' => array (
158       "type" => "phpExtension",
159       'description' => 'Almost essential: Without gettext, the auth-server will still work, but you will loose internationalization'
160       ),
161       'dom' => array (
162       "type" => "phpExtension",
163       'description' => 'Required to export the list of HotSpots as a RSS feed and for the geocoders'
164       ),
165       'libxml' => array (
166       "type" => "phpExtension",
167       'description' => 'Required to export the list of HotSpots as a RSS feed and for the geocoders'
168       ),
169       'mcrypt' => array (
170       "type" => "phpExtension",
171       'description' => 'Required by the optional Radius Authenticator'
172       ),
173       'mhash' => array (
174       "type" => "phpExtension",
175       'description' => 'Required by the optional Radius Authenticator'
176       ),
177       'xmlrpc' => array (
178       "type" => "phpExtension",
179       'description' => 'Required by the optional Radius Authenticator'
180       ),
181       "ldap" => array (
182       "type" => "phpExtension",
183       'description' => "Required by the optional LDAP Authenticator"
184       ),
185       'xml' => array (
186       "type" => "phpExtension",
187       'description' => 'Required for RSS support'
188       ),
189       'curl' => array (
190       "type" => "phpExtension",
191       'description' => 'Allows faster RSS support and required if you want to use Phlickr'
192       ),
193       'gd' => array (
194       "type" => "phpExtension",
195       'description' => 'Required if you want to generate graphical statistics'
196       ),
197       'xsl' => array (
198       "type" => "phpExtension",
199       'description' => 'Required if you want to generate a node list using XSLT stylesheets'
200       ),
201       /* Pecl libraries */
202       "radius" => array (
203       "type" => "peclStandard",
[1313]204       'description' => "Required by the optional Radius Authenticator.  If it's not detected, make sure it's installed (pecl list) AND loaded in php.ini (extension=radius.so)"
[1287]205       ),
[1151]206
[1287]207       /* Locally installed libraries */
208       "FCKeditor" => array (
209       "type" => "localLib",
[1313]210       "detectFiles" => "lib/fckeditor/fckeditor.php",
[1287]211       'description' => "Required by content type FCKEditor (WYSIWYG HTML)",
[1313]212       'website' => "http://www.fckeditor.net/",
213       'installSourceUrl' => "http://easynews.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor_2.5.tar.gz",
214       'installMethod' => "tarball",
215       'installDestination' => "/",
[1287]216       ),
[1313]217       
[1287]218       "FPDF" => array (
219       "type" => "localLib",
[1313]220       "detectFiles" => "lib/fpdf153/fpdf.php",
[1287]221       'description' => "Required if you want to be able to export the node list as a PDF file",
[1313]222       'website' => "http://www.fpdf.org/",
223       'installSourceUrl' => "http://www.fpdf.org/en/dl.php?v=153&f=tgz",
224       'installMethod' => "tarball",
225       'installDestination' => "/",
226       'filename' => "fpdf.tgz"
[1287]227       ),
228       "php-openid" => array (
229       "type" => "localLib",
230       "detectFiles" => "lib/php-openid-2.0.0-rc2/CHANGELOG",
231       'description' => "Required for OpenID support (both as a consumer and Identity provider)",
232       'website' => "http://www.openidenabled.com/php-openid/",
233       'installSourceUrl' => "http://openidenabled.com/files/php-openid/packages/php-openid-2.0.0-rc2.tar.bz2",
234       'installMethod' => "tarball",
235       'installDestination' => "/"
236       ),
237       'gmp' => array (
238       "type" => "phpExtension",
239       'description' => 'Required for good OpenID support (otherwise, BCmath will be used, which is MUCH slower)'
240       ),
241       'BCmath' => array (
242       "type" => "phpExtension",
243       'description' => 'Required for OpenID support, but ONLY if GMP above is not available'
244       ),
245       /* PEAR libraries */
246       'Auth_RADIUS' => array (
247       "type" => "pearStandard",
248       "detectFiles" => "Auth/RADIUS.php",
249       'description' => "Required by the optional Radius Authenticator"
250       ),
251       'Crypt_CHAP' => array (
252       "type" => "pearStandard",
253       "detectFiles" => "Crypt/CHAP.php",
254       'description' => "Required by the optional Radius Authenticator"
255       ),
256       "Cache" => array (
257       "type" => "pearStandard",
[1313]258       "detectFiles" => "Cache/Lite.php", #unsure whether this file still exists.
259       'description' => "Required if you want to turn on the experimental USE_CACHE_LITE in config.php",
[1287]260       ),
261       "HTML_Safe" => array (
262       "type" => "pearStandard",
263       "detectFiles" => "HTML/Safe.php",
[1313]264       'description' => "Optional for content type Langstring (and subtypes) to better strip out dangerous HTML",
265       'installSourceUrl' => "HTML_Safe-beta"
[1287]266       ),
267       "Image_Graph" => array (
268       "type" => "pearStandard",
269       "detectFiles" => "Image/Graph.php",
[1313]270       'description' => "Required if you want to generate graphical statistics",
271       'installSourceUrl' => "Image_graph-alpha"
[1287]272       ),
273       "Image_Canvas" => array (
274       "type" => "pearStandard",
275       "detectFiles" => "Image/Canvas.php",
[1313]276       'description' => "Required if you want to generate graphical statistics",
277       'installSourceUrl' => "Image_Canvas-alpha"
[1287]278       ),
279       "Image_Color" => array (
280       "type" => "pearStandard",
281       "detectFiles" => "Image/Color.php",
282       'description' => "Required if you want to generate graphical statistics"
283       ),
[1185]284
[1287]285       /* PHP extensions (custom installations) */
286       "Phlickr" => array (
287       "type" => "pearCustom",
288       "detectFiles" => "Phlickr/Api.php",
289       'description' => "Required by content type FlickrPhotostream",
290       'website' => "http://drewish.com/projects/phlickr/",
291       'installSourceUrl' => "http://superb-east.dl.sourceforge.net/sourceforge/phlickr/Phlickr-0.2.7.tgz"
292       ),
293       );
[1185]294
[1287]295       /**
296        * Object cache for the object factory (getObject())
297        */
298        private static $instanceArray = array();
[1185]299
[1287]300        private $_id;
[1185]301
[1287]302        /**
303         * Constructor
304         */
305         private function __construct($component) {
306             $this->_id = $component;
307         }
[1185]308
[1287]309         /**
310          * Get the entire array of Dependency
311          *
312          * @return boolean Returns whether the file has been found or not.
313          */
[1294]314          public static function getDependencies()
[1287]315          {
316              $retval = array();
[1185]317
[1287]318              foreach (self::$_components as $component_key=>$component_info) {
319                  $retval[] = self::getObject($component_key);
320              }
[1151]321
[1287]322              return $retval;
323          }
[1185]324
[1287]325          /** Use PHP internal functions to execute a command
[1306]326           Â @return: Return value of the command*/
[1287]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";
[1185]334
[1287]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          }
[938]342
[1287]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());
[938]356
[1287]357               foreach ($_paths as $_path) {
358                   // Formulate the absolute path
359                   $_fullPath = $_path . DIRECTORY_SEPARATOR . $file;
[938]360
[1287]361                   // Check it
362                   if (file_exists($_fullPath)) {
363                       return $_fullPath;
364                   }
365               }
[874]366
[1287]367               return false;
368           }
[857]369
[1287]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;
[938]386
[1287]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;
[857]399
[1287]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                            }
[938]408
[1287]409                            $returnValue = $_singleReturns;
410                        }
411                        else {
412                            $filePath = WIFIDOG_ABS_FILE_PATH . self::$_components[$component]["detectFiles"];
[994]413
[1287]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;
[994]427
[1287]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;
[994]432
[1287]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                            }
[994]437
[1287]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 {
[994]446
[1287]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                }
[994]459
[1287]460                return $returnValue;
461            }
[1185]462
[1294]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();
476foreach($components as $component) {
477    if($component->isMandatory()) {
478        $returnValue &= self::check($component->getId(), $errmsg);
479    }
480}
481
482                return $returnValue;
483            }
484           
[1287]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;
[1185]499
[1287]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());
[1185]510
[1287]511                             break;
512                         case "localLib":
[1306]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);
[1294]517                                                     
518                             }
519                             else {
[1306]520                                 $html .= sprintf(_("Sorry, i couldn't find the source for %s in installSourceUrl"),
521                                 $this->getId());
[1294]522                             }
[1287]523                             break;
[1313]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                                 
[1287]548                         case "pearCustom":
549                             if($this->getInstallSourceUrl()) {
550                                 $installSource=$this->getInstallSourceUrl();
551                             }
552                             else {
[1313]553                             $installSource=sprintf(_("url_to_the_tarball (Sorry, i couldn't find the source for %s in installSourceUrl)"), $this->getId());
[1287]554                             }
555                             $html .= sprintf(_("To install this custom PEAR extension, use 'sudo pear install %s'"), $installSource);
556                             break;
[1313]557                             
558                             
[1287]559                         default:
560                             $html .= sprintf(_("Sorry, I don't know how to install a %s extension"), $type);
561                     }
562                 }
563                 return $html;
564             }
[1185]565
[1287]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              {
[1185]573
[1287]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;
590               }
[1185]591
[1287]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                    }
[1185]609
[1287]610                    return self::$instanceArray[$id];
611                }
[1185]612
[1287]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;
[1185]621
[1287]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                     }
[1185]633
[1287]634                     return $retval;
635                 }
[1185]636
[1287]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;
[1185]645
[1287]646                      if(!empty(self::$_components[$this->_id]['description'])) {
647                          $retval = self::$_components[$this->_id]['description'];
648                      }
[1185]649
[1287]650                      return $retval;
651                  }
[1313]652                 
[1185]653
[1287]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 {
[1306]725                               $installDestinationPath = WIFIDOG_ABS_FILE_PATH . "lib/" .$installDestinationPathOrig;
[1287]726                               $installMethod = $this->getInstallMethod();
727                               switch($installMethod) {
[1306]728                                   case "svn":
729                                       self::execVerbose("svn co ".escapeshellarg($installSourceUrl)." ".escapeshellarg      ($installDestinationPath), $output, $return, $errorMsg);
730
731
732                                       break;
733
[1287]734                                   case "tarball":
735                                       $downloadPath = WIFIDOG_ABS_FILE_PATH . "tmp/";
736                                       chdir($downloadPath);
[1313]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                                        }
[1287]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
789                           }
790                       }
791
792
793  }
794
795  /*
796   * Local variables:
797   * tab-width: 4
798   * c-basic-offset: 4
799   * c-hanging-comment-ender-p: nil
800   * End:
801   */
Note: See TracBrowser for help on using the browser.