Bearsampp 2025.8.29
Loading...
Searching...
No Matches
ActionEditVhost Class Reference

Public Member Functions

 __construct ($args)
 processWindow ($window, $id, $ctrl, $param1, $param2)

Data Fields

const GAUGE_DELETE = 2
const GAUGE_SAVE = 3

Private Attributes

 $initServerName
 $wbBtnCancel
 $wbBtnDelete
 $wbBtnDocRoot
 $wbBtnSave
 $wbInputDocRoot
 $wbInputServerName
 $wbLabelDocRoot
 $wbLabelExp
 $wbLabelServerName
 $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.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $args)

ActionEditVhost constructor. Initializes the virtual host editing window and its components.

Parameters
array$argsArguments passed to the constructor, typically containing the server name.

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

40 {
41 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
42
43 if (isset($args[0]) && !empty($args[0])) {
44 $filePath = $bearsamppRoot->getVhostsPath() . '/' . $args[0] . '.conf';
45 $fileContent = file_get_contents($filePath);
46 if (preg_match('/ServerName\s+(.*)/', $fileContent, $matchServerName) && preg_match('/DocumentRoot\s+"(.*)"/', $fileContent, $matchDocumentRoot)) {
47 $this->initServerName = trim($matchServerName[1]);
48 $initDocumentRoot = Util::formatWindowsPath(trim($matchDocumentRoot[1]));
49
50 $bearsamppWinbinder->reset();
51 $this->wbWindow = $bearsamppWinbinder->createAppWindow(sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
52
53 $this->wbLabelServerName = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_SERVER_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT);
54 $this->wbInputServerName = $bearsamppWinbinder->createInputText($this->wbWindow, $this->initServerName, 105, 13, 150, null);
55
56 $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_DOCUMENT_ROOT_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT);
57 $this->wbInputDocRoot = $bearsamppWinbinder->createInputText($this->wbWindow, $initDocumentRoot, 105, 43, 190, null, null, WBC_READONLY);
58 $this->wbBtnDocRoot = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110);
59
60 $this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $this->initServerName, $initDocumentRoot), 15, 80, 470, 50);
61
62 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 190);
63 $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 215, 132);
64 $this->wbBtnDelete = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_DELETE), 300, 132);
65 $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 385, 132);
66
67 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
68 $bearsamppWinbinder->mainLoop();
69 $bearsamppWinbinder->reset();
70 }
71 }
72 }
global $bearsamppLang
global $bearsamppRoot
const VHOST_EXP_LABEL
const VHOST_SERVER_NAME_LABEL
const BUTTON_BROWSE
const BUTTON_CANCEL
const BUTTON_DELETE
const VHOST_DOCUMENT_ROOT_LABEL
const BUTTON_SAVE
const EDIT_VHOST_TITLE
static formatWindowsPath($path)

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

Member Function Documentation

◆ processWindow()

processWindow ( $window,
$id,
$ctrl,
$param1,
$param2 )

Processes window events and handles user interactions.

Parameters
mixed$windowThe window object.
int$idThe ID of the control that triggered the event.
mixed$ctrlThe control object.
mixed$param1Additional parameter 1.
mixed$param2Additional parameter 2.

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

