Bearsampp 2026.3.26
API documentation
Loading...
Searching...
No Matches
ActionEditVhost Class Reference
Inheritance 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 form fields specific to the dialog This method should create all input fields, labels, and buttons

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
void

Reimplemented from ActionDialogBase.

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

73 {
75
76 // Load existing vhost data
77 $filePath = $bearsamppRoot->getVhostsPath() . '/' . $this->initValue . '.conf';
78 $fileContent = file_get_contents($filePath);
79 preg_match('/DocumentRoot\s+"(.*)"/', $fileContent, $matchDocumentRoot);
80 $initDocumentRoot = Util::formatWindowsPath(trim($matchDocumentRoot[1]));
81
82 $this->wbLabelServerName = $bearsamppWinbinder->createLabel(
83 $this->wbWindow,
85 15, 15, 85, null, WBC_RIGHT
86 );
87 $this->wbInputServerName = $bearsamppWinbinder->createInputText(
88 $this->wbWindow,
89 $this->initValue,
90 105, 13, 150, null
91 );
92
93 $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel(
94 $this->wbWindow,
96 15, 45, 85, null, WBC_RIGHT
97 );
98 $this->wbInputDocRoot = $bearsamppWinbinder->createInputText(
99 $this->wbWindow,
100 $initDocumentRoot,
101 105, 43, 190, null, null, WBC_READONLY
102 );
103 $this->wbBtnDocRoot = $bearsamppWinbinder->createButton(
104 $this->wbWindow,
106 300, 43, 110
107 );
108
109 $this->wbLabelExp = $bearsamppWinbinder->createLabel(
110 $this->wbWindow,
111 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $this->initValue, $initDocumentRoot),
112 15, 80, 470, 50
113 );
114 }
global $bearsamppLang
global $bearsamppRoot
const VHOST_EXP_LABEL
const VHOST_SERVER_NAME_LABEL
const BUTTON_BROWSE
const VHOST_DOCUMENT_ROOT_LABEL
static formatWindowsPath($path)

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

◆ deleteItem()

deleteItem ( )
protected

Delete the item

Returns
bool True on success, false on failure

Reimplemented from ActionDialogBase.

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

175 {
176 global $bearsamppRoot, $bearsamppOpenSsl;
177
178 return $bearsamppOpenSsl->removeCrt($this->initValue) &&
179 @unlink($bearsamppRoot->getVhostsPath() . '/' . $this->initValue . '.conf');
180 }

References $bearsamppRoot.

◆ getDeleteConfirmMessage()

getDeleteConfirmMessage ( )
protected

Get delete confirmation message

Returns
string The confirmation message

Reimplemented from ActionDialogBase.

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

200 {
201 global $bearsamppLang;
202 return sprintf($bearsamppLang->getValue(Lang::DELETE_VHOST), $this->initValue);
203 }
const DELETE_VHOST

References $bearsamppLang, and Lang\DELETE_VHOST.

◆ getDeleteDialogTitle()

getDeleteDialogTitle ( )
protected

Get the delete dialog title

Returns
string The delete dialog title

Reimplemented from ActionDialogBase.

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

44 {
45 global $bearsamppLang;
47 }
const DELETE_VHOST_TITLE

References $bearsamppLang, and Lang\DELETE_VHOST_TITLE.

◆ getDeleteErrorMessage()

getDeleteErrorMessage ( )
protected

Get error message after delete failure

Returns
string The error message

Reimplemented from ActionDialogBase.

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

212 {
214 return sprintf(
216 $bearsamppRoot->getVhostsPath() . '/' . $this->initValue . '.conf'
217 );
218 }
const VHOST_REMOVE_ERROR

References $bearsamppLang, $bearsamppRoot, and Lang\VHOST_REMOVE_ERROR.

◆ getDeleteSuccessMessage()

getDeleteSuccessMessage ( )
protected

Get success message after delete

Returns
string The success message

Reimplemented from ActionDialogBase.

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

