2024.8.23
Loading...
Searching...
No Matches
class.action.switchOnline.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 ActionSwitchOnline
12 * Handles the switching of the application between online and offline modes.
13 */
15{
16 /**
17 * ActionSwitchOnline constructor.
18 * Initializes the online/offline switch based on the provided arguments.
19 *
20 * @param array $args Arguments to determine the online/offline state.
21 */
22 public function __construct($args)
23 {
24 global $bearsamppConfig;
25
26 if (isset($args[0]) && $args[0] == Config::ENABLED || $args[0] == Config::DISABLED) {
28 $putOnline = $args[0] == Config::ENABLED;
29
30 $this->switchApache($putOnline);
31 $this->switchAlias($putOnline);
32 $this->switchVhosts($putOnline);
33 $this->switchFilezilla($putOnline);
34 $bearsamppConfig->replace(Config::CFG_ONLINE, $args[0]);
35 }
36 }
37
38 /**
39 * Switches the Apache configuration based on the online/offline state.
40 *
41 * @param bool $putOnline True to put online, false to put offline.
42 */
43 private function switchApache($putOnline)
44 {
45 global $bearsamppBins;
46 $bearsamppBins->getApache()->refreshConf($putOnline);
47 }
48
49 /**
50 * Switches the Apache aliases based on the online/offline state.
51 *
52 * @param bool $putOnline True to put online, false to put offline.
53 */
54 private function switchAlias($putOnline)
55 {
56 global $bearsamppBins;
57 $bearsamppBins->getApache()->refreshAlias($putOnline);
58 }
59
60 /**
61 * Switches the Apache virtual hosts based on the online/offline state.
62 *
63 * @param bool $putOnline True to put online, false to put offline.
64 */
65 private function switchVhosts($putOnline)
66 {
67 global $bearsamppBins;
68 $bearsamppBins->getApache()->refreshVhosts($putOnline);
69 }
70
71 /**
72 * Switches the Filezilla configuration based on the online/offline state.
73 *
74 * @param bool $putOnline True to put online, false to put offline.
75 */
76 private function switchFilezilla($putOnline)
77 {
78 global $bearsamppBins;
79
80 if ($putOnline) {
81 $bearsamppBins->getFilezilla()->setConf(array(
84 ));
85 } else {
86 $bearsamppBins->getFilezilla()->setConf(array(
87 BinFilezilla::CFG_IP_FILTER_ALLOWED => '127.0.0.1 ::1',
89 ));
90 }
91 }
92}
global $bearsamppBins
const DISABLED
const CFG_ONLINE
const ENABLED
static startLoading()
global $bearsamppConfig
Definition homepage.php:26