84 {
85 global $bearsamppRoot, $bearsamppBins, $bearsamppLang, $bearsamppOpenSsl, $bearsamppWinbinder;
86
87 $serverName = $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]);
88 $documentRoot = $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ]);
89
90 switch ($id) {
91 case $this->wbInputServerName[WinBinder::CTRL_ID]:
92 $bearsamppWinbinder->setText(
93 $this->wbLabelExp[WinBinder::CTRL_OBJ],
94 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot)
95 );
96 $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($serverName) ? false : true);
97 break;
98 case $this->wbBtnDocRoot[WinBinder::CTRL_ID]:
99 $documentRoot = $bearsamppWinbinder->sysDlgPath($window, $bearsamppLang->getValue(Lang::VHOST_DOC_ROOT_PATH), $documentRoot);
100 if ($documentRoot && is_dir($documentRoot)) {
101 $bearsamppWinbinder->setText($this->wbInputDocRoot[WinBinder::CTRL_OBJ], $documentRoot . '\\');
102 $bearsamppWinbinder->setText(
103 $this->wbLabelExp[WinBinder::CTRL_OBJ],
104 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot . '\\')
105 );
106 // Reload to add host
108 }
109 break;
110 case $this->wbBtnSave[WinBinder::CTRL_ID]:
111 $bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_SAVE + 1);
112 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
113
114 if (!Util::isValidDomainName($serverName)) {
115 $bearsamppWinbinder->messageBoxError(
116 sprintf($bearsamppLang->getValue(Lang::VHOST_NOT_VALID_DOMAIN), $serverName),
118 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
119 break;
120 }
121
122 if ($serverName != $this->initServerName && is_file($bearsamppRoot->getVhostsPath() . '/' . $serverName . '.conf')) {
123 $bearsamppWinbinder->messageBoxError(
124 sprintf($bearsamppLang->getValue(Lang::VHOST_ALREADY_EXISTS), $serverName),
125 sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName));
126 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
127 break;
128 }
129
130 // Remove old vhost
131 $bearsamppOpenSsl->removeCrt($this->initServerName);
132 @unlink($bearsamppRoot->getVhostsPath() . '/' . $this->initServerName . '.conf');
133
134 if ($bearsamppOpenSsl->createCrt($serverName) && file_put_contents($bearsamppRoot->getVhostsPath() . '/' . $serverName . '.conf', $bearsamppBins->getApache()->getVhostContent($serverName, $documentRoot)) !== false) {
135 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
136
137 $bearsamppBins->getApache()->getService()->restart();
138 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
139
140 $bearsamppWinbinder->messageBoxInfo(
141 sprintf($bearsamppLang->getValue(Lang::VHOST_CREATED), $serverName, $serverName, $documentRoot),
142 sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName));
143 $bearsamppWinbinder->destroyWindow($window);
144 } else {
145 $bearsamppWinbinder->messageBoxError(
147 sprintf($bearsamppLang->getValue(Lang::EDIT_VHOST_TITLE), $this->initServerName));
148 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
149 }
150 // Reload to remove host
152
153 break;
154 case $this->wbBtnDelete[WinBinder::CTRL_ID]:
155 $bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_DELETE + 1);
156
157 $boxTitle = $bearsamppLang->getValue(Lang::DELETE_VHOST_TITLE);
158 $confirm = $bearsamppWinbinder->messageBoxYesNo(
159 sprintf($bearsamppLang->getValue(Lang::DELETE_VHOST), $this->initServerName),
160 $boxTitle);
161
162 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
163
164 if ($confirm) {
165 if ($bearsamppOpenSsl->removeCrt($this->initServerName) && @unlink($bearsamppRoot->getVhostsPath() . '/' . $this->initServerName . '.conf')) {
166 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
167
168 $bearsamppBins->getApache()->getService()->restart();
169 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
170
171 $bearsamppWinbinder->messageBoxInfo(
172 sprintf($bearsamppLang->getValue(Lang::VHOST_REMOVED), $this->initServerName),
173 $boxTitle);
174 $bearsamppWinbinder->destroyWindow($window);
175 } else {
176 $bearsamppWinbinder->messageBoxError(
177 sprintf($bearsamppLang->getValue(Lang::VHOST_REMOVE_ERROR), $bearsamppRoot->getVhostsPath() . '/' . $this->initServerName . '.conf'),
178 $boxTitle);
179 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
180 }
181 }
182 break;
183 case IDCLOSE:
184 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
185 $bearsamppWinbinder->destroyWindow($window);
186 break;
187 }
188 }
global $bearsamppBins
const VHOST_REMOVE_ERROR
const VHOST_CREATED_ERROR
const VHOST_CREATED
const VHOST_NOT_VALID_DOMAIN
const DELETE_VHOST_TITLE
const DELETE_VHOST
const ADD_VHOST_TITLE
const VHOST_ALREADY_EXISTS
const VHOST_DOC_ROOT_PATH
const VHOST_REMOVED
static getActionRestart($sName)
static isValidDomainName($domainName)

References $bearsamppBins, $bearsamppLang, $bearsamppRoot, Lang\ADD_VHOST_TITLE, WinBinder\CTRL_ID, WinBinder\CTRL_OBJ, Lang\DELETE_VHOST, Lang\DELETE_VHOST_TITLE, Lang\EDIT_VHOST_TITLE, TplService\getActionRestart(), Util\isValidDomainName(), BinApache\SERVICE_NAME, Lang\VHOST_ALREADY_EXISTS, Lang\VHOST_CREATED, Lang\VHOST_CREATED_ERROR, Lang\VHOST_DOC_ROOT_PATH, Lang\VHOST_EXP_LABEL, Lang\VHOST_NOT_VALID_DOMAIN, Lang\VHOST_REMOVE_ERROR, and Lang\VHOST_REMOVED.

Field Documentation

◆ $initServerName

$initServerName
private

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

◆ $wbBtnCancel

$wbBtnCancel
private

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

◆ $wbBtnDelete

$wbBtnDelete
private

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

◆ $wbBtnDocRoot

$wbBtnDocRoot
private

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

◆ $wbBtnSave

$wbBtnSave
private

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

◆ $wbInputDocRoot

$wbInputDocRoot
private

Definition at line 22 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 21 of file class.action.editVhost.php.

◆ $wbLabelExp

$wbLabelExp
private

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

◆ $wbLabelServerName

$wbLabelServerName
private

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

◆ $wbProgressBar

$wbProgressBar
private

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

◆ $wbWindow

$wbWindow
private

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

◆ GAUGE_DELETE

const GAUGE_DELETE = 2

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

◆ GAUGE_SAVE

const GAUGE_SAVE = 3

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


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