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>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-03-20 16:18:35 +01:00
|
|
|
*/
|
2014-05-27 10:46:18 +02:00
|
|
|
class ServerConfig {
|
2014-03-20 16:18:35 +01:00
|
|
|
/*
|
2014-04-12 12:14:37 +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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Server Config Instance
|
|
|
|
*
|
2014-06-13 17:24:59 +02:00
|
|
|
* @param mixed $id Config Id
|
|
|
|
* @param mixed $host Server Ip
|
|
|
|
* @param mixed $port Server Port
|
|
|
|
* @param mixed $user XmlRpc User
|
|
|
|
* @param mixed $pass XmlRpc Password
|
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
|
|
|
}
|
|
|
|
}
|