moved web service url constant to ManiaControl class

This commit is contained in:
Steffen Schröder 2014-02-15 18:41:03 +01:00
parent e1eeee1e4c
commit dac702b627
4 changed files with 18 additions and 17 deletions

View File

@ -37,38 +37,38 @@ class ErrorHandler {
$message .= "Trace: {$ex->getTraceAsString()}" . PHP_EOL; $message .= "Trace: {$ex->getTraceAsString()}" . PHP_EOL;
logMessage($message); logMessage($message);
$error = array();
$error["Type"] = "Exception"; $error["Type"] = "Exception";
$error["Message"] = $message; $error["Message"] = $message;
$error['OperatingSystem'] = php_uname(); $error['OperatingSystem'] = php_uname();
$error['PHPVersion'] = phpversion(); $error['PHPVersion'] = phpversion();
if ($this->maniaControl->server != null) { if ($this->maniaControl->server) {
$error['ServerLogin'] = $this->maniaControl->server->login; $error['ServerLogin'] = $this->maniaControl->server->login;
} else { } else {
$error['ServerLogin'] = null; $error['ServerLogin'] = '';
} }
if ($this->maniaControl->settingManager != null && $this->maniaControl->updateManager != null) { if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
$error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL); $error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
$error['ManiaControlVersion'] = $this->maniaControl->updateManager->getCurrentBuildDate(); $error['ManiaControlVersion'] = $this->maniaControl->updateManager->getCurrentBuildDate();
} else { } else {
$error['UpdateChannel'] = null; $error['UpdateChannel'] = '';
$error['ManiaControlVersion'] = ManiaControl::VERSION; $error['ManiaControlVersion'] = ManiaControl::VERSION;
} }
$json = json_encode($error); $json = json_encode($error);
$info = base64_encode($json); $info = base64_encode($json);
$url = UpdateManager::URL_WEBSERVICE . "errorreport?error=" . urlencode($info); $url = ManiaControl::URL_WEBSERVICE . "errorreport?error=" . urlencode($info);
$success = FileUtil::loadFile($url); $success = FileUtil::loadFile($url);
if (!json_decode($success)) { if (!json_decode($success)) {
logMessage("Exception-Report failed"); logMessage("Exception-Report failed!");
} else { } else {
logMessage("Exception successfully reported!"); logMessage("Exception successfully reported!");
} }
$this->maniaControl->restart(); $this->maniaControl->restart();
exit(); exit();
} }
@ -87,6 +87,7 @@ class ErrorHandler {
// Error suppressed // Error suppressed
return false; return false;
} }
// Log error // Log error
$errorTag = $this->getErrorTag($errorNumber); $errorTag = $this->getErrorTag($errorNumber);
$message = "{$errorTag}: {$errorString} in File '{$errorFile}' on Line {$errorLine}!"; $message = "{$errorTag}: {$errorString} in File '{$errorFile}' on Line {$errorLine}!";
@ -116,7 +117,7 @@ class ErrorHandler {
$json = json_encode($error); $json = json_encode($error);
$info = base64_encode($json); $info = base64_encode($json);
$url = UpdateManager::URL_WEBSERVICE . "errorreport?error=" . urlencode($info); $url = ManiaControl::URL_WEBSERVICE . "errorreport?error=" . urlencode($info);
$success = FileUtil::loadFile($url); $success = FileUtil::loadFile($url);
if (!json_decode($success)) { if (!json_decode($success)) {

View File

@ -44,6 +44,7 @@ class ManiaControl implements CommandListener {
const OS_WIN = 'Windows'; const OS_WIN = 'Windows';
const CONNECT_TIMEOUT = 20; const CONNECT_TIMEOUT = 20;
const SCRIPT_TIMEOUT = 20; const SCRIPT_TIMEOUT = 20;
const URL_WEBSERVICE = 'http://ws.maniacontrol.com/';
const SETTING_PERMISSION_SHUTDOWN = 'Shutdown ManiaControl'; const SETTING_PERMISSION_SHUTDOWN = 'Shutdown ManiaControl';
const SETTING_PERMISSION_RESTART = 'Restart ManiaControl'; const SETTING_PERMISSION_RESTART = 'Restart ManiaControl';

View File

@ -9,7 +9,7 @@ use ManiaControl\Update\UpdateManager;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class reports Usage * Class reporting ManiaControl Usage for the Server
* *
* @author steeffeen & kremsy * @author steeffeen & kremsy
*/ */
@ -26,28 +26,28 @@ class UsageReporter implements TimerListener {
private $maniaControl = null; private $maniaControl = null;
/** /**
* Create a new Server Settings Instance * Create a new Usage Reporter Instance
* *
* @param ManiaControl $maniaControl * @param ManiaControl $maniaControl
*/ */
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DISABLE_USAGE_REPORTING, false);
$this->maniaControl->timerManager->registerTimerListening($this, 'reportUsage', 1000 * 60 * self::UPDATE_MINUTE_COUNT); $this->maniaControl->timerManager->registerTimerListening($this, 'reportUsage', 1000 * 60 * self::UPDATE_MINUTE_COUNT);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_DISABLE_USAGE_REPORTING, false);
} }
/** /**
* Reports Usage every xx Minutes * Reports Usage every xx Minutes
* *
* @param $time * @param float $time
*/ */
public function reportUsage($time) { public function reportUsage($time) {
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DISABLE_USAGE_REPORTING)) { if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DISABLE_USAGE_REPORTING)) {
return; return;
} }
$properties = array(); $properties = array();
$properties['ManiaControlVersion'] = ManiaControl::VERSION; $properties['ManiaControlVersion'] = ManiaControl::VERSION;
$properties['OperatingSystem'] = php_uname(); $properties['OperatingSystem'] = php_uname();
@ -74,7 +74,7 @@ class UsageReporter implements TimerListener {
$json = json_encode($properties); $json = json_encode($properties);
$info = base64_encode($json); $info = base64_encode($json);
$this->maniaControl->fileReader->loadFile(UpdateManager::URL_WEBSERVICE . "/usagereport?info=" . urlencode($info), function ($response, $error) { $this->maniaControl->fileReader->loadFile(ManiaControl::URL_WEBSERVICE . "/usagereport?info=" . urlencode($info), function ($response, $error) {
$response = json_decode($response); $response = json_decode($response);
if ($error || !$response) { if ($error || !$response) {
$this->maniaControl->log("Error while Sending data: " . $error); $this->maniaControl->log("Error while Sending data: " . $error);

View File

@ -28,7 +28,6 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
const SETTING_AUTO_UPDATE = 'Perform update automatically'; const SETTING_AUTO_UPDATE = 'Perform update automatically';
const SETTING_PERMISSION_UPDATE = 'Update Core'; const SETTING_PERMISSION_UPDATE = 'Update Core';
const SETTING_PERMISSION_UPDATECHECK = 'Check Core Update'; const SETTING_PERMISSION_UPDATECHECK = 'Check Core Update';
const URL_WEBSERVICE = 'http://ws.maniacontrol.com/';
const CHANNEL_RELEASE = 'release'; const CHANNEL_RELEASE = 'release';
const CHANNEL_BETA = 'beta'; const CHANNEL_BETA = 'beta';
const CHANNEL_NIGHTLY = 'nightly'; const CHANNEL_NIGHTLY = 'nightly';
@ -289,7 +288,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
} }
/** @var Plugin $pluginClass */ /** @var Plugin $pluginClass */
$pluginId = $pluginClass::getId(); $pluginId = $pluginClass::getId();
$url = self::URL_WEBSERVICE . 'plugins?id=' . $pluginId; $url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
$dataJson = FileUtil::loadFile($url); $dataJson = FileUtil::loadFile($url);
$pluginVersions = json_decode($dataJson); $pluginVersions = json_decode($dataJson);
if (!$pluginVersions || !isset($pluginVersions[0])) { if (!$pluginVersions || !isset($pluginVersions[0])) {
@ -312,7 +311,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
*/ */
private function checkCoreUpdateAsync($function, $ignoreVersion = false) { private function checkCoreUpdateAsync($function, $ignoreVersion = false) {
$updateChannel = $this->getCurrentUpdateChannelSetting(); $updateChannel = $this->getCurrentUpdateChannelSetting();
$url = self::URL_WEBSERVICE . 'versions?update=1&current=1&channel=' . $updateChannel; $url = ManiaControl::URL_WEBSERVICE . 'versions?update=1&current=1&channel=' . $updateChannel;
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function, $ignoreVersion) { $this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function, $ignoreVersion) {
$versions = json_decode($dataJson); $versions = json_decode($dataJson);