Skip to content

Commit 622cfa0

Browse files
Merge pull request #312 from thiagogomesverissimo/issue298-config-model
Issue298 config model
2 parents c825973 + b2b61fe commit 622cfa0

6 files changed

Lines changed: 96 additions & 5 deletions

File tree

app/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Config extends Model
8+
{
9+
//
10+
}

app/Http/Controllers/ConfigController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers;
44

55
use Illuminate\Http\Request;
6+
use App\Config;
67

78
class ConfigController extends Controller
89
{
@@ -13,7 +14,20 @@ public function __construct()
1314

1415
public function index()
1516
{
17+
$configs = Config::all();
1618
$consumer_deploy_key = env('CONSUMER_DEPLOY_KEY');
17-
return view('config/index',compact('consumer_deploy_key'));
19+
return view('config/index',compact('consumer_deploy_key','configs'));
20+
}
21+
22+
public function config(Request $request)
23+
{
24+
$config = Config::where('key','dhcp_global')->first();
25+
if(is_null($config)) $config = new Config;
26+
$config->key = 'dhcp_global';
27+
$config->value = $request->dhcp_global;
28+
$config->save();
29+
30+
$request->session()->flash('alert-success', 'Configuração atualizada com sucesso!');
31+
return redirect("/config");
1832
}
1933
}

app/Http/Controllers/DhcpController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Http\Request;
66
use App\Rede;
77
use App\Equipamentos;
8+
use App\Config;
89

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

34+
$dhcp_global = Config::where('key','dhcp_global')->first();
35+
if(is_null($dhcp_global)){
36+
$dhcp_global = new Config;
37+
$dhcp_global->value = '';
38+
}
39+
3340
$dhcp = <<<HEREDOC
3441
# {$date}
3542
# build success
36-
ddns-update-style none;
37-
default-lease-time 86400;
38-
max-lease-time 86400;
39-
authoritative;
43+
{$dhcp_global->value}
4044
shared-network "default" {
4145
4246
HEREDOC;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateConfigsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('configs', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->timestamps();
19+
$table->text('key');
20+
$table->longText('value')->nullable();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::dropIfExists('configs');
32+
}
33+
}

resources/views/config/index.blade.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,33 @@
3535
</form>
3636
</div>
3737

38+
<div>
39+
40+
<br>
41+
<form action="/config" method="post">
42+
{{csrf_field()}}
43+
<div class="panel panel-default">
44+
<div class="panel-heading">Configurações para DHCP</div>
45+
<div class="panel-body">
46+
<div class="form-group">
47+
<label for="dhcp_global">Parâmetros globais</label>
48+
49+
@if(!is_null($configs->where('key','dhcp_global')->first()))
50+
<textarea rows="4" cols="50" class="form-control" name="dhcp_global">{{$configs->where('key','dhcp_global')->first()->value}}</textarea>
51+
@else
52+
<textarea rows="4" cols="50" class="form-control" name="dhcp_global">ddns-update-style none;
53+
default-lease-time 86400;
54+
max-lease-time 86400;
55+
authoritative;</textarea>
56+
@endif
57+
</div>
58+
59+
<div class="form-group">
60+
<input type="submit" class="btn btn-primary" value="Enviar Dados">
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
</form>
66+
3867
@stop

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# config
1717
Route::get('/config', 'ConfigController@index');
18+
Route::post('/config', 'ConfigController@config');
1819
Route::post('/freeradius/sincronize', 'FreeradiusController@sincronize');
1920

2021
# APIs

0 commit comments

Comments
 (0)