4 // by Mischa Peters <mischa at high5 dot nl>
5 // Copyright (c) 2022 High5!
6 // License Info: LICENSE.TXT
10 // Template File: message.tpl
12 // Template Variables:
16 // POST / GET Variables:
23 require_once './functions.inc.php';
24 include './languages/' . check_language() . '.lang';
26 $SESSID_USERNAME = check_session();
27 $ROLE = check_role($SESSID_USERNAME);
29 if ($ROLE == ADMIN_ROLE) {
30 $list_domains = list_domains();
32 $list_domains = list_domains($SESSID_USERNAME);
35 if ($_SERVER['REQUEST_METHOD'] == "GET") {
36 $table = filter_input(INPUT_GET, 'table', FILTER_DEFAULT);
37 $delete = filter_input(INPUT_GET, 'delete', FILTER_DEFAULT);
38 $domain = filter_input(INPUT_GET, 'domain', FILTER_VALIDATE_DOMAIN);
39 $domain_key = array_search($domain, array_column($list_domains, 'domain'));
40 $domain_exist = in_array($domain, array_column($list_domains, 'domain'));
42 if ($ROLE == ADMIN_ROLE && $domain_exist && $table == "domain") {
45 $dbh->beginTransaction();
47 $sth = $dbh->prepare("SELECT COUNT(*) FROM log WHERE domain=?");
48 $sth->execute(array($domain));
49 $count_log = $sth->fetchColumn();
51 $sth = $dbh->prepare("DELETE FROM log WHERE domain=?");
52 $sth->execute(array($domain));
53 if ($sth->rowCount() != $count_log) {
54 throw new RuntimeException('Unable to delete entries from the logs table.');
57 $sth = $dbh->prepare("SELECT COUNT(*) FROM vacation WHERE domain=?");
58 $sth->execute(array($domain));
59 $count_vacation = $sth->fetchColumn();
61 $sth = $dbh->prepare("DELETE FROM vacation WHERE domain=?");
62 $sth->execute(array($domain));
63 if ($sth->rowCount() != $count_vacation) {
64 throw new RuntimeException('Unable to delete entries from the vacation table.');
67 $sth = $dbh->prepare("SELECT COUNT(*) FROM alias WHERE domain=?");
68 $sth->execute(array($domain));
69 $count_alias = $sth->fetchColumn();
71 $sth = $dbh->prepare("DELETE FROM alias WHERE domain=?");
72 $sth->execute(array($domain));
73 if ($sth->rowCount() != $count_alias) {
74 throw new RuntimeException('Unable to delete entries from the alias table.');
77 $sth = $dbh->prepare("SELECT COUNT(*) FROM mailbox WHERE domain=?");
78 $sth->execute(array($domain));
79 $count_mailbox = $sth->fetchColumn();
81 $sth = $dbh->prepare("DELETE FROM mailbox WHERE domain=?");
82 $sth->execute(array($domain));
83 if ($sth->rowCount() != $count_mailbox) {
84 throw new RuntimeException('Unable to delete entries from the mailbox table.');
87 $sth = $dbh->prepare("SELECT COUNT(*) FROM domain_admins WHERE domain=?");
88 $sth->execute(array($domain));
89 $count_domain_admins = $sth->fetchColumn();
91 $sth = $dbh->prepare("DELETE FROM domain_admins WHERE domain=?");
92 $sth->execute(array($domain));
93 if ($sth->rowCount() != $count_domain_admins) {
94 throw new RuntimeException('Unable to delete entries from the domain_admins table.');
97 $sth = $dbh->prepare("SELECT COUNT(*) FROM domain WHERE domain=?");
98 $sth->execute(array($domain));
99 $count_domain = $sth->fetchColumn();
101 $sth = $dbh->prepare("DELETE FROM domain WHERE domain=?");
102 $sth->execute(array($domain));
103 if ($sth->rowCount() != $count_domain) {
104 throw new RuntimeException('Unable to delete entry from the domain table.');
108 header("Location: list-domain.php");
109 } catch (RuntimeException $e) {
110 $message = $e->getMessage();
112 } catch (PDOException $e) {
113 $message = $e->getMessage();
117 if ($ROLE == ADMIN_ROLE && $table == "admin") {
119 $dbh = pdo_connect();
120 $dbh->beginTransaction();
122 $sth = $dbh->prepare("SELECT COUNT(*) FROM admin WHERE username=?");
123 $sth->execute(array($delete));
124 $count_admin = $sth->fetchColumn();
126 $sth = $dbh->prepare("DELETE FROM admin WHERE username=?");
127 $sth->execute(array($delete));
128 if ($sth->rowCount() != $count_admin) {
129 throw new RuntimeException('Unable to delete entry from the admin table.');
132 $sth = $dbh->prepare("SELECT COUNT(*) FROM domain_admins WHERE username=?");
133 $sth->execute(array($delete));
134 $count_domain_admins = $sth->fetchColumn();
136 $sth = $dbh->prepare("DELETE FROM domain_admins WHERE username=?");
137 $sth->execute(array($delete));
138 if ($sth->rowCount() != $count_domain_admins) {
139 throw new RuntimeException('Unable to delete entries from the domain_admins table.');
143 header("Location: list-admin.php");
144 } catch (RuntimeException $e) {
145 $message = $e->getMessage();
147 } catch (PDOException $e) {
148 $message = $e->getMessage();
153 if ($domain_exist && ($table == 'alias' || $table == 'mailbox')) {
155 $dbh = pdo_connect();
156 $sth = $dbh->prepare("DELETE FROM alias WHERE address=? AND domain=?");
157 $sth->bindParam(1, $delete, PDO::PARAM_STR);
158 $sth->bindParam(2, $domain, PDO::PARAM_STR);
160 if ($sth->rowCount() != 1) {
161 throw new RuntimeException('alias');
163 logging($SESSID_USERNAME, $domain, $LANG['Logging_alias_delete'], $delete);
165 header("Location: list-virtual.php?domain=$domain");
166 } catch (RuntimeException $e) {
167 $message = $LANG['Delete_delete_error'] . "<b>$delete</b> (" . $e->getMessage() . ")!</span>";
168 } catch (PDOException $e) {
169 $message = $LANG['Delete_delete_error'] . "<b>$delete</b> (alias)!</span> " . $e-getMessage();
173 $dbh = pdo_connect();
174 $sth = $dbh->prepare("DELETE FROM mailbox WHERE username=? AND domain=?");
175 $sth->bindParam(1, $delete, PDO::PARAM_STR);
176 $sth->bindParam(2, $domain, PDO::PARAM_STR);
178 if ($sth->rowCount() != 1) {
179 throw new RuntimeException('mailbox');
181 logging($SESSID_USERNAME, $domain, $LANG['Logging_mailbox_delete'], $delete);
183 $sth = $dbh->prepare("DELETE FROM vacation WHERE email=? AND domain=?");
184 $sth->bindParam(1, $delete, PDO::PARAM_STR);
185 $sth->bindParam(2, $domain, PDO::PARAM_STR);
187 header("Location: list-virtual.php?domain=$domain");
188 } catch (RuntimeException $e) {
189 $message = $LANG['Delete_delete_error'] . "<b>$delete</b> (" . $e->getMessage() . ")!</span>";
190 } catch (PDOException $e) {
191 $message = $LANG['Delete_delete_error'] . "<b>$delete</b> (mailbox)!</span>";
195 include './templates/header.tpl';
196 include './templates/menu.tpl';
197 include './templates/message.tpl';
198 include './templates/footer.tpl';