]> git.mxchange.org Git - friendica.git/blob - mod/install.php
Improve Console/Config display for array values
[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    = notags(trim(defaults($_POST, 'dbhost'   , 'localhost')));
165                         $dbuser    = notags(trim(defaults($_POST, 'dbuser'   , ''         )));
166                         $dbpass    = notags(trim(defaults($_POST, 'dbpass'   , ''         )));
167                         $dbdata    = notags(trim(defaults($_POST, 'dbdata'   , ''         )));
168                         $phpath    = notags(trim(defaults($_POST, 'phpath'   , ''         )));
169                         $adminmail = notags(trim(defaults($_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                                 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
188
189                                 '$baseurl' => System::baseUrl(),
190
191                                 '$phpath' => $phpath,
192
193                                 '$submit' => L10n::t('Submit'),
194                         ]);
195                         return $o;
196                 }; break;
197                 case 3: { // Site settings
198                         $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
199                         $dbuser = notags(trim($_POST['dbuser']));
200                         $dbpass = notags(trim($_POST['dbpass']));
201                         $dbdata = notags(trim($_POST['dbdata']));
202                         $phpath = notags(trim($_POST['phpath']));
203
204                         $adminmail = notags(trim($_POST['adminmail']));
205                         $timezone = ((x($_POST, 'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
206                         /* Installed langs */
207                         $lang_choices = L10n::getAvailableLanguages();
208
209                         $tpl = get_markup_template('install_settings.tpl');
210                         $o .= replace_macros($tpl, [
211                                 '$title' => $install_title,
212                                 '$pass' => L10n::t('Site settings'),
213
214                                 '$status' => $wizard_status,
215
216                                 '$dbhost' => $dbhost,
217                                 '$dbuser' => $dbuser,
218                                 '$dbpass' => $dbpass,
219                                 '$dbdata' => $dbdata,
220                                 '$phpath' => $phpath,
221
222                                 '$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'],
223
224
225                                 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
226                                 '$language' => ['language', L10n::t('System Language:'), 'en', L10n::t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices],
227                                 '$baseurl' => System::baseUrl(),
228
229
230
231                                 '$submit' => L10n::t('Submit'),
232
233                         ]);
234                         return $o;
235                 }; break;
236
237         }
238 }
239
240 function manual_config(App $a) {
241         $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8');
242         $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.');
243         $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
244         return $o;
245 }
246
247 function load_database_rem($v, $i) {
248         $l = trim($i);
249         if (strlen($l)>1 && ($l[0] == "-" || ($l[0] == "/" && $l[1] == "*"))) {
250                 return $v;
251         } else  {
252                 return $v."\n".$i;
253         }
254 }
255
256 function what_next() {
257         $baseurl = System::baseUrl();
258         return
259                 L10n::t('<h1>What next</h1>')
260                 ."<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
261                 .L10n::t('Please see the file "INSTALL.txt".')
262                 ."</p><p>"
263                 .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)
264                 ."</p>";
265 }