Преглед изворни кода

Added checks in the installer

Sergio Brighenti пре 6 година
родитељ
комит
535fce4f8f

+ 7 - 5
.htaccess

@@ -1,6 +1,8 @@
 Options -Indexes
 Options -Indexes
-RewriteEngine On
-RewriteRule ^(app|bin|bootstrap|resources|storage|vendor|logs)(/.*|)$ - [NC,F]
-RewriteCond %{REQUEST_FILENAME} !-f
-RewriteCond %{REQUEST_FILENAME} !-d
-RewriteRule ^(.*)$ index.php [QSA,L]
+<IfModule mod_rewrite.c>
+    RewriteEngine On
+    RewriteRule ^(app|bin|bootstrap|resources|storage|vendor|logs)(/.*|)$ - [NC,F]
+    RewriteCond %{REQUEST_FILENAME} !-f
+    RewriteCond %{REQUEST_FILENAME} !-d
+    RewriteRule ^(.*)$ index.php [QSA,L]
+</IfModule>

+ 5 - 0
app/Controllers/DashboardController.php

@@ -128,6 +128,11 @@ class DashboardController extends Controller
 
 
 	public function applyTheme(Request $request, Response $response): Response
 	public function applyTheme(Request $request, Response $response): Response
 	{
 	{
+		if (!is_writable('static/bootstrap/css/bootstrap.min.css')) {
+			Session::alert(lang('cannot_write_file'), 'danger');
+			return redirect($response, route('system'));
+		}
+
 		file_put_contents('static/bootstrap/css/bootstrap.min.css', file_get_contents($request->getParam('css')));
 		file_put_contents('static/bootstrap/css/bootstrap.min.css', file_get_contents($request->getParam('css')));
 		return redirect($response, 'system')
 		return redirect($response, 'system')
 			->withAddedHeader('Cache-Control', 'no-cache, no-store, must-revalidate')
 			->withAddedHeader('Cache-Control', 'no-cache, no-store, must-revalidate')

+ 11 - 2
install/index.php

@@ -131,8 +131,16 @@ $app->post('/', function (Request $request, Response $response) use (&$config) {
 		$config['db']['username'] = $request->getParam('db_user');
 		$config['db']['username'] = $request->getParam('db_user');
 		$config['db']['password'] = $request->getParam('db_password');
 		$config['db']['password'] = $request->getParam('db_password');
 
 
+		if (!is_writable($config['storage_dir'])) {
+			Session::alert('The storage folder is not writable (' . $config['storage_dir'] . ')', 'danger');
+			return redirect($response, '.');
+		}
 
 
-		file_put_contents(__DIR__ . '/../config.php', '<?php' . PHP_EOL . 'return ' . var_export($config, true) . ';');
+		$ret = file_put_contents(__DIR__ . '/../config.php', '<?php' . PHP_EOL . 'return ' . var_export($config, true) . ';');
+		if ($ret === false) {
+			Session::alert('The config folder is not writable (' . __DIR__ . '/../config.php' . ')', 'danger');
+			return redirect($response, '.');
+		}
 	}
 	}
 
 
 	$dsn = $config['db']['connection'] === 'sqlite' ? __DIR__ . '/../' . $config['db']['dsn'] : $config['db']['dsn'];
 	$dsn = $config['db']['connection'] === 'sqlite' ? __DIR__ . '/../' . $config['db']['dsn'] : $config['db']['dsn'];
@@ -142,7 +150,8 @@ $app->post('/', function (Request $request, Response $response) use (&$config) {
 
 
 		migrate($config);
 		migrate($config);
 	} catch (PDOException $exception) {
 	} catch (PDOException $exception) {
-
+		Session::alert("Cannot connect to the database: {$exception->getMessage()} [{$exception->getCode()}]", 'danger');
+		return redirect($response, '.');
 	}
 	}
 
 
 	if (!$installed) {
 	if (!$installed) {

+ 8 - 0
install/templates/install.twig

@@ -19,6 +19,14 @@
 </head>
 </head>
 <body>
 <body>
 <div class="container">
 <div class="container">
+    {% for type, message in alerts %}
+        <div class="alert alert-{{ type }} alert-dismissible fade show" role="alert">
+            {{ message }}
+            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
+                <span aria-hidden="true">&times;</span>
+            </button>
+        </div>
+    {% endfor %}
     <div class="row justify-content-center">
     <div class="row justify-content-center">
         <div class="col-md-8">
         <div class="col-md-8">
             <div class="card mt-3">
             <div class="card mt-3">

+ 1 - 0
resources/lang/en.lang.php

@@ -84,4 +84,5 @@ return [
 	'user_deleted' => 'User deleted.',
 	'user_deleted' => 'User deleted.',
 	'cannot_delete' => 'You cannot delete yourself.',
 	'cannot_delete' => 'You cannot delete yourself.',
 	'cannot_demote' => 'You cannot demote yourself.',
 	'cannot_demote' => 'You cannot demote yourself.',
+	'cannot_write_file' => 'The destination path is not writable.',
 ];
 ];

+ 1 - 0
resources/lang/it.lang.php

@@ -84,4 +84,5 @@ return [
 	'user_deleted' => 'Utente rimosso.',
 	'user_deleted' => 'Utente rimosso.',
 	'cannot_delete' => 'Non puoi eliminare te stesso.',
 	'cannot_delete' => 'Non puoi eliminare te stesso.',
 	'cannot_demote' => 'Non puoi degradare te stesso. ',
 	'cannot_demote' => 'Non puoi degradare te stesso. ',
+	'cannot_write_file' => 'Il percorso di destinazione non è scrivibile.',
 ];
 ];