2024.8.23
Loading...
Searching...
No Matches
BinXlight Class Reference
+ Inheritance diagram for BinXlight:
+ Collaboration diagram for BinXlight:

Public Member Functions

 __construct ($id, $type)
 
 changePort ($port, $checkUsed=false, $wbProgressBar=null)
 
 checkPort ($port, $showWindow=false)
 
 getExe ()
 
 getLog ()
 
 getPort ()
 
 getService ()
 
 getUiPort ()
 
 rebuildConf ()
 
 reload ($id=null, $type=null)
 
 setEnable ($enabled, $showWindow=false)
 
 setPort ($port)
 
 setSslPort ($SslPort)
 
 setVersion ($version)
 
 switchVersion ($version, $showWindow=false)
 
- Public Member Functions inherited from Module
 __toString ()
 
 getCurrentPath ()
 
 getId ()
 
 getName ()
 
 getRelease ()
 
 getRootPath ()
 
 getSymlinkPath ()
 
 getType ()
 
 getVersion ()
 
 getVersionList ()
 
 isEnable ()
 
 update ($sub=0, $showWindow=false)
 

Data Fields

const LOCAL_CFG_EXE = 'xlightExe'
 
const LOCAL_CFG_PORT = 'xlightPort'
 
const LOCAL_CFG_SSL_PORT = 'xlightSslPort'
 
const ROOT_CFG_ENABLE = 'xlightEnable'
 
const ROOT_CFG_VERSION = 'xlightVersion'
 
const SERVICE_NAME = 'bearsamppxlight'
 
const SERVICE_PARAMS = ' -startall'
 
- Data Fields inherited from Module
const BUNDLE_RELEASE = 'bundleRelease'
 

Protected Member Functions

 replaceAll ($params)
 
 updateConfig ($version=null, $sub=0, $showWindow=false)
 
- Protected Member Functions inherited from Module
 __construct ()
 
 replace ($key, $value)
 

Private Attributes

 $exe
 
 $log
 
 $port
 
 $service
 
 $SslPort
 

Additional Inherited Members

- Protected Attributes inherited from Module
 $bearsamppConf
 
 $bearsamppConfRaw
 
 $currentPath
 
 $enable
 
 $name
 
 $release = 'N/A'
 
 $rootPath
 
 $symlinkPath
 
 $version
 

Detailed Description

Class BinXlight

This class represents the Xlight FTP server module in the Bearsampp application. It handles the configuration, initialization, and management of the Xlight FTP server.

Definition at line 16 of file class.bin.xlight.php.

Constructor & Destructor Documentation

◆ __construct()

BinXlight::__construct ( $id,
$type )

Constructs a BinXlight object and initializes the module.

Parameters
string$idThe ID of the module.
string$typeThe type of the module.

Definition at line 41 of file class.bin.xlight.php.

41 {
42 Util::logInitClass($this);
43 $this->reload($id, $type);
44 }
reload($id=null, $type=null)
static logInitClass($classInstance)

References Module\$id, Module\$type, Util\logInitClass(), and reload().

Member Function Documentation

◆ changePort()

BinXlight::changePort ( $port,
$checkUsed = false,
$wbProgressBar = null )

Changes the port used by the Xlight FTP server.

Parameters
int$portThe new port number.
bool$checkUsedWhether to check if the port is already in use.
mixed | null$wbProgressBarThe progress bar object for UI updates (optional).
Returns
bool|int True if the port was successfully changed, false if invalid, or the process using the port.

Definition at line 167 of file class.bin.xlight.php.

167 {
168 global $bearsamppWinbinder;
169
170 if (!Util::isValidPort($port)) {
171 Util::logError($this->getName() . ' port not valid: ' . $port);
172 return false;
173 }
174
175 $port = intval($port);
176 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
177
178 $isPortInUse = Util::isPortInUse($port);
179 if (!$checkUsed || $isPortInUse === false) {
180 // bearsampp.conf
181 $this->setSmtpPort($port);
182 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
183
184 // conf
185 $this->update();
186 $bearsamppWinbinder->incrProgressBar($wbProgressBar);
187
188 return true;
189 }
190
191 Util::logDebug($this->getName() . ' port in used: ' . $port . ' - ' . $isPortInUse);
192 return $isPortInUse;
193 }
update($sub=0, $showWindow=false)
static logError($data, $file=null)
static isValidPort($port)
static logDebug($data, $file=null)
static isPortInUse($port)

