Bearsampp 2026.9.23
Loading...
Searching...
No Matches
ActionEditVhost Class Reference
Inheritance diagram for ActionEditVhost:
Collaboration diagram for ActionEditVhost:

Data Fields

const GAUGE_SAVE = 3
Data Fields inherited from ActionDialogBase
const GAUGE_DELETE = 2
const GAUGE_SAVE = 2

Protected Member Functions

 createFormFields ($bearsamppWinbinder)
 deleteItem ()
 getDeleteConfirmMessage ()
 getDeleteDialogTitle ()
 getDeleteErrorMessage ()
 getDeleteSuccessMessage ()
 getDialogTitle ()
 getFormValues ($bearsamppWinbinder)
 getGaugeSave ()
 getSaveErrorMessage ()
 getSaveSuccessMessage ($values)
 getWindowTitle ()
 handleCustomEvent ($window, $id, $ctrl, $param1, $param2)
 initializeDialog ($args)
 itemExists ($values)
 restartService ()
 saveItem ($values)
 validateInput ($values)
Protected Member Functions inherited from ActionDialogBase
 createButtons ($bearsamppWinbinder)
 getGaugeDelete ()
 handleDelete ($window)
 handleSave ($window)
 isEditMode ()

Private Attributes

 $wbBtnDocRoot
 $wbInputDocRoot
 $wbInputServerName
 $wbLabelDocRoot
 $wbLabelExp
 $wbLabelServerName

Additional Inherited Members

Public Member Functions inherited from ActionDialogBase
 __construct ($args)
 processWindow ($window, $id, $ctrl, $param1, $param2)
Protected Attributes inherited from ActionDialogBase
 $initValue
 $wbBtnCancel
 $wbBtnDelete
 $wbBtnSave
 $wbProgressBar
 $wbWindow

Detailed Description

Class ActionEditVhost Handles the editing of virtual hosts within the Bearsampp application.

Definition at line 15 of file class.action.editVhost.php.

Member Function Documentation

◆ createFormFields()

createFormFields ( $bearsamppWinbinder)
protected

Create the form fields for the edit vhost dialog.

Parameters
object$bearsamppWinbinderThe WinBinder instance.
Returns
void

Reimplemented from ActionDialogBase.

Definition at line 117 of file class.action.editVhost.php.

118 {
120
121 // Load existing vhost data
122 $filePath = Path::getVhostsPath() . '/' . $this->initValue . '.conf';
123 $fileContent = file_get_contents($filePath);
124 preg_match('/DocumentRoot\s+"(.*)"/', $fileContent, $matchDocumentRoot);
125 $initDocumentRoot = Path::formatWindowsPath(trim($matchDocumentRoot[1]));
126
127 $this->wbLabelServerName = $bearsamppWinbinder->createLabel(
128 $this->wbWindow,
130 15,
131 15,
132 85,
133 null,
134 WBC_RIGHT
135 );
136 $this->wbInputServerName = $bearsamppWinbinder->createInputText(
137 $this->wbWindow,
138 $this->initValue,
139 105,
140 13,
141 150,
142 null
143 );
144
145 $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel(
146 $this->wbWindow,
148 15,
149 45,
150 85,
151 null,
152 WBC_RIGHT
153 );
154 $this->wbInputDocRoot = $bearsamppWinbinder->createInputText(
155 $this->wbWindow,
156 $initDocumentRoot,
157 105,
158 43,
159 190,
160 null,
161 null,
162 WBC_READONLY
163 );
164 $this->wbBtnDocRoot = $bearsamppWinbinder->createButton(
165 $this->wbWindow,
167 300,
168 43,
169 110
170 );
171
172 $this->wbLabelExp = $bearsamppWinbinder->createLabel(
173 $this->wbWindow,
174 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $this->initValue, $initDocumentRoot),
175 15,
176 80,
177 470,
178 50
179 );
180 }
global $bearsamppLang
global $bearsamppRoot
const VHOST_EXP_LABEL
const VHOST_SERVER_NAME_LABEL
const BUTTON_BROWSE
const VHOST_DOCUMENT_ROOT_LABEL
static formatWindowsPath($path)
static getVhostsPath($aetrayPath=false)

