diff --git a/.htaccess b/.htaccess index 6db69bfe..d808e49a 100755 --- a/.htaccess +++ b/.htaccess @@ -34,7 +34,7 @@ Options -Indexes RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] - RewriteRule ^(.*)$ public/$1 [L] + #RewriteRule ^(.*)$ public/$1 [L] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . diff --git a/app/Http/Middleware/InstalledCheck.php b/app/Http/Middleware/InstalledCheck.php index 1ba9264d..ff08a3e0 100644 --- a/app/Http/Middleware/InstalledCheck.php +++ b/app/Http/Middleware/InstalledCheck.php @@ -6,16 +6,26 @@ namespace App\Http\Middleware; use Closure; +use Illuminate\Http\Request; class InstalledCheck { /** * Check the app.key to see whether we're installed or not * + * If the default key is set and we're not in any of the installer routes + * show the message that we need to be installed + * + * @param Request $request + * @param Closure $next + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed */ - public function handle($request, Closure $next) + public function handle(Request $request, Closure $next) { - if (config('app.key') === 'NOT_INSTALLED') { + if (config('app.key') === 'base64:zdgcDqu9PM8uGWCtMxd74ZqdGJIrnw812oRMmwDF6KY=' + && !$request->is(['install', 'install/*']) + && !$request->is(['update', 'update/*']) + ) { return view('system.errors.not_installed'); } diff --git a/app/helpers.php b/app/helpers.php index 53ff1198..042b1dd6 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -14,3 +14,17 @@ if (!function_exists('setting')) { return $settingRepo->retrieve($key); } } + +/** + * Wrap the asset URL in the publicBaseUrl that's been + * set + */ +if (!function_exists('public_asset')) { + function public_asset($path, $parameters = [], $secure = null) + { + $publicBaseUrl = app()->publicUrlPath(); + $path = $publicBaseUrl . $path; + + return url($path, $parameters, $secure); + } +} diff --git a/bootstrap/application.php b/bootstrap/application.php index e2c422fc..6f9afbd6 100644 --- a/bootstrap/application.php +++ b/bootstrap/application.php @@ -12,7 +12,8 @@ if (!defined('DS')) { */ class Application extends LaravelApplication { - private $publicPath; + private $publicDirPath, + $publicUrlPath = '/'; public function __construct(string $basePath = null) { @@ -48,9 +49,32 @@ class Application extends LaravelApplication * Override paths */ - public function setPublicPath($publicPath) + public function setPublicPath($publicDirPath) { - $this->publicPath = $publicPath; + $this->publicDirPath = $publicDirPath; + } + + /** + * Added for the custom filesystem driver. Used in the index.php + * in the root of the install to set it to point to /public, + * instead of just / + * + * @param $publicUrlPath + */ + public function setPublicUrlPath($publicUrlPath) + { + $this->publicUrlPath = $publicUrlPath; + } + + /** + * Added for the custom filesystem driver lookup on what to use + * for the base URL + * + * @return string + */ + public function publicUrlPath() + { + return $this->publicUrlPath ?: '/'; } public function configPath($path = '') @@ -70,7 +94,7 @@ class Application extends LaravelApplication public function publicPath() { - return $this->publicPath ?: $this->basePath . DS . 'public'; + return $this->publicDirPath ?: $this->basePath . DS . 'public'; } public function resourcePath($path = '') diff --git a/config/app.php b/config/app.php index e929fa06..a3692c44 100755 --- a/config/app.php +++ b/config/app.php @@ -12,7 +12,9 @@ return [ 'locale' => env('APP_LOCALE', 'en'), 'fallback_locale' => 'en', - 'key' => env('APP_KEY', 'NOT_INSTALLED'), + # Is the default key cipher. Needs to be changed, otherwise phpVMS will think + # that it isn't installed. Doubles as a security feature, so keys are scrambled + 'key' => env('APP_KEY', 'base64:zdgcDqu9PM8uGWCtMxd74ZqdGJIrnw812oRMmwDF6KY='), 'cipher' => 'AES-256-CBC', 'log' => env('APP_LOG', 'daily'), @@ -71,6 +73,7 @@ return [ App\Providers\AuthServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, + Nwidart\Modules\LaravelModulesServiceProvider::class, ], 'aliases' => [ diff --git a/index.php b/index.php index 33e3cd1f..889788ea 100755 --- a/index.php +++ b/index.php @@ -9,7 +9,9 @@ $path_to_phpvms_folder = __DIR__; require $path_to_phpvms_folder.'/bootstrap/autoload.php'; $app = require_once $path_to_phpvms_folder.'/bootstrap/app.php'; + $app->setPublicPath(__DIR__ . '/public'); +$app->setPublicUrlPath(env('APP_PUBLIC_URL', '/public')); $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); diff --git a/modules/Installer/Config/config.php b/modules/Installer/Config/config.php index 7c70537c..500d7ba4 100644 --- a/modules/Installer/Config/config.php +++ b/modules/Installer/Config/config.php @@ -5,8 +5,6 @@ return [ 'version' => '7.0.0' ], - 'env_filename' => 'env.php', - 'extensions' => [ 'openssl', 'pdo', diff --git a/modules/Installer/Http/Controllers/InstallerController.php b/modules/Installer/Http/Controllers/InstallerController.php index 2124c6ec..810dd320 100644 --- a/modules/Installer/Http/Controllers/InstallerController.php +++ b/modules/Installer/Http/Controllers/InstallerController.php @@ -12,6 +12,8 @@ use Modules\Installer\Services\DatabaseService; use Modules\Installer\Services\EnvironmentService; use Modules\Installer\Services\RequirementsService; +use Symfony\Component\HttpFoundation\File\Exception\FileException; + class InstallerController extends AppBaseController { @@ -31,7 +33,7 @@ class InstallerController extends AppBaseController */ public function index() { - if(config('app.key') !== 'NOT_INSTALLED') { + if(config('app.key') !== 'base64:zdgcDqu9PM8uGWCtMxd74ZqdGJIrnw812oRMmwDF6KY=') { return view('installer::errors/already-installed'); } @@ -127,14 +129,19 @@ class InstallerController extends AppBaseController { Log::info('ENV setup', $request->toArray()); - $this->envService->createEnvFile( - $request->input('db_conn'), - $request->input('db_host'), - $request->input('db_port'), - $request->input('db_name'), - $request->input('db_user'), - $request->input('db_pass') - ); + try { + $this->envService->createEnvFile( + $request->input('db_conn'), + $request->input('db_host'), + $request->input('db_port'), + $request->input('db_name'), + $request->input('db_user'), + $request->input('db_pass') + ); + } catch(FileException $e) { + flash()->error($e->getMessage()); + return redirect(route('installer.step2')); + } # Needs to redirect so it can load the new .env Log::info('Redirecting to database setup'); diff --git a/modules/Installer/Resources/views/app.blade.php b/modules/Installer/Resources/views/app.blade.php index ce188121..ebd122cc 100644 --- a/modules/Installer/Resources/views/app.blade.php +++ b/modules/Installer/Resources/views/app.blade.php @@ -14,9 +14,9 @@ - - - + + + {{----}}
@@ -68,7 +68,7 @@ {{----}} - + {{----}} {{----}} diff --git a/modules/Installer/Services/EnvironmentService.php b/modules/Installer/Services/EnvironmentService.php index a0334316..849182e6 100644 --- a/modules/Installer/Services/EnvironmentService.php +++ b/modules/Installer/Services/EnvironmentService.php @@ -4,6 +4,10 @@ namespace Modules\Installer\Services; use Illuminate\Encryption\Encrypter; use Log; +use Symfony\Component\Filesystem\Exception\IOException; +use Symfony\Component\HttpFoundation\File\Exception\FileException; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Filesystem\Exception\IOExceptionInterface; class EnvironmentService { @@ -51,11 +55,7 @@ class EnvironmentService if(\extension_loaded('apc')) { $opts['CACHE_DRIVER'] = 'apc'; } else { - if($opts['APP_ENV'] === 'dev') { - $opts['CACHE_DRIVER'] = 'array'; - } else { - $opts['CACHE_DRIVER'] = 'file'; - } + $opts['CACHE_DRIVER'] = 'array'; } return $opts; @@ -83,17 +83,26 @@ class EnvironmentService /** * Get the template file name and write it out * @param $opts + * @throws \Symfony\Component\HttpFoundation\File\Exception\FileException */ protected function writeEnvFile($opts) { - $env_file = \App::environmentPath(); - $env_file .= config('installer.env_filename'); + $env_file = \App::environmentFilePath(); + + if(file_exists($env_file) && !is_writable($env_file)) { + Log::error('Permissions on existing env.php is not writable'); + throw new FileException('Can\'t write to the env.php file! Check the permissions'); + } + + $fp = fopen($env_file, 'wb'); + if($fp === false) { + throw new FileException('Couldn\'t write the env.php. (' . error_get_last() .')'); + } # render it within Blade and log the contents $env_contents = view('installer::stubs/env', $opts); Log::info($env_contents); - $fp = fopen($env_file, 'w'); fwrite($fp, $env_contents); fclose($fp); } diff --git a/modules/Installer/Services/RequirementsService.php b/modules/Installer/Services/RequirementsService.php index 8c202715..4bc310a6 100644 --- a/modules/Installer/Services/RequirementsService.php +++ b/modules/Installer/Services/RequirementsService.php @@ -48,6 +48,8 @@ class RequirementsService { */ public function checkPermissions(): array { + clearstatcache(); + $directories = []; foreach (config('installer.permissions') as $dir) { diff --git a/resources/views/admin/app.blade.php b/resources/views/admin/app.blade.php index 1e38d2f5..6508559d 100644 --- a/resources/views/admin/app.blade.php +++ b/resources/views/admin/app.blade.php @@ -8,14 +8,13 @@ - + - - {{--{!! Html::style(url('/assets/admin/css/vendor.min.css')) !!}--}} - {!! Html::style(url('/assets/admin/css/admin.css')) !!} + +