From abb39e62f9d1299bd86a56a44f9e868cd435c75c Mon Sep 17 00:00:00 2001 From: Inext68 Date: Wed, 3 Jun 2026 14:21:20 +0200 Subject: [PATCH] 1.0.7 --- install.php | 53 ++++++++++++------- .../919b72ede39b52e755aee01e73b78d3b.php | 5 ++ 2 files changed, 39 insertions(+), 19 deletions(-) create mode 100755 storage/framework/views/919b72ede39b52e755aee01e73b78d3b.php diff --git a/install.php b/install.php index 19ad6f5b..2db9a988 100644 --- a/install.php +++ b/install.php @@ -206,6 +206,19 @@ if (in_array($mode, ['Fresh Install su Apache (LAMP tradizionale)', 'Restore da } } +// ── Web server user detection ───────────────────────── +$wwwUser = 'www-data'; +$sudo = ''; +if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $detected = trim(shell_exec('ps aux | grep -E "apache|httpd" | grep -v grep | head -1 | awk \'{print $1}\'') ?: ''); + if ($detected !== '' && $detected !== 'root') { + $wwwUser = $detected; + } + if (function_exists('posix_getuid') && posix_getuid() === 0) { + $sudo = "sudo -u {$wwwUser} "; + } +} + // ══════════════════════════════════════════════════════ // MODE 1: FRESH INSTALL APACHE // ══════════════════════════════════════════════════════ @@ -251,7 +264,7 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') { } // APP_KEY - runCapture("php artisan key:generate --force"); + runCapture("{$sudo}php artisan key:generate --force"); ok('APP_KEY generata'); // Config @@ -332,7 +345,7 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') { println(color(' 3/7 — INSTALLAZIONE DIPENDENZE', 'yellow')); println(color('══════════════════════════════════════════', 'yellow')); - run('composer install --no-dev --optimize-autoloader', 'Installazione dipendenze Composer...'); + run("{$sudo}composer install --no-dev --optimize-autoloader", 'Installazione dipendenze Composer...'); ok('Dipendenze PHP installate'); // ── Step 4: Package discovery ──────────────────── @@ -341,7 +354,7 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') { println(color(' 4/7 — REGISTRAZIONE PACCHETTI', 'yellow')); println(color('══════════════════════════════════════════', 'yellow')); - runCapture("php artisan package:discover --ansi 2>/dev/null"); + runCapture("{$sudo}php artisan package:discover --ansi 2>/dev/null"); ok('Pacchetti registrati'); // ── Step 5: Schema + Seed ──────────────────────── @@ -362,13 +375,13 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') { } } else { // SQLite fallback: usa le migration (install.sql è solo per MySQL) - if (!run('php artisan migrate --seed --force', 'Esecuzione migration e seed...')) { + if (!run("{$sudo}php artisan migrate --seed --force", 'Esecuzione migration e seed...')) { fail('Migration fallita. Verifica la configurazione SQLite.'); } } ok('Database popolato con struttura e dati base'); - runCapture('php artisan storage:link --force 2>/dev/null'); + runCapture("{$sudo}php artisan storage:link --force 2>/dev/null"); // ── Step 6: Admin user (via PDO — no tinker) ───── println(); @@ -385,12 +398,12 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') { } else { // SQLite: usa seeder (l'admin verrà creato da DatabaseSeeder) // Poi aggiorna la password con quella scelta dall'utente - runCapture("php artisan tinker --execute=" . escapeshellarg( + runCapture("{$sudo}php artisan tinker --execute=" . escapeshellarg( "\$u = \App\Models\User::first(); " . "if (\$u) { " . - "\$u->name = " . var_export($adminName, true) . "; " . - "\$u->email = " . var_export($adminEmail, true) . "; " . - "\$u->password = bcrypt(" . var_export($adminPass, true) . "); " . + "\$u->name = " . var_export(\$adminName, true) . "; " . + "\$u->email = " . var_export(\$adminEmail, true) . "; " . + "\$u->password = bcrypt(" . var_export(\$adminPass, true) . "); " . "\$u->is_admin = true; " . "\$u->status = 'active'; " . "\$u->permissions = " . var_export([ @@ -406,6 +419,10 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') { ok("Amministratore {$adminEmail} configurato"); } + // Clear all caches after schema + admin creation + runCapture("{$sudo}php artisan optimize:clear 2>/dev/null"); + ok('Cache ottimizzate'); + // ── Step 7: Asset ──────────────────────────────── println(); println(color('══════════════════════════════════════════', 'yellow')); @@ -414,8 +431,8 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') { $hasNpm = checkCmd('npm'); if ($hasNpm && confirm('Compilare gli asset frontend con npm?')) { - run('npm install', 'Installazione dipendenze npm...'); - run('npm run build', 'Compilazione asset...'); + run("{$sudo}npm install", 'Installazione dipendenze npm...'); + run("{$sudo}npm run build", 'Compilazione asset...'); ok('Asset compilati'); } else { if (!$hasNpm) warn('npm non disponibile — asset non compilati (AdminLTE via CDN)'); @@ -425,7 +442,6 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') { // ── Permissions ────────────────────────────────── if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { info('Impostazione permessi...'); - $wwwUser = trim(shell_exec('ps aux | grep -E "apache|httpd" | grep -v grep | head -1 | awk \'{print \$1}\'') ?: 'www-data'); runCapture("chown -R {$wwwUser}:{$wwwUser} storage bootstrap/cache 2>/dev/null"); chmod("{$scriptDir}/storage", 0775); chmod("{$scriptDir}/bootstrap/cache", 0775); @@ -691,7 +707,7 @@ if ($mode === 'Restore da Backup (Apache)') { file_put_contents('.env', $dotenv); // Generate APP_KEY - runCapture('php artisan key:generate --force'); + runCapture("{$sudo}php artisan key:generate --force"); ok('APP_KEY rigenerata'); // Import database @@ -721,16 +737,15 @@ if ($mode === 'Restore da Backup (Apache)') { } // Composer - run('composer install --no-dev --optimize-autoloader', 'Installazione dipendenze Composer...'); - runCapture('php artisan package:discover --ansi 2>/dev/null'); + run("{$sudo}composer install --no-dev --optimize-autoloader", 'Installazione dipendenze Composer...'); + runCapture("{$sudo}php artisan package:discover --ansi 2>/dev/null"); // Storage link + cache - runCapture('php artisan storage:link --force 2>/dev/null'); - runCapture('php artisan optimize:clear'); + runCapture("{$sudo}php artisan storage:link --force 2>/dev/null"); + runCapture("{$sudo}php artisan optimize:clear"); // Permissions if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - $wwwUser = trim(shell_exec('ps aux | grep -E "apache|httpd" | grep -v grep | head -1 | awk \'{print \$1}\'') ?: 'www-data'); runCapture("chown -R {$wwwUser}:{$wwwUser} storage bootstrap/cache 2>/dev/null"); chmod("{$scriptDir}/storage", 0775); chmod("{$scriptDir}/bootstrap/cache", 0775); @@ -758,7 +773,7 @@ if ($mode === 'Restore da Backup (Apache)') { } } else { // SQLite fallback: usa tinker - $result = runCapture("php artisan tinker --execute=" . escapeshellarg( + $result = runCapture("{$sudo}php artisan tinker --execute=" . escapeshellarg( "\$e = \App\Models\User::where('email', " . var_export($adminEmail, true) . ")->exists(); " . "if (!\$e) { " . "\$u = new \App\Models\User; " . diff --git a/storage/framework/views/919b72ede39b52e755aee01e73b78d3b.php b/storage/framework/views/919b72ede39b52e755aee01e73b78d3b.php new file mode 100755 index 00000000..be72951d --- /dev/null +++ b/storage/framework/views/919b72ede39b52e755aee01e73b78d3b.php @@ -0,0 +1,5 @@ +startSection('title', __('Page Expired')); ?> +startSection('code', '419'); ?> +startSection('message', __('Page Expired')); ?> + +make('errors::minimal', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?> \ No newline at end of file