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

Revision 1306, 34.2 KB (checked in by benoitg, 6 years ago)
  • Commit most of Robin Jones install script improvements.
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
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
36/**
37 * @package    WiFiDogAuthServer
38 * @author     Philippe April
39 * @author     Max Horváth <max.horvath@freenet.de>
40 * @author     Benoit Grégoire <bock@step.polymtl.ca>
41 * @copyright  2005-2007 Philippe April
42 * @copyright  2005-2007 Max Horváth, Horvath Web Consulting
43 * @copyright  2006-2007 Benoit Grégoire, Technologies Coeus inc.
44 * @version    Subversion $Id$
45 * @link       http://www.wifidog.org/
46 */
47
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":  Standard (in the PEAR reposidory) PEAR PHP module
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       * 'installMethod' => For localLib, the protocol to be used to download and install the dependency.  Currently, allowed values are:
92       *        'tarball': Decompress a tarball in wifidog/lib
93       * 'installDestination' => For localLib, the path, relative to wifidog/lib where the dependency should be installed
94       *
95       * @var array
96       */
97
98       private static $_components = array(
99       /* PHP extensions (mandatory) */
100       'mbstring' => array (
101       'mandatory' => true,
102       "type" => "phpExtension",
103       'description' => 'Required for core auth-server and RSS support'
104       ),
105       'session' => array (
106       'mandatory' => true,
107       "type" => "phpExtension",
108       'description' => 'Required for core auth-server'
109       ),
110       'pgsql' => array (
111       'mandatory' => true,
112       "type" => "phpExtension",
113       'description' => 'Required for auth-server to connect to Postgresql database'
114       ),
115       "Smarty" => array (
116       'mandatory' => true,
117       "type" => "localLib",
118       "detectFiles" => "lib/Smarty-2.6.18/libs/Smarty.class.php",
119       'description' => "Required for all parts of wifidog",
120       'website' => "http://smarty.php.net/",
121       'installSourceUrl' => "http://smarty.php.net/do_download.php?download_file=Smarty-2.6.18.tar.gz",
122       'installMethod' => "tarball",
123       'installDestination' => "/"
124       ),
125     
126       /* PHP extensions (optional) */
127       "simplepie" => array (
128       "type" => "localLib",
129       "detectFiles" => "lib/simplepie/simplepie.inc",
130       '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.",
131       'website' => "http://simplepie.org/",
132       'installSourceUrl' => "http://svn.simplepie.org/simplepie/branches/1.0/",
133       'installMethod' => "svn",
134       'installDestination' => "simplepie"
135       ),
136       'jpgraph' => array (
137       "type" => "localLib",
138       "detectFiles" => "lib/jpgraph-1.22/src/jpgraph.php",
139       'description' => "JpGraph is a Object-Oriented Graph creating library for PHP.
140JpGraph 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.",
141       'website' => "http://www.aditus.nu/jpgraph/",
142       'installSourceUrl' => "http://hem.bredband.net/jpgraph/jpgraph-1.22.tar.gz",
143       'installMethod' => "tarball",
144       'installDestination' => "/"
145        ),
146       'feedpressreview' => array (
147       "type" => "localLib",
148       "detectFiles" => "lib/feedpressreview/FeedPressReview.inc",
149       '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.",
150       'website' => "http://projects.coeus.ca/feedpressreview/",
151       'installSourceUrl' => "http://projects.coeus.ca/svn/feedpressreview/trunk/",
152       'installMethod' => "svn",
153       'installDestination' => "feedpressreview"
154        ),
155       'gettext' => array (
156       "type" => "phpExtension",
157       'description' => 'Almost essential: Without gettext, the auth-server will still work, but you will loose internationalization'
158       ),
159       'dom' => array (
160       "type" => "phpExtension",
161       'description' => 'Required to export the list of HotSpots as a RSS feed and for the geocoders'
162       ),
163       'libxml' => array (
164       "type" => "phpExtension",
165       'description' => 'Required to export the list of HotSpots as a RSS feed and for the geocoders'
166       ),
167       'mcrypt' => array (
168       "type" => "phpExtension",
169       'description' => 'Required by the optional Radius Authenticator'
170       ),
171       'mhash' => array (
172       "type" => "phpExtension",
173       'description' => 'Required by the optional Radius Authenticator'
174       ),
175       'xmlrpc' => array (
176       "type" => "phpExtension",
177       'description' => 'Required by the optional Radius Authenticator'
178       ),
179       "ldap" => array (
180       "type" => "phpExtension",
181       'description' => "Required by the optional LDAP Authenticator"
182       ),
183       'xml' => array (
184       "type" => "phpExtension",
185       'description' => 'Required for RSS support'
186       ),
187       'curl' => array (
188       "type" => "phpExtension",
189       'description' => 'Allows faster RSS support and required if you want to use Phlickr'
190       ),
191       'gd' => array (
192       "type" => "phpExtension",
193       'description' => 'Required if you want to generate graphical statistics'
194       ),
195       'xsl' => array (
196       "type" => "phpExtension",
197       'description' => 'Required if you want to generate a node list using XSLT stylesheets'
198       ),
199       /* Pecl libraries */
200       "radius" => array (
201       "type" => "peclStandard",
202       'description' => "Required by the optional Radius Authenticator"
203       ),
204
205       /* Locally installed libraries */
206       "FCKeditor" => array (
207       "type" => "localLib",
208       "detectFiles" => "lib/FCKeditor/fckeditor.php",
209       'description' => "Required by content type FCKEditor (WYSIWYG HTML)",
210       'website' => "http://www.fckeditor.net/"
211       ),
212       "FPDF" => array (
213       "type" => "localLib",
214       "detectFiles" => "lib/fpdf/fpdf.php",
215       'description' => "Required if you want to be able to export the node list as a PDF file",
216       'website' => "http://www.fpdf.org/"
217       ),
218       "php-openid" => array (
219       "type" => "localLib",
220       "detectFiles" => "lib/php-openid-2.0.0-rc2/CHANGELOG",
221       'description' => "Required for OpenID support (both as a consumer and Identity provider)",
222       'website' => "http://www.openidenabled.com/php-openid/",
223       'installSourceUrl' => "http://openidenabled.com/files/php-openid/packages/php-openid-2.0.0-rc2.tar.bz2",
224       'installMethod' => "tarball",
225       'installDestination' => "/"
226       ),
227       'gmp' => array (
228       "type" => "phpExtension",
229       'description' => 'Required for good OpenID support (otherwise, BCmath will be used, which is MUCH slower)'
230       ),
231       'BCmath' => array (
232       "type" => "phpExtension",
233       'description' => 'Required for OpenID support, but ONLY if GMP above is not available'
234       ),
235       /* PEAR libraries */
236       'Auth_RADIUS' => array (
237       "type" => "pearStandard",
238       "detectFiles" => "Auth/RADIUS.php",
239       'description' => "Required by the optional Radius Authenticator"
240       ),
241       'Crypt_CHAP' => array (
242       "type" => "pearStandard",
243       "detectFiles" => "Crypt/CHAP.php",
244       'description' => "Required by the optional Radius Authenticator"
245       ),
246       "Cache" => array (
247       "type" => "pearStandard",
248       "detectFiles" => "Cache/Lite.php",
249       'description' => "Required if you want to turn on the experimental USE_CACHE_LITE in config.php"
250       ),
251       "HTML_Safe" => array (
252       "type" => "pearStandard",
253       "detectFiles" => "HTML/Safe.php",
254       'description' => "Optional for content type Langstring (and subtypes) to better strip out dangerous HTML"
255       ),
256       "Image_Graph" => array (
257       "type" => "pearStandard",
258       "detectFiles" => "Image/Graph.php",
259       'description' => "Required if you want to generate graphical statistics"
260       ),
261       "Image_Canvas" => array (
262       "type" => "pearStandard",
263       "detectFiles" => "Image/Canvas.php",
264       'description' => "Required if you want to generate graphical statistics"
265       ),
266       "Image_Color" => array (
267       "type" => "pearStandard",
268       "detectFiles" => "Image/Color.php",
269       'description' => "Required if you want to generate graphical statistics"
270       ),
271
272       /* PHP extensions (custom installations) */
273       "Phlickr" => array (
274       "type" => "pearCustom",
275       "detectFiles" => "Phlickr/Api.php",
276       'description' => "Required by content type FlickrPhotostream",
277       'website' => "http://drewish.com/projects/phlickr/",
278       'installSourceUrl' => "http://superb-east.dl.sourceforge.net/sourceforge/phlickr/Phlickr-0.2.7.tgz"
279       ),
280       );
281
282       /**
283        * Object cache for the object factory (getObject())
284        */
285        private static $instanceArray = array();
286
287        private $_id;
288
289        /**
290         * Constructor
291         */
292         private function __construct($component) {
293             $this->_id = $component;
294         }
295
296         /**
297          * Get the entire array of Dependency
298          *
299          * @return boolean Returns whether the file has been found or not.
300          */
301          public static function getDependencies()
302          {
303              $retval = array();
304
305              foreach (self::$_components as $component_key=>$component_info) {
306                  $retval[] = self::getObject($component_key);
307              }
308
309              return $retval;
310          }
311
312          /** Use PHP internal functions to execute a command
313           Â @return: Return value of the command*/
314          function execVerbose($command, & $output, & $return_var, &$errMsg = null) {
315              $errMsg .= "Executing: $command <br/>";
316              exec($command.'  2>&1', $output, $return_var);
317              if ($return_var != 0)
318              $errMsg .= "<p style='color:red'><em>Error:</em>  Command did not complete successfully  (returned $return_var): <br/>\n";
319              else
320              $errMsg .= "<p style='color:green'><em>Command completed successfully</em>  (returned $return_var): <br/>\n";
321
322              if (($return_var != 0) && $output) {
323                  foreach ($output as $output_line)
324                  $errMsg .= " $output_line <br/>\n";
325              }
326              $errMsg .= "</p>\n";
327              return $return_var;
328          }
329
330          /**
331           * Checks if a file exists, including checking in the include path
332           *
333           * @param string $file Path or name of a file
334           *
335           * @return boolean Returns whether the file has been found or not.
336           *
337           * @author Aidan Lister <aidan@php.net>
338           * @link http://aidanlister.com/repos/v/function.file_exists_incpath.php
339           */
340           public static function file_exists_incpath($file)
341           {
342               $_paths = explode(PATH_SEPARATOR, get_include_path());
343
344               foreach ($_paths as $_path) {
345                   // Formulate the absolute path
346                   $_fullPath = $_path . DIRECTORY_SEPARATOR . $file;
347
348                   // Check it
349                   if (file_exists($_fullPath)) {
350                       return $_fullPath;
351                   }
352               }
353
354               return false;
355           }
356
357           /**
358            * Checks if a component is available.
359            *
360            * This function checks, if a specific component is available to be used
361            * by Wifidog.
362            *
363            * @param string $component Name of component to be checked.
364            * @param string $errmsg    Reference of a string which would contain an
365            *                          error message.
366            *
367            * @return boolean Returns whether the component has been found or not.
368            */
369            public static function check($component, &$errmsg = null)
370            {
371                // Init values
372                $returnValue = false;
373
374                // Check, if the requested component can be found.
375                if (isset(self::$_components[$component])) {
376                    // What are we checking for?
377                    if (self::$_components[$component]["type"] == "phpExtension" || self::$_components[$component]["type"] == "peclStandard") {
378                        // Warning: extension_loaded(string) is case sensitive
379                        $returnValue = extension_loaded($component);
380                    }
381                    else if (self::$_components[$component]["type"] == "localLib") {
382                        if (is_array(self::$_components[$component]["detectFiles"])) {
383                            $_singleReturns = true;
384                            foreach (self::$_components[$component]["detectFiles"] as $_fileNames) {
385                                $filePath = WIFIDOG_ABS_FILE_PATH . $_fileNames;
386
387                                if (!file_exists($filePath)) {
388                                    echo "TEST";
389                                    $_singleReturns = false;
390                                    // The component has NOT been found. Return error message.
391                                    $errmsg .= sprintf(_("File %s not found"), $filePath);
392                                    break;
393                                }
394                            }
395
396                            $returnValue = $_singleReturns;
397                        }
398                        else {
399                            $filePath = WIFIDOG_ABS_FILE_PATH . self::$_components[$component]["detectFiles"];
400
401                            if (file_exists($filePath)) {
402                                // The component has been found.
403                                $returnValue = true;
404                            }
405                            else {
406                                // The component has NOT been found. Return error message.
407                                $errmsg .= sprintf(_("File %s not found"), $filePath);
408                            }
409                        }
410                    }
411                    else if (self::$_components[$component]["type"] == "pearStandard" || self::$_components[$component]["type"] == "pearCustom") {
412                        if (is_array(self::$_components[$component]["detectFiles"])) {
413                            $_singleReturns = true;
414
415                            foreach (self::$_components[$component]["detectFiles"] as $_fileNames) {
416                                // We need to use a custom file_exists to also check in the include path
417                                if (!self::file_exists_incpath($_fileNames)) {
418                                    $_singleReturns = false;
419
420                                    // The component has NOT been found. Return error message.
421                                    $errmsg .= sprintf(_("File %s not found in %s"), $_fileNames, get_include_path());
422                                }
423                            }
424
425                            $returnValue = $_singleReturns;
426                        } else {
427                            // We need to use a custom file_exists to also check in the include path
428                            if (self::file_exists_incpath(self::$_components[$component]["detectFiles"])) {
429                                // The component has been found.
430                                $returnValue = true;
431                            }
432                            else {
433
434                                // The component has NOT been found. Return error message.
435                                $errmsg .= sprintf(_("File %s not found in %s"), self::$_components[$component]["detectFiles"], get_include_path());
436                            }
437                        }
438                    }
439                    else {
440                        throw new Exception(sprintf("Unknown component type: %s", self::$_components[$component]["type"]));
441                    }
442                } else {
443                    // The requested component has not been defined in this class.
444                    throw new Exception("Component not found");
445                }
446
447                return $returnValue;
448            }
449
450                       /**
451            * Checks if one of the mandatory components is missing.
452            *
453            * @param string $errmsg    Reference of a string which would contain an
454            *                          error message.
455            *
456            * @return boolean Returns false if any components are missing.
457            */
458            public static function checkMandatoryComponents(&$errmsg = null)
459            {
460                // Init values
461                $returnValue = true;
462$components = self::getDependencies();
463foreach($components as $component) {
464    if($component->isMandatory()) {
465        $returnValue &= self::check($component->getId(), $errmsg);
466    }
467}
468
469                return $returnValue;
470            }
471           
472            /** Use PHP internal functions to download a file */
473            static public function downloadFile($remoteURL, $localPath) {
474                set_time_limit(1500); // 25 minutes timeout
475                return copy($remoteURL, $localPath);
476            }
477            /**
478             * Get a UI to install the component
479             *
480             * @return html markup.
481             */
482             public function getInstallUI()
483             {
484                 // Init values
485                 $html = false;
486
487                 // Check, if the requested component can be found.
488                 if (self::check($this->getId())) {
489                     //Component already installed
490                 }
491                 else {
492                     // What are we checking for?
493                     $type = $this->getType();
494                     switch ($type) {
495                         case "phpExtension":
496                             $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());
497
498                             break;
499                         case "localLib":
500                             if($this->getInstallSourceUrl()) {
501                                 $name = $this->getId().'_install';
502                                 $value = sprintf(_("Install %s"), $this->getId());
503                                 $html .= sprintf("<input type='submit' name='%s' value='%s'/>", $name, $value);
504                                                     
505                             }
506                             else {
507                                 $html .= sprintf(_("Sorry, i couldn't find the source for %s in installSourceUrl"),
508                                 $this->getId());
509                             }
510
511
512                             break;
513                             //case "pearStandard":
514                             //    break;
515                         case "pearCustom":
516                             if($this->getInstallSourceUrl()) {
517                                 $installSource=$this->getInstallSourceUrl();
518                             }
519                             else {
520                                 $installSource=sprintf(_("url_to_the_tarball (Sorry, i couldn't find the source for %s in installSourceUrl)"), $this->getId());
521                             }
522                             $html .= sprintf(_("To install this custom PEAR extension, use 'sudo pear install %s'"), $installSource);
523                             break;
524                         default:
525                             $html .= sprintf(_("Sorry, I don't know how to install a %s extension"), $type);
526                     }
527                 }
528                 return $html;
529             }
530
531             /**
532              * Get a UI to install the component
533              *
534              * @return true if something was processed.
535              */
536              public function processInstallUI(&$errMsg=null)
537              {
538
539                  $retval = false;
540                  $name = $this->getId().'_install';
541                  if(!empty($_REQUEST[$name]))
542                  {
543                      $this->install($errMsg);
544                  }
545                   
546                  return $retval;
547              }
548              /**
549               * Retreives the id of the object
550               *
551               * @return The id, a string
552               */
553               public function getId() {
554                   return $this->_id;
555               }
556
557               /**
558                * Get an instance of the object
559                *
560                * @param string $id The object id
561                *
562                * @return mixed The Content object, or null if there was an error
563                *               (an exception is also thrown)
564                *
565                * @see GenericObject
566                * @static
567                * @access public
568                */
569                public static function &getObject($id)
570                {
571                    if(!isset(self::$instanceArray[$id])) {
572                        self::$instanceArray[$id] = new self($id);
573                    }
574
575                    return self::$instanceArray[$id];
576                }
577
578                /**
579                 * Get website URL for the dependency (if available)
580                 *
581                 * @return URL or null
582                 */
583                 public function getWebsiteURL()
584                 {
585                     $retval = null;
586
587                     if(self::$_components[$this->_id]["type"] == "phpExtension") {
588                         $retval = "http://www.php.net/" . $this->_id . "/";
589                     } else if(self::$_components[$this->_id]["type"] == "pearStandard") {
590                         $retval = "http://pear.php.net/package/" . $this->_id . "/";
591                     } else if(self::$_components[$this->_id]["type"] == "peclStandard") {
592                         $retval = "http://pecl.php.net/package/" . $this->_id . "/";
593                     } else {
594                         if(!empty(self::$_components[$this->_id]['website'])) {
595                             $retval = self::$_components[$this->_id]['website'];
596                         }
597                     }
598
599                     return $retval;
600                 }
601
602                 /**
603                  * Get the description of the dependency (if available)
604                  *
605                  * @return String or null
606                  */
607                  public function getDescription()
608                  {
609                      $retval = null;
610
611                      if(!empty(self::$_components[$this->_id]['description'])) {
612                          $retval = self::$_components[$this->_id]['description'];
613                      }
614
615                      return $retval;
616                  }
617
618                  /**
619                   * 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)
620                   *
621                   * @return String or null
622                   */
623                   public function getInstallSourceUrl()
624                   {
625                       $retval = null;
626                       if(!empty(self::$_components[$this->_id]['installSourceUrl'])) {
627                           $retval = self::$_components[$this->_id]['installSourceUrl'];
628                       }
629                       return $retval;
630                   }
631                   /**
632                    * Get the install method for this dependency (only for those that can be directly installed by the auth server)                  *
633                    * @return String or null
634                    */
635                    public function getInstallMethod()
636                    {
637                        $retval = null;
638                        if(!empty(self::$_components[$this->_id]['installMethod'])) {
639                            $retval = self::$_components[$this->_id]['installMethod'];
640                        }
641                        return $retval;
642                    }
643
644                    /**
645                     * Get the install destination.  Interpretation depends on the install method.  Usisally the parameter to be passed to tar or SVN                 *
646                     * @return String or null
647                     */
648                     public function getInstallDestination()
649                     {
650                         $retval = null;
651                         if(!empty(self::$_components[$this->_id]['installDestination'])) {
652                             $retval = self::$_components[$this->_id]['installDestination'];
653                         }
654                         return $retval;
655                     }
656                     /**
657                      * Get the type of the dependency
658                      *
659                      * @return String
660                      */
661                      public function getType()
662                      {
663                          return self::$_components[$this->_id]['type'];
664                      }
665
666                      /**
667                       * Get the type of the dependency
668                       *
669                       * @return String
670                       */
671                       public function isMandatory()
672                       {
673                           $retval = null;
674
675                           if(!empty(self::$_components[$this->_id]['mandatory'])) {
676                               $retval = true;
677                           }
678
679                           return $retval;
680                       }
681
682                       public function install(&$errorMsg = null){
683                           $installSourceUrl = $this->getInstallSourceUrl();
684                           $installDestinationPathOrig = $this->getInstallDestination();
685                           if(!$installSourceUrl || !$installDestinationPathOrig) {
686                               $errorMsg .= "<em style=\"color:red\">Error:</em>Either the install source or destination path is missing<br/>\n";
687                           }
688                           else {
689                               $installDestinationPath = WIFIDOG_ABS_FILE_PATH . "lib/" .$installDestinationPathOrig;
690                               $installMethod = $this->getInstallMethod();
691                               switch($installMethod) {
692                                   case "svn":
693                                       self::execVerbose("svn co ".escapeshellarg($installSourceUrl)." ".escapeshellarg      ($installDestinationPath), $output, $return, $errorMsg);
694
695
696                                       break;
697
698                                   case "tarball":
699                                       $downloadPath = WIFIDOG_ABS_FILE_PATH . "tmp/";
700                                       chdir($downloadPath);
701                                       $filename_array = preg_split("/\//", $installSourceUrl);
702                                       $filename = array_pop($filename_array);
703
704
705                                       if (!file_exists($downloadPath . $filename)){
706                                           $errorMsg .= "Downloading tarball ($installSourceUrl) : ";
707                                           //execVerbose("wget \"$phlickr_full_url\" 2>&1", $output, $return);
708                                           self::downloadFile($installSourceUrl, $downloadPath . $filename);
709
710                                           if (!file_exists($downloadPath . $filename)) { # Error occured, print output of wget
711                                               $errorMsg .= sprintf("<em style=\"color:red\">Error:</em> Unable to download $installSourceUrl to $destinationPath<br/>\n");
712                                               return false;
713                                           }
714                                           else {
715                                               $errorMsg .= "OK<br/>";
716                                           }
717                                       }
718                                       else {
719                                           $errorMsg .= "Tarball $filename already present<br/>\n";
720                                       }
721                                       chdir($installDestinationPath);
722                                       //pretty_print_r($installDestinationPath);
723                                       if(preg_match("/(.tgz$)|(.tar.gz$)/",$filename)) {
724                                           $errorMsg .= "Archive is in gzip format<br/>";
725                                           $params = "-zxf";
726                                       }
727                                       else if(preg_match("/\.bz2$/",$filename)) {
728                                           $errorMsg .= "Archive is in bz2 format<br/>";
729                                                                                      $params = "-jxf";
730                                       }
731                                       else {
732                                           $errorMsg .= "Unable to determine the archive format from the filemname<br/>";
733                                           return;
734                                       }
735                                       $errorMsg .= "Uncompressing : ";
736                                       $execRetval = self::execVerbose("tar $params ".$downloadPath . $filename, $output, $return, $errorMsg);
737                                       if($execRetval==0) {
738                                           $errorMsg .= "OK<br/>";
739                                       }
740                                       else {
741                                           $errorMsg .= "<em style=\"color:red\">Decompression failed</em><br/>";
742                                           return;
743                                       }
744                                       break;
745                                   default:
746                                       $errorMsg .= "Unknown install method $installMethod<br/>";
747                               }//End switch
748                           }
749                       }
750
751
752  }
753
754  /*
755   * Local variables:
756   * tab-width: 4
757   * c-basic-offset: 4
758   * c-hanging-comment-ender-p: nil
759   * End:
760   */
Note: See TracBrowser for help on using the browser.