3 namespace Friendica\Module;
6 use Friendica\BaseModule;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Renderer;
10 use Friendica\Util\Strings;
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 Renderer::$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 = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
73 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '')));
74 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '')));
75 $dbdata = Strings::escapeTags(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 = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
87 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '')));
88 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '')));
89 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '')));
90 $timezone = Strings::escapeTags(trim(defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ)));
91 $language = Strings::escapeTags(trim(defaults($_POST, 'language', Core\Installer::DEFAULT_LANG)));
92 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '')));
94 // If we cannot connect to the database, return to the Database config wizard
95 if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) {
96 self::$currentWizardStep = self::DATABASE_CONFIG;
100 $phpath = self::$installer->getPHPPath();
102 if (!self::$installer->createConfig($phpath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $a->getBasePath())) {
106 self::$installer->installDatabase();
112 public static function content()
118 $install_title = L10n::t('Friendica Communications Server - Setup');
120 switch (self::$currentWizardStep) {
121 case self::SYSTEM_CHECK:
122 $phppath = defaults($_POST, 'phpath', null);
124 $status = self::$installer->checkEnvironment($a->getBaseURL(), $phppath);
126 $tpl = Renderer::getMarkupTemplate('install_checks.tpl');
127 $output .= Renderer::replaceMacros($tpl, [
128 '$title' => $install_title,
129 '$pass' => L10n::t('System check'),
130 '$checks' => self::$installer->getChecks(),
131 '$passed' => $status,
132 '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
133 '$next' => L10n::t('Next'),
134 '$reload' => L10n::t('Check again'),
135 '$phpath' => $phppath,
136 '$baseurl' => $a->getBaseURL()
140 case self::DATABASE_CONFIG:
141 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost' , Core\Installer::DEFAULT_HOST)));
142 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser' , '' )));
143 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass' , '' )));
144 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata' , '' )));
145 $phpath = Strings::escapeTags(trim(defaults($_POST, 'phpath' , '' )));
146 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '' )));
148 $tpl = Renderer::getMarkupTemplate('install_db.tpl');
149 $output .= Renderer::replaceMacros($tpl, [
150 '$title' => $install_title,
151 '$pass' => L10n::t('Database connection'),
152 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
153 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
154 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
155 'checks' => self::$installer->getChecks(),
156 '$dbhost' => ['dbhost',
157 L10n::t('Database Server Name'),
161 '$dbuser' => ['dbuser',
162 L10n::t('Database Login Name'),
167 '$dbpass' => ['dbpass',
168 L10n::t('Database Login Password'),
170 L10n::t("For security reasons the password must not be empty"),
172 '$dbdata' => ['dbdata',
173 L10n::t('Database Name'),
177 '$adminmail' => ['adminmail',
178 L10n::t('Site administrator email address'),
180 L10n::t('Your account email address must match this in order to use the web admin panel.'),
184 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
185 '$baseurl' => $a->getBaseURL(),
186 '$phpath' => $phpath,
187 '$submit' => L10n::t('Submit')
191 case self::SITE_SETTINGS:
192 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
193 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '' )));
194 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '' )));
195 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '' )));
196 $phpath = Strings::escapeTags(trim(defaults($_POST, 'phpath', '' )));
198 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '')));
200 $timezone = defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ);
201 /* Installed langs */
202 $lang_choices = L10n::getAvailableLanguages();
204 $tpl = Renderer::getMarkupTemplate('install_settings.tpl');
205 $output .= Renderer::replaceMacros($tpl, [
206 '$title' => $install_title,
207 '$checks' => self::$installer->getChecks(),
208 '$pass' => L10n::t('Site settings'),
209 '$dbhost' => $dbhost,
210 '$dbuser' => $dbuser,
211 '$dbpass' => $dbpass,
212 '$dbdata' => $dbdata,
213 '$phpath' => $phpath,
214 '$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'],
215 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
216 '$language' => ['language',
217 L10n::t('System Language:'),
218 Core\Installer::DEFAULT_LANG,
219 L10n::t('Set the default language for your Friendica installation interface and to send emails.'),
221 '$baseurl' => $a->getBaseURL(),
222 '$submit' => L10n::t('Submit')
227 $db_return_text = "";
229 if (count(self::$installer->getChecks()) == 0) {
230 $txt = '<p style="font-size: 130%;">';
231 $txt .= L10n::t('Your Friendica site database has been installed.') . EOL;
232 $db_return_text .= $txt;
235 $tpl = Renderer::getMarkupTemplate('install_finished.tpl');
236 $output .= Renderer::replaceMacros($tpl, [
237 '$title' => $install_title,
238 '$checks' => self::$installer->getChecks(),
239 '$pass' => L10n::t('Installation finished'),
240 '$text' => $db_return_text . self::whatNext($a),
250 * Creates the text for the next steps
252 * @param App $a The global App
254 * @return string The text for the next steps
255 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
257 private static function whatNext($a)
259 $baseurl = $a->getBaseUrl();
261 L10n::t('<h1>What next</h1>')
262 . "<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
263 . L10n::t('Please see the file "INSTALL.txt".')
265 . 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)