summaryrefslogtreecommitdiffstats
path: root/modules-available/debugconfig/page.inc.php
blob: 27ef94fd4df98badedad3a0771138de98c387d73 (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

class Page_debugConfig extends Page
{

	const DEFAULT_CONFIG = array("enabled" => false, "debugServer" => "127.0.0.1", "port" => 5500);

	protected function doPreprocess()
	{
		User::load();
		if (!User::hasPermission('superadmin')) {
			Message::addError('main.no-permission');
			Util::redirect('?do=Main');
		}
		if (Request::post('action') === 'debugconf') {
			$this->setConfig();
		}
		elseif (Request::post("action") === "clearRelay") {
			$this->clearRelay();
		}
		elseif (Request::post("action") === "refreshList") {
			$this->getActiveRelays();
		}
	}

	protected function doRender()
	{
		$debug_config = $this->getConfig();
		Render::addTemplate('debugconfig', array("debugEnabled" => $debug_config["enabled"], "debugServer" => $debug_config["debugServer"], "port" => $debug_config["port"]));
		$relays = $this->getActiveRelays();
		Render::addTemplate('relaystatus', array("activeRelays" => $relays));
	}
	
	private function getConfig()
	{
		if (Property::getRemoteDebugConfig() == Null) {
			Property::setRemoteDebugConfig(self::DEFAULT_CONFIG);
		}
		return Property::getRemoteDebugConfig();
	}
	
	private function setConfig()
	{
		$enabled = isset($_POST['toggleDebug']) ? true : false;
		Property::setRemoteDebugConfig(array('enabled' => $enabled, 'debugServer' => Request::post('debugServer'), 'port' => Request::post('port')));
	}

	private function getActiveRelays()
	{
		$relays = Property::getList("DispatchedRelay");
		foreach ($relays as $key => $value) {
			$task = Taskmanager::status($value);
			$finished = Taskmanager::isFinished($task);
			//$endpoints = $task["data"]["endpoints"];
			if ($task["statusCode"] == "NO_SUCH_INSTANCE" || $finished) {
				Property::removeFromList("DispatchedRelay", $value);
				unset($relays[$key]);
			}
			$relays[$key] = array("id" => $value, "port" => $task["data"]["listenPort"], 
				"code" => $task["statusCode"], "cltAddress" => $task["data"]["cltAddr"]);
			//$relays[$key] = array("id" => $value, "bwlpclient" => $endpoints[0], "debugserver" => $endpoints[1]);
		}
		return $relays;
	}	

	private function clearRelay()
	{
		Property::removeFromList("DispatchedRelay", Request::post("relayid"));
	}
}