summaryrefslogtreecommitdiffstats
path: root/modules/sysconfig.inc.php
blob: e4751ec4313fc7e032a69ad70fa40f31029fca4c (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
<?php

User::load();

function render_module()
{
	if (!isset($_REQUEST['action'])) $_REQUEST['action'] = 'list';
	switch ($_REQUEST['action']) {
	case 'remotelist':
		list_remote_configs();
		break;
	case 'list':
		list_configs();
		break;
	default:
		Message::addError('invalid-action', $_REQUEST['action']);
		break;
	}
}

function list_configs()
{
	if (!User::hasPermission('superadmin')) {
		Message::addError('no-permission');
		return;
	}
	$files = array();
	foreach (glob(CONFIG_TGZ_LIST_DIR . '/*.tgz') as $file) {
		$files[] = array(
			'file' => $file
		);
	}
	Render::addTemplate('page-tgz-list', array('files' => $files));
}

function list_remote_configs()
{
	if (!User::hasPermission('superadmin')) {
		Message::addError('no-permission');
		return;
	}
	$data = Util::download(CONFIG_REMOTE_TGZ . '/list.php', 4, $code);
	if ($code !== 200) {
		Message::addError('remote-timeout', CONFIG_REMOTE_TGZ);
		return;
	}
	$list = json_decode($data, true);
	if (!is_array($list)) {
		Message::addError('remote-parse-failed', $data);
		return;
	}
	$id = 0;
	foreach ($list as &$item) {
		$item['id'] = 'download' . (++$id);
	}
	Render::addTemplate('page-remote-tgz-list', array('files' => $list));
}