206 {
207 global $bearsamppLang;
208 return sprintf($bearsamppLang->getValue(Lang::VHOST_REMOVED), $this->initValue);
209 }
const VHOST_REMOVED

References $bearsamppLang, and Lang\VHOST_REMOVED.

◆ getDialogTitle()

getDialogTitle ( )
protected

Get the dialog title for messages

Returns
string The dialog title

Reimplemented from ActionDialogBase.

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

38 {
39 global $bearsamppLang;
40 return sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initValue);
41 }
const EDIT_VHOST_TITLE

References $bearsamppLang, and Lang\EDIT_VHOST_TITLE.

◆ getFormValues()

getFormValues ( $bearsamppWinbinder)
protected

Get the current form values

Parameters
object$bearsamppWinbinderThe WinBinder instance
Returns
array Associative array of form values

Reimplemented from ActionDialogBase.

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

117 {
118 return [
119 'serverName' => $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]),
120 'documentRoot' => $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ])
121 ];
122 }

References WinBinder\CTRL_OBJ.

◆ getGaugeSave()

getGaugeSave ( )
protected

Get the gauge value for save operation (can be overridden)

Returns
int The gauge value

Reimplemented from ActionDialogBase.

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

27 {
28 return self::GAUGE_SAVE;
29 }

◆ getSaveErrorMessage()

getSaveErrorMessage ( )
protected

Get error message after save failure

Returns
string The error message

Reimplemented from ActionDialogBase.

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

194 {
195 global $bearsamppLang;
197 }
const VHOST_CREATED_ERROR

References $bearsamppLang, and Lang\VHOST_CREATED_ERROR.

◆ getSaveSuccessMessage()

getSaveSuccessMessage ( $values)
protected

Get success message after save

Parameters
array$valuesThe form values
Returns
string The success message

Reimplemented from ActionDialogBase.

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

183 {
184 global $bearsamppLang;
185 return sprintf(
187 $values['serverName'],
188 $values['serverName'],
189 $values['documentRoot']
190 );
191 }
const VHOST_CREATED

References $bearsamppLang, and Lang\VHOST_CREATED.

◆ getWindowTitle()

getWindowTitle ( )
protected

Get the dialog window title

Returns
string The window title

Reimplemented from ActionDialogBase.

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

32 {
33 global $bearsamppLang;
34 return sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initValue);
35 }

References $bearsamppLang, and Lang\EDIT_VHOST_TITLE.

◆ handleCustomEvent()

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

Handle custom events (can be overridden by child classes)

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 226 of file class.action.editVhost.php.

227 {
228 global $bearsamppLang, $bearsamppWinbinder;
229
230 $serverName = $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]);
231 $documentRoot = $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ]);
232
233 // Handle server name input change
234 if ($id == $this->wbInputServerName[WinBinder::CTRL_ID]) {
235 $bearsamppWinbinder->setText(
236 $this->wbLabelExp[WinBinder::CTRL_OBJ],
237 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot)
238 );
239 $bearsamppWinbinder->setEnabled(
240 $this->wbBtnSave[WinBinder::CTRL_OBJ],
241 !empty($serverName)
242 );
243 }
244
245 // Handle browse button
246 if ($id == $this->wbBtnDocRoot[WinBinder::CTRL_ID]) {
247 $documentRoot = $bearsamppWinbinder->sysDlgPath(
248 $window,
250 $documentRoot
251 );
252 if ($documentRoot && is_dir($documentRoot)) {
253 $bearsamppWinbinder->setText($this->wbInputDocRoot[WinBinder::CTRL_OBJ], $documentRoot . '\\');
254 $bearsamppWinbinder->setText(
255 $this->wbLabelExp[WinBinder::CTRL_OBJ],
256 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot . '\\')
257 );
258 }
259 }
260 }
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 window

Parameters
array$argsCommand line arguments
Returns
bool True if initialization successful, false otherwise

