summaryrefslogtreecommitdiffstats
path: root/modules/webinterface.inc.php
blob: f37802770ac1fe5f1ab72eff24358593d8b0a54a (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php

class Page_WebInterface extends Page
{

	protected function doPreprocess()
	{
		User::load();
		if (!User::hasPermission('superadmin')) {
			Message::addError('no-permission');
			Util::redirect('?do=Main');
		}
		switch (Request::post('action')) {
			case 'https':
				$this->actionConfigureHttps();
				break;
			case 'password':
				$this->actionShowHidePassword();
				break;
		}
	}

	private function actionConfigureHttps()
	{
		$task = false;
		switch (Request::post('mode')) {
			case 'off':
				$task = $this->setHttpsOff();
				break;
			case 'random':
				$task = $this->setHttpsRandomCert();
				break;
			case 'custom':
				$task = $this->setHttpsCustomCert();
				break;
		}
		if (isset($task['id'])) {
			Session::set('https-id', $task['id']);
			Util::redirect('?do=WebInterface&show=httpsupdate');
		}
	}
	
	private function actionShowHidePassword()
	{
		Property::setPasswordFieldType(Request::post('mode') === 'show' ? 'text' : 'password');
		Util::redirect('?do=WebInterface');
	}

	protected function doRender()
	{
		Render::setTitle(Dictionary::translate('lang_titleWebinterface'));
		if (Request::get('show') === 'httpsupdate') {
			Render::addTemplate('webinterface/httpd-restart', array('taskid' => Session::get('https-id')));
		}
		Render::addTemplate('webinterface/https');
		$data = array();
		if (Property::getPasswordFieldType() === 'text')
			$data['selected_show'] = 'checked';
		else
			$data['selected_hide'] = 'checked';
		Render::addTemplate('webinterface/passwords', $data);
	}

	private function setHttpsOff()
	{
		return Taskmanager::submit('LighttpdHttps', array());
	}

	private function setHttpsRandomCert()
	{
		return Taskmanager::submit('LighttpdHttps', array(
				'proxyip' => Property::getServerIp()
		));
	}

	private function setHttpsCustomCert()
	{
		return Taskmanager::submit('LighttpdHttps', array(
				'importcert' => Request::post('certificate', 'bla'),
				'importkey' => Request::post('privatekey', 'bla'),
				'importchain' => Request::post('cachain', '')
		));
	}

}