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

Protected Member Functions

 createFormFields ($bearsamppWinbinder)
 deleteItem ()
 getDeleteConfirmMessage ()
 getDeleteDialogTitle ()
 getDeleteErrorMessage ()
 getDeleteSuccessMessage ()
 getDialogTitle ()
 getFormValues ($bearsamppWinbinder)
 getSaveErrorMessage ()
 getSaveSuccessMessage ($values)
 getWindowTitle ()
 handleCustomEvent ($window, $id, $ctrl, $param1, $param2)
 itemExists ($values)
 restartService ()
 saveItem ($values)
 validateInput ($values)
Protected Member Functions inherited from ActionDialogBase
 createButtons ($bearsamppWinbinder)
 getGaugeDelete ()
 getGaugeSave ()
 handleDelete ($window)
 handleSave ($window)
 initializeDialog ($args)
 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)
Data Fields inherited from ActionDialogBase
const GAUGE_DELETE = 2
const GAUGE_SAVE = 2
Protected Attributes inherited from ActionDialogBase
 $initValue
 $wbBtnCancel
 $wbBtnDelete
 $wbBtnSave
 $wbProgressBar
 $wbWindow

Detailed Description

Class ActionAddVhost Handles the creation of a new virtual host (vhost) in the Bearsampp application.

Definition at line 14 of file class.action.addVhost.php.

Member Function Documentation

◆ createFormFields()

createFormFields ( $bearsamppWinbinder)
protected

Create the form fields for the add vhost dialog.

Parameters
object$bearsamppWinbinderThe WinBinder instance.
Returns
void

Reimplemented from ActionDialogBase.

Definition at line 71 of file class.action.addVhost.php.

72 {
74
75 $initServerName = 'test.local';
76 $initDocumentRoot = Path::formatWindowsPath(Path::getWwwPath()) . '\\' . $initServerName;
77
78 $this->wbLabelServerName = $bearsamppWinbinder->createLabel(
79 $this->wbWindow,
81 15,
82 15,
83 85,
84 null,
85 WBC_RIGHT
86 );
87 $this->wbInputServerName = $bearsamppWinbinder->createInputText(
88 $this->wbWindow,
89 $initServerName,
90 105,
91 13,
92 150,
93 null
94 );
95
96 $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel(
97 $this->wbWindow,
99 15,
100 45,
101 85,
102 null,
103 WBC_RIGHT
104 );
105 $this->wbInputDocRoot = $bearsamppWinbinder->createInputText(
106 $this->wbWindow,
107 $initDocumentRoot,
108 105,
109 43,
110 190,
111 null,
112 null,
113 WBC_READONLY
114 );
115 $this->wbBtnDocRoot = $bearsamppWinbinder->createButton(
116 $this->wbWindow,
118 300,
119 43,
120 110
121 );
122
123 $this->wbLabelExp = $bearsamppWinbinder->createLabel(
124 $this->wbWindow,
125 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $initServerName, $initDocumentRoot),
126 15,
127 80,
128 470,
129 50
130 );
131 }
global $bearsamppLang
global $bearsamppRoot
const VHOST_EXP_LABEL
const VHOST_SERVER_NAME_LABEL
const BUTTON_BROWSE
const VHOST_DOCUMENT_ROOT_LABEL
static getWwwPath($aetrayPath=false)
static formatWindowsPath($path)

References $bearsamppLang, $bearsamppRoot, Lang\BUTTON_BROWSE, Path\formatWindowsPath(), Path\getWwwPath(), 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. Not used in add mode.

Returns
bool Always returns false.

Reimplemented from ActionDialogBase.

Definition at line 220 of file class.action.addVhost.php.

221 {
222 // Not used in add mode
223 return false;
224 }

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
protected

Get the delete confirmation message. Not used in add mode.

Returns
string Empty string.

Reimplemented from ActionDialogBase.

Definition at line 262 of file class.action.addVhost.php.

263 {
264 // Not used in add mode
265 return '';
266 }

◆ getDeleteDialogTitle()

getDeleteDialogTitle ( )
protected

Get the delete dialog title.

Returns
string Empty string, not used in add mode.

Reimplemented from ActionDialogBase.

Definition at line 58 of file class.action.addVhost.php.

59 {
60 // Not used in add mode
61 return '';
62 }

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
protected

Get the error message after delete failure. Not used in add mode.

Returns
string Empty string.

Reimplemented from ActionDialogBase.

Definition at line 284 of file class.action.addVhost.php.

285 {
286 // Not used in add mode
287 return '';
288 }

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
protected

Get the success message after delete. Not used in add mode.

Returns
string Empty string.

Reimplemented from ActionDialogBase.

Definition at line 273 of file class.action.addVhost.php.

274 {
275 // Not used in add mode
276 return '';
277 }

◆ getDialogTitle()

getDialogTitle ( )
protected

Get the dialog title for message boxes.

Returns
string The localized dialog title.

Reimplemented from ActionDialogBase.

Definition at line 46 of file class.action.addVhost.php.

47 {
48 global $bearsamppLang;
49
50 return $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE);
51 }
const ADD_VHOST_TITLE

References $bearsamppLang, and Lang\ADD_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 140 of file class.action.addVhost.php.

