2014-03-20 16:18:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Server;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Model Class holding the Server Config
|
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2017-02-04 11:49:23 +01:00
|
|
|
* @copyright 2014-2017 ManiaControl Team
|
2014-05-02 17:50:30 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-03-20 16:18:35 +01:00
|
|
|
*/
|
2014-06-20 19:05:59 +02:00
|
|
|
class Config {
|
2014-03-20 16:18:35 +01:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Public properties
|
2014-03-20 16:18:35 +01:00
|
|
|
*/
|
|
|
|
public $id = null;
|
|
|
|
public $host = null;
|
|
|
|
public $port = null;
|
2014-06-13 17:24:59 +02:00
|
|
|
public $user = null;
|
2014-03-20 16:18:35 +01:00
|
|
|
public $pass = null;
|
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Create a new server config instance
|
2014-03-20 16:18:35 +01:00
|
|
|
*
|
2014-06-20 19:05:59 +02:00
|
|
|
* @param mixed $id
|
|
|
|
* @param mixed $host
|
|
|
|
* @param mixed $port
|
|
|
|
* @param mixed $user
|
|
|
|
* @param mixed $pass
|
2014-03-20 16:18:35 +01:00
|
|
|
*/
|
2014-06-13 17:24:59 +02:00
|
|
|
public function __construct($id = null, $host = null, $port = null, $user = null, $pass = null) {
|
|
|
|
$this->id = $this->extractConfigData($id);
|
|
|
|
$this->host = $this->extractConfigData($host);
|
|
|
|
$this->port = $this->extractConfigData($port);
|
|
|
|
$this->user = $this->extractConfigData($user);
|
|
|
|
$this->pass = $this->extractConfigData($pass);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the actual Data from the given Config Param
|
|
|
|
*
|
|
|
|
* @param mixed $configParam
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function extractConfigData($configParam) {
|
|
|
|
if (is_array($configParam)) {
|
|
|
|
return (string)reset($configParam);
|
|
|
|
}
|
|
|
|
return (string)$configParam;
|
2014-05-27 08:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the Config Data
|
|
|
|
*
|
2014-06-13 17:24:59 +02:00
|
|
|
* @param string $message
|
2014-05-27 08:57:26 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
2014-06-13 17:24:59 +02:00
|
|
|
public function validate(&$message = null) {
|
|
|
|
// Host
|
|
|
|
if (!$this->host) {
|
|
|
|
$message = 'Missing Host!';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Port
|
|
|
|
if (!$this->port || $this->port === 'port') {
|
|
|
|
$message = 'Missing Port!';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// User
|
|
|
|
if (!$this->user) {
|
|
|
|
$message = 'Missing User!';
|
2014-05-27 10:46:18 +02:00
|
|
|
return false;
|
2014-05-27 08:57:26 +02:00
|
|
|
}
|
2014-06-13 17:24:59 +02:00
|
|
|
if (!in_array($this->user, array('SuperAdmin', 'Admin', 'User'))) {
|
|
|
|
$message = 'Invalid User!';
|
2014-05-27 08:57:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-06-13 17:24:59 +02:00
|
|
|
|
|
|
|
// Pass
|
|
|
|
if (!$this->pass) {
|
|
|
|
$message = 'Missing Pass!';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-27 08:57:26 +02:00
|
|
|
return true;
|
2014-03-20 16:18:35 +01:00
|
|
|
}
|
|
|
|
}
|