Commit 46184687 authored by Marius Burkard's avatar Marius Burkard
Browse files

- do not allow unknown arguments, fixes #18

parent 1946005f
...@@ -17,20 +17,20 @@ define('ISPC_WEBSERVER_NGINX', 2); ...@@ -17,20 +17,20 @@ define('ISPC_WEBSERVER_NGINX', 2);
class ISPConfig { class ISPConfig {
private static $is_cli_run = false; private static $is_cli_run = false;
private static $cli_script = false; private static $cli_script = false;
private static $autoload_files = array( private static $autoload_files = array(
'PXBashColor' => LIB_DIR . '/libbashcolor.inc.php' 'PXBashColor' => LIB_DIR . '/libbashcolor.inc.php'
); );
public static $WEBSERVER = ISPC_WEBSERVER_APACHE; public static $WEBSERVER = ISPC_WEBSERVER_APACHE;
private static function init() { private static function init() {
if(!isset($_GET)) { if(!isset($_GET)) {
$_GET = array(); $_GET = array();
} }
if(php_sapi_name() == 'cli') { if(php_sapi_name() == 'cli') {
self::$is_cli_run = true; self::$is_cli_run = true;
$argc = 0; $argc = 0;
$argv = array(); $argv = array();
if(isset($_SERVER['argc'])) { if(isset($_SERVER['argc'])) {
...@@ -39,11 +39,11 @@ class ISPConfig { ...@@ -39,11 +39,11 @@ class ISPConfig {
if(isset($_SERVER['argv'])) { if(isset($_SERVER['argv'])) {
$argv = $_SERVER['argv']; $argv = $_SERVER['argv'];
} }
if(isset($argv[0])) { if(isset($argv[0])) {
self::$cli_script = basename($argv[0]); self::$cli_script = basename($argv[0]);
} }
for($a = 1; $a < $argc; $a++) { for($a = 1; $a < $argc; $a++) {
if(substr($argv[$a], 0, 2) == '--') { if(substr($argv[$a], 0, 2) == '--') {
$sArg = substr($argv[$a], 2); $sArg = substr($argv[$a], 2);
...@@ -54,10 +54,13 @@ class ISPConfig { ...@@ -54,10 +54,13 @@ class ISPConfig {
$sValue = true; $sValue = true;
} }
$_GET[$sKey] = $sValue; $_GET[$sKey] = $sValue;
} else {
self::printHelp();
exit;
} }
} }
} }
if(!self::shallInstall('web')) { if(!self::shallInstall('web')) {
self::$WEBSERVER = ISPC_WEBSERVER_NONE; self::$WEBSERVER = ISPC_WEBSERVER_NONE;
} elseif(isset($_GET['use-nginx']) && $_GET['use-nginx']) { } elseif(isset($_GET['use-nginx']) && $_GET['use-nginx']) {
...@@ -66,17 +69,17 @@ class ISPConfig { ...@@ -66,17 +69,17 @@ class ISPConfig {
self::$WEBSERVER = ISPC_WEBSERVER_APACHE; self::$WEBSERVER = ISPC_WEBSERVER_APACHE;
} }
} }
private static function input() { private static function input() {
$input = fgets(STDIN); $input = fgets(STDIN);
return rtrim($input); return rtrim($input);
} }
public static function ask($prompt) { public static function ask($prompt) {
print $prompt . ': '; print $prompt . ': ';
return self::input(); return self::input();
} }
/** /**
* @param string $class_name * @param string $class_name
* @throws ISPConfigClassException * @throws ISPConfigClassException
...@@ -85,7 +88,7 @@ class ISPConfig { ...@@ -85,7 +88,7 @@ class ISPConfig {
if(preg_match('/^\w+$/', $class_name) === false) { if(preg_match('/^\w+$/', $class_name) === false) {
throw new ISPConfigClassException($class_name . ' is not a valid class name.'); throw new ISPConfigClassException($class_name . ' is not a valid class name.');
} }
$class_dir = LIB_DIR; $class_dir = LIB_DIR;
if(preg_match('/Exception$/', $class_name)) { if(preg_match('/Exception$/', $class_name)) {
$class_dir .= '/exceptions'; $class_dir .= '/exceptions';
...@@ -96,7 +99,7 @@ class ISPConfig { ...@@ -96,7 +99,7 @@ class ISPConfig {
} elseif(preg_match('/OS$/', $class_name)) { } elseif(preg_match('/OS$/', $class_name)) {
$class_dir .= '/os'; $class_dir .= '/os';
} }
$use_file = null; $use_file = null;
if(isset(self::$autoload_files[$class_name])) { if(isset(self::$autoload_files[$class_name])) {
$use_file = self::$autoload_files[$class_name]; $use_file = self::$autoload_files[$class_name];
...@@ -113,7 +116,7 @@ class ISPConfig { ...@@ -113,7 +116,7 @@ class ISPConfig {
if($class_name != 'ISPConfigLog') { if($class_name != 'ISPConfigLog') {
ISPConfigLog::debug('Trying to autoload class file "' . $use_file . '" for class "' . $class_name . '"'); ISPConfigLog::debug('Trying to autoload class file "' . $use_file . '" for class "' . $class_name . '"');
} }
if(!file_exists($use_file)) { if(!file_exists($use_file)) {
throw new ISPConfigClassException('File ' . $use_file . ' not found for class ' . $class_name . '.'); throw new ISPConfigClassException('File ' . $use_file . ' not found for class ' . $class_name . '.');
} }
...@@ -123,14 +126,14 @@ class ISPConfig { ...@@ -123,14 +126,14 @@ class ISPConfig {
throw new ISPConfigClassException($class_name . ' not found in file ' . LIB_DIR . '/class.' . $class_name . '.inc.php.'); throw new ISPConfigClassException($class_name . ' not found in file ' . LIB_DIR . '/class.' . $class_name . '.inc.php.');
} }
} }
/** /**
* @return boolean * @return boolean
*/ */
public static function isCLI() { public static function isCLI() {
return self::$is_cli_run; return self::$is_cli_run;
} }
/** /**
* @return string * @return string
*/ */
...@@ -145,7 +148,7 @@ class ISPConfig { ...@@ -145,7 +148,7 @@ class ISPConfig {
return true; return true;
} }
} }
public static function wantsInteractive() { public static function wantsInteractive() {
if(isset($_GET['interactive']) && $_GET['interactive']) { if(isset($_GET['interactive']) && $_GET['interactive']) {
return true; return true;
...@@ -153,7 +156,7 @@ class ISPConfig { ...@@ -153,7 +156,7 @@ class ISPConfig {
return false; return false;
} }
} }
public static function wantsAmavis() { public static function wantsAmavis() {
if(isset($_GET['use-amavis']) && $_GET['use-amavis']) { if(isset($_GET['use-amavis']) && $_GET['use-amavis']) {
return true; return true;
...@@ -161,7 +164,7 @@ class ISPConfig { ...@@ -161,7 +164,7 @@ class ISPConfig {
return false; return false;
} }
} }
public static function wantsPHP() { public static function wantsPHP() {
if(isset($_GET['use-php']) && $_GET['use-php']) { if(isset($_GET['use-php']) && $_GET['use-php']) {
return $_GET['use-php']; return $_GET['use-php'];
...@@ -169,7 +172,7 @@ class ISPConfig { ...@@ -169,7 +172,7 @@ class ISPConfig {
return false; return false;
} }
} }
public static function getISPConfigChannel() { public static function getISPConfigChannel() {
if(isset($_GET['channel']) && $_GET['channel']) { if(isset($_GET['channel']) && $_GET['channel']) {
return $_GET['channel']; return $_GET['channel'];
...@@ -177,7 +180,7 @@ class ISPConfig { ...@@ -177,7 +180,7 @@ class ISPConfig {
return 'stable'; return 'stable';
} }
} }
public static function getFTPPassivePorts() { public static function getFTPPassivePorts() {
if(isset($_GET['use-ftp-ports'])) { if(isset($_GET['use-ftp-ports'])) {
list($from, $to) = explode('-', $_GET['use-ftp-ports']); list($from, $to) = explode('-', $_GET['use-ftp-ports']);
...@@ -188,7 +191,7 @@ class ISPConfig { ...@@ -188,7 +191,7 @@ class ISPConfig {
} }
return false; return false;
} }
private static function printHelp() { private static function printHelp() {
$message = ' $message = '
...@@ -228,7 +231,7 @@ Possible arguments are: ...@@ -228,7 +231,7 @@ Possible arguments are:
--i-know-what-i-am-doing --i-know-what-i-am-doing
->Prevent the autoinstaller to ask for confirmation before continuing to reconfigure the server. ->Prevent the autoinstaller to ask for confirmation before continuing to reconfigure the server.
'; ';
ISPConfigLog::print($message); ISPConfigLog::print($message);
exit; exit;
} }
...@@ -238,16 +241,16 @@ Possible arguments are: ...@@ -238,16 +241,16 @@ Possible arguments are:
*/ */
public static function run() { public static function run() {
self::init(); self::init();
$pmatch = null; $pmatch = null;
$valid_args = array( $valid_args = array(
'help', 'debug', 'interactive', 'help', 'debug', 'interactive',
'use-nginx', 'use-amavis', 'use-php', 'use-ftp-ports', 'channel', 'lang', 'use-nginx', 'use-amavis', 'use-php', 'use-ftp-ports', 'channel', 'lang',
'no-web', 'no-mail', 'no-dns', 'no-firewall', 'no-roundcube', 'no-pma', 'no-mailman', 'no-quota', 'no-web', 'no-mail', 'no-dns', 'no-firewall', 'no-roundcube', 'no-pma', 'no-mailman', 'no-quota',
'i-know-what-i-am-doing' 'i-know-what-i-am-doing'
); );
reset($_GET); reset($_GET);
foreach(array_keys($_GET) as $key) { foreach(array_keys($_GET) as $key) {
if(!in_array($key, $valid_args, true)) { if(!in_array($key, $valid_args, true)) {
...@@ -255,7 +258,7 @@ Possible arguments are: ...@@ -255,7 +258,7 @@ Possible arguments are:
exit; exit;
} }
} }
if(isset($_GET['help']) && $_GET['help']) { if(isset($_GET['help']) && $_GET['help']) {
self::printHelp(); self::printHelp();
exit; exit;
...@@ -272,7 +275,7 @@ Possible arguments are: ...@@ -272,7 +275,7 @@ Possible arguments are:
self::printHelp(); self::printHelp();
exit; exit;
} }
if(!isset($_GET['i-know-what-i-am-doing']) || !$_GET['i-know-what-i-am-doing']) { 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 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"; print 'It should be run on a freshly installed server and all current configuration that you have done will most likely be lost!' . "\n";
...@@ -282,15 +285,15 @@ Possible arguments are: ...@@ -282,15 +285,15 @@ Possible arguments are:
exit; exit;
} }
} }
if(isset($_GET['debug']) && $_GET['debug']) { if(isset($_GET['debug']) && $_GET['debug']) {
ISPConfigLog::setLogPriority(ISPConfigLog::PRIO_DEBUG); ISPConfigLog::setLogPriority(ISPConfigLog::PRIO_DEBUG);
} }
// get operating system // get operating system
try { try {
$os = ISPConfigBaseOS::getOSVersion(); $os = ISPConfigBaseOS::getOSVersion();
ISPConfigLog::info('Starting perfect server setup for ' . $os['NAME'], true); ISPConfigLog::info('Starting perfect server setup for ' . $os['NAME'], true);
$installer = ISPConfigBaseOS::getOSInstance(); $installer = ISPConfigBaseOS::getOSInstance();
$installer->runPerfectSetup(); $installer->runPerfectSetup();
...@@ -298,8 +301,8 @@ Possible arguments are: ...@@ -298,8 +301,8 @@ Possible arguments are:
} catch(Exception $ex) { } catch(Exception $ex) {
throw $ex; throw $ex;
} }
exit; exit;
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment