3 * @file mod/install.php
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;
13 $install_wizard_pass = 1;
15 function install_init(App $a) {
17 // $baseurl/install/testrwrite to test if rewite in .htaccess is working
18 if ($a->argc == 2 && $a->argv[1] == "testrewrite") {
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";
28 Install::setInstallMode();
30 global $install_wizard_pass;
31 if (x($_POST, 'pass')) {
32 $install_wizard_pass = intval($_POST['pass']);
37 function install_post(App $a) {
38 global $install_wizard_pass;
40 switch($install_wizard_pass) {
44 break; // just in case return don't return :)
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']));
53 require_once("include/dba.php");
54 if (!dba::connect($dbhost, $dbuser, $dbpass, $dbdata)) {
55 $a->data['db_conn_failed'] = true;
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']));
73 dba::connect($dbhost, $dbuser, $dbpass, $dbdata);
75 Install::install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino);
82 function install_content(App $a) {
84 global $install_wizard_pass;
87 $install_title = L10n::t('Friendica Communications Server - Setup');
91 if (x($a->data, 'db_conn_failed')) {
92 $install_wizard_pass = 2;
93 $wizard_status = L10n::t('Could not connect to database.');
95 if (x($a->data, 'db_create_failed')) {
96 $install_wizard_pass = 2;
97 $wizard_status = L10n::t('Could not create table.');
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;
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;
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,
121 '$status' => L10n::t('Database already in use.'),
127 if (x($a->data, 'txt') && strlen($a->data['txt'])) {
128 $db_return_text .= manual_config($a);
131 if ($db_return_text != "") {
132 $tpl = get_markup_template('install.tpl');
133 return replace_macros($tpl, [
134 '$title' => $install_title,
136 '$text' => $db_return_text . what_next(),
140 switch ($install_wizard_pass) {
141 case 1: { // System check
143 if (x($_POST, 'phpath')) {
144 $phpath = notags(trim($_POST['phpath']));
147 list($checks, $checkspassed) = Install::check($phpath);
149 $tpl = get_markup_template('install_checks.tpl');
150 $o .= replace_macros($tpl, [
151 '$title' => $install_title,
152 '$pass' => L10n::t('System check'),
153 '$checks' => $checks,
154 '$passed' => $checkspassed,
155 '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
156 '$next' => L10n::t('Next'),
157 '$reload' => L10n::t('Check again'),
158 '$phpath' => $phpath,
159 '$baseurl' => System::baseUrl(),
164 case 2: { // Database config
166 $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
167 $dbuser = notags(trim($_POST['dbuser']));
168 $dbpass = notags(trim($_POST['dbpass']));
169 $dbdata = notags(trim($_POST['dbdata']));
170 $phpath = notags(trim($_POST['phpath']));
172 $adminmail = notags(trim($_POST['adminmail']));
174 $tpl = get_markup_template('install_db.tpl');
175 $o .= replace_macros($tpl, [
176 '$title' => $install_title,
177 '$pass' => L10n::t('Database connection'),
178 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
179 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
180 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
182 '$status' => $wizard_status,
184 '$dbhost' => ['dbhost', L10n::t('Database Server Name'), $dbhost, '', 'required'],
185 '$dbuser' => ['dbuser', L10n::t('Database Login Name'), $dbuser, '', 'required', 'autofocus'],
186 '$dbpass' => ['dbpass', L10n::t('Database Login Password'), $dbpass, L10n::t("For security reasons the password must not be empty"), 'required'],
187 '$dbdata' => ['dbdata', L10n::t('Database Name'), $dbdata, '', 'required'],
188 '$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'],
192 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
194 '$baseurl' => System::baseUrl(),
196 '$phpath' => $phpath,
198 '$submit' => L10n::t('Submit'),
203 case 3: { // Site settings
204 $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
205 $dbuser = notags(trim($_POST['dbuser']));
206 $dbpass = notags(trim($_POST['dbpass']));
207 $dbdata = notags(trim($_POST['dbdata']));
208 $phpath = notags(trim($_POST['phpath']));
210 $adminmail = notags(trim($_POST['adminmail']));
211 $timezone = ((x($_POST, 'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
212 /* Installed langs */
213 $lang_choices = L10n::getAvailableLanguages();
215 $tpl = get_markup_template('install_settings.tpl');
216 $o .= replace_macros($tpl, [
217 '$title' => $install_title,
218 '$pass' => L10n::t('Site settings'),
220 '$status' => $wizard_status,
222 '$dbhost' => $dbhost,
223 '$dbuser' => $dbuser,
224 '$dbpass' => $dbpass,
225 '$dbdata' => $dbdata,
226 '$phpath' => $phpath,
228 '$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'],
231 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
232 '$language' => ['language', L10n::t('System Language:'), 'en', L10n::t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices],
233 '$baseurl' => System::baseUrl(),
237 '$submit' => L10n::t('Submit'),
246 function manual_config(App $a) {
247 $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8');
248 $o = L10n::t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.');
249 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
253 function load_database_rem($v, $i) {
255 if (strlen($l)>1 && ($l[0] == "-" || ($l[0] == "/" && $l[1] == "*"))) {
262 function what_next() {
263 $baseurl = System::baseUrl();
265 L10n::t('<h1>What next</h1>')
266 ."<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
267 .L10n::t('Please see the file "INSTALL.txt".')
269 .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)