2024.8.23
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
10/**
11 * Class ActionChangePort
12 * Handles the process of changing the port for various services in the Bearsampp application.
13 */
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
31 /**
32 * ActionChangePort constructor.
33 * Initializes the port change process for the specified service.
34 *
35 * @param array $args The arguments passed to the constructor, where the first element specifies the service name.
36 */
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->getFilezilla()->getName() ) {
61 $this->bin = $bearsamppBins->getFilezilla();
62 $this->currentPort = $bearsamppBins->getFilezilla()->getPort();
63 $this->cntProcessActions = 3;
64 }
65 elseif ( $args[0] == $bearsamppBins->getMailhog()->getName() ) {
66 $this->bin = $bearsamppBins->getMailhog();
67 $this->currentPort = $bearsamppBins->getMailhog()->getSmtpPort();
68 $this->cntProcessActions = 3;
69 }
70 elseif ( $args[0] == $bearsamppBins->getMailpit()->getName() ) {
71 $this->bin = $bearsamppBins->getMailpit();
72 $this->currentPort = $bearsamppBins->getMailpit()->getSmtpPort();
73 $this->cntProcessActions = 3;
74 }
75 elseif ( $args[0] == $bearsamppBins->getMemcached()->getName() ) {
76 $this->bin = $bearsamppBins->getMemcached();
77 $this->currentPort = $bearsamppBins->getMemcached()->getPort();
78 $this->cntProcessActions = 3;
79 } elseif ($args[0] == $bearsamppBins->getXlight()->getName()) {
80 $this->bin = $bearsamppBins->getXlight();
81 $this->currentPort = $bearsamppBins->getXlight()->getPort();
82 $this->cntProcessActions = 3;
83 }
84 elseif ( $args[0] == $bearsamppBins->getXlight()->getName() ) {
85 $this->bin = $bearsamppBins->getXlight();
86 $this->currentPort = $bearsamppBins->getXlight()->getPort();
87 $this->cntProcessActions = 3;
88 }
89
90 $bearsamppWinbinder->reset();
91 $this->wbWindow = $bearsamppWinbinder->createAppWindow( sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_TITLE ), $args[0] ), 380, 170, WBC_NOTIFY, WBC_KEYDOWN | WBC_KEYUP );
92
93 $this->wbLabelCurrent = $bearsamppWinbinder->createLabel(
94 $this->wbWindow,
95 sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_CURRENT_LABEL ), $args[0], $this->currentPort ), 15, 15, 350
96 );
97
98 $this->wbLabelPort = $bearsamppWinbinder->createLabel( $this->wbWindow, $bearsamppLang->getValue( Lang::CHANGE_PORT_NEW_LABEL ) . ' :', 15, 45, 85, null, WBC_RIGHT );
99 $this->wbInputPort = $bearsamppWinbinder->createInputText( $this->wbWindow, $this->currentPort, 105, 43, 50, null, 5, WBC_NUMBER );
100
101 $this->wbProgressBar = $bearsamppWinbinder->createProgressBar( $this->wbWindow, $this->cntProcessActions + 1, 15, 107, 170 );
102 $this->wbBtnFinish = $bearsamppWinbinder->createButton( $this->wbWindow, $bearsamppLang->getValue( Lang::BUTTON_FINISH ), 190, 102 );
103 $this->wbBtnCancel = $bearsamppWinbinder->createButton( $this->wbWindow, $bearsamppLang->getValue( Lang::BUTTON_CANCEL ), 277, 102 );
104
105 $bearsamppWinbinder->setHandler( $this->wbWindow, $this, 'processWindow' );
106 $bearsamppWinbinder->setFocus( $this->wbInputPort[WinBinder::CTRL_OBJ] );
107 $bearsamppWinbinder->mainLoop();
108 $bearsamppWinbinder->reset();
109 }
110 }
111
112 /**
113 * Processes window events and handles user interactions.
114 *
115 * @param mixed $window The window object.
116 * @param int $id The control ID.
117 * @param mixed $ctrl The control object.
118 * @param mixed $param1 Additional parameter 1.
119 * @param mixed $param2 Additional parameter 2.
120 */
121 public function processWindow($window, $id, $ctrl, $param1, $param2)
122 {
123 global $bearsamppLang, $bearsamppWinbinder;
124 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::CHANGE_PORT_TITLE ), $this->bin );
125 $port = $bearsamppWinbinder->getText( $this->wbInputPort[WinBinder::CTRL_OBJ] );
126
127 switch ( $id ) {
128 case $this->wbInputPort[WinBinder::CTRL_ID]:
129 $bearsamppWinbinder->setEnabled( $this->wbBtnFinish[WinBinder::CTRL_OBJ], empty( $port ) ? false : true );
130 break;
131 case $this->wbBtnFinish[WinBinder::CTRL_ID]:
132 $bearsamppWinbinder->incrProgressBar( $this->wbProgressBar );
133 if ( $port == $this->currentPort ) {
134 $bearsamppWinbinder->messageBoxWarning( $bearsamppLang->getValue( Lang::CHANGE_PORT_SAME_ERROR ), $boxTitle );
135 $bearsamppWinbinder->resetProgressBar( $this->wbProgressBar );
136 break;
137 }
138 $changePort = $this->bin->changePort( $port, true, $this->wbProgressBar );
139 if ( $changePort === true ) {
140 $this->bin->getService()->restart();
141
142 $bearsamppWinbinder->messageBoxInfo(
143 sprintf( $bearsamppLang->getValue( Lang::PORT_CHANGED ), $this->bin, $port ),
144 $boxTitle
145 );
146 $bearsamppWinbinder->destroyWindow( $window );
147 }
148 else {
149 $bearsamppWinbinder->messageBoxError(
150 sprintf( $bearsamppLang->getValue( Lang::PORT_NOT_USED_BY ), $port, $changePort ),
151 $boxTitle
152 );
153 $bearsamppWinbinder->resetProgressBar( $this->wbProgressBar );
154 }
155 break;
156 case IDCLOSE:
157 case $this->wbBtnCancel[WinBinder::CTRL_ID]:
158 $bearsamppWinbinder->destroyWindow( $window );
159 break;
160 }
161 }
162}
global $bearsamppBins
global $bearsamppLang
$port
processWindow($window, $id, $ctrl, $param1, $param2)
const PORT_NOT_USED_BY
const BUTTON_CANCEL
const CHANGE_PORT_TITLE
const CHANGE_PORT_NEW_LABEL
const BUTTON_FINISH
const CHANGE_PORT_CURRENT_LABEL
const PORT_CHANGED
const CHANGE_PORT_SAME_ERROR