Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
<?php
2
 
3
////////////////////////////////////////////////////////////////////////////////
4
//                                                                            //
5
//   Copyright (C) 2006  Phorum Development Team                              //
6
//   http://www.phorum.org                                                    //
7
//                                                                            //
8
//   This program is free software. You can redistribute it and/or modify     //
9
//   it under the terms of either the current Phorum License (viewable at     //
10
//   phorum.org) or the Phorum License that was distributed with this file    //
11
//                                                                            //
12
//   This program is distributed in the hope that it will be useful,          //
13
//   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
14
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
15
//                                                                            //
16
//   You should have received a copy of the Phorum License                    //
17
//   along with this program.                                                 //
18
////////////////////////////////////////////////////////////////////////////////
19
 
20
    if(!defined("PHORUM_ADMIN")) return;
21
 
22
    if(!phorum_db_check_connection()){
23
        echo "A database connection could not be established.  Please edit include/db/config.php.";
24
        return;
25
    }
26
 
27
    include_once "./include/admin/PhorumInputForm.php";
28
 
29
    if(empty($_POST["step"])){
30
        $step = 0;
31
    } else {
32
        $step = $_POST["step"];
33
    }
34
 
35
    if(count($_POST)){
36
 
37
        // THIS IS THE WORK STEP
38
 
39
        switch ($step){
40
 
41
            case 5:
42
 
43
                if(!empty($_POST["admin_user"]) && !empty($_POST["admin_pass"]) && !empty($_POST["admin_pass2"]) && !empty($_POST["admin_email"])){
44
                    if($_POST["admin_pass"]!=$_POST["admin_pass2"]){
45
                        echo "The password fields do not match<br />";
46
                        $step=4;
47
                    } elseif(phorum_user_check_login($_POST["admin_user"], $_POST["admin_pass"])){
48
                        if($PHORUM["user"]["admin"]){
49
                            echo "Admin user already exists and has permissions<br />";
50
                        } else {
51
                            echo "That user already exists but does not have admin permissions<br />";
52
                            $step=4;
53
                        }
54
                    } else {
55
 
56
                        // add the user
57
                        $user = array( "username"=>$_POST["admin_user"], "password"=>$_POST["admin_pass"], "email"=>$_POST["admin_email"], "active"=>1, "admin"=>1 );
58
 
59
                        if(!phorum_user_add($user)){
60
 
61
                            echo "There was an error adding the user.<br />";
62
                            $step=4;
63
                        }
64
 
65
                        // set the default http_path so we can continue.
66
                        if(!empty($_SERVER["HTTP_REFERER"])) {
67
                            $http_path=$_SERVER["HTTP_REFERER"];
68
                        } elseif(!empty($_SERVER['HTTP_HOST'])) {
69
                            $http_path="http://".$_SERVER['HTTP_HOST'];
70
                            $http_path.=$_SERVER['PHP_SELF'];
71
                        } else {
72
                            $http_path="http://".$_SERVER['SERVER_NAME'];
73
                            $http_path.=$_SERVER['PHP_SELF'];
74
                        }
75
                        phorum_db_update_settings(array("http_path"=>dirname($http_path)));
76
                        phorum_db_update_settings(array("system_email_from_address"=>$_POST["admin_email"]));
77
 
78
 
79
                    }
80
                } else {
81
                    echo "Please fill in all fields.<br />";
82
                    $step=4;
83
                }
84
 
85
                break;
86
        }
87
 
88
    }
89
 
90
    // THIS IS THE OUTPUT STEP
91
 
92
    if($PHORUM["installed"]) $step=5;
93
 