References $port, Module\getName(), Util\isPortInUse(), Util\isValidPort(), Util\logDebug(), Util\logError(), and Module\update().

◆ checkPort()

BinXlight::checkPort ( $port,
$showWindow = false )

Checks if a port is used by the Xlight FTP server.

Parameters
int$portThe port number to check.
bool$showWindowWhether to show a message box with the result.
Returns
bool True if the port is used by Xlight, false otherwise.

Definition at line 202 of file class.bin.xlight.php.

202 {
203 global $bearsamppLang, $bearsamppWinbinder;
204 $boxTitle = sprintf($bearsamppLang->getValue(Lang::CHECK_PORT_TITLE), $this->getName(), $port);
205
206 if (!Util::isValidPort($port)) {
207 Util::logError($this->getName() . ' port not valid: ' . $port);
208 return false;
209 }
210
211 $headers = Util::getHeaders('127.0.0.1', $port);
212 if (!empty($headers)) {
213 if (Util::contains($headers[0], 'Xlight')) {
214 Util::logDebug($this->getName() . ' port ' . $port . ' is used by: ' . str_replace('220 ', '', $headers[0]));
215 if ($showWindow) {
216 $bearsamppWinbinder->messageBoxInfo(
217 sprintf($bearsamppLang->getValue(Lang::PORT_USED_BY), $port, str_replace('220 ', '', $headers[0])),
218 $boxTitle
219 );
220 }
221 return true;
222 }
223 Util::logDebug($this->getName() . ' port ' . $port . ' is used by another application');
224 if ($showWindow) {
225 $bearsamppWinbinder->messageBoxWarning(
226 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED_BY), $port),
227 $boxTitle
228 );
229 }
230 } else {
231 Util::logDebug($this->getName() . ' port ' . $port . ' is not used');
232 if ($showWindow) {
233 $bearsamppWinbinder->messageBoxError(
234 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED), $port),
235 $boxTitle
236 );
237 }
238 }
239
240 return false;
241 }
global $bearsamppLang
const PORT_NOT_USED_BY
const CHECK_PORT_TITLE
const PORT_USED_BY
const PORT_NOT_USED
static getHeaders($host, $port, $ssl=false)
static contains($string, $search)

References $bearsamppLang, $port, Lang\CHECK_PORT_TITLE, Util\contains(), Util\getHeaders(), Module\getName(), Util\isValidPort(), Util\logDebug(), Util\logError(), Lang\PORT_NOT_USED, Lang\PORT_NOT_USED_BY, and Lang\PORT_USED_BY.

◆ getExe()

BinXlight::getExe ( )

Gets the executable file path for the Xlight FTP server.

Returns
string The executable file path.

Definition at line 372 of file class.bin.xlight.php.

372 {
373 return $this->exe;
374 }

References $exe.

◆ getLog()

BinXlight::getLog ( )

Gets the log file path for the Xlight FTP server.

Returns
string The log file path.

Definition at line 363 of file class.bin.xlight.php.

363 {
364 return $this->log;
365 }

References $log.

◆ getPort()

BinXlight::getPort ( )

Gets the port used by the Xlight FTP server.

Returns
int The port number.

Definition at line 399 of file class.bin.xlight.php.

399 {
400 return $this->port;
401 }

References $port.

◆ getService()

BinXlight::getService ( )

Gets the service object for the Xlight FTP server.

Returns
Win32Service The service object.

Definition at line 322 of file class.bin.xlight.php.

322 {
323 return $this->service;
324 }

References $service.

◆ getUiPort()

BinXlight::getUiPort ( )

Gets the SSL port used by the Xlight FTP server.

Returns
int The SSL port number.

Definition at line 381 of file class.bin.xlight.php.

381 {
382 return $this->SslPort;
383 }

References $SslPort.

◆ rebuildConf()

BinXlight::rebuildConf ( )

Rebuilds the configuration in the Windows Registry.

Returns
bool True if the configuration was successfully rebuilt, false otherwise.

Definition at line 139 of file class.bin.xlight.php.

139 {
140 global $bearsamppRegistry;
141
142 $exists = $bearsamppRegistry->exists(
144 'SYSTEM\CurrentControlSet\Services\\' . self::SERVICE_NAME . '\Parameters',
146 );
147 if ($exists) {
148 return $bearsamppRegistry->setExpandStringValue(
150 'SYSTEM\CurrentControlSet\Services\\' . self::SERVICE_NAME . '\Parameters',
152 sprintf(self::SERVICE_PARAMS, $this->SslPort, $this->port)
153 );
154 }
155
156 return false;
157 }
const INFO_APP_PARAMETERS
const HKEY_LOCAL_MACHINE

