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\Strings;
13 use Friendica\Util\Temporal;
15 class Install extends BaseModule
18 * Step one - System check
20 const SYSTEM_CHECK = 1;
22 * Step two - Database configuration
24 const DATABASE_CONFIG = 2;
26 * Step three - Adapat site settings
28 const SITE_SETTINGS = 3;
30 * Step four - All steps finished
35 * @var int The current step of the wizard
37 private static $currentWizardStep;
40 * @var Core\Installer The installer
42 private static $installer;
44 public static function init()
48 // route: install/testrwrite
49 // $baseurl/install/testrwrite to test if rewrite in .htaccess is working
50 if ($a->getArgumentValue(1, '') == 'testrewrite') {
51 // Status Code 204 means that it worked without content
52 Core\System::httpExit(204);
55 // We overwrite current theme css, because during install we may not have a working mod_rewrite
56 // so we may not have a css at all. Here we set a static css file for the install procedure pages
57 Renderer::$theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css';
59 self::$installer = new Core\Installer();
60 self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK);
63 public static function post()
67 switch (self::$currentWizardStep) {
68 case self::SYSTEM_CHECK:
69 case self::DATABASE_CONFIG:
70 // Nothing to do in these steps
73 case self::SITE_SETTINGS:
74 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
75 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '')));
76 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '')));
77 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '')));
79 // If we cannot connect to the database, return to the previous step
80 if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) {
81 self::$currentWizardStep = self::DATABASE_CONFIG;
87 $urlpath = $a->getURLPath();
88 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
89 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '')));
90 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '')));
91 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '')));
92 $timezone = Strings::escapeTags(trim(defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ)));
93 $language = Strings::escapeTags(trim(defaults($_POST, 'language', Core\Installer::DEFAULT_LANG)));
94 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '')));
96 // If we cannot connect to the database, return to the Database config wizard
97 if (!self::$installer->checkDB($dbhost, $dbuser, $dbpass, $dbdata)) {
98 self::$currentWizardStep = self::DATABASE_CONFIG;
102 $phpath = self::$installer->getPHPPath();
104 if (!self::$installer->createConfig($phpath, $urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $timezone, $language, $adminmail, $a->getBasePath())) {
108 self::$installer->installDatabase();
114 public static function content()
120 $install_title = L10n::t('Friendica Communications Server - Setup');
122 switch (self::$currentWizardStep) {
123 case self::SYSTEM_CHECK:
124 $phppath = defaults($_POST, 'phpath', null);
126 $status = self::$installer->checkEnvironment($a->getBaseURL(), $phppath);
128 $tpl = Renderer::getMarkupTemplate('install_checks.tpl');
129 $output .= Renderer::replaceMacros($tpl, [
130 '$title' => $install_title,
131 '$pass' => L10n::t('System check'),
132 '$checks' => self::$installer->getChecks(),
133 '$passed' => $status,
134 '$see_install' => L10n::t('Please see the file "INSTALL.txt".'),
135 '$next' => L10n::t('Next'),
136 '$reload' => L10n::t('Check again'),
137 '$phpath' => $phppath,
138 '$baseurl' => $a->getBaseURL()
142 case self::DATABASE_CONFIG:
143 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost' , Core\Installer::DEFAULT_HOST)));
144 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser' , '' )));
145 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass' , '' )));
146 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata' , '' )));
147 $phpath = Strings::escapeTags(trim(defaults($_POST, 'phpath' , '' )));
148 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '' )));
150 $tpl = Renderer::getMarkupTemplate('install_db.tpl');
151 $output .= Renderer::replaceMacros($tpl, [
152 '$title' => $install_title,
153 '$pass' => L10n::t('Database connection'),
154 '$info_01' => L10n::t('In order to install Friendica we need to know how to connect to your database.'),
155 '$info_02' => L10n::t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
156 '$info_03' => L10n::t('The database you specify below should already exist. If it does not, please create it before continuing.'),
157 'checks' => self::$installer->getChecks(),
158 '$dbhost' => ['dbhost',
159 L10n::t('Database Server Name'),
163 '$dbuser' => ['dbuser',
164 L10n::t('Database Login Name'),
169 '$dbpass' => ['dbpass',
170 L10n::t('Database Login Password'),
172 L10n::t("For security reasons the password must not be empty"),
174 '$dbdata' => ['dbdata',
175 L10n::t('Database Name'),
179 '$adminmail' => ['adminmail',
180 L10n::t('Site administrator email address'),
182 L10n::t('Your account email address must match this in order to use the web admin panel.'),
186 '$lbl_10' => L10n::t('Please select a default timezone for your website'),
187 '$baseurl' => $a->getBaseURL(),
188 '$phpath' => $phpath,
189 '$submit' => L10n::t('Submit')
193 case self::SITE_SETTINGS:
194 $dbhost = Strings::escapeTags(trim(defaults($_POST, 'dbhost', Core\Installer::DEFAULT_HOST)));
195 $dbuser = Strings::escapeTags(trim(defaults($_POST, 'dbuser', '' )));
196 $dbpass = Strings::escapeTags(trim(defaults($_POST, 'dbpass', '' )));
197 $dbdata = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '' )));
198 $phpath = Strings::escapeTags(trim(defaults($_POST, 'phpath', '' )));
200 $adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '')));
202 $timezone = defaults($_POST, 'timezone', Core\Installer::DEFAULT_TZ);
203 /* Installed langs */
204 $lang_choices = L10n::getAvailableLanguages();
206 $tpl = Renderer::getMarkupTemplate('install_settings.tpl');
207 $output .= Renderer::replaceMacros($tpl, [
208 '$title' => $install_title,
209 '$checks' => self::$installer->getChecks(),
210 '$pass' => L10n::t('Site settings'),
211 '$dbhost' => $dbhost,
212 '$dbuser' => $dbuser,
213 '$dbpass' => $dbpass,
214 '$dbdata' => $dbdata,
215 '$phpath' => $phpath,
216 '$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'],
217 '$timezone' => Temporal::getTimezoneField('timezone', L10n::t('Please select a default timezone for your website'), $timezone, ''),
218 '$language' => ['language',
219 L10n::t('System Language:'),
220 Core\Installer::DEFAULT_LANG,
221 L10n::t('Set the default language for your Friendica installation interface and to send emails.'),
223 '$baseurl' => $a->getBaseURL(),
224 '$submit' => L10n::t('Submit')
229 $db_return_text = "";
231 if (count(self::$installer->getChecks()) == 0) {
232 $txt = '<p style="font-size: 130%;">';
233 $txt .= L10n::t('Your Friendica site database has been installed.') . EOL;
234 $db_return_text .= $txt;
237 $tpl = Renderer::getMarkupTemplate('install_finished.tpl');
238 $output .= Renderer::replaceMacros($tpl, [
239 '$title' => $install_title,
240 '$checks' => self::$installer->getChecks(),
241 '$pass' => L10n::t('Installation finished'),
242 '$text' => $db_return_text . self::whatNext($a),
252 * Creates the text for the next steps
254 * @param App $a The global App
256 * @return string The text for the next steps
257 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
259 private static function whatNext($a)
261 $baseurl = $a->getBaseUrl();
263 L10n::t('<h1>What next</h1>')
264 . "<p>".L10n::t('IMPORTANT: You will need to [manually] setup a scheduled task for the worker.')
265 . L10n::t('Please see the file "INSTALL.txt".')
267 . 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)