]> git.mxchange.org Git - friendica.git/blob - mod/install.php
Update install procedure
[friendica.git] / mod / install.php
1 <?php
2 /**
3  * @file mod/install.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Install;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
11 use Friendica\Util\Temporal;
12
13 $install_wizard_pass = 1;
14
15 function install_init(App $a) {
16
17         // $baseurl/install/testrwrite to test if rewite in .htaccess is working
18         if ($a->argc == 2 && $a->argv[1] == "testrewrite") {
19                 echo "ok";
20                 killme();
21         }
22
23         // We overwrite current theme css, because during install we could not have a working mod_rewrite
24         // so we could not have a css at all. Here we set a static css file for the install procedure pages
25         $a->config['system']['theme'] = "../install";
26         $a->theme['stylesheet'] = System::baseUrl()."/view/install/style.css";
27
28         Install::setInstallMode();
29
30         global $install_wizard_pass;
31         if (x($_POST, 'pass')) {
32                 $install_wizard_pass = intval($_POST['pass']);
33         }
34
35 }
36
37 function install_post(App $a) {
38         global $install_wizard_pass;
39
40         switch($install_wizard_pass) {
41                 case 1:
42                 case 2:
43                         return;
44                         break; // just in case return don't return :)
45                 case 3:
46                         $urlpath = $a->get_path();
47                         $dbhost = notags(trim($_POST['dbhost']));
48                         $dbuser = notags(trim($_POST['dbuser']));
49                         $dbpass = notags(trim($_POST['dbpass']));
50                         $dbdata = notags(trim($_POST['dbdata']));
51                         $phpath = notags(trim($_POST['phpath']));
52
53                         require_once("include/dba.php");
54                         if (!dba::connect($dbhost, $dbuser, $dbpass, $dbdata)) {
55                                 $a->data['db_conn_failed'] = true;
56                         }
57
58                         return;
59                         break;
60                 case 4:
61                         $urlpath = $a->get_path();
62                         $dbhost = notags(trim($_POST['dbhost']));
63                         $dbuser = notags(trim($_POST['dbuser']));
64                         $dbpass = notags(trim($_POST['dbpass']));
65                         $dbdata = notags(trim($_POST['dbdata']));
66                         $phpath = notags(trim($_POST['phpath']));
67                         $timezone = notags(trim($_POST['timezone']));
68                         $language = notags(trim($_POST['language']));
69                         $adminmail = notags(trim($_POST['adminmail']));
70
71                         // connect to db
72                         dba::connect($dbhost, $dbuser, $dbpass, $dbdata);
73
74                         Install::install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail);
75
76                         return;
77                 break;
78         }
79 }
80
81 function install_content(App $a) {
82
83         global $install_wizard_pass;
84         $o = '';
85         $wizard_status = "";
86         $install_title = L10n::t('Friendica Communications Server - Setup');
87
88
89
90         if (x($a->data, 'db_conn_failed')) {
91                 $install_wizard_pass = 2;
92                 $wizard_status = L10n::t('Could not connect to database.');
93         }
94         if (x($a->data, 'db_create_failed')) {
95                 $install_wizard_pass = 2;
96                 $wizard_status = L10n::t('Could not create table.');
97         }
98
99         $db_return_text = "";
100         if (x($a->data, 'db_installed')) {
101                 $txt = '<p style="font-size: 130%;">';
102                 $txt .= L10n::t('Your Friendica site database has been installed.') . EOL;
103                 $db_return_text .= $txt;
104         }
105
106         if (x($a->data, 'db_failed')) {
107                 $txt = L10n::t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
108                 $txt .= L10n::t('Please see the file "INSTALL.txt".') . EOL ."<hr>";
109                 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL;
110                 $db_return_text .= $txt;
111         }
112
113         if (dba::$connected) {
114                 $r = q("SELECT COUNT(*) as `total` FROM `user`");
115                 if (DBM::is_result($r) && $r[0]['total']) {
116                         $tpl = get_markup_template('install.tpl');
117                         return replace_macros($tpl, [
118                                 '$title' => $install_title,
119                                 '$pass' => '',
120                                 '$status' => L10n::t('Database already in use.'),
121                                 '$text' => '',
122                         ]);
123                 }
124         }
125
126         if (x($a->data, 'txt') && strlen($a->data['txt'])) {
127                 $db_return_text .= manual_config($a);
128         }
129
130         if ($db_return_text != "") {
131                 $tpl = get_markup_template('install.tpl');
132                 return replace_macros($tpl, [
133                         '$title' => $install_title,
134                         '$pass' => "",
135                         '$text' => $db_return_text . what_next(),
136                 ]);
137         }
138
139         switch ($install_wizard_pass) {
140                 case 1: { // System check
141
142                         $phpath = defaults($_POST, 'phpath', 'php');
143
144                         list($checks, $checkspassed) = Install::check($phpath);
145
146                         $tpl = get_markup_template('install_checks.tpl');
147                         $o .= replace_macros($tpl, [
148                                 '$title' => $install_title,
149                                 '$pass' => L10n::t('System check'),
150                                 '$checks' => $checks,
151                                 '$passed' => $checkspassed,
152                                 '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
153                                 '$next' => L10n::t('Next'),
154                                 '$reload' => L10n::t('Check again'),
155                                 '$phpath' => $phpath,
156                                 '$baseurl' => System::baseUrl(),
157                         ]);
158                         return $o;
159                 }; break;
160
161                 case 2: { // Database config
162
163                         $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
164                         $dbuser = notags(trim($_POST['dbuser']));
165                         $dbpass = notags(trim($_POST['dbpass']));
166                         $dbdata = notags(trim($_POST['dbdata']));
167                         $phpath = notags(trim($_POST['phpath']));
168
169                         $adminmail = notags(trim($_POST['adminmail']));
170
171                         $tpl = get_markup_template('install_db.tpl');
172                         $o .= replace_macros($tpl, [
173                                 '$title' => $install_title,
174                                 '$pass' => L10n::t('Database connection'),
175                                 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
176                                 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
177                                 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
178
179                                 '$status' => $wizard_status,
180
181                                 '$dbhost' => ['dbhost', L10n::t('Database Server Name'), $dbhost, '', 'required'],
182                                 '$dbuser' => ['dbuser', L10n::t('Database Login Name'), $dbuser, '', 'required', 'autofocus'],
183                                 '$dbpass' => ['dbpass', L10n::t('Database Login Password'), $dbpass, L10n::t("For security reasons the password must not be empty"), 'required'],
184                                 '$dbdata' => ['dbdata', L10n::t('Database Name'), $dbdata, '', 'required'],
185                                 '$adminmail' => ['adminmail', L10n::t('Site administrator email address'), $adminmail, L10n::t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'],
186
187
188
189                                 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
190
191                                 '$baseurl' => System::baseUrl(),
192
193                                 '$phpath' => $phpath,
194
195                                 '$submit' => L10n::t('Submit'),
196
197                         ]);
198                         return $o;
199                 }; break;
200                 case 3: { // Site settings
201                         $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
202                         $dbuser = notags(trim($_POST['dbuser']));
203                         $dbpass = notags(trim($_POST['dbpass']));
204                         $dbdata = notags(trim($_POST['dbdata']));
205                         $phpath = notags(trim($_POST['phpath']));
206
207                         $adminmail = notags(trim($_POST['adminmail']));
208                         $timezone = ((x($_POST, 'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
209                         /* Installed langs */
210                         $lang_choices = L10n::getAvailableLanguages();
211
212                         $tpl = get_markup_template('install_settings.tpl');
213                         $o .= replace_macros($tpl, [
214                                 '$title' => $install_title,
215                                 '$pass' => L10n::t('Site settings'),
216
217                                 '$status' => $wizard_status,
218
219                                 '$dbhost' => $dbhost,
220                                 '$dbuser' => $dbuser,
221                                 '$dbpass' => $dbpass,
222                                 '$dbdata' => $dbdata,
223                                 '$phpath' => $phpath,
224
225                                 '$adminmail' => ['adminmail', L10n::t('Site administrator email address'), $adminmail, L10n::t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'],
226
227
228                                 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
229                                 '$language' => ['language', L10n::t('System Language:'), 'en', L10n::t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices],
230                                 '$baseurl' => System::baseUrl(),
231
232
233
234                                 '$submit' => L10n::t('Submit'),
235
236                         ]);
237                         return $o;
238                 }; break;
239
240         }
241 }
242
243 function manual_config(App $a) {
244         $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8');
245         $o = L10n::t('The database configuration file "config/local.ini.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.');
246         $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
247         return $o;
248 }
249
250 function load_database_rem($v, $i) {
251         $l = trim($i);
252         if (strlen($l)>1 && ($l[0] == "-" || ($l[0] == "/" && $l[1] == "*"))) {
253                 return $v;
254         } else  {
255                 return $v."\n".$i;
256         }
257 }
258
259 function what_next() {
260         $baseurl = System::baseUrl();
261         return
262                 L10n::t('<h1>What next</h1>')
263                 ."<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
264                 .L10n::t('Please see the file "INSTALL.txt".')
265                 ."</p><p>"
266                 .L10n::t('Go to your new Friendica node <a href="%s/register">registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.', $baseurl)
267                 ."</p>";
268 }