source: trunk/install.php @ 1847

Revision 1847, 21.9 KB checked in by Xiping.Wang, 16 months ago (diff)

[trunk] 1.change logged layout to float. 2.Signup form refactor

Line 
1<?php
2/**
3 * --------------------------------------------------------------
4 * omCollab Installation Utility
5 * -----------------------------
6 * Version    : 1.3
7 * Description: Installs the omCollab application suite
8 *              (MediaWiki, WordPress, omBookmarks, omExplore)
9 * Author     : Pete Dakin <petedakin@gmail.com> for BearingPoint
10 * --------------------------------------------------------------
11 */
12
13
14require_once( 'common/skins/mike2/common.php' );
15require_once( 'w/maintenance/install-utils.inc' );
16
17install_version_checks(); #here we use the wiki's version checker
18
19function omcollab_installation_dir(){
20        $sInstallScriptUri       = $_SERVER['REQUEST_URI'];
21        $iInstallScriptUriLength = strlen( $_SERVER['REQUEST_URI'] ) - strlen( basename($_SERVER['SCRIPT_NAME']) );
22        return str_replace( basename($_SERVER['SCRIPT_NAME'])
23                          , ''
24                          , $sInstallScriptUri
25                          , $iInstallScriptUriLength );
26}
27
28?>
29<html>
30
31<head>
32        <title>omCollab Installer</title>
33        <style>
34   *                { margin:0pt; padding:0pt; }
35   body             { margin:10pt;color:black; font-family:verdana,sans-serif; font-size:8pt; font-size-adjust:none; font-style:normal; font-variant:normal; font-weight:normal; line-height:normal; }
36  .header-corner-tl { background: url(<?php echo omcollab_installation_dir() ?>common/skins/mike2/images/corner-tl-w.png) 0 0 no-repeat; width: 10px; height: 10px; line-height: 1px; font-size: 1px; }
37  .header-corner-t  { background: #4F81BD; border-top: 3px solid #385D8A; height: 7px; line-height: 1px; font-size: 1px; }
38  .header-corner-tr { background: url(<?php echo omcollab_installation_dir() ?>common/skins/mike2/images/corner-tr-w.png) 0 0 no-repeat; width: 10px; height: 10px; line-height: 1px; font-size: 1px; }
39  .header-corner-ml { background: #4F81BD; border-left: 3px solid #385D8A; width: 7px; }
40  .header-corner-m  { background: #4F81BD; color: #DCE6F2; }
41  .header-corner-mr { background: #4F81BD; border-right: 3px solid #385D8A; width: 7px; }
42  .header-corner-bl { background: url(<?php echo omcollab_installation_dir() ?>common/skins/mike2/images/corner-bl-w.png) 0 0 no-repeat; width: 10px; height: 10px; line-height: 1px; font-size: 1px; }
43  .header-corner-b  { background: #4F81BD; border-bottom: 3px solid #385D8A; height: 7px; line-height: 1px; font-size: 1px; }
44  .header-corner-br { background: url(<?php echo omcollab_installation_dir() ?>common/skins/mike2/images/corner-br-w.png) 0 0 no-repeat; width: 10px; height: 10px; line-height: 1px; font-size: 1px; }
45        </style>
46    <link rel="shortcut icon" href="favicon.ico" />
47</head>
48
49<body>
50<pre style="text-align:left;">
51<?php echo omCollabRoundBox('','<img src="common/skins/mike2/images/omCollab-logo-165x48.gif">'); ?>
52
53<h1>Installation utility for the omCollab Suite</h1>
54<?php
55
56if( isset($_POST['do']) && $_POST['do']='install' ){
57       
58        $omcollab_admin_email         = '';
59       
60        $omcollab_db_hostname         = '';
61        $omcollab_db_table_prefix     = '';
62        $path_to_mysql                = '';
63       
64        $omwiki_database_name         = '';
65        $omwiki_db_username           = '';
66        $omwiki_db_password           = '';
67       
68        $omblogs_database_name        = '';
69        $omblogs_db_username          = '';
70        $omblogs_db_password          = '';
71
72        $ombookmarks_database_name    = '';
73        $ombookmarks_db_username      = '';
74        $ombookmarks_db_password      = '';
75       
76        $omforum_database_name            = '';
77        $omforum_db_username              = '';
78        $omforum_db_password              = '';
79       
80        $omcollab_application_name      = '';
81        $omwiki_application_name      = '';
82        $omblog_application_name      = '';
83        $ombookmarks_application_name = '';
84        $omforum_application_name         = '';
85        $omexplore_application_name   = '';
86       
87        $omcollab_initial_skin        = '';
88        $omwiki_use_short_urls        = '';
89       
90        $omwiki_enable_docconvert   = '';
91        $omwiki_docconvert_oo_path  = '';
92       
93        $omcollab_google_analytics    = '';
94        $omcollab_google_cse_code     = '';
95        $omcollab_google_cse_forid    = '';
96        $omcollab_google_blog_key     = '';
97       
98        extract( $_POST, EXTR_IF_EXISTS );
99       
100        $aErrors = array();
101       
102        if( empty( $omcollab_admin_email          ) ) $aErrors[] = 'Admin email';       
103        if( empty( $omcollab_db_hostname          ) ) $aErrors[] = 'Database hostname (eg localhost)';
104        if( empty( $omcollab_db_table_prefix      ) ) $aErrors[] = 'Database table prefix (eg "om")';
105        if( empty( $path_to_mysql                 ) ) $aErrors[] = 'Full path to mysql (eg \path\to\mysql\)';
106        if( empty( $omwiki_database_name          ) ) $aErrors[] = 'Wiki database name';
107        if( empty( $omwiki_db_username            ) ) $aErrors[] = 'Wiki database username';
108        if( empty( $omwiki_db_password            ) ) $aErrors[] = 'Wiki database password';
109        if( empty( $omblogs_database_name         ) ) $aErrors[] = 'Blogs database name';
110        if( empty( $omblogs_db_username           ) ) $aErrors[] = 'Blogs database username';
111        if( empty( $omblogs_db_password           ) ) $aErrors[] = 'Blogs database password';
112        if( empty( $ombookmarks_database_name     ) ) $aErrors[] = 'Bookmarks database name';
113        if( empty( $ombookmarks_db_username       ) ) $aErrors[] = 'Bookmarks database username';
114        if( empty( $ombookmarks_db_password       ) ) $aErrors[] = 'Bookmarks database password';
115        if( empty( $omforum_database_name                 ) ) $aErrors[] = 'Forum database name';
116        if( empty( $omforum_db_username                   ) ) $aErrors[] = 'Forum database username';
117        if( empty( $omforum_db_password                   ) ) $aErrors[] = 'Forum database password';
118        if( empty( $omcollab_application_name     ) ) $aErrors[] = 'omCollab application name (eg "omCollab Portal")';
119        if( empty( $omwiki_application_name       ) ) $aErrors[] = 'Wiki application name (eg "omCollab Wiki")';
120        if( empty( $omblog_application_name       ) ) $aErrors[] = 'Blog application name (eg "omCollab Blogs")';
121        if( empty( $ombookmarks_application_name  ) ) $aErrors[] = 'Bookmarks application name (eg "omBookmarks")';
122        if( empty( $omforum_application_name      ) ) $aErrors[] = 'Forum application name (eg "omCollab Forum")';
123        if( empty( $omexplore_application_name    ) ) $aErrors[] = 'Explore application name (eg "omCollab Explore")';
124       
125        #figure out the directory in which the app is being installed
126        $omcollab_installation_dir = omcollab_installation_dir();
127       
128        #set a couple of values that don't get posted
129        $omcollab_http_hostname             = $_SERVER['HTTP_HOST'];
130        $_POST['omcollab_http_hostname']    = $omcollab_http_hostname;
131        $_POST['omcollab_installation_dir'] = $omcollab_installation_dir;
132       
133       
134        #make sure last character of table prefix is an underscore
135        if( substr( $omcollab_db_table_prefix, -1 ) != '_' ){
136                $omcollab_db_table_prefix .= '_';
137                $_POST['omcollab_db_table_prefix'] .= '_';
138        }
139       
140        #verify location of mysql executable
141        $sOpSys = '';
142        if( isset( $_SERVER['WINDIR'] ) ){
143                $sOpSys = 'WIN';
144        }
145        $sMySqlExecutable = "{$path_to_mysql}mysql" . ( $sOpSys == 'WIN' ? '.exe' : '' );
146        if( ! file_exists( $sMySqlExecutable ) || is_dir( $sMySqlExecutable ) ){
147                $aErrors[] = "Path to MySql is incorrect (tried '$sMySqlExecutable')";
148        }
149       
150        #verify that OpenOffice executables exist if DocConvert extension is enabled
151
152        if($omwiki_enable_docconvert == true)
153        {
154                $output = null;
155                $result = null;
156               
157                if($sOpSys == 'WIN')
158                        $docConvertCmd = "\"$omwiki_docconvert_oo_path" . "unopkg\" add w\extensions\DocConvert\DocConvert.oxt -f";
159                else
160                        $docConvertCmd = "$omwiki_docconvert_oo_path" . "unopkg add w/extensions/DocConvert/DocConvert.oxt -f";
161               
162                exec($docConvertCmd,$output,$result);
163                       
164                if($result == 1)
165                {
166                        $aErrors[] = "Path to OpenOffice.org program directory is incorrect or not in your system path variable (tried '$docConvertCmd')";
167                }
168        }
169       
170        #die if any errors so far
171        if( ! empty( $aErrors ) ){
172                die( "ERROR: Missing or invalid...\n\n" . implode( "\n", $aErrors ) . "\n\n" . '<a href="javascript:history.go(-1);">Go back</a>' );
173        }
174       
175        #test the db connections
176        $DbIni = array();
177       
178        $DbIni ['wiki'] ['Database']      = $omwiki_database_name;
179        $DbIni ['wiki'] ['Username']      = $omwiki_db_username;
180        $DbIni ['wiki'] ['Password']      = $omwiki_db_password;
181       
182        $DbIni ['blogs'] ['Database']     = $omblogs_database_name;
183        $DbIni ['blogs'] ['Username']     = $omblogs_db_username;
184        $DbIni ['blogs'] ['Password']     = $omblogs_db_password;
185       
186        $DbIni ['bookmarks'] ['Database'] = $ombookmarks_database_name;
187        $DbIni ['bookmarks'] ['Username'] = $ombookmarks_db_username;
188        $DbIni ['bookmarks'] ['Password'] = $ombookmarks_db_password;
189
190        $DbIni ['forum'] ['Database']     = $omforum_database_name;
191        $DbIni ['forum'] ['Username']     = $omforum_db_username;
192        $DbIni ['forum'] ['Password']     = $omforum_db_password;
193       
194        $aApps = array( 'wiki', 'blogs', 'bookmarks', 'forum' );
195        foreach( $aApps as $sAppDb ){
196                $rConn = mysql_connect( $omcollab_db_hostname
197                                      , $DbIni [ $sAppDb ] [ 'Username' ]
198                                      , $DbIni [ $sAppDb ] [ 'Password' ]
199                                      , true );
200                if( ! $rConn ) {
201                        $aErrors[] = "\n\n$sAppDb:\n\n" . trim( strip_tags( $sErrors ) );
202                }
203
204                if( ! mysql_select_db( $DbIni [ $sAppDb ] [ 'Database' ] ) ){
205                        $aErrors[] = "\n\n$sAppDb:\n\nCouldn't connect to the $sAppDb database.";
206                }
207
208                if( ! mysql_ping( $rConn ) ){
209                        $aErrors[] = "\n\n$sAppDb:\n\nCouldn't ping the db host with the credentials supplied.";
210                }
211        }
212        if( ! empty( $aErrors ) ){
213                die( "\n\nERROR: Database errors...<dir>" . implode( "\n", $aErrors ) . "\n\n" . '</dir><a href="javascript:history.go(-1);">Go back</a>' );
214        }
215       
216        $_POST[ 'default_style_num' ] = 2;
217        if( $omcollab_initial_skin == "red" ) {
218                $_POST[ 'default_style_num' ] = 3;
219        } else if ( $omcollab_initial_skin == "green") { // Green skin setting. Edited by zhongzhen.
220        $_POST[ 'default_system_num' ] = 4;
221    }
222   
223        #replace within sql dumps (these will be saved as temp files)
224        $aAppPlaceholders = array( 'wiki'      => array( 'omwiki_database_name'
225                                                       , 'omcollab_db_table_prefix' )
226                                                       
227                                 , 'blogs'     => array( 'omblogs_database_name'
228                                                       , 'omcollab_db_table_prefix'
229                                                       , 'omcollab_http_hostname'
230                                                       , 'omcollab_installation_dir'
231                                                       , 'omblog_application_name'
232                                                       , 'omcollab_admin_email' )
233                                                       
234                                 , 'bookmarks' => array( 'ombookmarks_database_name'
235                                                       , 'omcollab_db_table_prefix' )
236                                 
237                                 , 'forum'         => array( 'omforum_database_name'
238                                                                           , 'omcollab_db_table_prefix'
239                                                                           , 'omcollab_admin_email'
240                                                                           , 'omcollab_installation_dir'
241                                                                           , 'omforum_application_name'
242                                                                           , 'default_style_num' )
243                                 );                                                   
244
245        foreach( $aAppPlaceholders as $sApp => $aPlaceholders ){
246                if ($sApp == 'wiki' && $omcollab_initial_skin == 'red')
247                        $sSqlConfigure = file_get_contents( "_InstallationResources/om{$sApp}_red.sql" );
248                else if ($sApp == 'wiki' && $omcollab_initial_skin == 'green')
249            $sSqlConfigure = file_get_contents( "_InstallationResources/om{$sApp}_green.sql" );
250        else
251                        $sSqlConfigure = file_get_contents( "_InstallationResources/om{$sApp}.sql" );
252                       
253                foreach( $aPlaceholders as $sPlaceholder ){
254                        $sSqlConfigure = str_replace( '{' . $sPlaceholder . '}', $_POST[ $sPlaceholder ], $sSqlConfigure );
255                }
256                $aAppPlaceholders[ $sApp ][ 'sql' ] = $sSqlConfigure;
257                $sTmpFilename =  "_InstallationResources/om{$sApp}_temp.sql";
258                file_put_contents( $sTmpFilename, $sSqlConfigure );
259        }
260       
261        #set up wiki for short urls if the web server is Apache and the user checked the box
262        if( $omwiki_use_short_urls && stripos( $_SERVER['SERVER_SOFTWARE'], 'apache' ) !== false ){
263        $_POST['omwiki_script_path']  = "{$omcollab_installation_dir}w";
264        $_POST['omwiki_article_path'] = "{$omcollab_installation_dir}w/$1";
265        }else{
266            $_POST['omwiki_script_path']  = "{$omcollab_installation_dir}w";
267        $_POST['omwiki_article_path'] = "{$omcollab_installation_dir}w/index.php/$1";
268        }
269       
270        #shell to mysql and build the databases from the dumpfiles
271        $aDbs         = array( 'wiki', 'blogs', 'bookmarks', 'forum' );
272        $aExecResults = array();
273        foreach( $aDbs as $sDb ){
274                $sCommand = "$sMySqlExecutable "
275                          . "-h {$omcollab_db_hostname} "
276                                  . "-u {$DbIni[$sDb]['Username']} "
277                                  . "-p{$DbIni[$sDb]['Password']} "
278                                  . "{$DbIni[$sDb]['Database']} < "
279                                  . realpath("_InstallationResources/om{$sDb}_temp.sql");
280                exec( $sCommand, $aOutput );
281                $aExecResults[$sCommand][] = $aOutput;
282        }
283       
284        #if the above went well, we can
285        # - set up the wiki dirname & htaccess
286        # - rewrite the omconfig.php file
287        # - rename this installation file
288        # - rewrite the main index file to point to the wiki (default app)
289        # - remove the temporary sqldump files
290       
291        #rename wiki directory and set the .htaccess file if the web server is Apache and the user checked the box
292        if( $omwiki_use_short_urls && stripos( $_SERVER['SERVER_SOFTWARE'], 'apache' ) !== false ){
293        //rename( 'wiki', 'w' ); //renames the wiki directory
294        copy( '_InstallationResources/.htaccess', './.htaccess' );
295        }
296       
297        #replace within omconfig.php and rewrite
298        $aPlaceholders = array( 'omcollab_installation_dir'
299                              , 'omcollab_admin_email'
300                              , 'omcollab_db_hostname'
301                              , 'omwiki_database_name'
302                              , 'omwiki_db_username'
303                              , 'omwiki_db_password'
304                              , 'omcollab_db_table_prefix'
305                              , 'omblogs_database_name'
306                              , 'omblogs_db_username'
307                              , 'omblogs_db_password'
308                              , 'omcollab_db_table_prefix'
309                              , 'ombookmarks_database_name'
310                              , 'ombookmarks_db_username'
311                              , 'ombookmarks_db_password'
312                              , 'omcollab_db_table_prefix'
313                              , 'omforum_database_name'
314                              , 'omforum_db_username'
315                              , 'omforum_db_password'
316                              , 'omcollab_db_table_prefix'
317                              , 'omcollab_application_name'
318                              , 'omwiki_application_name'
319                              , 'omblog_application_name'
320                              , 'ombookmarks_application_name'
321                              , 'omforum_application_name'
322                              , 'omexplore_application_name'
323                              , 'omwiki_script_path'
324                              , 'omwiki_article_path'
325                              , 'omcollab_initial_skin'
326                              , 'omcollab_google_analytics'
327                              , 'omcollab_google_cse_code'
328                              , 'omcollab_google_cse_forid'
329                              , 'omcollab_google_blog_key'
330                                                  , 'omwiki_enable_docconvert'
331                                                  , 'omwiki_docconvert_oo_path');
332   
333        $sOmConfigPhp = file_get_contents( '_InstallationResources/omconfig.php' );
334    foreach( $aPlaceholders as $sPlaceholder ){
335        $sOmConfigPhp = str_replace( '{' . $sPlaceholder . '}', $_POST[ $sPlaceholder ], $sOmConfigPhp );
336    }
337    file_put_contents( 'common/omconfig.php', $sOmConfigPhp );
338   
339    #remove the temporary sqldump files
340        /*
341    unlink( '_InstallationResources/omwiki_temp.sql' );
342    unlink( '_InstallationResources/omblogs_temp.sql' );
343    unlink( '_InstallationResources/ombookmarks_temp.sql' );
344    unlink( '_InstallationResources/omforum_temp.sql' );
345    */
346   
347    #rename install.php
348    copy( dirname( __file__) . '/install.php', dirname( __file__) . '/install.completed.php' );
349    unlink( dirname( __file__) . '/install.php' );
350   
351        #rewrite index.php
352    unlink( dirname(__file__) . '/index.php'); // Created by zhongzhen for new design
353        copy('_InstallationResources/index_temp.php', dirname(__file__) . '/index.php'); // Created by zhongzhen for new design
354        //$sIndexContents = "<" . "?php\ninclude( \"home.php\" );\n?" . ">";
355        //file_put_contents( 'index.php', $sIndexContents );
356       
357        die( "\n\nInstallation completed with probable success!\n\nCheck it <a href='$omcollab_installation_dir'>here</a>!" );
358
359}
360
361?>
362
363Welcome to the installation utility for the omCollab Suite.
364Your inputs will be checked, and a certain amount of sanity checking will take place.
365Please read the <a href="readme.txt" target="_blank">readme</a>!
366<form method="post" action="install.php">
367<input type="hidden" name="do" value="install">
368<input name="omcollab_admin_email"> Admin email
369<input name="omcollab_db_hostname"> Database hostname ( eg <span style="color:blue;font-weight:bold;">localhost</span> )
370<input name="omcollab_db_table_prefix"> Database table prefix ( eg "<span style="color:blue;font-weight:bold;">om</span>" )
371<input name="path_to_mysql"> Full path to mysql ( eg <span style="color:blue;font-weight:bold;">\path\to\mysql\ or D:\xamppfiles\mysql\bin\</span> )
372<input name="omwiki_database_name"> Wiki database name
373<input name="omwiki_db_username"> Wiki database username
374<input name="omwiki_db_password"> Wiki database password
375<input name="omblogs_database_name"> Blogs database name
376<input name="omblogs_db_username"> Blogs database username
377<input name="omblogs_db_password"> Blogs database password
378<input name="ombookmarks_database_name"> Bookmarks database name
379<input name="ombookmarks_db_username"> Bookmarks database username
380<input name="ombookmarks_db_password"> Bookmarks database password
381<input name="omforum_database_name"> Forum database name
382<input name="omforum_db_username"> Forum database username
383<input name="omforum_db_password"> Forum database password
384<input name="omcollab_application_name"> omCollab application name ( eg "<span style="color:blue;font-weight:bold;">omCollab Portal</span>" )
385<input name="omwiki_application_name"> Wiki application name ( eg "<span style="color:blue;font-weight:bold;">omCollab Wiki</span>" )
386<input name="omblog_application_name"> Blog application name ( eg "<span style="color:blue;font-weight:bold;">omCollab Blogs</span>" )
387<input name="ombookmarks_application_name"> Bookmarks application name (eg "<span style="color:blue;font-weight:bold;">omCollab Bookmarks</span>")
388<input name="omforum_application_name"> Forum application name (eg "<span style="color:blue;font-weight:bold;">omCollab Forum</span>")
389<input name="omexplore_application_name"> Explore application name (eg "<span style="color:blue;font-weight:bold;">omCollab Explore</span>")
390
391Initial Configuration
392<input name="omcollab_initial_skin" type="radio" value="" checked> Mike2 ( blue skin with <span style="color:blue;font-weight:bold;">wiki</span> + <span style="color:blue;font-weight:bold;">blogs</span> + <span style="color:blue;font-weight:bold;">bookmarks</span> + <span style="color:blue;font-weight:bold;">explore</span> )
393<input name="omcollab_initial_skin" type="radio" value="green"> Open-sustainability ( green skin with <span style="color:blue;font-weight:bold;">wiki</span> + <span style="color:blue;font-weight:bold;">blogs</span> + <span style="color:blue;font-weight:bold;">bookmarks</span> + <span style="color:blue;font-weight:bold;">explore</span> )
394<input name="omcollab_initial_skin" type="radio" value="red"> Mike2red ( red skin with <span style="color:blue;font-weight:bold;">wiki</span> + <span style="color:blue;font-weight:bold;">blogs</span> + <span style="color:blue;font-weight:bold;">bookmarks</span> )
395
396Use short URLs in MediaWiki?
397<?php  if( stripos( $_SERVER['SERVER_SOFTWARE'], 'apache' ) !== false ): ?>
398<input name="omwiki_use_short_urls" type="checkbox" checked> ( read <a href="readme.txt" target="_blank">this</a> and <a href='http://www.mediawiki.org/wiki/Manual:Short_URL' target='_blank'>this</a> first! )
399<?php endif; ?>
400
401Enable DocConvert Extension for MS Word to MediaWiki Conversion?
402<input name="omwiki_enable_docconvert" type="checkbox">
403If Enabled, make sure you have OpenOffice.org installed, and enter your fully qualified path to the Open Office "program" directory here:
404Example: C:\Program Files\OpenOffice.org 3\program\
405<input name="omwiki_docconvert_oo_path" type="text">
406Alternatively, leave this blank and have the Open Office program path (directory where soffice executable is) on your system path envinronment variable.
407If you add OpenOffice program directory to system path environment variable, make sure you reset your web server before going forward.
408
409Google extras <span style="color:red;font-weight:bold;">Optional [requires Google account]</span>.
410You'll need to look closely at your Google-provided code to retrieve the required values (copy and paste the relevant values here)
411<input name="omcollab_google_analytics"> Google Anayltics Code ( Harvest Google Analytics for your site. Looks something like "<span style="color:blue;font-weight:bold;">ZZ-9999999-9</span>" or leave blank )
412<input name="omcollab_google_cse_code"> Google Custom Search Code ( Show Google results for your site. Takes the form of "<span style="color:blue;font-weight:bold;">999999999999999999999:xxxxxxxxxxx</span>" or leave blank )
413<input name="omcollab_google_cse_forid"> Google Custom Search FORID Code ( Required when using the custom search defined above. Takes the form of "<span style="color:blue;font-weight:bold;">an integer provided by Google</span>" or leave blank )
414<input name="omcollab_google_blog_key"> Google API Key for blogbar ( Required for integrated blog searches in omCollab Explore. Takes the form of "<span style="color:blue;font-weight:bold;">an 86-character long API code</span>" or leave blank )
415
416<input type="Submit" name="submit" value="Install omCollab">
417</form>
418
419</pre>
420</body>
421</html>
Note: See TracBrowser for help on using the repository browser.