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
232 lines (212 loc) · 6.54 KB
/
index.php
File metadata and controls
232 lines (212 loc) · 6.54 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
$TAB = "SERVER";
// Main include
include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
// Check user
if ($_SESSION["userContext"] != "admin") {
header("Location: /list/user");
exit();
}
// Check POST request
if (!empty($_POST["save"])) {
// Check token
verify_csrf($_POST);
// Set restart flag
$v_restart = "yes";
if (empty($_POST["v_restart"])) {
$v_restart = "no";
}
// Update config
if (!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($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot " . $v_restart,
$output,
$return_var,
);
check_return_code($return_var, $output);
unset($output);
unlink($new_conf);
}
// Update config1
if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config1"])) {
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_config1"]));
fclose($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot-1 " . $v_restart,
$output,
$return_var,
);
check_return_code($return_var, $output);
unset($output);
unlink($new_conf);
}
// Update config2
if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config2"])) {
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_config2"]));
fclose($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot-2 " . $v_restart,
$output,
$return_var,
);
check_return_code($return_var, $output);
unset($output);
unlink($new_conf);
}
// Update config3
if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config3"])) {
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_config3"]));
fclose($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot-3 " . $v_restart,
$output,
$return_var,
);
check_return_code($return_var, $output);
unset($output);
unlink($new_conf);
}
// Update config4
if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config4"])) {
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_config4"]));
fclose($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot-4 " . $v_restart,
$output,
$return_var,
);
check_return_code($return_var, $output);
unset($output);
unlink($new_conf);
}
// Update config5
if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config5"])) {
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_config5"]));
fclose($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot-5 " . $v_restart,
$output,
$return_var,
);
check_return_code($return_var, $output);
unset($output);
unlink($new_conf);
}
// Update config6
if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config6"])) {
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_config6"]));
fclose($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot-6 " . $v_restart,
$output,
$return_var,
);
check_return_code($return_var, $output);
unset($output);
unlink($new_conf);
}
// Update config7
if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config7"])) {
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_config7"]));
fclose($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot-7 " . $v_restart,
$output,
$return_var,
);
check_return_code($return_var, $output);
unset($output);
unlink($new_conf);
}
// Update config8
if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config8"])) {
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_config8"]));
fclose($fp);
exec(
HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " dovecot-8 " . $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 have been saved.");
}
}
// List config
exec(HESTIA_CMD . "v-list-sys-dovecot-config json", $output, $return_var);
$data = json_decode(implode("", $output), true);
unset($output);
$v_config_path = $data["CONFIG"]["config_path"];
$v_config_path1 = $data["CONFIG"]["config_path1"];
$v_config_path2 = $data["CONFIG"]["config_path2"];
$v_config_path3 = $data["CONFIG"]["config_path3"];
$v_config_path4 = $data["CONFIG"]["config_path4"];
$v_config_path5 = $data["CONFIG"]["config_path5"];
$v_config_path6 = $data["CONFIG"]["config_path6"];
$v_config_path7 = $data["CONFIG"]["config_path7"];
$v_config_path8 = $data["CONFIG"]["config_path8"];
$v_service_name = strtoupper("dovecot");
// Read config
$v_config = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path);
if (!empty($v_config_path1)) {
$v_config1 = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path1);
}
if (!empty($v_config_path2)) {
$v_config2 = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path2);
}
if (!empty($v_config_path3)) {
$v_config3 = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path3);
}
if (!empty($v_config_path4)) {
$v_config4 = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path4);
}
if (!empty($v_config_path5)) {
$v_config5 = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path5);
}
if (!empty($v_config_path6)) {
$v_config6 = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path6);
}
if (!empty($v_config_path7)) {
$v_config7 = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path7);
}
if (!empty($v_config_path8)) {
$v_config8 = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path8);
}
// Render page
render_page($user, $TAB, "edit_server_dovecot");
// Flush session messages
unset($_SESSION["error_msg"]);
unset($_SESSION["ok_msg"]);