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

Constructor & Destructor Documentation

◆ __construct()

ActionEditVhost::__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 38 of file class.action.editVhost.php.

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

ActionEditVhost::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 82 of file class.action.editVhost.php.

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

ActionEditVhost::$initServerName
private

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

◆ $wbBtnCancel

ActionEditVhost::$wbBtnCancel
private

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

◆ $wbBtnDelete

ActionEditVhost::$wbBtnDelete
private

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

◆ $wbBtnDocRoot

ActionEditVhost::$wbBtnDocRoot
private

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

◆ $wbBtnSave

ActionEditVhost::$wbBtnSave
private

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

◆ $wbInputDocRoot

ActionEditVhost::$wbInputDocRoot
private

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

◆ $wbInputServerName

ActionEditVhost::$wbInputServerName
private

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

◆ $wbLabelDocRoot

ActionEditVhost::$wbLabelDocRoot
private

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

◆ $wbLabelExp

ActionEditVhost::$wbLabelExp
private

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

◆ $wbLabelServerName

ActionEditVhost::$wbLabelServerName
private

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

◆ $wbProgressBar

ActionEditVhost::$wbProgressBar
private

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

◆ $wbWindow

ActionEditVhost::$wbWindow
private

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

◆ GAUGE_DELETE

const ActionEditVhost::GAUGE_DELETE = 2

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

◆ GAUGE_SAVE

const ActionEditVhost::GAUGE_SAVE = 3

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


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