2024.8.23
Loading...
Searching...
No Matches
ActionAddVhost Class Reference

Public Member Functions

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

Data Fields

const GAUGE_SAVE = 2
 

Private Attributes

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

Constructor & Destructor Documentation

◆ __construct()

ActionAddVhost::__construct ( $args)

ActionAddVhost constructor. Initializes the window and its components for adding a new virtual host.

Parameters
array$argsArguments passed to the constructor.

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

36 {
37 global $bearsamppRoot, $bearsamppLang, $bearsamppWinbinder;
38
39 $initServerName = 'test.local';
40 $initDocumentRoot = Util::formatWindowsPath($bearsamppRoot->getWwwPath()) . '\\' . $initServerName;
41
42 $bearsamppWinbinder->reset();
43 $this->wbWindow = $bearsamppWinbinder->createAppWindow($bearsamppLang->getValue(Lang::ADD_VHOST_TITLE), 490, 200, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP);
44
45 $this->wbLabelServerName = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_SERVER_NAME_LABEL) . ' :', 15, 15, 85, null, WBC_RIGHT);
46 $this->wbInputServerName = $bearsamppWinbinder->createInputText($this->wbWindow, $initServerName, 105, 13, 150, null);
47
48 $this->wbLabelDocRoot = $bearsamppWinbinder->createLabel($this->wbWindow, $bearsamppLang->getValue(Lang::VHOST_DOCUMENT_ROOT_LABEL) . ' :', 15, 45, 85, null, WBC_RIGHT);
49 $this->wbInputDocRoot = $bearsamppWinbinder->createInputText($this->wbWindow, $initDocumentRoot, 105, 43, 190, null, null, WBC_READONLY);
50 $this->wbBtnDocRoot = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_BROWSE), 300, 43, 110);
51
52 $this->wbLabelExp = $bearsamppWinbinder->createLabel($this->wbWindow, sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $initServerName, $initDocumentRoot), 15, 80, 470, 50);
53
54 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, self::GAUGE_SAVE + 1, 15, 137, 275);
55 $this->wbBtnSave = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_SAVE), 300, 132);
56 $this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow, $bearsamppLang->getValue(Lang::BUTTON_CANCEL), 387, 132);
57
58 $bearsamppWinbinder->setHandler($this->wbWindow, $this, 'processWindow');
59 $bearsamppWinbinder->mainLoop();
60 $bearsamppWinbinder->reset();
61 }
global $bearsamppLang
global $bearsamppRoot
const VHOST_EXP_LABEL
const VHOST_DOCUMENT_ROOT_LABEL
const BUTTON_CANCEL
const BUTTON_SAVE
const ADD_VHOST_TITLE
const VHOST_SERVER_NAME_LABEL
const BUTTON_BROWSE
static formatWindowsPath($path)

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

Member Function Documentation

◆ processWindow()

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

Processes window events and handles user interactions.

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

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

