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\Core\Renderer;
12 use Friendica\Util\Temporal;
14 class Install extends BaseModule
17 * Step one - System check
19 const SYSTEM_CHECK = 1;
21 * Step two - Database configuration
23 const DATABASE_CONFIG = 2;
25 * Step three - Adapat site settings
27 const SITE_SETTINGS = 3;
29 * Step four - All steps finished
34 * @var int The current step of the wizard
36 private static $currentWizardStep;
39 * @var Core\Installer The installer
41 private static $installer;
43 public static function init()
47 // route: install/testrwrite
48 // $baseurl/install/testrwrite to test if rewrite in .htaccess is working
49 if ($a->getArgumentValue(1, '') == 'testrewrite') {
50 // Status Code 204 means that it worked without content
51 Core\System::httpExit(204);
54 // We overwrite current theme css, because during install we may not have a working mod_rewrite
55 // so we may not have a css at all. Here we set a static css file for the install procedure pages
56 $a->theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css';
58 self::$installer = new Core\Installer();
59 self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK);
62 public static function post()
66 switch (self::$currentWizardStep) {
67 case self::SYSTEM_CHECK:
68 case self::DATABASE_CONFIG:
69 // Nothing to do in these steps
72 case self::SITE_SETTINGS:
73 $dbhost = notags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
74 $dbuser = notags(trim(defaults($_POST, 'dbuser', '')));
75 $dbpass = notags(trim(defaults($_POST, 'dbpass', '')));
76 $dbdata = notags(trim(defaults($_POST, 'dbdata', '')));
78 // If we cannot connect to the database, return to the previous step
79 if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) {
80 self::$currentWizardStep = self::DATABASE_CONFIG;
86 $urlpath = $a->getURLPath();
87 $dbhost = notags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
88 $dbuser = notags(trim(defaults($_POST, 'dbuser', '')));
89 $dbpass = notags(trim(defaults($_POST, 'dbpass', '')));
90 $dbdata = notags(trim(defaults($_POST, 'dbdata', '')));
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;
101 $phpath = self::$installer->getPHPPath();
103 if (!self::$installer->createConfig($phpath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $a->getBasePath())) {
107 self::$installer->installDatabase();
113 public static function content()
119 $install_title = L10n::t('Friendica Communctions Server - Setup');
121 switch (self::$currentWizardStep) {
122 case self::SYSTEM_CHECK:
123 $phppath = defaults($_POST, 'phpath', null);
125 $status = self::$installer->checkEnvironment($a->getBaseURL(), $phppath);
127 $tpl = get_markup_template('install_checks.tpl');
128 $output .= Renderer::replaceMacros($tpl, [
129 '$title' => $install_title,
130 '$pass' => L10n::t('System check'),
131 '$checks' => self::$installer->getChecks(),
132 '$passed' => $status,
133 '$see_install' => L10n::t('Please see the file "Install.txt".'),
134 '$next' => L10n::t('Next'),
135 '$reload' => L10n::t('Check again'),
136 '$phpath' => $phppath,
137 '$baseurl' => $a->getBaseURL()
141 case self::DATABASE_CONFIG:
142 $dbhost = notags(trim(defaults($_POST, 'dbhost' , Core\Installer::DEFAULT_HOST)));
143 $dbuser = notags(trim(defaults($_POST, 'dbuser' , '' )));
144 $dbpass = notags(trim(defaults($_POST, 'dbpass' , '' )));
145 $dbdata = notags(trim(defaults($_POST, 'dbdata' , '' )));
146 $phpath = notags(trim(defaults($_POST, 'phpath' , '' )));
147 $adminmail = notags(trim(defaults($_POST, 'adminmail', '' )));
149 $tpl = get_markup_template('install_db.tpl');
150 $output .= Renderer::replaceMacros($tpl, [
151 '$title' => $install_title,
152 '$pass' => L10n::t('Database connection'),
153 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
154 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
155 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
156 'checks' => self::$installer->getChecks(),
157 '$dbhost' => ['dbhost',
158 L10n::t('Database Server Name'),
162 '$dbuser' => ['dbuser',
163 L10n::t('Database Login Name'),
168 '$dbpass' => ['dbpass',
169 L10n::t('Database Login Password'),
171 L10n::t("For security reasons the password must not be empty"),
173 '$dbdata' => ['dbdata',
174 L10n::t('Database Name'),
178 '$adminmail' => ['adminmail',
179 L10n::t('Site administrator email address'),
181 L10n::t('Your account email address must match this in order to use the web admin panel.'),
185 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
186 '$baseurl' => $a->getBaseURL(),
187 '$phpath' => $phpath,
188 '$submit' => L10n::t('Submit')
192 case self::SITE_SETTINGS:
193 $dbhost = notags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
194 $dbuser = notags(trim(defaults($_POST, 'dbuser', '' )));
195 $dbpass = notags(trim(defaults($_POST, 'dbpass', '' )));
196 $dbdata = notags(trim(defaults($_POST, 'dbdata', '' )));
197 $phpath = notags(trim(defaults($_POST, 'phpath', '' )));
199 $adminmail = notags(trim(defaults($_POST, 'adminmail', '')));
201 $timezone = defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ);
202 /* Installed langs */
203 $lang_choices = L10n::getAvailableLanguages();
205 $tpl = get_markup_template('install_settings.tpl');
206 $output .= Renderer::replaceMacros($tpl, [
207 '$title' => $install_title,
208 '$checks' => self::$installer->getChecks(),
209 '$pass' => L10n::t('Site settings'),
210 '$dbhost' => $dbhost,
211 '$dbuser' => $dbuser,
212 '$dbpass' => $dbpass,
213 '$dbdata' => $dbdata,
214 '$phpath' => $phpath,
215 '$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'],
216 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
217 '$language' => ['language',
218 L10n::t('System Language:'),
219 Core\Installer::DEFAULT_LANG,
220 L10n::t('Set the default language for your Friendica installation interface and to send emails.'),
222 '$baseurl' => $a->getBaseURL(),
223 '$submit' => L10n::t('Submit')
228 $db_return_text = "";
230 if (count(self::$installer->getChecks()) == 0) {
231 $txt = '<p style="font-size: 130%;">';
232 $txt .= L10n::t('Your Friendica site database has been installed.') . EOL;
233 $db_return_text .= $txt;
236 $tpl = get_markup_template('install_finished.tpl');
237 $output .= Renderer::replaceMacros($tpl, [
238 '$title' => $install_title,
239 '$checks' => self::$installer->getChecks(),
240 '$pass' => L10n::t('Installation finished'),
241 '$text' => $db_return_text . self::whatNext($a),
251 * Creates the text for the next steps
253 * @param App $a The global App
255 * @return string The text for the next steps
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)