forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
78 lines (64 loc) · 2.27 KB
/
index.php
File metadata and controls
78 lines (64 loc) · 2.27 KB
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
<?php
error_reporting(NULL);
$TAB = 'SERVER';
// Main include
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
// Check user
if ($_SESSION['user'] != 'admin') {
header("Location: /list/user");
exit;
}
// Check POST request
if (!empty($_POST['save'])) {
// Check token
if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
header('location: /login/');
exit();
}
// Set restart flag
$v_restart = 'yes';
if (empty($_POST['v_restart'])) $v_restart = 'no';
// Update option
if (!empty($_POST['v_options'])) {
exec ('mktemp', $mktemp_output, $return_var);
$new_conf = $mktemp_output[0];
$fp = fopen($new_conf, 'w');
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_options']));
fclose($fp);
exec (HESTIA_CMD."v-change-sys-service-config ".$new_conf." postgresql-hba ".$v_restart, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
unlink($new_conf);
}
// Update config
if ((empty($_SESSION['error_msg'])) && (!empty($_POST['v_config']))) {
exec ('mktemp', $mktemp_output, $return_var);
$new_conf = $mktemp_output[0];
$fp = fopen($new_conf, 'w');
fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config']));
fclose($new_conf);
exec (HESTIA_CMD."v-change-sys-service-config ".$new_conf." postgresql " .$v_restart, $output, $return_var);
check_return_code($return_var,$output);
unset($output);
unlink($new_conf);
}
// Set success message
if (empty($_SESSION['error_msg'])) {
$_SESSION['ok_msg'] = _('Changes has been saved.');
}
}
// List config
exec (HESTIA_CMD."v-list-sys-pgsql-config json", $output, $return_var);
$data = json_decode(implode('', $output), true);
unset($output);
$v_options_path = $data['CONFIG']['pg_hba_path'];
$v_config_path = $data['CONFIG']['config_path'];
$v_service_name = strtoupper('postgresql');
// Read config
$v_options = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_options_path);
$v_config = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path);
// Render page
render_page($user, $TAB, 'edit_server_pgsql');
// Flush session messages
unset($_SESSION['error_msg']);
unset($_SESSION['ok_msg']);