References $bearsamppLang, $bearsamppRoot, Lang\BUTTON_BROWSE, Path\formatWindowsPath(), Path\getVhostsPath(), Lang\VHOST_DOCUMENT_ROOT_LABEL, Lang\VHOST_EXP_LABEL, and Lang\VHOST_SERVER_NAME_LABEL.

Here is the call graph for this function:

◆ deleteItem()

deleteItem ( )
protected

Delete the vhost configuration file and its SSL certificate.

Returns
bool True on success, false on failure.

Reimplemented from ActionDialogBase.

Definition at line 274 of file class.action.editVhost.php.

275 {
276 global $bearsamppRoot, $bearsamppOpenSsl;
277
278 return $bearsamppOpenSsl->removeCrt($this->initValue) &&
279 @unlink(Path::getVhostsPath() . '/' . $this->initValue . '.conf');
280 }

References $bearsamppRoot, and Path\getVhostsPath().

Here is the call graph for this function:

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
protected

Get the delete confirmation message.

Returns
string The localized confirmation message with the server name.

Reimplemented from ActionDialogBase.

Definition at line 318 of file class.action.editVhost.php.

319 {
320 global $bearsamppLang;
321
322 return sprintf($bearsamppLang->getValue(Lang::DELETE_VHOST), $this->initValue);
323 }
const DELETE_VHOST

References $bearsamppLang, and Lang\DELETE_VHOST.

◆ getDeleteDialogTitle()

getDeleteDialogTitle ( )
protected

Get the delete dialog title.

Returns
string The localized delete dialog title.

Reimplemented from ActionDialogBase.

Definition at line 72 of file class.action.editVhost.php.

73 {
74 global $bearsamppLang;
75
77 }
const DELETE_VHOST_TITLE

References $bearsamppLang, and Lang\DELETE_VHOST_TITLE.

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
protected

Get the error message after delete failure.

Returns
string The localized error message with the file path.

Reimplemented from ActionDialogBase.

Definition at line 342 of file class.action.editVhost.php.

343 {
345
346 return sprintf(
348 Path::getVhostsPath() . '/' . $this->initValue . '.conf'
349 );
350 }
const VHOST_REMOVE_ERROR

References $bearsamppLang, $bearsamppRoot, Path\getVhostsPath(), and Lang\VHOST_REMOVE_ERROR.

Here is the call graph for this function:

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
protected

Get the success message after delete.

Returns
string The localized success message with the server name.

Reimplemented from ActionDialogBase.

Definition at line 330 of file class.action.editVhost.php.

331 {
332 global $bearsamppLang;
333
334 return sprintf($bearsamppLang->getValue(Lang::VHOST_REMOVED), $this->initValue);
335 }
const VHOST_REMOVED

References $bearsamppLang, and Lang\VHOST_REMOVED.

◆ getDialogTitle()

getDialogTitle ( )
protected

Get the dialog title for message boxes.

Returns
string The localized dialog title with the server name.

Reimplemented from ActionDialogBase.

Definition at line 60 of file class.action.editVhost.php.

61 {
62 global $bearsamppLang;
63
64 return sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initValue);
65 }
const EDIT_VHOST_TITLE

References $bearsamppLang, and Lang\EDIT_VHOST_TITLE.

◆ getFormValues()

getFormValues ( $bearsamppWinbinder)
protected

Get the current form values from the input controls.

Parameters
object$bearsamppWinbinderThe WinBinder instance.
Returns
array Associative array with 'serverName' and 'documentRoot' keys.

Reimplemented from ActionDialogBase.

Definition at line 189 of file class.action.editVhost.php.

190 {
191 return [
192 'serverName' => $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]),
193 'documentRoot' => $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ])
194 ];
195 }

References WinBinder\CTRL_OBJ.

◆ getGaugeSave()

getGaugeSave ( )
protected

Get the gauge value for save operation.

Returns
int The gauge value.

Reimplemented from ActionDialogBase.

Definition at line 38 of file class.action.editVhost.php.

39 {
40 return self::GAUGE_SAVE;
41 }

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
protected

Get the error message after save failure.

Returns
string The localized error message.

Reimplemented from ActionDialogBase.

Definition at line 306 of file class.action.editVhost.php.