94
    switch ($step){
95
 
96
        case 0:
97
 
98
            $frm =& new PhorumInputForm ("", "post", "Continue ->");
99
            $frm->addbreak("Welcome to Phorum");
100
            $frm->addmessage("This wizard will setup Phorum on your server.  The first step is to prepare the database.  Phorum has already confirmed that it can connect to your database.  Press continue when you are ready.");
101
            $frm->hidden("module", "install");
102
            $frm->hidden("step", "2");
103
            $frm->show();
104
 
105
            break;
106
 
107
        case 2:
108
            // ok, fresh install
109
 
110
            $err=phorum_db_create_tables();
111
 
112
            if($err){
113
                $message="Could not create tables, database said:<blockquote>$err</blockquote>";
114
                $message.="Your database user will need to have create table permissions.  If you know what the error is (tables already exist, etc.) and want to continue, click the button below.";
115
            } else {
116
                $message="Tables created.  Next we will check your cache settings. Press continue when ready.";
117
 
118
                // setup vars for initial settings
119
                $tmp_dir = (substr(__FILE__, 0, 1)=="/") ? "/tmp" : "C:\\Windows\\Temp";
120
 
121
                $default_forum_options=array(
122
                'forum_id'=>0,
123
                'moderation'=>0,
124
                'email_moderators'=>0,
125
                'pub_perms'=>1,
126
                'reg_perms'=>15,
127
                'display_fixed'=>0,
128
                'template'=>'default',
129
                'language'=>'english',
130
                'threaded_list'=>0,
131
                'threaded_read'=>0,
132
                'reverse_threading'=>0,
133
                'float_to_top'=>1,
134
                'list_length_flat'=>30,
135
                'list_length_threaded'=>15,
136
                'read_length'=>30,
137
                'display_ip_address'=>0,
138
                'allow_email_notify'=>0,
139
                'check_duplicate'=>1,
140
                'count_views'=>2,
141
                'max_attachments'=>0,
142
                'allow_attachment_types'=>'',
143
                'max_attachment_size'=>0,
144
                'max_totalattachment_size'=>0,
145
                'vroot'=>0,
146
                );
147
 
148
                // insert the default module settings
149
                // hooks
150
 
151
                $hooks_initial=array(
152
                'format'=>array(
153
                        'mods'=>array('smileys','bbcode'),
154
                        'funcs'=>array('phorum_mod_smileys','phorum_bb_code')
155
                        )
156
                );
157
 
158
                $mods_initial=array(
159
                    'html'   =>0,
160
                    'replace'=>0,
161
                    'smileys'=>1,
162
                    'bbcode' =>1
163
                );
164
 
165
                // set initial settings
166
                $settings=array(
167
                "title" => "Phorum 5",
168
                "cache" => "$tmp_dir",
169
                "session_timeout" => "30",
170
                "short_session_timeout" => "60",
171
                "tight_security" => "0",
172
                "session_path" => "/",
173
                "session_domain" => "",
174
                "admin_session_salt" => microtime(),
175
                "cache_users" => "0",
176
                "register_email_confirm" => "0",
177
                "default_template" => "default",
178
                "default_language" => "english",
179
                "use_cookies" => "1",
180
                "use_bcc" => "1",
181
                "use_rss" => "1",
182
                "internal_version" => "" . PHORUMINTERNAL . "",
183
                "PROFILE_FIELDS" => array(array('name'=>"real_name",'length'=> 255, 'html_disabled'=>1)),
184
                "enable_pm" => "1",
185
                "user_edit_timelimit" => "0",
186
                "enable_new_pm_count" => "1",
187
                "enable_dropdown_userlist" => "1",
188
                "enable_moderator_notifications" => "1",
189
                "show_new_on_index" => "1",
190
                "dns_lookup" => "1",
191
                "tz_offset" => "0",
192
                "user_time_zone" => "1",
193
                "user_template" => "0",
194
                "registration_control" => "1",
195
                "file_uploads" => "0",
196
                "file_types" => "",
197
                "max_file_size" => "",
198
                "file_space_quota" => "",
199
                "file_offsite" => "0",
200
                "system_email_from_name" => "",
201
                "hide_forums" => "1",
202
                "enable_new_pm_count" => "1",
203
                "track_user_activity" => "86400",
204
                "html_title" => "Phorum",
205
                "head_tags" => "",
206
                "cache_users" => 0,
207
                "redirect_after_post" => "list",
208
                "reply_on_read_page" => 1,
209
                "status" => "normal",
210
                "use_new_folder_style" => 1,
211
                "default_forum_options" => $default_forum_options,
212
                "hooks"=> $hooks_initial,
213
                "mods" => $mods_initial
214
 
215
                );
216
 
217
                phorum_db_update_settings($settings);
218
 
219
                // posting forum and test-message
220
 
221
                // create a test forum
222
                $forum=array(
223
                "name"=>'Test Forum',
224
                "active"=>1,
225
                "description"=>'This is a test forum.  Feel free to delete it or edit after installation.',
226
                "template"=>'default',
227
                "folder_flag"=>0,
228
                "parent_id"=>0,
229
                "list_length_flat"=>30,
230
                "list_length_threaded"=>15,
231
                "read_length"=>20,
232
                "moderation"=>0,
233
                "threaded_list"=>0,
234
                "threaded_read"=>0,
235
                "float_to_top"=>1,
236
                "display_ip_address"=>0,
237
                "allow_email_notify"=>1,
238
                "language"=>'english',
239
                "email_moderators"=>0,
240
                "display_order"=>0,
241
                "edit_post"=>1,
242
                "pub_perms" =>  1,
243
                "reg_perms" =>  15
244
                );
245
 
246
                $GLOBALS["PHORUM"]['forum_id']=phorum_db_add_forum($forum);
247
                $GLOBALS["PHORUM"]['vroot']=0;
248
 
249
                // create a test post
250
                $test_message=array(
251
                "forum_id" => $GLOBALS['PHORUM']["forum_id"],
252
                "thread" => 0,
253
                "parent_id" => 0,
254
                "author" => 'Phorum Installer',
255
                "subject" => 'Test Message',
256
                "email" => '',
257
                "ip" => '127.0.0.1',
258
                "user_id" => 0,
259
                "moderator_post" => 0,
260
                "closed" => 0,
261
                "status" => PHORUM_STATUS_APPROVED,
262
                "sort" => PHORUM_SORT_DEFAULT,
263
                "msgid" => '',
264
                "body" => "This is a test message.  You can delete it after install using the admin.\n\nPhorum 5 Team"
265
                );
266
 
267
                phorum_db_post_message($test_message);
268
 
269
                include_once ("./include/thread_info.php");
270
 
271
                phorum_update_thread_info($test_message["thread"]);
272
 
273
                phorum_db_update_forum_stats(true);
274
 
275
            }
276
 
277
            $frm =& new PhorumInputForm ("", "post", "Continue ->");
278
            $frm->addbreak("Creating tables....");
279
            $frm->addmessage($message);
280
            $frm->hidden("step", "6");
281
            $frm->hidden("module", "install");
282
            $frm->show();
283
 
284
            break;
285
 
286
        case 4:
287
 
288
            $frm =& new PhorumInputForm ("", "post");
289
            $frm->hidden("step", "5");
290
            $frm->hidden("module", "install");
291
            $frm->addbreak("Creating An Administrator");
292
            $frm->addmessage("Please enter the following information.  This can be your user information or you can create an administrator that is separate from yourself.<br /><br />Note: If you are using a pre-existing authentication database, please enter the username and password of the admin user that already exists.");
293
            $admin_user = isset($_POST["admin_user"]) ? $_POST["admin_user"] : "";
294
            $admin_email = isset($_POST["admin_email"]) ? $_POST["admin_email"] : "";
295
            $frm->addrow("Admin User Name", $frm->text_box("admin_user", $admin_user, 30));
296
            $frm->addrow("Admin Email Address", $frm->text_box("admin_email", $admin_email, 30));
297
            $frm->addrow("Admin Password", $frm->text_box("admin_pass", "", 30, 0, true));
298
            $frm->addrow("(again)", $frm->text_box("admin_pass2", "", 30, 0, true));
299
            $frm->show();
300
 
301
            break;
302
 
303
        case 5:
304
 
305
            phorum_db_update_settings( array("installed"=>1) );
306
            echo "The setup is complete.  You can now go to <a href=\"$_SERVER[PHP_SELF]\">the admin</a> and start making Phorum all your own.<br /><br /><strong>Here are some things you will want to look at:</strong><br /><br /><a href=\"$_SERVER[PHP_SELF]?module=settings\">The General Settings page</a><br /><br /><a href=\"$_SERVER[PHP_SELF]?module=mods\">Pre-installed modules</a><br /><br /><a href=\"docs/faq.txt\">The FAQ</a><br /><br /><a href=\"docs/performance.txt\">How to get peak performance from Phorum</a><br /><br /><strong>For developers:</strong><br /><br /><a href=\"docs/creating_mods.txt\">Module Creation</a><br /><br /><a href=\"docs/permissions.txt\">How Phorum permisssions work</a><br /><br /><a href=\"docs/CODING-STANDARDS\">The Phorum Team's codings standards</a>";
307
 
308
            break;
309
 
310
        case 6:
311
            // try to figure out if we can write to the cache directory
312
            $message = "";
313
            error_reporting(0);
314
            $err = false;
315
            if ($fp = fopen($PHORUM["cache"] . "/phorum-install-test", "w+")) {
316
                unlink($PHORUM["cache"] . "/phorum-install-test");
317
            }
318
            else {
319
                // in this case the normal setting is wrong, so try ./cache
320
                $PHORUM["cache"] = "./cache";
321
                $settings = array("cache" => $PHORUM["cache"]);
322
                if (!phorum_db_update_settings($settings)) {
323
                    $message .= "Database error updating settings.<br />";
324
                    $err = true;
325
                }
326
                elseif ($fp = fopen($PHORUM["cache"] . "/phorum-install-test", "w+")) {
327
                    unlink($PHORUM["cache"] . "/phorum-install-test");
328
                }
329
                else {
330
                    $err = true;
331
                }
332
 
333
            }
334
            error_reporting(E_WARN);
335
            if ($message == "") {
336
                if($err){
337
                    $message.="Your cache directory is not writable. Please change the permissions on '/cache' inside the Phorum directory to allow writing. In Unix, you may have to use this command: chmod 777 cache<br /><br />If you want to continue anyway and set a cache directory manually, press continue. Note that you must do this, Phorum will not work without a valid cache.";
338
                } else {
339
                    $message.="Cache directory set.  Next we will create a user with administrator privileges.  Press continue when ready.";
340
                }
341
            }
342
 
343
            $frm =& new PhorumInputForm ("", "post", "Continue ->");
344
            $frm->hidden("module", "install");
345
            $frm->addbreak("Checking cache....");
346
            $frm->addmessage($message);
347
            $frm->hidden("step", "4");
348
            $frm->show();
349
 
350
            break;
351
    }
352
 
353
?>