1
0
Fork 0

Merge pull request #3372 from pixelfed/staging

Add Web Installer
This commit is contained in:
daniel 2022-04-10 05:52:22 -06:00 committed by GitHub
commit 32faf578e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 350 additions and 4 deletions

View File

@ -0,0 +1,214 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use App\User;
class InstallController extends Controller
{
public function index(Request $request)
{
abort_if(file_exists(base_path('.env')), 404);
return view('installer.index');
}
public function getRequirements()
{
abort_if(file_exists(base_path('.env')), 404);
$reqs = [];
$phpExtensions = [
'bcmath',
'ctype',
'curl',
'intl',
'json',
'mbstring',
'openssl',
'gd',
'redis',
'pdo_mysql',
'pdo_pgsql'
];
$dirs = [
'bootstrap',
'storage'
];
$reqs['php'] = [
'version' => PHP_VERSION,
'supported' => (bool) version_compare(PHP_VERSION, 7.4),
'min_version' => '7.4',
'memory_limit' => [
'recommended' => '256M',
'actual' => ini_get('memory_limit'),
],
'upload_max_filesize' => [
'recommended' => '15M',
'actual' => ini_get('upload_max_filesize')
],
'post_max_size' => [
'recommended' => '15M',
'actual' => ini_get('post_max_size')
]
];
$reqs['php']['extensions'] = collect($phpExtensions)
->map(function($ext) {
return [ 'name' => $ext, 'loaded' => extension_loaded($ext) ];
});
$reqs['permissions'] = collect($dirs)
->map(function($path) {
return [
'name' => $path,
'writable' => is_writable(base_path($path)),
'mode' => substr(sprintf('%o', fileperms(base_path($path))), -4),
'path' => base_path($path)
];
});
return $reqs;
}
public function store(Request $request)
{
abort_if(file_exists(base_path('.env')), 404, 'The .env configuration file already exists.');
return $this->checkPermissions($request);
return response()->json($request->all(), 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
}
protected function checkPermissions($request)
{
abort_if(file_exists(base_path('.env')), 404);
if( file_exists(base_path('.env'))) {
return response('Found existing .env file, aborting installation', 400);
}
if( !is_writable(base_path('storage/')) ) {
return response('Permission Problem(s), cannot write to bootstrap or storage directories', 400);
}
return $this->checkDatabase($request);
}
protected function checkDatabase($request)
{
abort_if(file_exists(base_path('.env')), 404);
$driver = $request->input('db_driver', 'mysql');
$name = $request->input('db_name', 'pixelfed');
$host = $request->input('db_host', 'localhost');
$username = $request->input('db_username');
$password = $request->input('db_password');
$dsn = "{$driver}:dbname={$name};host={$host}";
$dbh = new \PDO($dsn, $username, $password);
try {
$dbh->query('SELECT count(*) from INFORMATION_SCHEMA.TABLES');
} catch (\PDOException $e) {
return response($e, 400);
}
$this->createConfiguration($request);
}
protected function createConfiguration($request)
{
abort_if(file_exists(base_path('.env')), 404);
$source = base_path('.env.example');
$target = base_path('.env');
@copy($source, $target);
$this->updateConfig('APP_URL=http://localhost', 'APP_URL=https://'.$request->input('domain'));
$this->updateConfig('APP_NAME="Pixelfed Prod"', 'APP_NAME="'.$request->input('name').'"');
$this->updateConfig('APP_DOMAIN="localhost"', 'APP_DOMAIN="'.$request->input('domain').'"');
$this->updateConfig('ADMIN_DOMAIN="localhost"', 'ADMIN_DOMAIN="'.$request->input('domain').'"');
$this->updateConfig('SESSION_DOMAIN="localhost"', 'SESSION_DOMAIN="'.$request->input('domain').'"');
$this->updateConfig('DB_CONNECTION=mysql', 'DB_CONNECTION='.$request->input('db_driver'));
$this->updateConfig('DB_HOST=127.0.0.1', 'DB_HOST='.$request->input('db_host'));
$this->updateConfig('DB_PORT=3306', 'DB_PORT='.$request->input('db_port'));
$this->updateConfig('DB_DATABASE=pixelfed', 'DB_DATABASE='.$request->input('db_name'));
$this->updateConfig('DB_USERNAME=pixelfed', 'DB_USERNAME='.$request->input('db_username'));
$this->updateConfig('DB_PASSWORD=pixelfed', 'DB_PASSWORD='.$request->input('db_password'));
$this->updateConfig('CACHE_DRIVER=redis', 'CACHE_DRIVER='.$request->input('cache_driver'));
$this->updateConfig('QUEUE_DRIVER=redis', 'QUEUE_DRIVER='.$request->input('queue_driver'));
$this->updateConfig('REDIS_SCHEME=tcp', 'REDIS_SCHEME='.$request->input('redis_scheme'));
$this->updateConfig('REDIS_HOST=127.0.0.1', 'REDIS_HOST='.$request->input('redis_host'));
$this->updateConfig('REDIS_PORT=6379', 'REDIS_PORT='.$request->input('redis_port'));
$this->updateConfig('REDIS_PASSWORD=null', 'REDIS_PASSWORD='.$request->input('redis_password'));
$this->updateConfig('ACTIVITY_PUB=false', 'ACTIVITY_PUB=' .($request->input('features.activitypub') ? 'true' : 'false'));
$this->updateConfig('AP_INBOX=false', 'AP_INBOX=' .($request->input('features.activitypub') ? 'true' : 'false'));
$this->updateConfig('AP_REMOTE_FOLLOW=false', 'AP_REMOTE_FOLLOW=' .($request->input('features.activitypub') ? 'true' : 'false'));
$this->updateConfig('OPEN_REGISTRATION=true', 'OPEN_REGISTRATION=' .($request->input('features.open_registration') ? 'true' : 'false'));
$this->updateConfig('ENFORCE_EMAIL_VERIFICATION=true', 'ENFORCE_EMAIL_VERIFICATION=' .($request->input('mail_address_verify') ? 'true' : 'false'));
$this->updateConfig('PF_OPTIMIZE_IMAGES=true', 'PF_OPTIMIZE_IMAGES=' .($request->input('optimize_media') ? 'true' : 'false'));
$this->updateConfig('MAX_PHOTO_SIZE=15000', 'MAX_PHOTO_SIZE=' .($request->input('max_upload_size') * 1000));
$this->updateConfig('MEDIA_TYPES=image/jpeg,image/png,image/gif', 'MEDIA_TYPES=' .implode(',', $request->input('mime_types')));
$this->updateConfig('OAUTH_ENABLED=true', 'OAUTH_ENABLED=true');
if($request->input('optimize_media') == true) {
$this->updateConfig('IMAGE_QUALITY=80', 'IMAGE_QUALITY=' .$request->input('image_quality'));
}
sleep(1);
Artisan::call('config:cache');
sleep(1);
Artisan::call('key:generate --force');
sleep(1);
Artisan::call('migrate --force');
sleep(1);
Artisan::call('config:cache');
if($request->has('features.activitypub') && $request->input('features.activitypub') == true) {
Artisan::call('instance:actor');
}
if($request->filled(['admin_username', 'admin_password', 'admin_email'])) {
$user = new User;
$user->username = $request->input('admin_username', 'admin');
$user->name = $request->input('admin_username', 'admin');
$user->email = $request->input('admin_email');
$user->password = bcrypt($request->input('admin_password'));
$user->is_admin = true;
$user->email_verified_at = now();
$user->save();
}
}
protected function updateConfig($key, $value)
{
$f = file_get_contents(base_path('.env'));
if(strpos($f, $key) !== false) {
$u = str_replace($key, $value, $f);
} else {
$u = $f;
$u .= $value . PHP_EOL;
}
sleep(1);
file_put_contents(base_path('.env'), $u);
}
public function precheckDatabase(Request $request)
{
$driver = $request->input('db_driver', 'mysql');
$name = $request->input('db_name', 'pixelfed');
$host = $request->input('db_host', 'localhost');
$username = $request->input('db_username');
$password = $request->input('db_password');
$dsn = "{$driver}:dbname={$name};host={$host}";
$dbh = new \PDO($dsn, $username, $password);
try {
$dbh->query('SELECT count(*) from INFORMATION_SCHEMA.TABLES');
} catch (\PDOException $e) {
return response($e, 400);
}
}
}

View File

@ -39,6 +39,10 @@ class ImageOptimize implements ShouldQueue
*/
public function handle()
{
if(config('pixelfed.optimize_image') == false) {
return;
}
$media = $this->media;
$path = storage_path('app/'.$media->media_path);
if (!is_file($path) || $media->skip_optimize) {

View File

@ -14,6 +14,9 @@ class ConfigCacheService
{
$cacheKey = self::CACHE_KEY . $key;
$ttl = now()->addHours(12);
if(!config('instance.enable_cc')) {
return config($key);
}
return Cache::remember($cacheKey, $ttl, function() use($key) {

View File

@ -14,7 +14,7 @@ class AddProvidersColumnToOauthClientsTable extends Migration
public function up()
{
Schema::table('oauth_clients', function (Blueprint $table) {
if(Schema::hasColumn('oauth_clients', 'provider') == false) {
if(Schema::hasTable('oauth_clients') && Schema::hasColumn('oauth_clients', 'provider') == false) {
$table->string('provider')->after('secret')->nullable();
}
});
@ -27,8 +27,10 @@ class AddProvidersColumnToOauthClientsTable extends Migration
*/
public function down()
{
Schema::table('oauth_clients', function (Blueprint $table) {
$table->dropColumn('provider');
});
if(Schema::hasTable('oauth_clients')) {
Schema::table('oauth_clients', function (Blueprint $table) {
$table->dropColumn('provider');
});
}
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCacheTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('cache');
}
}

2
public/js/installer.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
/*! @source http://purl.eligrey.com/github/canvas-toBlob.js/blob/master/canvas-toBlob.js */

View File

@ -22,6 +22,7 @@
"/js/rempos.js": "/js/rempos.js?id=6adb34adf68f74778365143b28fb5b9b",
"/js/spa.js": "/js/spa.js?id=17b1356e5fbae1788e19262b09b66354",
"/js/stories.js": "/js/stories.js?id=814a25875cac8987d85c801dcb453114",
"/js/installer.js": "/js/installer.js?id=a8f4368b72ab447cc36e90321cabf256",
"/js/manifest.js": "/js/manifest.js?id=03b8ee72f882070cabba951c4e5291ed",
"/js/home-m9we36ik.js": "/js/home-m9we36ik.js?id=c24d81bce180fc13ce03cc0ea8efb286",
"/js/compose-m9we36ik.js": "/js/compose-m9we36ik.js?id=884530b8963f483c8c20bf16300e51ea",

View File

@ -0,0 +1,79 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<title>Pixelfed Installer</title>
<link rel="manifest" href="/manifest.json">
<link href="/css/app.css" rel="stylesheet" data-stylesheet="light">
<style type="text/css">
body {
background: linear-gradient(rgba(29, 38, 113, 0.8), rgba(195, 55, 100, 0.8));
}
.btn {
min-width: 100px;
}
.btn-primary {
min-width: 200px;
font-weight: bold;
}
.form-group {
margin-bottom: 1.5rem;
}
.form-group label {
font-weight: bold;
}
.form-control::placeholder {
color: #cbd5e1;
}
.form-control {
background:#f5f8fa;
border-color:#f5f8fa;
}
.form-control:focus {
color: #000;
background:#f5f8fa;
border-color:#f5f8fa;
box-shadow: none
}
</style>
</head>
<body class="loggedIn">
<main id="content">
<noscript>
<div class="container">
<p class="pt-5 text-center lead">Please enable javascript to view this content.</p>
</div>
</noscript>
<div class="container w-100 h-100">
<div class="row w-100 h-100 d-flex align-items-center justify-content-center">
<div class="col-12">
<p class="text-center py-3">
<a href="/installer">
<img src="/img/pixelfed-icon-color.svg" width="60" height="60">
</a>
</p>
<router-view></router-view>
<p class="d-flex justify-content-between text-white pt-2 px-2">
<a class="font-weight-bold text-white" href="https://docs.pixelfed.org/running-pixelfed/installation.html" target="_blank">Help</a>
<span class="font-weight-bold">v{{config('pixelfed.version')}}</span>
</p>
</div>
</div>
</div>
</main>
<script type="text/javascript" src="/js/manifest.js"></script>
<script type="text/javascript" src="/js/vendor.js"></script>
<script type="text/javascript" src="/js/installer.js"></script>
</body>
</html>

View File

@ -529,6 +529,14 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('{username}', 'ProfileController@permalinkRedirect');
});
Route::group(['prefix' => 'installer'], function() {
Route::get('api/requirements', 'InstallController@getRequirements')->withoutMiddleware(['web']);
Route::post('precheck/database', 'InstallController@precheckDatabase')->withoutMiddleware(['web']);
Route::post('store', 'InstallController@store')->withoutMiddleware(['web']);
Route::get('/', 'InstallController@index')->withoutMiddleware(['web']);
Route::get('/{q}', 'InstallController@index')->withoutMiddleware(['web'])->where('q', '.*');
});
Route::get('stories/{username}', 'ProfileController@stories');
Route::get('p/{id}', 'StatusController@shortcodeRedirect');
Route::get('c/{collection}', 'CollectionController@show');