Reimplemented from ActionDialogBase.

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

50 {
51 global $bearsamppRoot;
52
53 if (!isset($args[0]) || empty($args[0])) {
54 return false;
55 }
56
57 $filePath = $bearsamppRoot->getVhostsPath() . '/' . $args[0] . '.conf';
58 if (!file_exists($filePath)) {
59 return false;
60 }
61
62 $fileContent = file_get_contents($filePath);
63 if (!preg_match('/ServerName\s+(.*)/', $fileContent, $matchServerName) ||
64 !preg_match('/DocumentRoot\s+"(.*)"/', $fileContent, $matchDocumentRoot)) {
65 return false;
66 }
67
68 $this->initValue = trim($matchServerName[1]);
69 return true;
70 }

References $bearsamppRoot.

◆ itemExists()

itemExists ( $values)
protected

Check if the item already exists (for add/edit operations)

Parameters
array$valuesThe form values
Returns
bool True if exists, false otherwise

Reimplemented from ActionDialogBase.

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

139 {
140 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
141
142 // Only check if name changed
143 if ($values['serverName'] != $this->initValue && is_file($bearsamppRoot->getVhostsPath() . '/' . $values['serverName'] . '.conf')) {
144 $bearsamppWinbinder->messageBoxError(
145 sprintf($bearsamppLang->getValue(Lang::VHOST_ALREADY_EXISTS), $values['serverName']),
146 $this->getDialogTitle()
147 );
148 return true;
149 }
150
151 return false;
152 }
const VHOST_ALREADY_EXISTS

References $bearsamppLang, $bearsamppRoot, and Lang\VHOST_ALREADY_EXISTS.

◆ restartService()

restartService ( )
protected

Restart the service after save/delete

Returns
void

Reimplemented from ActionDialogBase.

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

221 {
222 global $bearsamppBins;
223 $bearsamppBins->getApache()->getService()->restart();
224 }
global $bearsamppBins

References $bearsamppBins.

◆ saveItem()

saveItem ( $values)
protected

Save the item (create or update)

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

Reimplemented from ActionDialogBase.

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

155 {
156 global $bearsamppRoot, $bearsamppBins, $bearsamppOpenSsl;
157
158 // Remove old vhost and certificate
159 $bearsamppOpenSsl->removeCrt($this->initValue);
160 @unlink($bearsamppRoot->getVhostsPath() . '/' . $this->initValue . '.conf');
161
162 // Create new SSL certificate
163 if (!$bearsamppOpenSsl->createCrt($values['serverName'])) {
164 return false;
165 }
166
167 // Create new vhost configuration file
168 return file_put_contents(
169 $bearsamppRoot->getVhostsPath() . '/' . $values['serverName'] . '.conf',
170 $bearsamppBins->getApache()->getVhostContent($values['serverName'], $values['documentRoot'])
171 ) !== false;
172 }

References $bearsamppBins, and $bearsamppRoot.

◆ 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 124 of file class.action.editVhost.php.

125 {
126 global $bearsamppLang;
127
128 if (!Util::isValidDomainName($values['serverName'])) {
129 return [
130 'valid' => false,
131 'error' => sprintf($bearsamppLang->getValue(Lang::VHOST_NOT_VALID_DOMAIN), $values['serverName'])
132 ];
133 }
134
135 return ['valid' => true];
136 }
const VHOST_NOT_VALID_DOMAIN
static isValidDomainName($domainName)

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

Field Documentation

◆ $wbBtnDocRoot

$wbBtnDocRoot
private

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

◆ $wbInputDocRoot

$wbInputDocRoot
private

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

◆ $wbInputServerName

$wbInputServerName
private

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

◆ $wbLabelDocRoot

$wbLabelDocRoot
private

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

◆ $wbLabelExp

$wbLabelExp
private

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

◆ $wbLabelServerName

$wbLabelServerName
private

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

◆ GAUGE_SAVE

const GAUGE_SAVE = 3

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


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