33namespace 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.
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 }
0 commit comments