References Registry\HKEY_LOCAL_MACHINE, and Nssm\INFO_APP_PARAMETERS.

◆ reload()

BinXlight::reload ( $id = null,
$type = null )

Reloads the module configuration based on the provided ID and type.

Parameters
string | null$idThe ID of the module. If null, the current ID is used.
string | null$typeThe type of the module. If null, the current type is used.

Reimplemented from Module.

Definition at line 52 of file class.bin.xlight.php.

52 {
55
56 $this->name = $bearsamppLang->getValue(Lang::XLIGHT);
57 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
58 parent::reload($id, $type);
59
60 $this->enable = $this->enable && $bearsamppConfig->getRaw(self::ROOT_CFG_ENABLE);
61 $this->service = new Win32Service(self::SERVICE_NAME);
62 $this->log = $bearsamppRoot->getLogsPath() . '/xlight.log';
63
64 if ($this->bearsamppConfRaw !== false) {
65 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
66 $this->SslPort = intval($this->bearsamppConfRaw[self::LOCAL_CFG_SSL_PORT]);
67 $this->port = intval($this->bearsamppConfRaw[self::LOCAL_CFG_PORT]);
68 }
69
70 if (!$this->enable) {
71 Util::logInfo($this->name . ' is not enabled!');
72 return;
73 }
74 if (!is_dir($this->currentPath)) {
75 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
76 return;
77 }
78 if (!is_dir($this->symlinkPath)) {
79 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
80 return;
81 }
82 if (!is_file($this->bearsamppConf)) {
83 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
84 return;
85 }
86 if (!is_file($this->exe)) {
87 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
88 return;
89 }
90 if (empty($this->SslPort)) {
91 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_SSL_PORT, $this->SslPort));
92 return;
93 }
94 if (empty($this->port)) {
95 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_INVALID_PARAMETER), self::LOCAL_CFG_PORT, $this->port));
96 return;
97 }
98
99 $nssm = new Nssm(self::SERVICE_NAME);
100 $nssm->setDisplayName(APP_TITLE . ' ' . $this->getName());
101 $nssm->setBinPath($this->exe);
102 $nssm->setParams(sprintf(self::SERVICE_PARAMS, $this->SslPort, $this->port));
103 $nssm->setStart(Nssm::SERVICE_DEMAND_START);
104 $nssm->setStdout($bearsamppRoot->getLogsPath() . '/xlight.log');
105 $nssm->setStderr($bearsamppRoot->getLogsPath() . '/xlight.error.log');
106
107 $this->service->setNssm($nssm);
108 }
global $bearsamppRoot
const ERROR_FILE_NOT_FOUND
const XLIGHT
const ERROR_INVALID_PARAMETER
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
const SERVICE_DEMAND_START
static logReloadClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26
const APP_TITLE
Definition root.php:12

References $bearsamppConfig, $bearsamppLang, $bearsamppRoot, Module\$id, Module\$type, APP_TITLE, Lang\ERROR_CONF_NOT_FOUND, Lang\ERROR_EXE_NOT_FOUND, Lang\ERROR_FILE_NOT_FOUND, Lang\ERROR_INVALID_PARAMETER, Module\getName(), LOCAL_CFG_EXE, Util\logError(), Util\logInfo(), Util\logReloadClass(), Nssm\SERVICE_DEMAND_START, and Lang\XLIGHT.

Referenced by __construct(), setEnable(), and setVersion().

+ Here is the caller graph for this function:

◆ replaceAll()

BinXlight::replaceAll ( $params)
protected

Replaces multiple key-value pairs in the configuration file.

Parameters
array$paramsAn associative array of key-value pairs to replace.

Reimplemented from Module.

Definition at line 115 of file class.bin.xlight.php.

115 {
116 $content = file_get_contents($this->bearsamppConf);
117
118 foreach ($params as $key => $value) {
119 $content = preg_replace('|' . $key . ' = .*|', $key . ' = ' . '"' . $value.'"', $content);
120 $this->bearsamppConfRaw[$key] = $value;
121 switch ($key) {
123 $this->SslPort = intval($value);
124 break;
126 $this->port = intval($value);
127 break;
128 }
129 }
130
131 file_put_contents($this->bearsamppConf, $content);
132 }
const LOCAL_CFG_SSL_PORT

