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