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