References LOCAL_CFG_PORT, and LOCAL_CFG_SSL_PORT.

◆ setEnable()

BinXlight::setEnable ( $enabled,
$showWindow = false )

Enables or disables the Xlight FTP server.

Parameters
bool$enabledWhether to enable or disable the server.
bool$showWindowWhether to show a message box with the result.

Definition at line 332 of file class.bin.xlight.php.

332 {
333 global $bearsamppConfig, $bearsamppLang, $bearsamppWinbinder;
334
335 if ($enabled == Config::ENABLED && !is_dir($this->currentPath)) {
336 Util::logDebug($this->getName() . ' cannot be enabled because bundle ' . $this->getVersion() . ' does not exist in ' . $this->currentPath);
337 if ($showWindow) {
338 $bearsamppWinbinder->messageBoxError(
339 sprintf($bearsamppLang->getValue(Lang::ENABLE_BUNDLE_NOT_EXIST), $this->getName(), $this->getVersion(), $this->currentPath),
340 sprintf($bearsamppLang->getValue(Lang::ENABLE_TITLE), $this->getName())
341 );
342 }
343 $enabled = Config::DISABLED;
344 }
345
346 Util::logInfo($this->getName() . ' switched to ' . ($enabled == Config::ENABLED ? 'enabled' : 'disabled'));
347 $this->enable = $enabled == Config::ENABLED;
348 $bearsamppConfig->replace(self::ROOT_CFG_ENABLE, $enabled);
349
350 $this->reload();
351 if ($this->enable) {
352 Util::installService($this, $this->port, null, $showWindow);
353 } else {
354 Util::removeService($this->service, $this->name);
355 }
356 }
const DISABLED
const ENABLED
const ENABLE_TITLE
const ENABLE_BUNDLE_NOT_EXIST
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static removeService($service, $name)

References $bearsamppConfig, $bearsamppLang, Config\DISABLED, Lang\ENABLE_BUNDLE_NOT_EXIST, Lang\ENABLE_TITLE, Config\ENABLED, Module\getName(), Module\getVersion(), Util\installService(), Util\logDebug(), Util\logInfo(), reload(), and Util\removeService().

◆ setPort()

BinXlight::setPort ( $port)

Sets the port for the Xlight FTP server.

Parameters
int$portThe port number.

Definition at line 408 of file class.bin.xlight.php.

408 {
409 $this->replace(self::LOCAL_CFG_PORT, $port);
410 }
replace($key, $value)

References $port, and Module\replace().

◆ setSslPort()

BinXlight::setSslPort ( $SslPort)

Sets the SSL port for the Xlight FTP server.

Parameters
int$SslPortThe SSL port number.

Definition at line 390 of file class.bin.xlight.php.

390 {
391 $this->replace(self::LOCAL_CFG_SSL_PORT, $SslPort);
392 }

References $SslPort, and Module\replace().

◆ setVersion()

BinXlight::setVersion ( $version)

Sets the version of the Xlight FTP server.

Parameters
string$versionThe version to set.

Reimplemented from Module.

Definition at line 310 of file class.bin.xlight.php.

310 {
311 global $bearsamppConfig;
312 $this->version = $version;
313 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
314 $this->reload();
315 }

References $bearsamppConfig, Module\$version, and reload().

Referenced by updateConfig().

+ Here is the caller graph for this function:

◆ switchVersion()

BinXlight::switchVersion ( $version,
$showWindow = false )

Switches the version of the Xlight FTP server.

Parameters
string$versionThe version to switch to.
bool$showWindowWhether to show a message box with the result.
Returns
bool True if the version was successfully switched, false otherwise.

Definition at line 250 of file class.bin.xlight.php.

250 {
251 Util::logDebug('Switch ' . $this->name . ' version to ' . $version);
252 return $this->updateConfig($version, 0, $showWindow);
253 }
updateConfig($version=null, $sub=0, $showWindow=false)

References Module\$version, Util\logDebug(), and updateConfig().

◆ updateConfig()

BinXlight::updateConfig ( $version = null,
$sub = 0,
$showWindow = false )
protected

Updates the configuration of the Xlight FTP server.

Parameters
string | null$versionThe version to update to. If null, the current version is used.
int$subThe sub-level for logging indentation.
bool$showWindowWhether to show a message box with the result.
Returns
bool True if the configuration was successfully updated, false otherwise.

