aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controller/visitor/InstallController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/front/controller/visitor/InstallController.php')
-rw-r--r--application/front/controller/visitor/InstallController.php44
1 files changed, 31 insertions, 13 deletions
diff --git a/application/front/controller/visitor/InstallController.php b/application/front/controller/visitor/InstallController.php
index 7cb32777..418d4a49 100644
--- a/application/front/controller/visitor/InstallController.php
+++ b/application/front/controller/visitor/InstallController.php
@@ -4,10 +4,10 @@ declare(strict_types=1);
4 4
5namespace Shaarli\Front\Controller\Visitor; 5namespace Shaarli\Front\Controller\Visitor;
6 6
7use Shaarli\ApplicationUtils;
8use Shaarli\Container\ShaarliContainer; 7use Shaarli\Container\ShaarliContainer;
9use Shaarli\Front\Exception\AlreadyInstalledException; 8use Shaarli\Front\Exception\AlreadyInstalledException;
10use Shaarli\Front\Exception\ResourcePermissionException; 9use Shaarli\Front\Exception\ResourcePermissionException;
10use Shaarli\Helper\ApplicationUtils;
11use Shaarli\Languages; 11use Shaarli\Languages;
12use Shaarli\Security\SessionManager; 12use Shaarli\Security\SessionManager;
13use Slim\Http\Request; 13use Slim\Http\Request;
@@ -39,7 +39,8 @@ class InstallController extends ShaarliVisitorController
39 // Before installation, we'll make sure that permissions are set properly, and sessions are working. 39 // Before installation, we'll make sure that permissions are set properly, and sessions are working.
40 $this->checkPermissions(); 40 $this->checkPermissions();
41 41
42 if (static::SESSION_TEST_VALUE 42 if (
43 static::SESSION_TEST_VALUE
43 !== $this->container->sessionManager->getSessionParameter(static::SESSION_TEST_KEY) 44 !== $this->container->sessionManager->getSessionParameter(static::SESSION_TEST_KEY)
44 ) { 45 ) {
45 $this->container->sessionManager->setSessionParameter(static::SESSION_TEST_KEY, static::SESSION_TEST_VALUE); 46 $this->container->sessionManager->setSessionParameter(static::SESSION_TEST_KEY, static::SESSION_TEST_VALUE);
@@ -53,6 +54,21 @@ class InstallController extends ShaarliVisitorController
53 $this->assignView('cities', $cities); 54 $this->assignView('cities', $cities);
54 $this->assignView('languages', Languages::getAvailableLanguages()); 55 $this->assignView('languages', Languages::getAvailableLanguages());
55 56
57 $phpEol = new \DateTimeImmutable(ApplicationUtils::getPhpEol(PHP_VERSION));
58
59 $permissions = array_merge(
60 ApplicationUtils::checkResourcePermissions($this->container->conf),
61 ApplicationUtils::checkDatastoreMutex()
62 );
63
64 $this->assignView('php_version', PHP_VERSION);
65 $this->assignView('php_eol', format_date($phpEol, false));
66 $this->assignView('php_has_reached_eol', $phpEol < new \DateTimeImmutable());
67 $this->assignView('php_extensions', ApplicationUtils::getPhpExtensionsRequirement());
68 $this->assignView('permissions', $permissions);
69
70 $this->assignView('pagetitle', t('Install Shaarli'));
71
56 return $response->write($this->render('install')); 72 return $response->write($this->render('install'));
57 } 73 }
58 74
@@ -65,17 +81,18 @@ class InstallController extends ShaarliVisitorController
65 // This part makes sure sessions works correctly. 81 // This part makes sure sessions works correctly.
66 // (Because on some hosts, session.save_path may not be set correctly, 82 // (Because on some hosts, session.save_path may not be set correctly,
67 // or we may not have write access to it.) 83 // or we may not have write access to it.)
68 if (static::SESSION_TEST_VALUE 84 if (
85 static::SESSION_TEST_VALUE
69 !== $this->container->sessionManager->getSessionParameter(static::SESSION_TEST_KEY) 86 !== $this->container->sessionManager->getSessionParameter(static::SESSION_TEST_KEY)
70 ) { 87 ) {
71 // Step 2: Check if data in session is correct. 88 // Step 2: Check if data in session is correct.
72 $msg = t( 89 $msg = t(
73 '<pre>Sessions do not seem to work correctly on your server.<br>'. 90 '<pre>Sessions do not seem to work correctly on your server.<br>' .
74 'Make sure the variable "session.save_path" is set correctly in your PHP config, '. 91 'Make sure the variable "session.save_path" is set correctly in your PHP config, ' .
75 'and that you have write access to it.<br>'. 92 'and that you have write access to it.<br>' .
76 'It currently points to %s.<br>'. 93 'It currently points to %s.<br>' .
77 'On some browsers, accessing your server via a hostname like \'localhost\' '. 94 'On some browsers, accessing your server via a hostname like \'localhost\' ' .
78 'or any custom hostname without a dot causes cookie storage to fail. '. 95 'or any custom hostname without a dot causes cookie storage to fail. ' .
79 'We recommend accessing your server via it\'s IP address or Fully Qualified Domain Name.<br>' 96 'We recommend accessing your server via it\'s IP address or Fully Qualified Domain Name.<br>'
80 ); 97 );
81 $msg = sprintf($msg, $this->container->sessionManager->getSavePath()); 98 $msg = sprintf($msg, $this->container->sessionManager->getSavePath());
@@ -94,7 +111,8 @@ class InstallController extends ShaarliVisitorController
94 public function save(Request $request, Response $response): Response 111 public function save(Request $request, Response $response): Response
95 { 112 {
96 $timezone = 'UTC'; 113 $timezone = 'UTC';
97 if (!empty($request->getParam('continent')) 114 if (
115 !empty($request->getParam('continent'))
98 && !empty($request->getParam('city')) 116 && !empty($request->getParam('city'))
99 && isTimeZoneValid($request->getParam('continent'), $request->getParam('city')) 117 && isTimeZoneValid($request->getParam('continent'), $request->getParam('city'))
100 ) { 118 ) {
@@ -104,7 +122,7 @@ class InstallController extends ShaarliVisitorController
104 122
105 $login = $request->getParam('setlogin'); 123 $login = $request->getParam('setlogin');
106 $this->container->conf->set('credentials.login', $login); 124 $this->container->conf->set('credentials.login', $login);
107 $salt = sha1(uniqid('', true) .'_'. mt_rand()); 125 $salt = sha1(uniqid('', true) . '_' . mt_rand());
108 $this->container->conf->set('credentials.salt', $salt); 126 $this->container->conf->set('credentials.salt', $salt);
109 $this->container->conf->set('credentials.hash', sha1($request->getParam('setpassword') . $login . $salt)); 127 $this->container->conf->set('credentials.hash', sha1($request->getParam('setpassword') . $login . $salt));
110 128
@@ -113,7 +131,7 @@ class InstallController extends ShaarliVisitorController
113 } else { 131 } else {
114 $this->container->conf->set( 132 $this->container->conf->set(
115 'general.title', 133 'general.title',
116 'Shared bookmarks on '.escape(index_url($this->container->environment)) 134 'Shared bookmarks on ' . escape(index_url($this->container->environment))
117 ); 135 );
118 } 136 }
119 137
@@ -150,7 +168,7 @@ class InstallController extends ShaarliVisitorController
150 protected function checkPermissions(): bool 168 protected function checkPermissions(): bool
151 { 169 {
152 // Ensure Shaarli has proper access to its resources 170 // Ensure Shaarli has proper access to its resources
153 $errors = ApplicationUtils::checkResourcePermissions($this->container->conf); 171 $errors = ApplicationUtils::checkResourcePermissions($this->container->conf, true);
154 if (empty($errors)) { 172 if (empty($errors)) {
155 return true; 173 return true;
156 } 174 }