This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
297 lines (282 loc) · 9.9 KB
/
edit.php
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
if (isset($_GET['mailbox'])){
$account=$_GET['mailbox'];
$passwort_inv = "class='validate'";
$passwort_wied_inv = "class='validate'";
$speicher_inv = "class='validate'";
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
if (isset($_POST['passwort'])){
if (isset($_POST['passwort_wied'])){
if ($_POST['passwort'] === $_POST['passwort_wied']){
$password = $_POST['passwort'];
} else {
$passwort_wied_inv = "data-error='Wiederholtes Passwort ist nicht identisch' class='validate invalid'";
}
} else {
$passwort_wied_inv = "data-error='Passwort muss wiederholt werden' class='validate invalid'";
}
} else {
$passwort = "";
$passwort_inv = "data-error='Passwort nicht gesetzt' class='validate invalid'";
}
if (isset($_POST['speicher'])){
$speicher = $_POST['speicher'];
} else {
$speicher = "";
$peicher_inv = "data-error='Speicher MB nicht gesetzt' class='validate invalid'";
}
if (isset($_POST['account_enabled'])){
$account_enabled = "true";
} else {
$account_enabled = "false";
}
if (isset($_POST['sendonly'])){
$sendonly = "true";
} else {
$sendonly = "false";
}
if ($speicher !== ""){
if ($password !== ""){
$salt = substr(sha1(rand()), 0, 16);
$password = "{SHA512-CRYPT}" . crypt($password, "$6$$salt");
$sql = "UPDATE accounts SET password='$password', quota=$speicher, enabled=$account_enabled, sendonly=$sendonly WHERE id=$account";
} else {
$sql = "UPDATE accounts SET quota=$speicher, enabled=$account_enabled, sendonly=$sendonly WHERE id=$account";
}
if ($conn->query($sql) === TRUE) {
echo "<p class=green-text>Der Account wurde erfolgreich aktualisiert.</p>";
echo "<meta http-equiv='refresh' content='3; URL=/?seite=mailboxes'>";
exit;
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
exit;
}
}
} else {
$sql = "SELECT * FROM accounts WHERE id='$account'";
$result = $conn->query($sql);
if ($result->num_rows > 0){
// output data of each row
while($row = $result->fetch_assoc()) {
$username = $row["username"];
$domain = $row["domain"];
$speicher = $row["quota"];
if ($row["enabled"] === "1"){
$account_enabled = "true";
} else {
$account_enabled = "false";
}
if ($row["sendonly"] === "1"){
$sendonly = "true";
} else {
$sendonly = "false";
}
}
} else {
echo "<tr><br><br><span class='red-text'>Ungültige ID.</span></tr>";
}
}
?>
<h1>Account editieren</h1>
<p>Hier kannst du den Account editieren. Wenn du kein neues Passwort setzen willst, einfach leer lassen.</p>
<div class="row">
<form action="?seite=edit&mailbox=<?php echo $account;?>" method=post class="col s12">
<div class="row">
<div class="input-field col s9 m5">
<i class="material-icons prefix">mail</i>
<input id="username" name="username" type="text" value=<?php echo "'$username'"; echo $username_inv; ?> disabled>
<label for="username">Username</label>
</div>
<div class="col s1">
<span class="btn-large disabled teal">@</span>
</div>
<div class="input-field col s12 m6">
<select name="domain" disabled>
<option value="" disabled selected>Wähle Domain aus</option>
<?php
echo "<option value='$domain' selected>$domain</option>";
?>
</select>
<label>Domain</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<i class="material-icons prefix">lock</i>
<input id="passwort" name="passwort" type="password" <?php echo $passwort_inv; ?>>
<label for="passwort">Passwort</label>
</div>
<div class="input-field col s6">
<input id="passwort_wied" name="passwort_wied" type="password" <?php echo $passwort_wied_inv; ?>>
<label for="passwort_wied">Passwort wiederholen</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<i class="material-icons prefix">save</i>
<input id="speicher" name="speicher" type="number" value=<?php echo "'$speicher' "; echo $speicher_inv; ?>>
<label for="speicher">Speicher MB</label>
</div>
</div>
<div class="row">
<div class="col s12">
<p>Account aktiviert?
<div class="switch">
<label>
Nein
<input name="account_enabled" type="checkbox"
<?php
if ($account_enabled === "true"){
echo "checked='checked'>";
} else {
echo " >";
}
?>
<span class="lever"></span>
Ja
</label>
</div>
</p>
</div>
<div class="col s12">
<p>Nur senden?
<div class="switch">
<label>
Nein
<input name="sendonly" type="checkbox"
<?php
if ($sendonly === "true"){
echo "checked='checked'>";
} else {
echo " >";
}
?>
<span class="lever"></span>
Ja
</label>
</div>
</p>
</div>
<div class="row">
<div class="input-field col s12">
<button class="btn waves-effect waves-light" type="submit" name="add-domain">Speichern
<i class="material-icons right">save</i>
</button>
</div>
</div>
</form>
</div>
<?php
} elseif (isset($_GET['aliases'])){
$alias = $_GET['aliases'];
$username_inv = "class='validate'";
$zielmail_inv = "class='validate'";
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
if (isset($_POST['zielmail'])){
$zielmail = $_POST['zielmail'];
$zielmail_arr = explode('@', $zielmail);
$zielmail_user = $zielmail_arr[0];
$zielmail_domain = $zielmail_arr[1];
} else {
$zielmail_str = "";
$zielmail_inv = "data-error='Username nicht gesetzt' class='validate invalid'";
}
if (isset($_POST['alias_enabled'])){
$alias_enabled = "true";
} else {
$alias_enabled = "false";
}
if ($zielmail !== ""){
$sql = "UPDATE aliases SET destination_username='$zielmail_user', destination_domain='$zielmail_domain', enabled=$alias_enabled WHERE id=$alias";
if ($conn->query($sql) === TRUE) {
echo "<p class=green-text>Die Alias wurde erfolgreich aktualisiert.</p>";
echo "<meta http-equiv='refresh' content='3; URL=/?seite=aliases'>";
exit;
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
exit;
}
}
} else {
$sql = "SELECT * FROM aliases WHERE id='$alias'";
$result = $conn->query($sql);
if ($result->num_rows > 0){
// output data of each row
while($row = $result->fetch_assoc()) {
$username = $row["source_username"];
$domain = $row["source_domain"];
$zielmail = $row["destination_username"]."@".$row["destination_domain"];
if ($row["enabled"] === "1"){
$alias_enabled = "true";
} else {
$alias_enabled = "false";
}
}
} else {
echo "<tr><br><br><span class='red-text'>Ungültige ID.</span></tr>";
}
}
?>
<h2>Alias editieren</h2>
<p>Hier kannst du die Alias editieren</p>
<div class="row">
<form action="?seite=edit&aliases=<?php echo $alias;?>" method=post class="col s12">
<div class="row">
<div class="input-field col s9 m5">
<i class="material-icons prefix">mail</i>
<input id="username" name="username" type="text" value=<?php echo "'$username'"; echo $username_inv; ?> disabled>
<label for="username">Username</label>
</div>
<div class="col s1">
<span class="btn-large disabled teal">@</span>
</div>
<div class="input-field col s12 m6">
<select name="domain" disabled>
<option value="" disabled selected>Wähle Domain aus</option>
<?php
echo "<option value='$domain' selected>$domain</option>";
?>
</select>
<label>Domain</label>
</div>
</div>
<div class="row">
<div class="input-field col s9 m5">
<i class="material-icons prefix">mail_outline</i>
<input id="zielmail" name="zielmail" type="email" value=<?php echo "'$zielmail'"; echo $zielmail_inv; ?>>
<label for="zielmail">Ziel E-Mail-Adresse</label>
</div>
</div>
<div class="row">
<div class="col s12">
<p>Alias aktiviert?
<div class="switch">
<label>
Nein
<input name="alias_enabled" type="checkbox"
<?php
if ($alias_enabled === "true"){
echo "checked='checked'>";
} else {
echo " >";
}
?>
<span class="lever"></span>
Ja
</label>
</div>
</p>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<button class="btn waves-effect waves-light" type="submit" name="add-domain">Speichern
<i class="material-icons right">save</i>
</button>
</div>
</div>
</form>
</div>
<?php
}
?>