141 {
142 return [
143 'serverName' => $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]),
144 'documentRoot' => $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ])
145 ];
146 }

References WinBinder\CTRL_OBJ.

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
protected

Get the error message after save failure.

Returns
string The localized error message.

Reimplemented from ActionDialogBase.

Definition at line 250 of file class.action.addVhost.php.

251 {
252 global $bearsamppLang;
253
255 }
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 233 of file class.action.addVhost.php.

234 {
235 global $bearsamppLang;
236
237 return sprintf(
239 $values['serverName'],
240 $values['serverName'],
241 $values['documentRoot']
242 );
243 }
const VHOST_CREATED

References $bearsamppLang, and Lang\VHOST_CREATED.

◆ getWindowTitle()

getWindowTitle ( )
protected

Get the dialog window title.

Returns
string The localized window title.

Reimplemented from ActionDialogBase.

Definition at line 34 of file class.action.addVhost.php.

35 {
36 global $bearsamppLang;
37
38 return $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE);
39 }

References $bearsamppLang, and Lang\ADD_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 312 of file class.action.addVhost.php.

313 {
314 global $bearsamppLang, $bearsamppWinbinder;
315
316 $serverName = $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]);
317 $documentRoot = $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ]);
318
319 // Handle server name input change
320 if ($id == $this->wbInputServerName[WinBinder::CTRL_ID]) {
321 $bearsamppWinbinder->setText(
322 $this->wbLabelExp[WinBinder::CTRL_OBJ],
323 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot)
324 );
325 $bearsamppWinbinder->setEnabled(
326 $this->wbBtnSave[WinBinder::CTRL_OBJ],
327 !empty($serverName)
328 );
329 }
330
331 // Handle browse button
332 if ($id == $this->wbBtnDocRoot[WinBinder::CTRL_ID]) {
333 $documentRoot = $bearsamppWinbinder->sysDlgPath(
334 $window,
336 $documentRoot
337 );
338 if ($documentRoot && is_dir($documentRoot)) {
339 $bearsamppWinbinder->setText($this->wbInputDocRoot[WinBinder::CTRL_OBJ], $documentRoot . '\\');
340 $bearsamppWinbinder->setText(
341 $this->wbLabelExp[WinBinder::CTRL_OBJ],
342 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot . '\\')
343 );
344 }
345 }
346 }
const VHOST_DOC_ROOT_PATH

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

◆ itemExists()

itemExists ( $values)
protected

Check if a vhost configuration file already exists.

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

Reimplemented from ActionDialogBase.

Definition at line 176 of file class.action.addVhost.php.

177 {
178 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
179
180 if (is_file(Path::getVhostsPath() . '/' . $values['serverName'] . '.conf')) {
181 $bearsamppWinbinder->messageBoxError(
182 sprintf($bearsamppLang->getValue(Lang::VHOST_ALREADY_EXISTS), $values['serverName']),
183 $this->getDialogTitle()
184 );
185
186 return true;
187 }
188
189 return false;
190 }
const VHOST_ALREADY_EXISTS
static getVhostsPath($aetrayPath=false)

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.

Returns
void

Reimplemented from ActionDialogBase.

Definition at line 295 of file class.action.addVhost.php.

296 {
297 global $bearsamppBins;
298 $bearsamppBins->getApache()->getService()->restart();
299 }
global $bearsamppBins

References $bearsamppBins.

◆ saveItem()

saveItem ( $values)
protected

Save the vhost configuration file and create an SSL certificate.

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

Reimplemented from ActionDialogBase.

Definition at line 199 of file class.action.addVhost.php.

200 {
201 global $bearsamppRoot, $bearsamppBins, $bearsamppOpenSsl;
202
203 // Create SSL certificate
204 if (!$bearsamppOpenSsl->createCrt($values['serverName'])) {
205 return false;
206 }
207
208 // Create vhost configuration file
209 return file_put_contents(
210 Path::getVhostsPath() . '/' . $values['serverName'] . '.conf',
211 $bearsamppBins->getApache()->getVhostContent($values['serverName'], $values['documentRoot'])
212 ) !== false;
213 }

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 155 of file class.action.addVhost.php.

156 {
157 global $bearsamppLang;
158
159 if (!Util::isValidDomainName($values['serverName'])) {
160 return [
161 'valid' => false,
162 'error' => sprintf($bearsamppLang->getValue(Lang::VHOST_NOT_VALID_DOMAIN), $values['serverName'])
163 ];
164 }
165
166 return ['valid' => true];
167 }
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 25 of file class.action.addVhost.php.

◆ $wbInputDocRoot

$wbInputDocRoot
private

Definition at line 23 of file class.action.addVhost.php.

◆ $wbInputServerName

$wbInputServerName
private

Definition at line 19 of file class.action.addVhost.php.

◆ $wbLabelDocRoot

$wbLabelDocRoot
private

Definition at line 21 of file class.action.addVhost.php.

◆ $wbLabelExp

$wbLabelExp
private

Definition at line 27 of file class.action.addVhost.php.

◆ $wbLabelServerName

$wbLabelServerName
private

Definition at line 17 of file class.action.addVhost.php.


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