307 {
308 global $bearsamppLang;
309
311 }
const VHOST_CREATED_ERROR

References $bearsamppLang, and Lang\VHOST_CREATED_ERROR.

◆ getSaveSuccessMessage()

getSaveSuccessMessage ( $values)
protected

Get the success message after saving.

Parameters
array$valuesThe form values.
Returns
string The localized success message.

Reimplemented from ActionDialogBase.

Definition at line 289 of file class.action.editVhost.php.

290 {
291 global $bearsamppLang;
292
293 return sprintf(
295 $values['serverName'],
296 $values['serverName'],
297 $values['documentRoot']
298 );
299 }
const VHOST_CREATED

References $bearsamppLang, and Lang\VHOST_CREATED.

◆ getWindowTitle()

getWindowTitle ( )
protected

Get the dialog window title.

Returns
string The localized window title with the server name.

Reimplemented from ActionDialogBase.

Definition at line 48 of file class.action.editVhost.php.

49 {
50 global $bearsamppLang;
51
52 return sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initValue);
53 }

References $bearsamppLang, and Lang\EDIT_VHOST_TITLE.

◆ handleCustomEvent()

handleCustomEvent ( $window,
$id,
$ctrl,
$param1,
$param2 )
protected

Handle custom window events (server name input change and browse button).

Parameters
resource$windowThe window resource.
int$idThe control ID.
resource$ctrlThe control resource.
mixed$param1Additional parameter 1.
mixed$param2Additional parameter 2.
Returns
void

Reimplemented from ActionDialogBase.

Definition at line 374 of file class.action.editVhost.php.

375 {
376 global $bearsamppLang, $bearsamppWinbinder;
377
378 $serverName = $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]);
379 $documentRoot = $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ]);
380
381 // Handle server name input change
382 if ($id == $this->wbInputServerName[WinBinder::CTRL_ID]) {
383 $bearsamppWinbinder->setText(
384 $this->wbLabelExp[WinBinder::CTRL_OBJ],
385 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot)
386 );
387 $bearsamppWinbinder->setEnabled(
388 $this->wbBtnSave[WinBinder::CTRL_OBJ],
389 !empty($serverName)
390 );
391 }
392
393 // Handle browse button
394 if ($id == $this->wbBtnDocRoot[WinBinder::CTRL_ID]) {
395 $documentRoot = $bearsamppWinbinder->sysDlgPath(
396 $window,
398 $documentRoot
399 );
400 if ($documentRoot && is_dir($documentRoot)) {
401 $bearsamppWinbinder->setText($this->wbInputDocRoot[WinBinder::CTRL_OBJ], $documentRoot . '\\');
402 $bearsamppWinbinder->setText(
403 $this->wbLabelExp[WinBinder::CTRL_OBJ],
404 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot . '\\')
405 );
406 }
407 }
408 }
const VHOST_DOC_ROOT_PATH

References $bearsamppLang, WinBinder\CTRL_ID, WinBinder\CTRL_OBJ, Lang\VHOST_DOC_ROOT_PATH, and Lang\VHOST_EXP_LABEL.

◆ initializeDialog()

initializeDialog ( $args)
protected

Initialize the dialog by loading the existing vhost configuration.

Parameters
array$argsCommand line arguments where $args[0] is the server name.
Returns
bool True if initialization successful, false otherwise.

Reimplemented from ActionDialogBase.

Definition at line 86 of file class.action.editVhost.php.

87 {
88 global $bearsamppRoot;
89
90 if (!isset($args[0]) || empty($args[0])) {
91 return false;
92 }
93
94 $filePath = Path::getVhostsPath() . '/' . $args[0] . '.conf';
95 if (!file_exists($filePath)) {
96 return false;
97 }
98
99 $fileContent = file_get_contents($filePath);
100 if (!preg_match('/ServerName\s+(.*)/', $fileContent, $matchServerName) ||
101 !preg_match('/DocumentRoot\s+"(.*)"/', $fileContent, $matchDocumentRoot)) {
102 return false;
103 }
104
105 $this->initValue = trim($matchServerName[1]);
106
107 return true;
108 }

References $bearsamppRoot, and Path\getVhostsPath().

Here is the call graph for this function:

◆ itemExists()

itemExists ( $values)
protected

