Commit 273fd1e1 authored by Timothée Jaussoin's avatar Timothée Jaussoin

Move the configuration to the .env file to support per-instances configurations

Complete the README
parent dfc619a1
Pipeline #15330 passed with stages
in 1 minute and 9 seconds
flexisip-account-manager/
rpmbuild/
.env.*
flexiapi/node_modules
flexiapi/public/hot
flexiapi/public/storage
flexiapi/public/css/*.style.css
flexiapi/storage/*.key
flexiapi/vendor
flexiapi/.env
......
......@@ -5,6 +5,10 @@ APP_DEBUG=false
APP_URL=http://localhost
APP_SIP_DOMAIN=
INSTANCE_COPYRIGHT=
INSTANCE_INTRO_REGISTRATION=
INSTANCE_CUSTOM_THEME=false
LOG_CHANNEL=stack
DB_DATABASE=/var/www/flexiapi/db.sqlite
......
......@@ -26,6 +26,41 @@ Complete all the other variables in the `.env` file:
- SMTP configuration
- App name, SIP domain…
### Multi instances environement
FlexiAPI can also handle multi domains setup.
To do so, configure several web servers virtualhosts and set a specific `APP_ENV` environement variable in each of them.
With Apache, use the [mod_env](https://httpd.apache.org/docs/2.4/mod/mod_env.html) module.
SetEnv APP_ENV foobar
On nginx use `fastcgi_param` to pass the parameter directly to PHP.
location ~ [^/]\.php(/|$) {
include /etc/nginx/fastcgi_params;
fastcgi_param APP_ENV foobar;
}
Note that if `APP_ENV` is not set FlexiAPI will directly use the default `.env` file.
FlexiAPI will then try to load a custom configuration file with the following name `.env.$APP_ENV`. So for the previous example `.env.foobar`.
You can then configure your instances with specific values.
INSTANCE_COPYRIGHT="FooBar - Since 1997"
INSTANCE_INTRO_REGISTRATION="Welcome on the FooBar Server"
INSTANCE_CUSTOM_THEME=true
#### Custom theme
If you set `INSTANCE_CUSTOM_THEME` to true, FlexiAPI will try to load a CSS file located in `public/css/$APP_ENV.style.css`. If the file doesn't exists it will fallback to `public/css/style.css`.
We advise you to copy the `style.css` file and rename it to make your custom CSS configurations for your instance.
### SELinux
If you are running on a CentOS/RedHat machine, please ensure that SELinux is correctly configured.
......
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Configuration extends Model
{
protected $table = 'configuration';
protected $fillable = ['copyright', 'intro_registration', 'custom_theme'];
}
......@@ -10,7 +10,6 @@ use Carbon\Carbon;
use App\Account;
use App\Alias;
use App\Configuration;
use App\Rules\SIP;
use App\Helpers\Utils;
use App\Libraries\OvhSMS;
......@@ -41,8 +40,7 @@ class AccountController extends Controller
public function register(Request $request)
{
return view('account.register', [
'domain' => '@' . config('app.sip_domain'),
'configuration' => Configuration::first()
'domain' => '@' . config('app.sip_domain')
]);
}
......
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Configuration;
class ConfigurationController extends Controller
{
public function edit(Request $request)
{
$configuration = Configuration::first();
if (!$configuration) $configuration = new Configuration;
return view('admin.configuration.edit', [
'configuration' => $configuration
]);
}
public function update(Request $request)
{
$configuration = Configuration::first();
if (!$configuration) $configuration = new Configuration;
$configuration->copyright = $request->get('copyright');
$configuration->intro_registration = $request->get('intro_registration');
$configuration->custom_theme = $request->input('custom_theme', false);
$configuration->save();
return redirect()->route('admin.configuration.update');
}
}
<?php
return [
'copyright' => env('INSTANCE_COPYRIGHT', null),
'intro_registration' => env('INSTANCE_INTRO_REGISTRATION', null),
'custom_theme' => env('INSTANCE_CUSTOM_THEME', false),
];
\ No newline at end of file
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateConfigurationTable extends Migration
{
public function up()
{
Schema::create('configuration', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('copyright')->nullable();
$table->text('intro_registration')->nullable();
$table->boolean('custom_theme')->default(false);
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('configuration');
}
}
......@@ -40,12 +40,6 @@
</div>
<p class="mb-1">Manage the FlexiSIP accounts</p>
</a>
<a href="{{ route('admin.configuration.edit') }}" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">Configuration</h5>
</div>
<p class="mb-1">Configure the layout and other parameters</p>
</a>
</div>
@endif
......
......@@ -2,8 +2,8 @@
@section('content')
@if ($configuration && !empty($configuration->intro_registration))
<p>{!! nl2br($configuration->intro_registration) !!}</p>
@if (config('instance.intro_registration'))
<p>{!! nl2br(config('instance.intro_registration')) !!}</p>
@endif
<p>
You already have an account?
......
@extends('layouts.account')
@section('breadcrumb')
<li class="breadcrumb-item active" aria-current="page">Configuration</li>
@endsection
@section('content')
<h2>Configuration</h2>
{!! Form::open(['route' => 'admin.configuration.update']) !!}
<div class="form-row">
<div class="form-group col-md-6">
{!! Form::label('copyright', 'Copyright') !!}
{!! Form::text('copyright', $configuration->copyright, ['class' => 'form-control', 'placeholder' => 'Copyright']) !!}
</div>
</div>
<div class="form-row">
<div class="form-group">
{!! Form::label('intro_registration', 'Introduction text during Registration') !!}
{!! Form::textarea('intro_registration', $configuration->intro_registration, ['class' => 'form-control', 'placeholder' => 'Introduction text during registration']) !!}
</div>
</div>
<div class="form-check mb-3">
{!! Form::checkbox('custom_theme', 'checked', $configuration->custom_theme, ['class' => 'form-check-input', 'id' => 'custom_theme']) !!}
<label class="form-check-label" for="custom_theme">CSS spéficique</a></label>
</div>
<div class="form-row">
<button type="submit" class="btn btn-primary">Save</button>
</div>
{!! Form::close() !!}
@endsection
\ No newline at end of file
<!DOCTYPE html>
@php $configuration = \App\Configuration::first() @endphp
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
......@@ -9,8 +7,12 @@
<title>{{ config('app.name') }}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
@if ($configuration && $configuration->custom_theme)
<link rel="stylesheet" type="text/css" href="{{ asset('css/style.css') }}" >
@if (config('instance.custom_theme'))
@if (file_exists(public_path('css/'.config('app.env').'.style.css')))
<link rel="stylesheet" type="text/css" href="{{ asset('css/'.config('app.env').'.style.css') }}" >
@else
<link rel="stylesheet" type="text/css" href="{{ asset('css/style.css') }}" >
@endif
@endif
</head>
<body>
......@@ -19,8 +21,8 @@
</header>
@yield('body')
<footer class="text-center mt-2">
@if ($configuration)
{{ $configuration->copyright }}
@if (config('instance.copyright'))
{{ config('instance.copyright') }}
@endif
</footer>
</body>
......
......@@ -56,7 +56,4 @@ Route::group(['middleware' => 'auth.admin'], function () {
Route::get('admin/accounts/{id}/deactivate', 'Admin\AccountController@deactivate')->name('admin.account.deactivate');
Route::get('admin/accounts/{id}/admin', 'Admin\AccountController@admin')->name('admin.account.admin');
Route::get('admin/accounts/{id}/unadmin', 'Admin\AccountController@unadmin')->name('admin.account.unadmin');
Route::get('admin/configuration', 'Admin\ConfigurationController@edit')->name('admin.configuration.edit');
Route::post('admin/configuration', 'Admin\ConfigurationController@update')->name('admin.configuration.update');
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment