Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.action.changePort.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 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
15{
16 private $bin;
17 private $currentPort;
19
20 private $wbWindow;
21
23
24 private $wbLabelPort;
25 private $wbInputPort;
26
28 private $wbBtnFinish;
29 private $wbBtnCancel;
30
37 public function __construct($args)
38 {
39 global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
40
41 if ( isset( $args[0] ) && !empty( $args[0] ) ) {
42 $this->bin = $bearsamppBins->getApache();
43 $this->currentPort = $bearsamppBins->getApache()->getPort();
44 $this->cntProcessActions = 3;
45 if ( $args[0] == $bearsamppBins->getMysql()->getName() ) {
46 $this->bin = $bearsamppBins->getMysql();
47 $this->currentPort = $bearsamppBins->getMysql()->getPort();
48 $this->cntProcessActions = 3;
49 }
50 elseif ( $args[0] == $bearsamppBins->getMariadb()->getName() ) {
51 $this->bin = $bearsamppBins->getMariadb();
52 $this->currentPort = $bearsamppBins->getMariadb()->getPort();
53 $this->cntProcessActions = 3;
54 }
55 elseif ( $args[0] == $bearsamppBins->getPostgresql()->getName() ) {
56 $this->bin = $bearsamppBins->getPostgresql();
57 $this->currentPort = $bearsamppBins->getPostgresql()->getPort();
58 $this->cntProcessActions = 3;
59 }
60 elseif ( $args[0] == $bearsamppBins->getMailpit()->getName() ) {
61 $this->bin = $bearsamppBins->getMailpit();
62 $this->currentPort = $bearsamppBins->getMailpit()->getSmtpPort();
63 $this->cntProcessActions = 3;
64 }
65 elseif ( $args[0] == $bearsamppBins->getMemcached()->getName() ) {
66 $this->bin = $bearsamppBins->getMemcached();
67 $this->currentPort = $bearsamppBins->getMemcached()->getPort();
68 $this->cntProcessActions = 3;
69 } elseif ($args[0] == $bearsamppBins->getXlight()->getName()) {
70 $this->bin = $bearsamppBins->getXlight();
71 $this->currentPort = $bearsamppBins->getXlight()->getPort();
72 $this->cntProcessActions = 3;
73 }
74 elseif ( $args[0] == $bearsamppBins->getXlight()->getName() ) {
75 $this->bin = $bearsamppBins->getXlight();
76 $this->currentPort = $bearsamppBins->getXlight()->getPort();
77 $this->cntProcessActions = 3;
78 }
79
80 $bearsamppWinbinder->reset();
81 $this->wbWindow = $bearsamppWinbinder->createAppWindow( sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_TITLE ), $args[0] ), 380, 170, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP );
82
83 $this->wbLabelCurrent = $bearsamppWinbinder->createLabel(
84 $this->wbWindow,
85 sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_CURRENT_LABEL ), $args[0], $this->currentPort ), 15, 15, 350
86 );
87
88 $this->wbLabelPort = $bearsamppWinbinder->createLabel( $this->wbWindow, $bearsamppLang->getValue( Lang::CHANGE_PORT_NEW_LABEL ) . ' :', 15, 45, 85, null, WBC_RIGHT );
89 $this->wbInputPort = $bearsamppWinbinder->createInputText( $this->wbWindow, $this->currentPort, 105, 43, 50, null, 5, WBC_NUMBER );
90
91 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar( $this->wbWindow, $this->cntProcessActions + 1, 15, 107, 170 );
92 $this->wbBtnFinish = $bearsamppWinbinder->createButton( $this->wbWindow, $bearsamppLang->getValue( Lang::BUTTON_FINISH ), 190, 102 );
93 $this->wbBtnCancel = $bearsamppWinbinder->createButton( $this->wbWindow, $bearsamppLang->getValue( Lang::BUTTON_CANCEL ), 277, 102 );
94
95 $bearsamppWinbinder->setHandler( $this->wbWindow, $this, 'processWindow' );
96 $bearsamppWinbinder->setFocus( $this->wbInputPort[WinBinder::CTRL_OBJ] );
97 $bearsamppWinbinder->mainLoop();
98 $bearsamppWinbinder->reset();
99 }
100 }
101
111 public function processWindow($window, $id, $ctrl, $param1, $param2)
112 {
113 global $bearsamppLang, $bearsamppWinbinder;
114 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_TITLE ), $this->bin );
115 $port = $bearsamppWinbinder->getText( $this->wbInputPort[WinBinder::CTRL_OBJ] );
116
117 switch ( $id ) {
118 case $this->wbInputPort[WinBinder::CTRL_ID]:
119 $bearsamppWinbinder->setEnabled( $this->wbBtnFinish[WinBinder::CTRL_OBJ], empty( $port ) ? false : true );
120 break;
121 case $this->wbBtnFinish[WinBinder::CTRL_ID]:
122 $bearsamppWinbinder->incrProgressBar( $this->wbProgressBar );
123 if ( $port == $this->currentPort ) {
124 $bearsamppWinbinder->messageBoxWarning( $bearsamppLang->getValue( Lang::CHANGE_PORT_SAME_ERROR ), $boxTitle );
125 $bearsamppWinbinder->resetProgressBar( $this->wbProgressBar );
126 break;
127 }
128 $changePort = $this->bin->changePort( $port, true, $this->wbProgressBar );
129 if ( $changePort === true ) {
130 $this->bin->getService()->restart();
131
132 $bearsamppWinbinder->messageBoxInfo(
133 sprintf( $bearsamppLang->getValue( Lang::PORT_CHANGED ), $this->bin, $port ),
134 $boxTitle
135 );
136 $bearsamppWinbinder->destroyWindow( $window );
137 }
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}
global $bearsamppBins
global $bearsamppLang
$port
processWindow($window, $id, $ctrl, $param1, $param2)
const CHANGE_PORT_SAME_ERROR
const BUTTON_CANCEL
const CHANGE_PORT_CURRENT_LABEL
const CHANGE_PORT_TITLE
const CHANGE_PORT_NEW_LABEL
const PORT_CHANGED
const BUTTON_FINISH
const PORT_NOT_USED_BY