Skip to content

Commit

Permalink
Merge pull request #312 from thiagogomesverissimo/issue298-config-model
Browse files Browse the repository at this point in the history
Issue298 config model
  • Loading branch information
thiagogomesverissimo authored Oct 4, 2018
2 parents c825973 + b2b61fe commit 622cfa0
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Config extends Model
{
//
}
16 changes: 15 additions & 1 deletion app/Http/Controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Config;

class ConfigController extends Controller
{
Expand All @@ -13,7 +14,20 @@ public function __construct()

public function index()
{
$configs = Config::all();
$consumer_deploy_key = env('CONSUMER_DEPLOY_KEY');
return view('config/index',compact('consumer_deploy_key'));
return view('config/index',compact('consumer_deploy_key','configs'));
}

public function config(Request $request)
{
$config = Config::where('key','dhcp_global')->first();
if(is_null($config)) $config = new Config;
$config->key = 'dhcp_global';
$config->value = $request->dhcp_global;
$config->save();

$request->session()->flash('alert-success', 'Configuração atualizada com sucesso!');
return redirect("/config");
}
}
12 changes: 8 additions & 4 deletions app/Http/Controllers/DhcpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\Request;
use App\Rede;
use App\Equipamentos;
use App\Config;

use App\Utils\NetworkOps;
use App\Utils\Utils;
Expand All @@ -30,13 +31,16 @@ public function dhcpd(Request $request)
$ops = new NetworkOps;
$date = Utils::ItensUpdatedAt();

$dhcp_global = Config::where('key','dhcp_global')->first();
if(is_null($dhcp_global)){
$dhcp_global = new Config;
$dhcp_global->value = '';
}

$dhcp = <<<HEREDOC
# {$date}
# build success
ddns-update-style none;
default-lease-time 86400;
max-lease-time 86400;
authoritative;
{$dhcp_global->value}
shared-network "default" {
HEREDOC;
Expand Down
33 changes: 33 additions & 0 deletions database/migrations/2018_10_04_141540_create_configs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateConfigsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('configs', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->text('key');
$table->longText('value')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('configs');
}
}
29 changes: 29 additions & 0 deletions resources/views/config/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,33 @@
</form>
</div>

<div>

<br>
<form action="/config" method="post">
{{csrf_field()}}
<div class="panel panel-default">
<div class="panel-heading">Configurações para DHCP</div>
<div class="panel-body">
<div class="form-group">
<label for="dhcp_global">Parâmetros globais</label>

@if(!is_null($configs->where('key','dhcp_global')->first()))
<textarea rows="4" cols="50" class="form-control" name="dhcp_global">{{$configs->where('key','dhcp_global')->first()->value}}</textarea>
@else
<textarea rows="4" cols="50" class="form-control" name="dhcp_global">ddns-update-style none;
default-lease-time 86400;
max-lease-time 86400;
authoritative;</textarea>
@endif
</div>

<div class="form-group">
<input type="submit" class="btn btn-primary" value="Enviar Dados">
</div>
</div>
</div>
</div>
</form>

@stop
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# config
Route::get('/config', 'ConfigController@index');
Route::post('/config', 'ConfigController@config');
Route::post('/freeradius/sincronize', 'FreeradiusController@sincronize');

# APIs
Expand Down

0 comments on commit 622cfa0

Please sign in to comment.