aliroInstall.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /* A basic Aliro installer */
00004 
00005 class aliroInstall {
00006 
00007     private $config = array();
00008     private $credentials = array();
00009     private $corecredentials = array();
00010     private $header = '';
00011     private $title = '';
00012     private $checkDirs = array(
00013     // Each entry is hide/visible, paath, essential, admin also
00014     array (false, '/cache/html', true, false),
00015     array (false, '/cache/singleton', true, false),
00016     array (false, '/configs', true, false),
00017     array (true, '/images/stories', true, false),
00018     array (true, '/images/banners', true, false),
00019     array (false, '/media', true, false),
00020     array (false, '/classes', false, true),
00021     array (false, '/components', false, true),
00022     array (false, '/includes', false, true),
00023     array (false, '/modules', false, true),
00024     array (true, '/templates', false, true),
00025     array (true, '/language', false, false),
00026     array (false, '/mambots', false, false),
00027     array (false, '/parameters', false, false)
00028     );
00029     private $checkStatus = array();
00030     
00031     public function __construct () {
00032         $this->header = $this->T_('install the next generation Content Management System');
00033         $this->title = $this->T_('Install Aliro');
00034     }
00035 
00036     public function install () {
00037 
00038         $this->config['offline'] = '0';
00039         $this->config['lang'] = 'english';
00040         $this->config['sitename'] = $this->T_('Aliro Powered Site');
00041         $this->config['shownoauth'] = '0';
00042         $this->config['useractivation'] = '1';
00043         $this->config['uniquemail'] = '1';
00044         $this->config['offline_message'] = $this->T_('This site is down for maintenance.<br /> Please check back again soon.');
00045         $this->config['error_message'] = $this->T_('This site is temporarily unavailable.<br /> Please notify the System Administrator');
00046         $this->config['debug'] = '0';
00047         $this->config['lifetime'] = '900';
00048         $this->config['adminlife'] = '3600';
00049         $this->config['MetaDesc'] = $this->T_('Aliro - the accessible, dynamic portal engine and content management system');
00050         $this->config['MetaKeys'] = 'aliro, Aliro';
00051         $this->config['MetaAuthor'] = '1';
00052         $this->config['MetaTitle'] = '1';
00053         $this->config['locale'] = 'en';
00054         $this->config['offset'] = '0';
00055         $this->config['hideAuthor'] = '1';
00056         $this->config['hideCreateDate'] = '1';
00057         $this->config['hideModifyDate'] = '1';
00058         $this->config['hidePdf'] = '1';
00059         $this->config['hidePrint'] = '1';
00060         $this->config['hideEmail'] = '1';
00061         $this->config['enable_log_items'] = '0';
00062         $this->config['enable_log_searches'] = '0';
00063         $this->config['enable_stats'] = '0';
00064         $this->config['sef'] = '0';
00065         $this->config['vote'] = '0';
00066         $this->config['gzip'] = '0';
00067         $this->config['multipage_toc'] = '1';
00068         $this->config['link_titles'] = '0';
00069         $this->config['error_reporting'] = '-1';
00070         $this->config['register_globals'] = '0';
00071         $this->config['list_limit'] = '15';
00072         $this->config['caching'] = '0';
00073         $this->config['cachepath'] = '';
00074         $this->config['cachetime'] = '600';
00075         $this->config['mailer'] = 'mail';
00076         $this->config['mailfrom'] = '';
00077         $this->config['fromname'] = $this->T_('Aliro Powered Site');
00078         $this->config['sendmail'] = '/usr/sbin/sendmail';
00079         $this->config['smtpauth'] = '0';
00080         $this->config['smtpuser'] = '';
00081         $this->config['smtppass'] = '';
00082         $this->config['smtphost'] = 'localhost';
00083         $this->config['back_button'] = '0';
00084         $this->config['item_navigation'] = '0';
00085         $this->config['pagetitles'] = '1';
00086         $this->config['readmore'] = '1';
00087         $this->config['hits'] = '0';
00088         $this->config['icons'] = '1';
00089         $this->config['favicon'] = 'favicon.ico';
00090         $this->config['fileperms'] = '0644';
00091         $this->config['dirperms'] = '0755';
00092         $this->config['mbf_content'] = '0';
00093         $this->config['charset'] = 'utf-8';
00094         $this->config['locale_use_iconv'] = '0';
00095         $this->config['locale_use_gettext'] = '0';
00096         $this->config['locale_debug'] = '0';
00097         if (isset($_REQUEST['installform']) AND 'yes' == $_REQUEST['installform']) {
00098             if ($password = $this->createConfigs()) {
00099                 $core = aliroCore::getInstance();
00100                 $this->completionHTML($password, $core->getCfg('live_site'), $core->getCfg('admin_site'));
00101                 return;
00102             }
00103         }
00104         $this->showInstallForm();
00105     }
00106     
00107     private function T_($string) {
00108         // To be elaborated to provide translation for installation process
00109         return function_exists('T_') ? T_($string) : $string;
00110     }
00111     
00112     private function completionHTML ($password, $livesite, $adminsite) {
00113         $adminlogin = $this->T_('Administrator login');
00114         $installed = $this->T_('Installation');
00115         $completed = $this->T_('Installation completed');
00116         $adusertxt = $this->T_('The default administrator name is <strong>admin</strong>.  You can change this if you have user management installed.');
00117         $adpwtxt = $this->T_('The initial password for the default administrator is: ')."<strong>$password</strong>";
00118         $instmsg1 = sprintf($this->T_('The basic installation is complete.  You can visit the administrator side of the new site %s here %s.'), '<a href="'.$adminsite.'">', '</a>');
00119         $instmsg2 = $this->T_('You are strongly recommended to login as administrator right away and review the site configuration');
00120         $instmsg3 = sprintf($this->T_('Or you can visit the empty user side of the site %s here %s.'), '<a href="'.$livesite.'">', '</a>');
00121         echo <<<COMPLETION
00122 {$this->topHTML()}
00123         <h2>$completed</h2>
00124         <fieldset>
00125             <legend>$adminlogin</legend>
00126             $adusertxt
00127             $adpwtxt
00128         </fieldset>
00129         <fieldset id="installdone">
00130             <legend>$installed</legend>
00131             $instmsg1
00132             $instmsg2
00133             $instmsg3
00134         </fieldset>
00135 {$this->bottomHTML()}
00136 
00137 COMPLETION;
00138 
00139     }
00140 
00141     private function createConfigs () {
00142         $this->credentials = $this->checkDatabaseConfig('gen');
00143         if (!$this->credentials) echo '<br />'.$this->T_('The general database details were not valid');
00144         $this->corecredentials = $this->checkDatabaseConfig('core');
00145         if (!$this->corecredentials) echo '<br />'.$this->T_('The core database details were not valid');
00146         if ($this->corecredentials AND $this->credentials) {
00147             $this->storeConfig ($this->corecredentials, 'corecredentials.php');
00148             $this->storeConfig ($this->credentials, 'credentials.php');
00149 
00150             $database = aliroCoreDatabase::getInstance();
00151             $info = criticalInfo::getInstance();
00152             $sql = file_get_contents($info->absolute_path.'/administrator/sql/aliro_core.sql');
00153             $database->setQuery($sql);
00154             $database->query_batch();
00155 
00156             $database = aliroDatabase::getInstance();
00157             $sql = file_get_contents($info->absolute_path.'/administrator/sql/aliro_general.sql');
00158             $database->setQuery($sql);
00159             $database->query_batch();
00160 
00161             $database = aliroCoreDatabase::getInstance();
00162             $database->setQuery ("SELECT COUNT(*) FROM #__core_users");
00163             if ($database->loadResult()) {
00164                 $this->storeConfig($this->config, 'configuration.php');
00165                 echo '<br />'.$this->T_('Not an empty user table - left untouched');
00166                 echo '<br />'.$this->T_('Site name and admin email not stored - please review config from admin interface');
00167                 $password = $this->T_('same as it was before');
00168                 echo aliroRequest::trace();
00169             }
00170             else {
00171                 $authenticator = aliroAdminAuthenticator::getInstance();
00172                 if (isset($_REQUEST['sitetitle'])) $this->config['sitename'] = $_REQUEST['sitetitle'];
00173                 if (isset($_REQUEST['adminemail'])) $this->config['mailfrom'] = $_REQUEST['adminemail'];
00174                 if (isset($_REQUEST['adminpassword'])) $password = $_REQUEST['adminpassword'];
00175                 else $password = $authenticator->makePassword();
00176                 $salt = $authenticator->makeSalt();
00177                 $md5password = md5($salt.$password);
00178                 $today = date('Y-m-d H:i:s');
00179                 $database->doSQL ("INSERT INTO #__core_users (password, salt, activation) VALUES ('$md5password', '$salt', '')");
00180                 $id = $database->insertid();
00181                 $database->doSQL ("INSERT INTO #__assignments VALUES (0, 'aUser', $id, 'Super Administrator')");
00182 
00183                 $database = aliroDatabase::getInstance();
00184                 $database->doSQL ("INSERT INTO #__users VALUES ($id, 'Super Administrator', 'admin', '{$this->config['mailfrom']}', 'Super Administrator', 0, 1, 25, '$today', '$today', '')");
00185                 
00186                 aliroFileManager::getInstance()->mosChmodRecursive($info->absolute_path);
00187             }
00188             $this->storeConfig($this->config, 'configuration.php');
00189             aliro::getInstance()->installed = true;
00190             $this->errorMessage();
00191 
00192             return $password;
00193         }
00194         else return false;
00195     }
00196 
00197     private function errorMessage () {
00198         $colours = array (
00199         _ALIRO_ERROR_FATAL => 'red',
00200         _ALIRO_ERROR_SEVERE => 'red',
00201         _ALIRO_ERROR_WARN => 'orange',
00202         _ALIRO_ERROR_INFORM => 'gren'
00203         );
00204         $messages = aliroRequest::getInstance()->pullErrorMessages();
00205         if (count($messages)) {
00206             $messagehtml = '';
00207             foreach ($colours as $severity=>$colour) if (isset($messages[$severity])) {
00208                 foreach ($messages[$severity] as $text) {
00209                     $messagehtml .= <<<ONE_ERROR_MESSAGE
00210                             <div style="color:$colour>
00211                                 $text
00212                             </div>
00213 ONE_ERROR_MESSAGE;
00214                 }
00215             }
00216             $html = <<<FULL_MESSAGE_SET
00217                     <!-- start Error Message area -->
00218                     <div id="errormessage">
00219                         $messagehtml
00220                     </div>
00221                     <!-- end Error Message area -->
00222 FULL_MESSAGE_SET;
00223 
00224         }
00225         else $html = '';
00226         echo $html;
00227     }
00228 
00229     public function storeConfig ($config, $configname, $overwrite=false) {
00230         static $counter = 0;
00231         foreach ($config as &$item) $item = base64_encode($item);
00232         $packed = serialize($config);
00233         $filename = $this->makeFileName ($configname);
00234         $filepath = criticalInfo::getInstance()->class_base.'/configs/'.$filename;
00235         if (file_exists($filepath) AND !$overwrite) {
00236             echo '<br />'.sprintf($this->T_('Configuration file %s (encoded) already exists'), $configname);
00237         }
00238         if ($f = fopen ($filepath, 'wb')) {
00239             fwrite ($f, '<?php');
00240             fwrite ($f, "\n\t".'$packed = \''.$packed."';");
00241             fwrite ($f, "\n?>");
00242             fclose($f);
00243         }
00244         else echo '<br />'.sprintf($this->T_('Unable to write configuration file %s'), $filepath);
00245     }
00246 
00247     private function makeFileName ($configname) {
00248         $info = criticalInfo::getInstance();
00249         $filename = md5($info->absolute_path.'/'.$configname).'.php';
00250         return $filename;
00251     }
00252 
00253     public function checkDatabaseConfig ($suffix) {
00254         $result = true;
00255         if (isset($_REQUEST['dbhost'.$suffix])) $credentials['dbhost'] = $_REQUEST['dbhost'.$suffix];
00256         else $result = false;
00257         if (isset($_REQUEST['dbname'.$suffix])) $credentials['dbname'] = $_REQUEST['dbname'.$suffix];
00258         else $result = false;
00259         if (isset($_REQUEST['dbusername'.$suffix])) $credentials['dbusername'] = $_REQUEST['dbusername'.$suffix];
00260         else $result = false;
00261         if (isset($_REQUEST['dbpassword'.$suffix])) $credentials['dbpassword'] = $_REQUEST['dbpassword'.$suffix];
00262         else $result = false;
00263         if (isset($_REQUEST['dbprefix'.$suffix])) $credentials['dbprefix'] = $_REQUEST['dbprefix'.$suffix];
00264         else $result = false;
00265         if ($result) {
00266             $database = new database ($credentials['dbhost'], $credentials['dbusername'], $credentials['dbpassword'], $credentials['dbname'], $credentials['dbprefix'], true);
00267             if (_ALIRO_DB_CONNECT_FAILED == $database->getErrorNum() OR _ALIRO_DB_NO_INTERFACE == $database->getErrorNum()) $result = false;
00268         }
00269         if ($result) return $credentials;
00270         else return false;
00271     }
00272 
00273     private function showInstallForm () {
00274         $coredb = $this->T_('Core Database details');
00275         $gendb = $this->T_('General Database details');
00276         $submit = $this->T_('Install Aliro');
00277         echo <<<FULL_HTML
00278 {$this->topHTML()}
00279         <form action="index.php" method="post">
00280         {$this->sayWelcome()}
00281         {$this->showLicence()}
00282         {$this->makeGeneralForm()}
00283         {$this->makeDBForm($coredb, 'core', $this->corecredentials)}
00284         {$this->makeDBForm($gendb, 'gen', $this->credentials)}
00285         <div>
00286             <input type="hidden" name="installform" value="yes" />
00287             <input type="submit" id="installaliro" value="$submit" />
00288         </div>
00289         </form>
00290 {$this->bottomHTML()}
00291 
00292 FULL_HTML;
00293 
00294     }
00295     
00296     public function tellUserNotInstalled () {
00297         $header = $this->T_('welcomes you to a new web site');
00298         $title = $this->T_('New Aliro site');
00299         $message = $this->T_('This will be an Aliro based site, but installation is not yet completed.  Please call back later');
00300         echo <<<NOT_INSTALLED
00301 {$this->topHTML($header, $title, true)}
00302         <fieldset>
00303             <legend>$title</legend>
00304             <div id="inputset">
00305                 <p>
00306                     $message
00307                 </p>
00308             </div>
00309         </fieldset>
00310 {$this->bottomHTML()}
00311         
00312 NOT_INSTALLED;
00313     }
00314         
00315     // Not yet sure if this will be needed
00316     public function installPage ($header, $title, $text, $userside=false) {
00317         echo <<<INSTALL_PAGE
00318 {$this->topHTML($header, $title)}
00319     $text
00320 {$this->bottomHTML()}
00321         
00322 INSTALL_PAGE;
00323     }
00324     
00325     private function topHTML ($header='', $title='', $userside=false) {
00326         if (!$header) $header = $this->header;
00327         if (!$title) $title = $this->title;
00328         $predir = $userside ? '' : '../';
00329         return <<<TOP_HTML
00330 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
00331 <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
00332     <head>
00333         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
00334         <title>$title</title>
00335         <link href="{$predir}templates/install.css" rel="stylesheet" type="text/css" media="screen" />
00336         <script type="text/javascript" src="../includes/js/add-event.js"></script>  
00337         <script type="text/javascript" src="../includes/js/popup.js"></script>
00338     </head>
00339     <body>
00340     <div id="headerwrapper">
00341         <div id="header">
00342             <div id="logo">
00343                 <h1>Aliro</h1>
00344                 <h2>$header</h2>
00345                 <a href="http://www.opensource.org/docs/definition.php">
00346                     <img src="http://www.opensource.org/trademarks/opensource/web/opensource-75x65.gif" alt="Open Source (OSI) Logo" width="75" height="65" />
00347                 </a>
00348             </div>
00349         </div>
00350     </div>
00351     <!-- end #headerwrapper -->
00352     <div id="page">
00353 
00354 TOP_HTML;
00355 
00356     }
00357     
00358     private function bottomHTML () {
00359         $version = new version();
00360         return <<<BOTTOM_HTML
00361     </div>
00362     <div id="footer">
00363         <p class="legal">Copyright &copy; 2008 Aliro Software Limited. All Rights Reserved.</p>
00364         {$version->footer()}
00365         <p class="credit">Template based on a design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></p>
00366     </div>  
00367     </body>
00368 </html>
00369 
00370 BOTTOM_HTML;
00371 
00372     }
00373     
00374     private function sayWelcome () {
00375         $welcome = $this->T_('Welcome to installing Aliro');
00376         $wtext = $this->T_('You only need to fill in a few simple fields to get Aliro started!  If in doubt, please visit the <a href="http://www.aliro.org/index.php?option=com_content&amp;task=view&amp;id=5&amp;indextype=2" rel="popup standard 800 600"> Aliro Quick Start Guide</a>.');
00377         return <<<SAY_WELCOME
00378         <fieldset>
00379             <legend>$welcome</legend>
00380             <p class="welcome">
00381                 $wtext
00382             </p>
00383         </fieldset>
00384         
00385 SAY_WELCOME;
00386 
00387     }
00388         
00389         
00390     
00391     private function showLicence () {
00392         $licence = $this->T_('Aliro Licensing');
00393         $agree = $this->T_('Aliro is in general distributed under the GNU Public Licence version 3+, but parts of Aliro are distributed under the Lesser GNU Public Licence 2.1+ so as to ensure that extension software is relatively unrestricted.  If in doubt about this matter, please contact Aliro.  Please tick the box to agree.');
00394         return <<<SHOW_LICENCE
00395         <fieldset>
00396             <legend>$licence</legend>
00397             <div id="inputset">
00398                 <label for="agreelicence">$agree</label><br />
00399                 <input type="checkbox" name="agreelicence" id="agreelicence" />
00400             </div>
00401         </fieldset>
00402         
00403 SHOW_LICENCE;
00404 
00405     }
00406 
00407     private function showFileNames () {
00408         $configfiles = $this->T_('Configuration files');
00409         $cfile = $this->T_('Configuration file');
00410         $gdbcred = $this->T_('General DB credentials file');
00411         $cdbcred = $this->T_('Core DB credentials file');
00412         $html = <<<FILE_NAMES
00413         <fieldset>
00414             <legend>$configfiles</legend>
00415             <p><label for="configfilename">$cfile</label>
00416             <input type="text" id="configfilename" size="40" readonly="readonly" value="{$this->makeFileName('configuration.php')}" /></p>
00417             <p><label for="generalDBfilename">$gdbcred</label>
00418             <input type="text" id="generalDBfilename" size="40" readonly="readonly" value="{$this->makeFileName('credentials.php')}" /></p>
00419             <p><label for="coreDBfilename">$cdbcred</label>
00420             <input type="text" id="coreDBfilename" size="40" readonly="readonly" value="{$this->makeFileName('corecredentials.php')}" /></p>
00421         </fieldset>
00422         
00423 FILE_NAMES;
00424 
00425         return $html;
00426     }
00427 
00428     public function makeDBForm ($legend, $suffix, $values) {
00429         $titles = array (
00430         'dbhost' => $this->T_('Host for database (commonly localhost)'),
00431         'dbname' => $this->T_('Database name'),
00432         'dbusername' => $this->T_('Database user name'),
00433         'dbpassword' => $this->T_('Database user password'),
00434         'dbprefix' => $this->T_('Prefix for database')
00435         );
00436         if (!isset($values['dbhost'])) $values['dbhost'] = 'localhost';
00437         if (!isset($values['dbname'])) $values['dbname'] = '';
00438         if (!isset($values['dbusername'])) $values['dbusername'] = '';
00439         if (!isset($values['dbpassword'])) $values['dbpassword'] = '';
00440         if (!isset($values['dbprefix'])) $values['dbprefix'] = 'aliro_';
00441         $values['dbdebug'] = 0;
00442 
00443         $html = <<<DB_HTML
00444 
00445         <div id="installdb$suffix">
00446         <fieldset>
00447         <legend>$legend</legend>
00448             <div class="inputset"><label for="dbhost$suffix">{$titles['dbhost']}</label><br />
00449                 <input id="dbhost$suffix" type="text" name="dbhost$suffix" value="{$values['dbhost']}" size="40" />
00450             </div>
00451             <div class="inputset"><label for="dbname$suffix">{$titles['dbname']}</label><br />
00452                 <input id="dbname$suffix" type="text" name="dbname$suffix" value="{$values['dbname']}" size="40" />
00453             </div>
00454             <div class="inputset"><label for="dbusername$suffix">{$titles['dbusername']}</label><br />
00455                 <input id="dbusername$suffix" type="text" name="dbusername$suffix" value="{$values['dbusername']}" size="40" />
00456             </div>
00457             <div class="inputset"><label for="dbpassword$suffix">{$titles['dbpassword']}</label><br />
00458                 <input id="dbpassword$suffix" type="text" name="dbpassword$suffix" value="{$values['dbpassword']}" size="40" />
00459             </div>
00460             <div class="inputset"><label for="dbprefix$suffix">{$titles['dbprefix']}</label><br />
00461                 <input id="dbprefix$suffix" type="text" name="dbprefix$suffix" value="{$values['dbprefix']}" size="40" />
00462             </div>
00463         </fieldset>
00464         </div>
00465 
00466 DB_HTML;
00467 
00468         return $html;
00469     }
00470 
00471     private function makeGeneralForm () {
00472         $legend = $this->T_('General Site Information');
00473         $titles = array (
00474         'sitetitle' => $this->T_('Site Title'),
00475         'adminpassword' => $this->T_('Admin Password'),
00476         'adminemail' => $this->T_('Admin Email')
00477         );
00478         $html = <<<GENERAL_HTML
00479 
00480         <div id="installgeneral">
00481         <fieldset>
00482         <legend>$legend</legend>
00483             <div class="inputset"><label for="sitetitle">{$titles['sitetitle']}</label><br />
00484                 <input id="sitetitle" type="text" name="sitetitle" size="80" />
00485             </div>
00486             <div class="inputset"><label for="adminpassword">{$titles['adminpassword']}</label><br />
00487                 <input id="adminpassword" type="text" name="adminpassword" size="80" />
00488             </div>
00489             <div class="inputset"><label for="adminemail">{$titles['adminemail']}</label><br />
00490                 <input id="adminemail" type="text" name="adminemail" size="80" />
00491             </div>
00492         </fieldset>
00493         </div>
00494 
00495 GENERAL_HTML;
00496 
00497         return $html;
00498     }
00499 }

Generated on Wed May 14 13:01:56 2008 for ALIRO by  doxygen 1.5.5