Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
class.action.changePort.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright (c) 2021-2026 Bearsampp
4
* License: GNU General Public License version 3 or later; see LICENSE.txt
5
* Author: Bear
6
* Website: https://bearsampp.com
7
* Github: https://github.com/Bearsampp
8
*/
9
14
class
ActionChangePort
15
{
17
private
$bin
;
19
private
$currentPort
;
21
private
$cntProcessActions
;
22
24
private
$wbWindow
;
25
27
private
$wbLabelCurrent
;
28
30
private
$wbLabelPort
;
32
private
$wbInputPort
;
33
35
private
$wbProgressBar
;
37
private
$wbBtnFinish
;
39
private
$wbBtnCancel
;
40
47
public
function
__construct
($args)
48
{
49
global
$bearsamppLang
,
$bearsamppBins
, $bearsamppWinbinder;
50
51
if
(isset($args[0]) && !empty($args[0])) {
52
$bin
=
$bearsamppBins
->getBinByName($args[0]);
53
if
(
$bin
!==
null
) {
54
$this->bin =
$bin
;
55
// Mailpit exposes an SMTP port separately; all other services use getPort()
56
$this->currentPort = ($args[0] ==
$bearsamppBins
->getMailpit()->getName())
57
?
$bin
->getSmtpPort()
58
:
$bin
->getPort();
59
}
else
{
60
$this->bin =
$bearsamppBins
->getApache();
61
$this->currentPort =
$bearsamppBins
->getApache()->getPort();
62
}
63
$this->cntProcessActions = 3;
64
65
$bearsamppWinbinder->reset();
66
$this->wbWindow = $bearsamppWinbinder->createAppWindow(
67
sprintf(
$bearsamppLang
->getValue(
Lang::CHANGE_PORT_TITLE
), $args[0]),
68
380,
69
170,
70
WBC_NOTIFY,
71
WBC_KEYDOWN | WBC_KEYUP
72
);
73
74
$this->wbLabelCurrent = $bearsamppWinbinder->createLabel(
75
$this->wbWindow,
76
sprintf(
$bearsamppLang
->getValue(
Lang::CHANGE_PORT_CURRENT_LABEL
), $args[0], $this->currentPort),
77
15,
78
15,
79
350
80
);
81
82
$this->wbLabelPort = $bearsamppWinbinder->createLabel($this->wbWindow,
$bearsamppLang
->getValue(
Lang::CHANGE_PORT_NEW_LABEL
) .
' :'
, 15, 45, 85,
null
, WBC_RIGHT);
83
$this->wbInputPort = $bearsamppWinbinder->createInputText($this->wbWindow, $this->currentPort, 105, 43, 50,
null
, 5, WBC_NUMBER);
84
85
$this->wbProgressBar = $bearsamppWinbinder->createProgressBar($this->wbWindow, $this->cntProcessActions + 1, 15, 107, 170);
86
$this->wbBtnFinish = $bearsamppWinbinder->createButton($this->wbWindow,
$bearsamppLang
->getValue(
Lang::BUTTON_FINISH
), 190, 102);
87
$this->wbBtnCancel = $bearsamppWinbinder->createButton($this->wbWindow,
$bearsamppLang
->getValue(
Lang::BUTTON_CANCEL
), 277, 102);
88
89
$bearsamppWinbinder->setHandler($this->wbWindow, $this,
'processWindow'
);
90
$bearsamppWinbinder->setFocus($this->wbInputPort[
WinBinder::CTRL_OBJ
]);
91
$bearsamppWinbinder->mainLoop();
92
$bearsamppWinbinder->reset();
93
}
94
}
95
105
public
function
processWindow
($window, $id, $ctrl, $param1, $param2)
106
{
107
global
$bearsamppLang
, $bearsamppWinbinder;
108
$boxTitle = sprintf(
$bearsamppLang
->getValue(
Lang::CHANGE_PORT_TITLE
), $this->bin);
109
$port
= $bearsamppWinbinder->getText($this->wbInputPort[
WinBinder::CTRL_OBJ
]);
110
111
switch
($id) {
112
case
$this->wbInputPort[
WinBinder::CTRL_ID
]:
113
$bearsamppWinbinder->setEnabled($this->wbBtnFinish[
WinBinder::CTRL_OBJ
], empty(
$port
) ?
false
:
true
);
114
break
;
115
case
$this->wbBtnFinish[
WinBinder::CTRL_ID
]:
116
$bearsamppWinbinder->incrProgressBar($this->wbProgressBar);
117
if
(
$port
== $this->currentPort) {
118
$bearsamppWinbinder->messageBoxWarning(
$bearsamppLang
->getValue(
Lang::CHANGE_PORT_SAME_ERROR
), $boxTitle);
119
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
120
break
;
121
}
122
$changePort = $this->bin->changePort(
$port
,
true
, $this->wbProgressBar);
123
if
($changePort ===
true
) {
124
Util::updateLoadingText
(
'Restarting '
. $this->bin->getName() .
'...'
);
125
$this->bin->getService()->restart();
126
127
// Rebuild tray/menu links (including localhost URL) with the new port values.
128
$menuContent =
TplApp::process
();
129
if
($menuContent !==
false
) {
130
file_put_contents(
Path::getIniFilePath
(),
Util::utf8ToCp1252
($menuContent));
131
}
132
133
$bearsamppWinbinder->messageBoxInfo(
134
sprintf(
$bearsamppLang
->getValue(
Lang::PORT_CHANGED
), $this->bin,
$port
),
135
$boxTitle
136
);
137
$bearsamppWinbinder->destroyWindow($window);
138
}
else
{
139
$bearsamppWinbinder->messageBoxError(
140
sprintf(
$bearsamppLang
->getValue(
Lang::PORT_NOT_USED_BY
),
$port
, $changePort),
141
$boxTitle
142
);
143
$bearsamppWinbinder->resetProgressBar($this->wbProgressBar);
144
}
145
break
;
146
case
IDCLOSE:
147
case
$this->wbBtnCancel[
WinBinder::CTRL_ID
]:
148
$bearsamppWinbinder->destroyWindow($window);
149
break
;
150
}
151
}
152
}
153
$bearsamppBins
global $bearsamppBins
Definition
ajax.apache.php:16
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
$port
$port
Definition
ajax.apache.php:34
ActionChangePort
Definition
class.action.changePort.php:15
ActionChangePort\$wbWindow
$wbWindow
Definition
class.action.changePort.php:24
ActionChangePort\$currentPort
$currentPort
Definition
class.action.changePort.php:19
ActionChangePort\__construct
__construct($args)
Definition
class.action.changePort.php:47
ActionChangePort\$bin
$bin
Definition
class.action.changePort.php:17
ActionChangePort\$wbLabelCurrent
$wbLabelCurrent
Definition
class.action.changePort.php:27
ActionChangePort\$wbLabelPort
$wbLabelPort
Definition
class.action.changePort.php:30
ActionChangePort\$wbBtnCancel
$wbBtnCancel
Definition
class.action.changePort.php:39
ActionChangePort\processWindow
processWindow($window, $id, $ctrl, $param1, $param2)
Definition
class.action.changePort.php:105
ActionChangePort\$wbProgressBar
$wbProgressBar
Definition
class.action.changePort.php:35
ActionChangePort\$cntProcessActions
$cntProcessActions
Definition
class.action.changePort.php:21
ActionChangePort\$wbBtnFinish
$wbBtnFinish
Definition
class.action.changePort.php:37
ActionChangePort\$wbInputPort
$wbInputPort
Definition
class.action.changePort.php:32
Lang\CHANGE_PORT_SAME_ERROR
const CHANGE_PORT_SAME_ERROR
Definition
class.lang.php:251
Lang\BUTTON_CANCEL
const BUTTON_CANCEL
Definition
class.lang.php:377
Lang\CHANGE_PORT_CURRENT_LABEL
const CHANGE_PORT_CURRENT_LABEL
Definition
class.lang.php:249
Lang\CHANGE_PORT_TITLE
const CHANGE_PORT_TITLE
Definition
class.lang.php:248
Lang\CHANGE_PORT_NEW_LABEL
const CHANGE_PORT_NEW_LABEL
Definition
class.lang.php:250
Lang\PORT_CHANGED
const PORT_CHANGED
Definition
class.lang.php:185
Lang\BUTTON_FINISH
const BUTTON_FINISH
Definition
class.lang.php:376
Lang\PORT_NOT_USED_BY
const PORT_NOT_USED_BY
Definition
class.lang.php:183
Path\getIniFilePath
static getIniFilePath($aetrayPath=false)
Definition
class.path.php:571
TplApp\process
static process()
Definition
class.tpl.app.php:43
Util\utf8ToCp1252
static utf8ToCp1252($data)
Definition
class.util.php:518
Util\updateLoadingText
static updateLoadingText($text)
Definition
class.util.php:585
WinBinder\CTRL_ID
const CTRL_ID
Definition
class.winbinder.php:21
WinBinder\CTRL_OBJ
const CTRL_OBJ
Definition
class.winbinder.php:22
sandbox
core
classes
actions
class.action.changePort.php
Generated by
1.17.0