Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da665e1

Browse files
committed
Changes during review with Laszlo
1 parent b21eaaa commit da665e1

10 files changed

Lines changed: 122 additions & 58 deletions

File tree

.env.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ APP_TIMEZONE="Europe/Dublin"
2525

2626
# Laravel log format (storage/log). See config/log.php and
2727
# https://laravel.com/docs/5.4/errors
28-
APP_LOG="single"
28+
LOG_CHANNEL="single"
2929

3030
# info by default, one of: debug, info, notice, warning, error, critical, alert, emergency.
3131
APP_LOG_LEVEL=debug

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ APP_URL="https://ixp.example.com"
2222
APP_TIMEZONE="UTC"
2323

2424
# Laravel log format (storage/log). See config/log.php and
25-
# https://laravel.com/docs/5.4/errors
26-
APP_LOG="single"
25+
# https://laravel.com/docs/11.x/logging
26+
LOG_CHANNEL="single"
2727

2828
# info by default, one of: debug, info, notice, warning, error, critical, alert, emergency.
29-
APP_LOG_LEVEL=debug
29+
LOG_LEVEL=debug
3030

3131
# MySQL Connection Details
3232
DB_HOST="127.0.0.1"

.phpstorm.meta.php/laravel.meta.php

Lines changed: 55 additions & 11 deletions
Large diffs are not rendered by default.

app/Http/Controllers/EnvConfigController.php renamed to app/Http/Controllers/SettingsController.php

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace IXP\Http\Controllers;
44