Reimplemented from Module.

Definition at line 263 of file class.bin.xlight.php.

263 {
264 global $bearsamppLang, $bearsamppWinbinder;
265
266 if (!$this->enable) {
267 return true;
268 }
269
270 $version = $version == null ? $this->version : $version;
271 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
272
273 $boxTitle = sprintf($bearsamppLang->getValue(Lang::SWITCH_VERSION_TITLE), $this->getName(), $version);
274
275 $bearsamppConf = str_replace('xlight' . $this->getVersion(), 'xlight' . $version, $this->bearsamppConf);
276 if (!file_exists($bearsamppConf)) {
277 Util::logError('bearsampp config files not found for ' . $this->getName() . ' ' . $version);
278 if ($showWindow) {
279 $bearsamppWinbinder->messageBoxError(
280 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_NOT_FOUND_ERROR), $this->getName() . ' ' . $version),
281 $boxTitle
282 );
283 }
284 return false;
285 }
286
287 $bearsamppConfRaw = parse_ini_file($bearsamppConf);
288 if ($bearsamppConfRaw === false || !isset($bearsamppConfRaw[self::ROOT_CFG_VERSION]) || $bearsamppConfRaw[self::ROOT_CFG_VERSION] != $version) {
289 Util::logError('bearsampp config file malformed for ' . $this->getName() . ' ' . $version);
290 if ($showWindow) {
291 $bearsamppWinbinder->messageBoxError(
292 sprintf($bearsamppLang->getValue(Lang::BEARSAMPP_CONF_MALFORMED_ERROR), $this->getName() . ' ' . $version),
293 $boxTitle
294 );
295 }
296 return false;
297 }
298
299 // bearsampp.conf
300 $this->setVersion($version);
301
302 return true;
303 }
setVersion($version)
const BEARSAMPP_CONF_NOT_FOUND_ERROR
const SWITCH_VERSION_TITLE
const BEARSAMPP_CONF_MALFORMED_ERROR

References Module\$bearsamppConf, Module\$bearsamppConfRaw, $bearsamppLang, Module\$version, Lang\BEARSAMPP_CONF_MALFORMED_ERROR, Lang\BEARSAMPP_CONF_NOT_FOUND_ERROR, Module\getName(), Module\getVersion(), Util\logDebug(), Util\logError(), setVersion(), and Lang\SWITCH_VERSION_TITLE.

Referenced by switchVersion().

+ Here is the caller graph for this function:

Field Documentation

◆ $exe

BinXlight::$exe
private

Definition at line 31 of file class.bin.xlight.php.

Referenced by getExe().

◆ $log

BinXlight::$log
private

Definition at line 29 of file class.bin.xlight.php.

Referenced by getLog().

◆ $port

BinXlight::$port
private

Definition at line 32 of file class.bin.xlight.php.

Referenced by changePort(), checkPort(), getPort(), and setPort().

◆ $service

BinXlight::$service
private

Definition at line 28 of file class.bin.xlight.php.

Referenced by getService().

◆ $SslPort

BinXlight::$SslPort
private

Definition at line 33 of file class.bin.xlight.php.

Referenced by getUiPort(), and setSslPort().

◆ LOCAL_CFG_EXE

const BinXlight::LOCAL_CFG_EXE = 'xlightExe'

Definition at line 24 of file class.bin.xlight.php.

Referenced by reload().

◆ LOCAL_CFG_PORT

const BinXlight::LOCAL_CFG_PORT = 'xlightPort'

Definition at line 26 of file class.bin.xlight.php.

Referenced by replaceAll().

◆ LOCAL_CFG_SSL_PORT

const BinXlight::LOCAL_CFG_SSL_PORT = 'xlightSslPort'

Definition at line 25 of file class.bin.xlight.php.

Referenced by replaceAll().

◆ ROOT_CFG_ENABLE

const BinXlight::ROOT_CFG_ENABLE = 'xlightEnable'

Definition at line 21 of file class.bin.xlight.php.

◆ ROOT_CFG_VERSION

const BinXlight::ROOT_CFG_VERSION = 'xlightVersion'

Definition at line 22 of file class.bin.xlight.php.

◆ SERVICE_NAME

◆ SERVICE_PARAMS

const BinXlight::SERVICE_PARAMS = ' -startall'

Definition at line 19 of file class.bin.xlight.php.


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