Check if a different vhost with the same server name already exists.

Parameters
array$valuesThe form values.
Returns
bool True if a conflicting vhost exists, false otherwise.

Reimplemented from ActionDialogBase.

Definition at line 225 of file class.action.editVhost.php.

226 {
227 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
228
229 // Only check if name changed
230 if ($values['serverName'] != $this->initValue && is_file(Path::getVhostsPath() . '/' . $values['serverName'] . '.conf')) {
231 $bearsamppWinbinder->messageBoxError(
232 sprintf($bearsamppLang->getValue(Lang::VHOST_ALREADY_EXISTS), $values['serverName']),
233 $this->getDialogTitle()
234 );
235
236 return true;
237 }
238
239 return false;
240 }
const VHOST_ALREADY_EXISTS

References $bearsamppLang, $bearsamppRoot, Path\getVhostsPath(), and Lang\VHOST_ALREADY_EXISTS.

Here is the call graph for this function:

◆ restartService()

restartService ( )
protected

Restart the Apache service after saving or deleting.

Returns
void

Reimplemented from ActionDialogBase.

Definition at line 357 of file class.action.editVhost.php.

358 {
359 global $bearsamppBins;
360 $bearsamppBins->getApache()->getService()->restart();
361 }
global $bearsamppBins

References $bearsamppBins.

◆ saveItem()

saveItem ( $values)
protected

Save the vhost configuration file, removing old config and certificate first.

Parameters
array$valuesThe form values.
Returns
bool True on success, false on failure.

Reimplemented from ActionDialogBase.

Definition at line 249 of file class.action.editVhost.php.

250 {
251 global $bearsamppRoot, $bearsamppBins, $bearsamppOpenSsl;
252
253 // Remove old vhost and certificate
254 $bearsamppOpenSsl->removeCrt($this->initValue);
255 @unlink(Path::getVhostsPath() . '/' . $this->initValue . '.conf');
256
257 // Create new SSL certificate
258 if (!$bearsamppOpenSsl->createCrt($values['serverName'])) {
259 return false;
260 }
261
262 // Create new vhost configuration file
263 return file_put_contents(
264 Path::getVhostsPath() . '/' . $values['serverName'] . '.conf',
265 $bearsamppBins->getApache()->getVhostContent($values['serverName'], $values['documentRoot'])
266 ) !== false;
267 }

References $bearsamppBins, $bearsamppRoot, and Path\getVhostsPath().

Here is the call graph for this function:

◆ validateInput()

validateInput ( $values)
protected

Validate the form input.

Parameters
array$valuesThe form values.
Returns
array ['valid' => bool, 'error' => string|null]

Reimplemented from ActionDialogBase.

Definition at line 204 of file class.action.editVhost.php.

205 {
206 global $bearsamppLang;
207
208 if (!Util::isValidDomainName($values['serverName'])) {
209 return [
210 'valid' => false,
211 'error' => sprintf($bearsamppLang->getValue(Lang::VHOST_NOT_VALID_DOMAIN), $values['serverName'])
212 ];
213 }
214
215 return ['valid' => true];
216 }
const VHOST_NOT_VALID_DOMAIN
static isValidDomainName($domainName)

References $bearsamppLang, Util\isValidDomainName(), and Lang\VHOST_NOT_VALID_DOMAIN.

Here is the call graph for this function:

Field Documentation

◆ $wbBtnDocRoot

$wbBtnDocRoot
private

Definition at line 26 of file class.action.editVhost.php.

◆ $wbInputDocRoot

$wbInputDocRoot
private

Definition at line 24 of file class.action.editVhost.php.

◆ $wbInputServerName

$wbInputServerName
private

Definition at line 20 of file class.action.editVhost.php.

◆ $wbLabelDocRoot

$wbLabelDocRoot
private

Definition at line 22 of file class.action.editVhost.php.

◆ $wbLabelExp

$wbLabelExp
private

Definition at line 28 of file class.action.editVhost.php.

◆ $wbLabelServerName

$wbLabelServerName
private

Definition at line 18 of file class.action.editVhost.php.

◆ GAUGE_SAVE

const GAUGE_SAVE = 3

Definition at line 31 of file class.action.editVhost.php.


The documentation for this class was generated from the following file: