3 namespace Friendica\Module;
6 use Friendica\BaseModule;
7 use Friendica\Database\DBA;
8 use Friendica\Database\DBStructure;
10 use Friendica\Core\L10n;
11 use Friendica\Util\Temporal;
13 class Install extends BaseModule
16 * Step one - System check
18 const SYSTEM_CHECK = 1;
20 * Step two - Database configuration
22 const DATABASE_CONFIG = 2;
24 * Step three - Adapat site settings
26 const SITE_SETTINGS = 3;
28 * Step four - All steps finished
33 * @var int The current step of the wizard
35 private static $currentWizardStep;
38 * @var Core\Installer The installer
40 private static $installer;
42 public static function init()
46 // route: install/testrwrite
47 // $baseurl/install/testrwrite to test if rewrite in .htaccess is working
48 if ($a->getArgumentValue(1, '') == 'testrewrite') {
49 // Status Code 204 means that it worked without content
50 Core\System::httpExit(204);
53 // We overwrite current theme css, because during install we may not have a working mod_rewrite
54 // so we may not have a css at all. Here we set a static css file for the install procedure pages
55 $a->theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css';
57 self::$installer = new Core\Installer();
58 self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK);
61 public static function post()
65 switch (self::$currentWizardStep) {
66 case self::SYSTEM_CHECK:
67 case self::DATABASE_CONFIG:
68 // Nothing to do in these steps
71 case self::SITE_SETTINGS:
72 $dbhost = notags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
73 $dbuser = notags(trim(defaults($_POST, 'dbuser', '')));
74 $dbpass = notags(trim(defaults($_POST, 'dbpass', '')));
75 $dbdata = notags(trim(defaults($_POST, 'dbdata', '')));
77 // If we cannot connect to the database, return to the previous step
78 if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) {
79 self::$currentWizardStep = self::DATABASE_CONFIG;
85 $urlpath = $a->getURLPath();
86 $dbhost = notags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
87 $dbuser = notags(trim(defaults($_POST, 'dbuser', '')));
88 $dbpass = notags(trim(defaults($_POST, 'dbpass', '')));
89 $dbdata = notags(trim(defaults($_POST, 'dbdata', '')));
90 $phpath = notags(trim(defaults($_POST, 'phpath', '')));
91 $timezone = notags(trim(defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ)));
92 $language = notags(trim(defaults($_POST, 'language', Core\Installer::DEFAULT_LANG)));
93 $adminmail = notags(trim(defaults($_POST, 'adminmail', '')));
95 // If we cannot connect to the database, return to the Database config wizard
96 if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) {
97 self::$currentWizardStep = self::DATABASE_CONFIG;
100 if (!self::$installer->createConfig($phpath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $a->getBasePath())) {
104 self::$installer->installDatabase();
110 public static function content()
116 $install_title = L10n::t('Friendica Communctions Server - Setup');
118 switch (self::$currentWizardStep) {
119 case self::SYSTEM_CHECK:
120 $phppath = defaults($_POST, 'phpath', null);
122 $status = self::$installer->checkEnvironment($a->getBaseURL(), $phppath);
124 $tpl = get_markup_template('install_checks.tpl');
125 $output .= replace_macros($tpl, [
126 '$title' => $install_title,
127 '$pass' => L10n::t('System check'),
128 '$checks' => self::$installer->getChecks(),
129 '$passed' => $status,
130 '$see_install' => L10n::t('Please see the file "Install.txt".'),
131 '$next' => L10n::t('Next'),
132 '$reload' => L10n::t('Check again'),
133 '$phpath' => $phppath,
134 '$baseurl' => $a->getBaseURL()
138 case self::DATABASE_CONFIG:
139 $dbhost = notags(trim(defaults($_POST, 'dbhost' , Core\Installer::DEFAULT_HOST)));
140 $dbuser = notags(trim(defaults($_POST, 'dbuser' , '' )));
141 $dbpass = notags(trim(defaults($_POST, 'dbpass' , '' )));
142 $dbdata = notags(trim(defaults($_POST, 'dbdata' , '' )));
143 $phpath = notags(trim(defaults($_POST, 'phpath' , '' )));
144 $adminmail = notags(trim(defaults($_POST, 'adminmail', '' )));
146 $tpl = get_markup_template('install_db.tpl');
147 $output .= replace_macros($tpl, [
148 '$title' => $install_title,
149 '$pass' => L10n::t('Database connection'),
150 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
151 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
152 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
153 'checks' => self::$installer->getChecks(),
154 '$dbhost' => ['dbhost',
155 L10n::t('Database Server Name'),
159 '$dbuser' => ['dbuser',
160 L10n::t('Database Login Name'),
165 '$dbpass' => ['dbpass',
166 L10n::t('Database Login Password'),
168 L10n::t("For security reasons the password must not be empty"),
170 '$dbdata' => ['dbdata',
171 L10n::t('Database Name'),
175 '$adminmail' => ['adminmail',
176 L10n::t('Site administrator email address'),
178 L10n::t('Your account email address must match this in order to use the web admin panel.'),
182 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
183 '$baseurl' => $a->getBaseURL(),
184 '$phpath' => $phpath,
185 '$submit' => L10n::t('Submit')
189 case self::SITE_SETTINGS:
190 $dbhost = notags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
191 $dbuser = notags(trim(defaults($_POST, 'dbuser', '' )));
192 $dbpass = notags(trim(defaults($_POST, 'dbpass', '' )));
193 $dbdata = notags(trim(defaults($_POST, 'dbdata', '' )));
194 $phpath = notags(trim(defaults($_POST, 'phpath', '' )));
196 $adminmail = notags(trim(defaults($_POST, 'adminmail', '')));
198 $timezone = defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ);
199 /* Installed langs */
200 $lang_choices = L10n::getAvailableLanguages();
202 $tpl = get_markup_template('install_settings.tpl');
203 $output .= replace_macros($tpl, [
204 '$title' => $install_title,
205 '$checks' => self::$installer->getChecks(),
206 '$pass' => L10n::t('Site settings'),
207 '$dbhost' => $dbhost,
208 '$dbuser' => $dbuser,
209 '$dbpass' => $dbpass,
210 '$dbdata' => $dbdata,
211 '$phpath' => $phpath,
212 '$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'],
213 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
214 '$language' => ['language',
215 L10n::t('System Language:'),
216 Core\Installer::DEFAULT_LANG,
217 L10n::t('Set the default language for your Friendica installation interface and to send emails.'),
219 '$baseurl' => $a->getBaseURL(),
220 '$submit' => L10n::t('Submit')
225 $db_return_text = "";
227 if (count(self::$installer->getChecks()) == 0) {
228 $txt = '<p style="font-size: 130%;">';
229 $txt .= L10n::t('Your Friendica site database has been installed.') . EOL;
230 $db_return_text .= $txt;
233 $tpl = get_markup_template('install_finished.tpl');
234 $output .= replace_macros($tpl, [
235 '$title' => $install_title,
236 '$checks' => self::$installer->getChecks(),
237 '$pass' => L10n::t('Installation finished'),
238 '$text' => $db_return_text . self::whatNext($a),
248 * Creates the text for the next steps
250 * @param App $a The global App
252 * @return string The text for the next steps
254 private static function whatNext($a)
256 $baseurl = $a->getBaseUrl();
258 L10n::t('<h1>What next</h1>')
259 . "<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
260 . L10n::t('Please see the file "INSTALL.txt".')
262 . 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)