summaryrefslogtreecommitdiffstats
path: root/modules-available/internetaccess/page.inc.php
blob: a92ba3e3b0968ce43b285ad0f5e00e03430628e4 (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
<?php

class Page_InternetAccess extends Page
{

	protected function doPreprocess()
	{
		User::load();

		if (!User::isLoggedIn()) {
			Message::addError('main.no-permission');
			Util::redirect('?do=Main');
		}

		$action = Request::any('action', 'show');

		if ($action == 'save') {
			if (User::hasPermission("configuration.safe")) {
				if (isset($_POST['PROXY_CONF'])) {
					$data = array();
					foreach (array('PROXY_CONF', 'PROXY_ADDR', 'PROXY_PORT', 'PROXY_USERNAME', 'PROXY_PASSWORD') as $key) {
						$data[$key] = Request::post($key, '');
					}
					if (!FileUtil::arrayToFile(CONFIG_PROXY_CONF, $data)) {
						Message::addError('main.error-write', CONFIG_PROXY_CONF);
						Util::redirect();
					} else {
						Message::addSuccess('settings-updated');
						Taskmanager::release(Taskmanager::submit('ReloadProxy'));
						$taskids = array();
						Trigger::stopDaemons(null, $taskids);
						$taskids = array();
						Trigger::startDaemons(null, $taskids);
						Session::set('ia-restart', $taskids);
						Util::redirect('?do=InternetAccess&show=update');
					}
				}
			}
		}
	}

	protected function doRender()
	{
		if (Request::any('show') === 'update') {
			$taskids = Session::get('ia-restart');
			if (is_array($taskids)) {
				Render::addTemplate('restart', $taskids);
			} else {
				Message::addError('invalid-action', 'Restart');
			}
		}
		$data = FileUtil::fileToArray(CONFIG_PROXY_CONF);
		if (!isset($data['PROXY_CONF']))
			$data['PROXY_CONF'] = 'AUTO';
		$data['selected_' . $data['PROXY_CONF']] = 'selected';

		$data['allowedSave'] = User::hasPermission("configuration.safe");

		Render::addTemplate('_page', $data);
	}

}