Bearsampp 2026.7.11
Loading...
Searching...
No Matches
class.action.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
13class Action
14{
15 // Constants for different actions
16 const ABOUT = 'about';
17 const ADD_ALIAS = 'addAlias';
18 const ADD_VHOST = 'addVhost';
19 const CHANGE_BROWSER = 'changeBrowser';
20 const CHANGE_DB_ROOT_PWD = 'changeDbRootPwd';
21 const CHANGE_PORT = 'changePort';
22 const CHECK_PORT = 'checkPort';
23 const CHECK_VERSION = 'checkVersion';
24 const CLEAR_FOLDERS = 'clearFolders';
25 const DEBUG_APACHE = 'debugApache';
26 const DEBUG_MARIADB = 'debugMariadb';
27 const DEBUG_MYSQL = 'debugMysql';
28 const DEBUG_POSTGRESQL = 'debugPostgresql';
29 const EDIT_ALIAS = 'editAlias';
30 const EDIT_VHOST = 'editVhost';
31 const ENABLE = 'enable';
32 const EXEC = 'exec';
33 const MAKE_ROOT_CA = 'makeRootCA';
34 const GEN_SSL_CERTIFICATE = 'genSslCertificate';
35 const DEL_SSL_CERTIFICATE = 'delSslCertificate';
36 const LAUNCH_STARTUP = 'launchStartup';
37 const MANUAL_RESTART = 'manualRestart';
38 const LOADING = 'loading';
39 const QUIT = 'quit';
40 const REBUILD_INI = 'rebuildIni';
41 const REFRESH_REPOS = 'refreshRepos';
42 const REFRESH_REPOS_STARTUP = 'refreshReposStartup';
43 const RELOAD = 'reload';
44 const RESTART = 'restart';
45 const RESTART_ALL_SERVICES = 'restartAllServices';
46 const SERVICE = 'service';
47 const START_ALL_SERVICES = 'startAllServices';
48 const STARTUP = 'startup';
49 const STOP_ALL_SERVICES = 'stopAllServices';
50 const SWITCH_APACHE_MODULE = 'switchApacheModule';
51 const SWITCH_LANG = 'switchLang';
52 const SWITCH_LOGS_VERBOSE = 'switchLogsVerbose';
53 const SWITCH_PHP_EXTENSION = 'switchPhpExtension';
54 const SWITCH_PHP_PARAM = 'switchPhpParam';
55 const SWITCH_ONLINE = 'switchOnline';
56 const SWITCH_VERSION = 'switchVersion';
57
58 const EXT = 'ext';
59
63 private $current;
64
69 public function __construct()
70 {
71 // Initialization code can be added here if needed
72 }
73
83 public function process()
84 {
85 if ($this->exists()) {
86 $action = UtilInput::cleanArgv(1);
87 $actionClass = 'Action' . ucfirst($action);
88
89 $args = array();
90 foreach ($_SERVER['argv'] as $key => $arg) {
91 if ($key > 1) {
92 $args[] = $action == self::EXT ? $arg : base64_decode($arg);
93 }
94 }
95
96 $this->current = null;
97 if (class_exists($actionClass)) {
98 Log::debug('Start ' . $actionClass);
99 $this->current = new $actionClass($args);
100 } elseif ($action == self::GEN_SSL_CERTIFICATE) {
101 global $bearsamppRoot, $bearsamppOpenSsl;
102 $bearsamppRoot->loadOpenSsl();
103 $bearsamppOpenSsl->genSslCertificate();
104 } elseif ($action == self::MAKE_ROOT_CA) {
105 global $bearsamppRoot, $bearsamppOpenSsl;
106 $bearsamppRoot->loadOpenSsl();
107 $bearsamppOpenSsl->makeRootCa();
108 } elseif ($action == self::DEL_SSL_CERTIFICATE) {
109 global $bearsamppRoot, $bearsamppOpenSsl;
110 $bearsamppRoot->loadOpenSsl();
111 $bearsamppOpenSsl->delSslCertificate();
112 }
113 }
114 }
115
127 public function call($actionName, $actionArgs = null)
128 {
129 $actionClass = 'Action' . ucfirst($actionName);
130 if (class_exists($actionClass)) {
131 Log::debug('Start ' . $actionClass);
132 new $actionClass($actionArgs);
133 }
134 }
135
144 public function exists()
145 {
146 return isset($_SERVER['argv'])
147 && isset($_SERVER['argv'][1])
148 && !empty($_SERVER['argv'][1]);
149 }
150}
global $bearsamppRoot
const ADD_ALIAS
const DEBUG_APACHE
const QUIT
const SWITCH_VERSION
const EDIT_VHOST
const MANUAL_RESTART
const DEBUG_MARIADB
const SWITCH_LOGS_VERBOSE
const STOP_ALL_SERVICES
const START_ALL_SERVICES
const CHANGE_DB_ROOT_PWD
const DEBUG_MYSQL
const SERVICE
const DEL_SSL_CERTIFICATE
const REBUILD_INI
const CHECK_VERSION
const MAKE_ROOT_CA
const CHANGE_PORT
const LOADING
call($actionName, $actionArgs=null)
const LAUNCH_STARTUP
const RELOAD
const RESTART_ALL_SERVICES
const ABOUT
const EDIT_ALIAS
const SWITCH_PHP_EXTENSION
const EXEC
const STARTUP
const ADD_VHOST
const RESTART
const REFRESH_REPOS
const REFRESH_REPOS_STARTUP
const DEBUG_POSTGRESQL
const SWITCH_PHP_PARAM
const GEN_SSL_CERTIFICATE
const CHECK_PORT
const CHANGE_BROWSER
const CLEAR_FOLDERS
const EXT
const SWITCH_ONLINE
const SWITCH_LANG
const SWITCH_APACHE_MODULE
const ENABLE
static debug($data, $file=null)
static cleanArgv($name, $type='text')