Skip to content
This repository was archived by the owner on May 19, 2020. It is now read-only.

Commit b538213

Browse files
committed
Firewall Settings
1 parent fac5fa0 commit b538213

File tree

16 files changed

+202
-48
lines changed

16 files changed

+202
-48
lines changed

Envoy.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
@if ($tag)
66
php artisan down
7-
git fetch --tags
8-
git checkout {{ $tag }}
7+
git pull
8+
composer install --no-dev --no-interaction
99
php artisan migrate
1010
php artisan up
1111
@endif

app/Disk.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,25 @@ public function match(File $file)
2929
return $this->checksum($file) == $file->checksum;
3030
}
3131

32-
protected function touch($path)
32+
protected function touch($filepath)
3333
{
3434
try {
35-
touch($path);
35+
$this->makeFoldersForFile($filepath);
36+
touch($filepath);
3637
} catch (\ErrorException $e) {
37-
throw new PermissionDeniedException($path);
38+
throw new PermissionDeniedException($filepath);
39+
}
40+
}
41+
42+
protected function makeFoldersForFile($filepath)
43+
{
44+
try {
45+
$directory = dirname($filepath);
46+
if (!is_dir($directory)) {
47+
mkdir($directory, 0755, true);
48+
}
49+
} catch (\ErrorException $e) {
50+
throw new PermissionDeniedException($filepath);
3851
}
3952
}
4053
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Modules;
4+
5+
use Facades\App\Disk;
6+
use App\Http\Controllers\Controller;
7+
use App\Models\Expressive\Firewall;
8+
use Illuminate\Http\Request;
9+
10+
class FirewallsController extends Controller
11+
{
12+
public function edit()
13+
{
14+
$file = Firewall::first();
15+
16+
return view('app.modules.firewall.edit', compact('file'));
17+
}
18+
19+
public function update(Request $request, Firewall $firewall)
20+
{
21+
$firewall->sections()->first()->update([
22+
'content' => $request->get('firewall')
23+
]);
24+
25+
// @TODO: should this be an event on File instead? Write every file as soon as they change.
26+
Disk::write($firewall);
27+
28+
return redirect('/module/firewalls/edit')->with('success', 'Your firewall settings has been updated!');
29+
}
30+
}

app/Http/ViewComposers/LayoutComposer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ protected function isUpdateAvailable()
3030
$dayInMinutes = Carbon::MINUTES_PER_HOUR * Carbon::HOURS_PER_DAY;
3131

3232
return Cache::remember('updateAvailable', $dayInMinutes, function () {
33-
return true;
3433
$latest = (new GitHub)->latestVersion();
3534

3635
return version_compare($latest, config('app.version')) === 1;

app/Models/Expressive/Firewall.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
class Firewall extends File
88
{
9+
use HasParentModel;
10+
911
const FILTER = ['path' => '/etc/rc.d/rc.firewall'];
1012

1113
protected static function boot()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Models\Expressive;
4+
5+
use Illuminate\Support\Str;
6+
use ReflectionClass;
7+
8+
/**
9+
* Note: This is a preview of an upcoming package from Tighten.
10+
**/
11+
trait HasParentModel
12+
{
13+
public function getParentClass()
14+
{
15+
static $parentClassName;
16+
17+
return $parentClassName ?: $parentClassName = (new ReflectionClass($this))->getParentClass()->getName();
18+
}
19+
20+
public function getTable()
21+
{
22+
if (!isset($this->table)) {
23+
return str_replace('\\', '', Str::snake(Str::plural(class_basename($this->getParentClass()))));
24+
}
25+
26+
return $this->table;
27+
}
28+
29+
public function getForeignKey()
30+
{
31+
return Str::snake(class_basename($this->getParentClass())) . '_' . $this->primaryKey;
32+
}
33+
34+
public function joiningTable($related)
35+
{
36+
$models = [
37+
Str::snake(class_basename($related)),
38+
Str::snake(class_basename($this->getParentClass())),
39+
];
40+
sort($models);
41+
42+
return strtolower(implode('_', $models));
43+
}
44+
}

config/app.php

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

1616
'name' => env('APP_NAME', 'Thunderwall'),
1717

18-
'version' => '0.0.3',
18+
'version' => '0.0.4',
1919

2020
/*
2121
|--------------------------------------------------------------------------
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="container">
5+
<div class="row">
6+
<div class="col-md-8 col-md-offset-2">
7+
8+
<form method="POST" action="/modules/firewall/{{ $file->id }}">
9+
{{ method_field('PUT') }}
10+
{{ csrf_field() }}
11+
12+
<div class="panel panel-default">
13+
<div class="panel-heading">
14+
<div class="level">
15+
<h5 class="flex">
16+
{{ $file->name }} <span class="small">{{ $file->path }}</span>
17+
</h5>
18+
</div>
19+
</div>
20+
21+
<div class="panel-body">
22+
@foreach($file->sections as $section)
23+
<div class="form-group">
24+
<textarea class="form-control" name="firewall" cols="5"
25+
rows="14">{{ $section->content }}</textarea>
26+
</div>
27+
@endforeach
28+
</div>
29+
30+
<div class="panel-footer">
31+
<div class="form-group">
32+
<input type="submit" class="btn btn-primary" value="{{ __('Apply') }}">
33+
</div>
34+
</div>
35+
</div>
36+
37+
</form>
38+
</div>
39+
</div>
40+
</div>
41+
@endsection

routes/web.php

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,11 @@
3131
Route::get('/version', 'VersionController@index');
3232
Route::post('/version/update', 'VersionController@update');
3333

34-
Route::group(['namespace' => 'Modules', 'prefix' => 'module', 'middleware' => 'auth'], function () {
34+
Route::group(['namespace' => 'Modules', 'prefix' => 'modules', 'middleware' => 'auth'], function () {
3535

36-
// Reverse Engineering File Route
37-
Route::get('/files/retrieve', 'RetrievesFilesController@index');
38-
Route::post('/files/retrieve', 'RetrievesFilesController@store');
39-
40-
// File REST Route
41-
Route::post('/files/{file}/commit', 'CommitsFileController@commit');
42-
Route::resource('/files', 'FilesController');
43-
44-
// File Section Routes
45-
Route::get('/files/{file}/sections', 'FileSectionsController@index');
46-
Route::get('/files/{file}/sections/edit', 'FileSectionsController@edit');
47-
Route::post('/files/{file}/sections', 'FileSectionsController@store');
48-
});
49-
50-
Route::group(['namespace' => 'Files', 'middleware' => 'auth'], function () {
51-
52-
// Reverse Engineering File Route
53-
Route::get('/files/retrieve', 'RetrievesFilesController@index');
54-
Route::post('/files/retrieve', 'RetrievesFilesController@store');
55-
56-
// File REST Route
57-
Route::post('/files/{file}/commit', 'CommitsFileController@commit');
58-
Route::resource('/files', 'FilesController');
59-
60-
// File Section Routes
61-
Route::get('/files/{file}/sections', 'FileSectionsController@index');
62-
Route::get('/files/{file}/sections/edit', 'FileSectionsController@edit');
63-
Route::post('/files/{file}/sections', 'FileSectionsController@store');
36+
// Firewall Module
37+
Route::get('/firewall/edit', 'FirewallsController@edit');
38+
Route::put('/firewall/{firewall}', 'FirewallsController@update');
6439
});
6540

6641
Route::get('{any}', 'RedirectsController@index')->where('any', '.*');

storage/tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)