|
1 | 1 | /** |
2 | 2 | * Frontend Advanced Settings - IP Whitelist Management |
3 | 3 | */ |
4 | | -(function($) { |
5 | | - 'use strict'; |
6 | | - |
7 | | - $(function() { |
8 | | - console.log('Maintenance IP management loaded'); |
| 4 | +$(document).on('rex:ready', function() { |
| 5 | + // Funktion zum Hinzufügen einer IP-Adresse zum Whitelist-Feld |
| 6 | + function addIpToWhitelist(ip) { |
| 7 | + var ipField = $('#maintenance-allowed-ips'); |
9 | 8 |
|
10 | | - // Funktion zum Hinzufügen einer IP-Adresse zum Whitelist-Feld |
11 | | - function addIpToWhitelist(ip) { |
12 | | - console.log('Adding IP:', ip); |
13 | | - var ipField = $('#maintenance-allowed-ips'); |
14 | | - |
15 | | - console.log('Field found:', ipField.length); |
16 | | - |
17 | | - if (!ipField.length) { |
18 | | - console.error('IP field not found'); |
19 | | - return; |
20 | | - } |
21 | | - |
22 | | - var currentValue = ipField.val().trim(); |
23 | | - console.log('Current value:', currentValue); |
24 | | - |
25 | | - if (currentValue === '') { |
26 | | - // Wenn das Feld leer ist, einfach die IP hinzufügen |
27 | | - ipField.val(ip); |
28 | | - console.log('Set value to:', ip); |
29 | | - } else { |
30 | | - // IP-Adressen als Array verarbeiten und alle Leerzeichen entfernen |
31 | | - var ips = currentValue.split(',').map(function(ip) { |
32 | | - return ip.trim(); |
33 | | - }).filter(function(ip) { |
34 | | - // Leere Einträge filtern |
35 | | - return ip !== ''; |
36 | | - }); |
37 | | - |
38 | | - console.log('Current IPs:', ips); |
39 | | - |
40 | | - // Prüfen, ob IP bereits enthalten ist |
41 | | - if (ips.indexOf(ip) === -1) { |
42 | | - ips.push(ip); |
43 | | - // Saubere Komma-getrennte Liste ohne unnötige Leerzeichen |
44 | | - ipField.val(ips.join(',')); |
45 | | - console.log('Updated value to:', ips.join(',')); |
46 | | - } else { |
47 | | - console.log('IP already exists'); |
48 | | - } |
49 | | - } |
| 9 | + if (!ipField.length) { |
| 10 | + console.error('IP field not found'); |
| 11 | + return; |
50 | 12 | } |
51 | 13 |
|
52 | | - // Client-IP-Adresse hinzufügen |
53 | | - $(document).on('click', '#maintenance-add-ip', function(e) { |
54 | | - e.preventDefault(); |
55 | | - console.log('Add IP button clicked'); |
56 | | - var currentIp = $(this).data('ip'); |
57 | | - console.log('IP from data attribute:', currentIp); |
58 | | - if (currentIp) { |
59 | | - addIpToWhitelist(currentIp); |
60 | | - } |
61 | | - }); |
| 14 | + var currentValue = ipField.val().trim(); |
62 | 15 |
|
63 | | - // Server-IP-Adresse hinzufügen |
64 | | - $(document).on('click', '#maintenance-add-server-ip', function(e) { |
65 | | - e.preventDefault(); |
66 | | - console.log('Add Server IP button clicked'); |
67 | | - var serverIp = $(this).data('ip'); |
68 | | - console.log('Server IP from data attribute:', serverIp); |
69 | | - if (serverIp) { |
70 | | - addIpToWhitelist(serverIp); |
| 16 | + if (currentValue === '') { |
| 17 | + // Wenn das Feld leer ist, einfach die IP hinzufügen |
| 18 | + ipField.val(ip); |
| 19 | + } else { |
| 20 | + // IP-Adressen als Array verarbeiten und alle Leerzeichen entfernen |
| 21 | + var ips = currentValue.split(',').map(function(ip) { |
| 22 | + return ip.trim(); |
| 23 | + }).filter(function(ip) { |
| 24 | + // Leere Einträge filtern |
| 25 | + return ip !== ''; |
| 26 | + }); |
| 27 | + |
| 28 | + // Prüfen, ob IP bereits enthalten ist |
| 29 | + if (ips.indexOf(ip) === -1) { |
| 30 | + ips.push(ip); |
| 31 | + // Saubere Komma-getrennte Liste ohne unnötige Leerzeichen |
| 32 | + ipField.val(ips.join(',')); |
71 | 33 | } |
72 | | - }); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + // Client-IP-Adresse hinzufügen |
| 38 | + $('#maintenance-add-ip').on('click', function(e) { |
| 39 | + e.preventDefault(); |
| 40 | + var currentIp = '<?= rex_server('REMOTE_ADDR', 'string', '') ?>'; |
| 41 | + addIpToWhitelist(currentIp); |
| 42 | + }); |
| 43 | + |
| 44 | + // Server-IP-Adresse hinzufügen |
| 45 | + $('#maintenance-add-server-ip').on('click', function(e) { |
| 46 | + e.preventDefault(); |
| 47 | + var serverIp = '<?= rex_server('SERVER_ADDR', 'string', '') ?>'; |
| 48 | + addIpToWhitelist(serverIp); |
73 | 49 | }); |
74 | | -})(jQuery); |
| 50 | +}); |
0 commit comments