55
/*
6-
* Copyright (C) 2009 - 2021 Internet Neutral Exchange Association Company Limited By Guarantee.
6+
* Copyright (C) 2009 - 2024 Internet Neutral Exchange Association Company Limited By Guarantee.
77
* All Rights Reserved.
88
*
99
* This file is part of IXP Manager.
@@ -33,43 +33,32 @@
3333
* .env file configurator Controller
3434
* @author Laszlo Kiss <[email protected]>
3535
* @author Barry O'Donovan <[email protected]>
36-
* @author Yann Robin <[email protected]>
3736
* @category IXP
3837
* @package IXP\Http\Controllers
39-
* @copyright Copyright (C) 2009 - 2021 Internet Neutral Exchange Association Company Limited By Guarantee
38+
* @copyright Copyright (C) 2009 - 2024 Internet Neutral Exchange Association Company Limited By Guarantee
4039
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL V2.0
4140
*/
42-
class EnvConfigController extends Controller
41+
class SettingsController extends Controller
4342
{
4443
protected DotEnvWriter $envWriter;
4544
protected Former $former;
46-
protected array $panelConfig;
45+
protected array $fe_settings;
4746

48-
/**
49-
* The minimum privileges required to access this controller.
50-
*
51-
* If you set this to less than the superuser, you need to manage privileges and access
52-
* within your own implementation yourself.
53-
*
54-
* @var int
55-
*/
56-
public static $minimum_privilege = User::AUTH_SUPERUSER;
5747

5848
public function __construct(Former $former, DotEnvWriter $envWriter) {
59-
$this->middleware('auth');
6049
$this->envWriter = $envWriter;
6150
$this->former = $former;
62-
$this->panelConfig = include(config_path('ixp_fe_config.php'));
51+
$this->fe_settings = config( 'ixp_fe_settings');
6352
}
6453

6554
/**
66-
* Collect rules from the panelconfig
55+
* Collect rules from the fe_settings configuration file which contains
56+
* arrays of 'panels' for the UI.
6757
*
6858
* @param array $panels
69-
*
7059
* @return array
7160
*/
72-
protected function gatherRules(array $panels): array
61+
private function gatherRules(array $panels): array
7362
{
7463
$rules = [];
7564
foreach($panels as $panel) {
@@ -90,7 +79,7 @@ protected function gatherRules(array $panels): array
9079
*
9180
* @return string|null
9281
*/
93-
protected function patternReplace(string|null $value,array $attributes): string|null
82+
private function patternReplace(string|null $value,array $attributes): string|null
9483
{
9584
// check value: if it is points to another value grab that and replace it
9685
preg_match_all('/\${([\w\.]+)}/',$value,$matches);
@@ -108,23 +97,23 @@ protected function patternReplace(string|null $value,array $attributes): string|
10897
/**
10998
* Display the form to update the .env
11099
*/
111-
protected function createForm()
100+
private function createForm()
112101
{
113-
$envConfig = new $this->envWriter();
114-
$envValues = $envConfig->getVariables();
102+
$envValues = $this->envWriter->getVariables();
115103

116104
$form = $this->former::open()->method('POST')
117105
->id('envForm')
118-
->action(route('env_config@update'))
106+
->action(route('settings@update'))
119107
->customInputWidthClass( 'col-8' )
120108
->customLabelWidthClass( 'col-4' )
121109
->actionButtonsCustomClass( "grey-box")
122-
->rules($this->gatherRules($this->panelConfig["panels"]));
110+
->rules($this->gatherRules($this->fe_settings["panels"]));
123111

124112
$form .= '<ul class="tabNavMenu" id="envFormTabs">';
125113
$first = true;
126114
$tabContents = [];
127-
foreach($this->panelConfig["panels"] as $panel => $content) {
115+
116+
foreach($this->fe_settings["panels"] as $panel => $content) {
128117
$form .= '<li>'
129118
.'<button class="tabButton'.($first ? ' active' : '').'" id="'.$panel.'-tab" data-target="#'.$panel.'-content" type="button">'.$content["title"].'</button></li>';
130119

@@ -134,7 +123,8 @@ protected function createForm()
134123
$tab .= '<p class="description">'.$content["description"].'</p>';
135124
}
136125

137-
if(isset($content["fields"]) && count($content["fields"]) > 0) {
126+
if(isset($content["fields"]) && count($content["fields"])) {
127+
138128
foreach($content["fields"] as $field => $param) {
139129
$title = $param["name"];
140130
if(isset($param["docs_url"]) && $param["docs_url"]) {
@@ -147,9 +137,11 @@ protected function createForm()
147137
}
148138

149139
switch($param["type"]) {
140+
150141
case 'radio':
151142
$input = Former::checkbox($field)->label($title)->check( $value === 'true' );
152143
break;
144+
153145
case 'select':
154146
if($param["options"]["type"] === 'array') {
155147
$options = $param["options"]["list"];
@@ -159,24 +151,28 @@ protected function createForm()
159151

160152
$input = Former::select($field)->label($title)->options($options,$value)->placeholder('Select an Option')->addClass( 'chzn-select' );
161153
break;
154+
162155
case 'textarea':
163156
$value = $this->patternReplace($value,$envValues);
164157

165158
$input = Former::textarea($field)->label($title)->value($value);
166159
break;
160+
167161
default: // text
168162
$value = $this->patternReplace($value,$envValues);
169-
170163
$input = Former::text($field)->label($title)->value($value);
171164
}
172165

173166
$tab .= '<div class="inputWrapper">'.$input;
167+
174168
if(isset($param["help"]) && $param["help"] !== '') {
175169
$tab .= '<div class="small"><i class="fa fa-info-circle tw-text-blue-600"></i> '.$param["help"].'</div>';
176170
}
171+
177172
$tab .= '</div>';
178173
}
179174
}
175+
180176
$tab .= '</div>';
181177
$tabContents[] = $tab;
182178
$first = false;
@@ -198,7 +194,7 @@ protected function createForm()
198194
*/
199195
protected function index()
200196
{
201-
return view( 'env-config.index' )->with( [
197+
return view( 'settings.index' )->with( [
202198
'form' => $this->createForm(),
203199
] );
204200
}

app/Services/DotEnvWriter.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
<?php
2-
/**
3-
* Original: MirazMac\DotEnv\Writer
4-
* https://github.com/MirazMac/DotEnvWriter
2+
3+
namespace IXP\Services;
4+
5+
/*
6+
* This file is part of IXP Manager.
7+
*
8+
* IXP Manager is free software: you can redistribute it and/or modify it
9+
* under the terms of the GNU General Public License as published by the Free
10+
* Software Foundation, version v2.0 of the License.
11+
*
12+
* IXP Manager is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15+
* more details.
16+
*
17+
* You should have received a copy of the GNU General Public License v2.0
18+
* along with IXP Manager. If not, see:
19+
*
20+
* http://www.gnu.org/licenses/gpl-2.0.html
21+
*
22+
*
23+
* Based on code from https://github.com/MirazMac/DotEnvWriter with MIT license.
524
*
625
* A PHP library to write values to .env files.
26+
*
727
*/
828

9-
namespace IXP\Services;
1029

11-
use Carbon\Carbon;
1230
use InvalidArgumentException;
13-
use LogicException;
1431
use const LOCK_EX;
1532

1633
class DotEnvWriter

resources/views/layouts/menu.foil.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@
383383
IXP UTILITIES
384384
</h6>
385385

386+
<li class="<?= !request()->is( 'settings/*' ) ?: 'active' ?>">
387+
<a href="<?= route( 'settings@edit' ) ?>" class="nav-link">
388+
Settings
389+
</a>
390+
</li>
391+
386392
<?php if( Gate::allows( 'viewHorizon' ) && config( 'queue.default' ) === 'redis' ): ?>
387393
<li>
388394
<a href="<?= route( 'horizon.index' ) ?>" class="nav-link" target="_ixpm_horizon">

resources/views/layouts/menus/superuser.foil.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@
157157
API Keys
158158
</a>
159159

160-
<a class="dropdown-item <?= !request()->is( 'env_config/edit' ) ?: 'active' ?>" href="<?= route('env_config@edit' )?>">
161-
.ENV Config
162-
</a>
163-
164160
<a id="active-sessions" class="dropdown-item <?= !request()->is( 'active-sessions/list' ) ?: 'active' ?>" href="<?= route('active-sessions@list' )?>">
165161
Active Sessions
166162
</a>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
?>
55

66
<?php $this->section( 'page-header-preamble' ) ?>
7-
.ENV File Configurator
7+
IXP Manager Settings
88
<?php $this->append() ?>
99

1010
<?php $this->section('content') ?>

routes/web-auth-superuser.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,15 @@
273273
///
274274
Route::get( 'search', 'SearchController@do' )->name( 'search' );
275275

276+
277+
/////////////////////////////////////////////////////////////////////////////////////////////////
278+
/////////////////////////////////////////////////////////////////////////////////////////////////
279+
///
276280
/// .ENV Configurator
277-
Route::group( [ 'prefix' => 'env_config' ], function() {
278-
Route::get( 'edit', 'EnvConfigController@index' )->name( 'env_config@edit' );
279-
Route::post( 'update', 'EnvConfigController@update' )->name( 'env_config@update' );
281+
///
282+
Route::group( [ 'prefix' => 'settings' ], function() {
283+
Route::get( 'edit', 'SettingsController@index' )->name( 'settings@edit' );
284+
Route::post( 'update', 'SettingsController@update' )->name( 'settings@update' );
280285
});
281286

282287
/////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)