root/trunk/www/setup.php

Revision 3179, 11.4 kB (checked in by demian, 1 week ago)

removing tinyfck dep

  • Property svn:eol-style set to native
Line 
1 <?php
2 /* Reminder: always indent with 4 spaces (no tabs). */
3 // +---------------------------------------------------------------------------+
4 // | Copyright (c) 2006, Demian Turner                                         |
5 // | All rights reserved.                                                      |
6 // |                                                                           |
7 // | Redistribution and use in source and binary forms, with or without        |
8 // | modification, are permitted provided that the following conditions        |
9 // | are met:                                                                  |
10 // |                                                                           |
11 // | o Redistributions of source code must retain the above copyright          |
12 // |   notice, this list of conditions and the following disclaimer.           |
13 // | o Redistributions in binary form must reproduce the above copyright       |
14 // |   notice, this list of conditions and the following disclaimer in the     |
15 // |   documentation and/or other materials provided with the distribution.    |
16 // | o The names of the authors may not be used to endorse or promote          |
17 // |   products derived from this software without specific prior written      |
18 // |   permission.                                                             |
19 // |                                                                           |
20 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       |
21 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         |
22 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR     |
23 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
24 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     |
25 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT          |
26 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     |
27 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |
28 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |
29 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE     |
30 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.      |
31 // |                                                                           |
32 // +---------------------------------------------------------------------------+
33 // | Seagull 0.6                                                               |
34 // +---------------------------------------------------------------------------+
35 // | setup.php                                                                 |
36 // +---------------------------------------------------------------------------+
37 // | Authors:                                                                  |
38 // |            Demian Turner <demian@phpkitchen.com>                          |
39 // |            Gerry Lachac <glachac@tethermedia.com>                         |
40 // |            Andy Crain <apcrain@fuse.net>                                  |
41 // +---------------------------------------------------------------------------+
42 // $Id: setup.php,v 1.5 2005/02/03 11:29:01 demian Exp $
43
44 /*
45 sgl setup
46 =========
47 - ability to upload and unzip/tar a packaged module
48 - file permission handling ideas from FUDforum installer
49 - more user-friendly error messages from Gallery2
50 - if no DB detected, prompt to create, otherwise offer to create tables
51
52
53 php ini
54 =======
55 - deal with register_globals and set session.use_trans_sid = 0
56 - allow_url_fopen = Off
57 - detect and deal with safe_mode
58 - magic_quotes must be off
59 - file_uploads ideally enabled
60
61 module setup
62 ============
63 - choose modules and permissions must be created and set at install time
64 - attempt to
65     - uncompress
66     - move to correct location
67     - apply user perms
68     - apply prefs
69     - add module's db tables to Config
70     - load module's schema + data
71     - add 'section' or 'screen' navigation links
72     - register module in registry
73 */
74
75 //  initialise
76
77 //  set initial paths according to install type
78 $pearTest = '@PHP-DIR@';
79 if ($pearTest != '@' . 'PHP-DIR'. '@') {
80     define('SGL_PEAR_INSTALLED', true);
81     $rootDir = '@PHP-DIR@/Seagull';
82     $varDir = '@DATA-DIR@/Seagull/var';
83 } else {
84     $rootDir = dirname(__FILE__) . '/..';
85     $varDir = dirname(__FILE__) . '/../var';
86 }
87
88 //  check for lib cache
89 define('SGL_CACHE_LIBS', (is_file($varDir . '/ENABLE_LIBCACHE.txt'))
90     ? true
91     : false);
92
93 //  are we doing a minimal install?
94 define('SGL_MINIMAL_INSTALL', (is_file($rootDir . '/MINIMAL_INSTALL.txt'))
95     ? true
96     : false);
97
98 require_once $rootDir . '/lib/SGL/FrontController.php';
99 require_once $rootDir . '/lib/SGL/Install/Common.php';
100 SGL_FrontController::init();
101 session_start();
102 $_SESSION['ERRORS'] = array();
103
104 //  check if requesting auth.txt download
105 if (isset($_GET['download']) && $_GET['download'] == 1) {
106     if (isset($_SESSION['authString'])) {
107         header("Content-Type: text/plain");
108         header("Content-Length: " . strlen($_SESSION['authString']));
109         header("Content-Description: Download AUTH.txt to your computer.");
110         header("Content-Disposition: attachment; filename=AUTH.txt");
111         print $_SESSION['authString'];
112         exit;
113     }
114 }
115
116 //  reroute to front controller
117 if (isset($_GET['start'])) {
118
119     //  remove installer info
120     @session_destroy();
121     $_SESSION = array();
122
123     //  clear session cookie
124     $c = &SGL_Config::singleton();
125     $conf = $c->getAll();
126     setcookie$conf['cookie']['name'], null, 0, $conf['cookie']['path'],
127                 $conf['cookie']['domain'], $conf['cookie']['secure']);
128
129     $aUrl = array(
130         'managerName' => 'default',
131         'moduleName'  => 'default',
132         'welcome'     => 1
133     );
134     SGL_HTTP::redirect($aUrl);
135 }
136
137 //  check authorization
138 if (is_file(SGL_PATH . '/var/INSTALL_COMPLETE.php')
139         && empty($_SESSION['valid'])) {
140
141     if (!empty($_POST['frmSetupPassword'])) {
142         $aLines = file(SGL_PATH . '/var/INSTALL_COMPLETE.php');
143         $secret = trim(substr($aLines[1], 1));
144         if ($_POST['frmSetupPassword'] != $secret) {
145             $_SESSION['message'] = 'incorrect password';
146             header('Location: setup.php');
147             exit;
148         } else {
149             $_SESSION['valid'] = true;
150             header('Location: setup.php');
151         }
152     } else {
153         SGL_Install_Common::printHeader();
154         SGL_Install_Common::printLoginForm();
155         SGL_Install_Common::printFooter();
156         exit;
157     }
158 }
159
160 // load QuickFormController libs
161 require_once 'HTML/QuickForm/Controller.php';
162 require_once 'HTML/QuickForm/Action/Next.php';
163 require_once 'HTML/QuickForm/Action/Back.php';
164 require_once 'HTML/QuickForm/Action/Display.php';
165
166 //  load wizard screens and qf overrides
167 require_once SGL_PATH . '/lib/SGL/Install/WizardLicenseAgreement.php';
168 require_once SGL_PATH . '/lib/SGL/Install/WizardSetupAuth.php';
169 require_once SGL_PATH . '/lib/SGL/Install/WizardDetectEnv.php';
170 //require_once SGL_PATH . '/lib/SGL/Install/WizardTestDbConnection.php';
171 //require_once SGL_PATH . '/lib/SGL/Install/WizardCreateDb.php';
172 require_once SGL_PATH . '/lib/SGL/Install/WizardCreateAdminUser.php';
173 require_once SGL_PATH . '/lib/SGL/Install/QuickFormOverride.php';
174
175 //  load tasks
176 require_once SGL_PATH . '/lib/SGL/Task/DetectEnv.php';
177 require_once SGL_PATH . '/lib/SGL/Task/Install.php';
178
179 class ActionProcess extends HTML_QuickForm_Action
180 {
181     function perform(&$page, $actionName)
182     {
183         $data = $page->controller->exportValues();
184
185 //          is this a rebuild?
186 //        $dbh = & SGL_DB::singleton();
187 //        $res = false;
188 //        if (!PEAR::isError($dbh)) {
189 //            require_once SGL_CORE_DIR . '/Sql.php';
190 //            $table = SGL_Sql::addTablePrefix('module');
191 //            $query = 'SELECT COUNT(*) FROM ' . $table;
192 //            $res = $dbh->getOne($query);
193 //        }
194 //
195 //        if (!PEAR::isError($res) && $res > 1) { // it's a re-install
196 //            $data['aModuleList'] = SGL_Install_Common::getModuleList();
197 //            if (count($data['aModuleList'])) {
198 //                foreach ($data['aModuleList'] as $key => $moduleName) {
199 //                    if (!SGL::moduleIsEnabled($moduleName)) {
200 //                        unset($data['aModuleList'][$key]);
201 //                    }
202 //                }
203 //            }
204 //        } else { // a new install
205 //            SGL_Error::pop();
206 //            if (PEAR::isError($dbh)) {
207 //                SGL_Error::pop(); // two errors produced
208 //            }
209             $data['aModuleList'] = SGL_Install_Common::getMinimumModuleList();
210 //        }
211
212         //  override with custom settings if they exist
213         $data = SGL_Install_Common::overrideDefaultInstallSettings($data);
214 //        $buildNavTask = 'SGL_Task_BuildNavigation';
215 //        if (in_array('cms', $data['aModuleList'])) {
216 //            require_once SGL_MOD_DIR . '/cms/init.php';
217 //            $buildNavTask = 'SGL_Task_BuildNavigation2';
218 //        }
219         $runner = new SGL_TaskRunner();
220         $runner->addData($data);
221 #        $runner->addTask(new SGL_Task_SetTimeout());
222         $runner->addTask(new SGL_Task_CreateConfig());
223         $runner->addTask(new SGL_Task_LoadCustomConfig());
224 #        $runner->addTask(new SGL_Task_DefineTableAliases());
225 #        $runner->addTask(new SGL_Task_DisableForeignKeyChecks());
226 $runner->addTask(new SGL_Task_PrepareInstallationProgressTable());
227 #        $runner->addTask(new SGL_Task_DropTables());
228 #        $runner->addTask(new SGL_Task_CreateTables());
229 #        $runner->addTask(new SGL_Task_LoadTranslations());
230 #        $runner->addTask(new SGL_Task_LoadDefaultData());
231 #        $runner->addTask(new SGL_Task_LoadSampleData());
232 #        $runner->addTask(new SGL_Task_LoadCustomData());
233 #        $runner->addTask(new SGL_Task_SyncSequences());
234 #        $runner->addTask(new $buildNavTask());
235 #        $runner->addTask(new SGL_Task_LoadBlockData());
236 #        $runner->addTask(new SGL_Task_CreateConstraints());
237 #        $runner->addTask(new SGL_Task_SyncSequences());
238 #        $runner->addTask(new SGL_Task_EnableForeignKeyChecks());
239
240 $runner->addTask(new SGL_Task_VerifyDbSetup());
241         $runner->addTask(new SGL_Task_CreateFileSystem());
242 #        $runner->addTask(new SGL_Task_CreateDataObjectEntities());
243 #        $runner->addTask(new SGL_Task_CreateDataObjectLinkFile());
244         $runner->addTask(new SGL_Task_UnLinkWwwData());
245         $runner->addTask(new SGL_Task_SymLinkWwwData());
246 #        $runner->addTask(new SGL_Task_AddTestDataToConfig());
247         $runner->addTask(new SGL_Task_CreateAdminUser());
248         $runner->addTask(new SGL_Task_InstallerCleanup());
249
250         $ok = $runner->main();
251     }
252 }
253
254 //  start wizard
255 $wizard =& new HTML_QuickForm_Controller('installationWizard');
256 $wizard->addPage(new WizardLicenseAgreement('page1'));
257 //$wizard->addPage(new WizardSetupAuth('page2'));
258 $wizard->addPage(new WizardDetectEnv('page3'));
259 //$wizard->addPage(new WizardTestDbConnection('page4'));
260 //$wizard->addPage(new WizardCreateDb('page5'));
261 $wizard->addPage(new WizardCreateAdminUser('page6'));
262
263 // We actually add these handlers here for the sake of example
264 // They can be automatically loaded and added by the controller
265 $wizard->addAction('display', new ActionDisplay());
266 $wizard->addAction('next', new HTML_QuickForm_Action_Next());
267 $wizard->addAction('back', new HTML_QuickForm_Action_Back());
268
269 // This is the action we should always define ourselves
270 $wizard->addAction('process', new ActionProcess());
271
272 $wizard->run();
273
274 if (SGL_Install_Common::errorsExist()) {
275     SGL_Install_Common::errorPrint();
276 }
277 ?>
278
Note: See TracBrowser for help on using the browser.