73 {
74 global $bearsamppRoot, $bearsamppBins, $bearsamppLang, $bearsamppOpenSsl, $bearsamppWinbinder;
75
76 $serverName = $bearsamppWinbinder->getText($this->wbInputServerName[WinBinder::CTRL_OBJ]);
77 $documentRoot = $bearsamppWinbinder->getText($this->wbInputDocRoot[WinBinder::CTRL_OBJ]);
78
79 switch ($id) {
80 case $this->wbInputServerName[WinBinder::CTRL_ID]:
81 $bearsamppWinbinder->setText(
82 $this->wbLabelExp[WinBinder::CTRL_OBJ],
83 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot)
84 );
85 $bearsamppWinbinder->setEnabled($this->wbBtnSave[WinBinder::CTRL_OBJ], empty($serverName) ? false : true);
86 break;
87 case $this->wbBtnDocRoot[WinBinder::CTRL_ID]:
88 $documentRoot = $bearsamppWinbinder->sysDlgPath($window, $bearsamppLang->getValue(Lang::VHOST_DOC_ROOT_PATH), $documentRoot);
89 if ($documentRoot && is_dir($documentRoot)) {
90 $bearsamppWinbinder->setText($this->wbInputDocRoot[WinBinder::CTRL_OBJ], $documentRoot . '\\');
91 $bearsamppWinbinder->setText(
92 $this->wbLabelExp[WinBinder::CTRL_OBJ],
93 sprintf($bearsamppLang->getValue(Lang::VHOST_EXP_LABEL), $serverName, $documentRoot . '\\')
94 );
95 }
96 break;
97 case $this->wbBtnSave[WinBinder::CTRL_ID]:
98 $bearsamppWinbinder->setProgressBarMax($this->wbProgressBar, self::GAUGE_SAVE + 1);
99 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
100
101 if (!Util::isValidDomainName($serverName)) {
102 $bearsamppWinbinder->messageBoxError(
103 sprintf($bearsamppLang->getValue(Lang::VHOST_NOT_VALID_DOMAIN), $serverName),
105 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
106 break;
107 }
108
109 if (is_file($bearsamppRoot->getVhostsPath() . '/' . $serverName . '.conf')) {
110 $bearsamppWinbinder->messageBoxError(
111 sprintf($bearsamppLang->getValue(Lang::VHOST_ALREADY_EXISTS), $serverName),
113 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
114 break;
115 }
116
117 if ($bearsamppOpenSsl->createCrt($serverName) && file_put_contents($bearsamppRoot->getVhostsPath() . '/' . $serverName . '.conf', $bearsamppBins->getApache()->getVhostContent($serverName, $documentRoot)) !== false) {
118 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
119
120 $bearsamppBins->getApache()->getService()->restart();
121 $bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
122
123 $bearsamppWinbinder->messageBoxInfo(
124 sprintf($bearsamppLang->getValue(Lang::VHOST_CREATED), $serverName, $serverName, $documentRoot),
126 $bearsamppWinbinder->destroyWindow($window);
127 } else {
128 $bearsamppWinbinder->messageBoxError($bearsamppLang->getValue(Lang::VHOST_CREATED_ERROR), $bearsamppLang->getValue(Lang::ADD_VHOST_TITLE));
129 $bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
130 }
131 break;
132 case IDCLOSE:
133 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
134 $bearsamppWinbinder->destroyWindow($window);
135 break;
136 }
137 }
global $bearsamppBins
const VHOST_NOT_VALID_DOMAIN
const VHOST_CREATED_ERROR
const VHOST_DOC_ROOT_PATH
const VHOST_CREATED
const VHOST_ALREADY_EXISTS
static isValidDomainName($domainName)

References $bearsamppBins, $bearsamppLang, $bearsamppRoot, Lang\ADD_VHOST_TITLE, WinBinder\CTRL_ID, WinBinder\CTRL_OBJ, Util\isValidDomainName(), Lang\VHOST_ALREADY_EXISTS, Lang\VHOST_CREATED, Lang\VHOST_CREATED_ERROR, Lang\VHOST_DOC_ROOT_PATH, Lang\VHOST_EXP_LABEL, and Lang\VHOST_NOT_VALID_DOMAIN.

Field Documentation

◆ $wbBtnCancel

ActionAddVhost::$wbBtnCancel
private

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

◆ $wbBtnDocRoot

ActionAddVhost::$wbBtnDocRoot
private

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

◆ $wbBtnSave

ActionAddVhost::$wbBtnSave
private

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

◆ $wbInputDocRoot

ActionAddVhost::$wbInputDocRoot
private

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

◆ $wbInputServerName

ActionAddVhost::$wbInputServerName
private

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

◆ $wbLabelDocRoot

ActionAddVhost::$wbLabelDocRoot
private

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

◆ $wbLabelExp

ActionAddVhost::$wbLabelExp
private

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

◆ $wbLabelServerName

ActionAddVhost::$wbLabelServerName
private

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

◆ $wbProgressBar

ActionAddVhost::$wbProgressBar
private

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

◆ $wbWindow

ActionAddVhost::$wbWindow
private

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

◆ GAUGE_SAVE

const ActionAddVhost::GAUGE_SAVE = 2

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


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