Browse code

implemented deletion of unused jabber domains

Bernd Wurst authored on01/05/2020 08:34:04
Showing3 changed files
... ...
@@ -56,3 +56,14 @@ output('</table>');
56 56
 
57 57
 addnew("new_account", "Neues Jabber-Konto anlegen");
58 58
 addnew("new_domain", "Eigene Domain für Jabber freischalten");
59
+
60
+$obsolete_domains = domains_without_accounts();
61
+
62
+if (count($obsolete_domains) > 0) {
63
+    output('<h4>Unbenutzte Jabber-Domains</h4>');
64
+    output('<p>Folgende Domains sind für die Nutzung im Jabber-Server eingerichtet, werden aber momentan nicht genutzt (kein Jabber-Account vorhanden).</p><ul>');
65
+    foreach ($obsolete_domains as $d) {
66
+        output('<li><strong>'.$d->fqdn.'</strong> '.internal_link('save', icon_delete('Domain aus dem Jabber-Server entfernen'), 'action=deldomain&domain='.$d->id).'</li>');
67
+    }
68
+    output('</ul>');
69
+}
... ...
@@ -142,6 +142,45 @@ function delete_jabber_account($id)
142 142
     logger(LOG_INFO, "modules/jabber/include/jabberaccounts", "jabber", "deleted account »{$id}«");
143 143
 }
144 144
 
145
+function domains_without_accounts() 
146
+{
147
+    $domains = get_domain_list((int) $_SESSION['customerinfo']['customerno']);
148
+    $accounts = get_jabber_accounts();
149
+    $obsolete_domains = array();
150
+    foreach ($domains as $d) {
151
+        if ($d->jabber != 1) {
152
+            continue;
153
+        }
154
+        $found = false;
155
+        foreach ($accounts as $a) {
156
+            if ($a['domain'] == $d->id) {
157
+                $found = true;
158
+            }
159
+        }
160
+        if (! $found) {
161
+            $obsolete_domains[] = $d;
162
+        }
163
+    }
164
+    return $obsolete_domains;
165
+}
166
+
167
+
168
+function delete_jabber_domain($id) 
169
+{
170
+    $d = new Domain((int) $id);
171
+    $d->ensure_customerdomain();
172
+    $obsolete_domains = domains_without_accounts();
173
+    $found = false;
174
+    foreach ($obsolete_domains as $od) {
175
+        if ($od->id == $d->id) {
176
+            $found = true;
177
+        }
178
+    }
179
+    if (! $found) {
180
+        system_failure('Diese Domain ist nicht unbenutzt.');
181
+    }
182
+    db_query("UPDATE kundendaten.domains SET jabber=0 WHERE jabber=1 AND id=?", array($d->id));
183
+}
145 184
 
146 185
 function new_jabber_domain($id)
147 186
 {
... ...
@@ -75,6 +75,25 @@ if ($_GET['action'] == 'new') {
75 75
     check_form_token('jabber_new_domain');
76 76
     new_jabber_domain($_REQUEST['domain']);
77 77
     header("Location: accounts");
78
+} elseif ($_GET['action'] == 'deldomain') {
79
+    $title = "Jabber-Domain löschen";
80
+    $section = 'jabber_accounts';
81
+    $domain = new Domain((int) $_GET['domain']);
82
+    $sure = user_is_sure();
83
+    if ($sure === null) {
84
+        are_you_sure("action=deldomain&domain={$_GET['domain']}", "Möchten Sie die Domain »".filter_output_html($domain->fqdn)."« aus der Jabber-Konfiguration entfernen?");
85
+    } elseif ($sure === true) {
86
+        delete_jabber_domain($domain->id);
87
+        if (! $debugmode) {
88
+            header("Location: accounts");
89
+        }
90
+    } elseif ($sure === false) {
91
+        if (! $debugmode) {
92
+            header("Location: accounts");
93
+        }
94
+    }
95
+
96
+
78 97
 } else {
79 98
     system_failure("Unimplemented action");
80 99
 }