Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
if(function_exists('spl_autoload_register')) {
spl_autoload_register('ISPConfig::autoload');
}
/**
* Main controller class
*
* @author croydon
*/
class ISPConfig {
private static $is_cli_run = false;
private static $cli_script = false;
private static $autoload_files = array(
'PXBashColor' => LIB_DIR . '/libbashcolor.inc.php'
);
private static function init() {
if(php_sapi_name() == 'cli') {
self::$is_cli_run = true;
$argc = 0;
$argv = array();
if(isset($_SERVER['argc'])) {
$argc = $_SERVER['argc'];
}
if(isset($_SERVER['argv'])) {
$argv = $_SERVER['argv'];
}
if(isset($argv[0])) {
self::$cli_script = basename($argv[0]);
}
for($a = 1; $a < $argc; $a++) {
if(substr($argv[$a], 0, 2) == '--') {
$sArg = substr($argv[$a], 2);
if(strpos($sArg, '=') !== false) {
list($sKey, $sValue) = explode('=', $sArg);
} else {
$sKey = $sArg;
$sValue = true;
}
private static function input() {
$input = fgets(STDIN);
return rtrim($input);
}
public static function ask($prompt) {
print $prompt . ': ';
return self::input();
}
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* @param string $class_name
* @throws ISPConfigClassException
*/
public static function autoload($class_name) {
if(preg_match('/^\w+$/', $class_name) === false) {
throw new ISPConfigClassException($class_name . ' is not a valid class name.');
}
$class_dir = LIB_DIR;
if(preg_match('/Exception$/', $class_name)) {
$class_dir .= '/exceptions';
} elseif(preg_match('/Module$/', $class_name)) {
$class_dir .= '/modules';
} elseif(preg_match('/API$/', $class_name)) {
$class_dir .= '/api';
} elseif(preg_match('/OS$/', $class_name)) {
$class_dir .= '/os';
}
$use_file = null;
if(isset(self::$autoload_files[$class_name])) {
$use_file = self::$autoload_files[$class_name];
} elseif(file_exists($class_dir . '/class.' . $class_name . '.inc.php')) {
$use_file = $class_dir . '/class.' . $class_name . '.inc.php';
} elseif(file_exists($class_dir . '/class.' . strtolower($class_name) . '.inc.php')) {
$use_file = $class_dir . '/class.' . strtolower($class_name) . '.inc.php';
} elseif(preg_match('/^ISPConfig\w+Exception$/', $class_name)) {
$use_file = LIB_DIR . '/exceptions/class.ISPConfigException.inc.php';
} else {
throw new ISPConfigClassException('No class file for ' . $class_name . ' found.');
}
if($class_name != 'ISPConfigLog') {
ISPConfigLog::debug('Trying to autoload class file "' . $use_file . '" for class "' . $class_name . '"');
}
if(!file_exists($use_file)) {
throw new ISPConfigClassException('File ' . $use_file . ' not found for class ' . $class_name . '.');
}
include_once $use_file;
if(!class_exists($class_name)) {
throw new ISPConfigClassException($class_name . ' not found in file ' . LIB_DIR . '/class.' . $class_name . '.inc.php.');
}
}
/**
* @return boolean
*/
public static function isCLI() {
return self::$is_cli_run;
}
/**
* @return string
*/
public static function getScriptName() {
return self::$cli_script;
}
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
private static function printHelp() {
$message = '
{FW}*
ISPConfig 3 Autoinstaller
{FW}*
Usage: ispc3-ai.sh [<argument>] [...]
This script automatically installs all needed packages for an ISPConfig 3 setup using the guidelines from the "Perfect Server Setup" howtos on www.howtoforge.com.
Possible arguments are:
--help ->Show this help page
--debug ->Enable verbose logging (logs each command with the exit code)
--interactive ->Don\'t install ISPConfig in non-interactive mode. This is needed if you want to use expert mode, e. g. to install a slave server that shall be integrated into an existing multiserver setup.
--use-nginx ->Use nginx webserver instead of apache2
--no-web ->Do not use ISPConfig on this server to manage webserver setting and don\'t install nginx/apache. This will also prevent installing an ISPConfig UI and implies --no-roundcube as well as --no-pma
--no-mail ->Do not use ISPConfig on this server to manage mailserver settings. This will install postfix for sending system mails, but not dovecot and not configure any settings for ISPConfig mail.
--no-dns ->Do not use ISPConfig on this server to manage DNS entries. Bind will be installed for local DNS caching / resolving only.
--no-firewall ->Do not install ufw and tell ISPConfig to not manage firewall settings on this server.
--no-roundcube ->Do not install roundcube webmail.
--no-pma ->Do not install PHPMyAdmin on this server.
--i-know-what-i-am-doing
->Prevent the autoinstaller to ask for confirmation before continuing to reconfigure the server.
';
ISPConfigLog::print($message);
exit;
}
/**
* @throws ISPConfigModuleException
*/
public static function run() {
self::init();
if(isset($_GET['help']) && $_GET['help']) {
self::printHelp();
exit;
}
if(!isset($_GET['i-know-what-i-am-doing']) || !$_GET['i-know-what-i-am-doing']) {
print PXBashColor::getString('<lightred>WARNING!</lightred> This script will reconfigure your complete server!') . "\n";
print 'It should be run on a freshly installed server and all current configuration that you have done will most likely be lost!' . "\n";
$ok = ISPConfig::ask('Type \'yes\' if you really want to continue');
if($ok !== 'yes') {
print PXBashColor::getString('<lightred>ABORTED</lightred>') . "\n";
exit;
}
}
if(isset($_GET['debug']) && $_GET['debug']) {
ISPConfigLog::setLogPriority(ISPConfigLog::PRIO_DEBUG);
}
// get operating system
try {
$os = ISPConfigBaseOS::getOSVersion();
ISPConfigLog::info('Starting perfect server setup for ' . $os['NAME'], true);
$installer = ISPConfigBaseOS::getOSInstance();
ISPConfigLog::warn('Please delete the log files in var/log/setup-* once you don\'t need them anymore because they contain your passwords!', true);
} catch(Exception $ex) {
throw $ex;
}
exit;
}
}