Project

General

Profile

Download (7.15 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_rfc2136.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23

    
24
##|+PRIV
25
##|*IDENT=page-services-rfc2136clients
26
##|*NAME=Services: RFC 2136 Clients
27
##|*DESCR=Allow access to the 'Services: RFC 2136 Clients' page.
28
##|*MATCH=services_rfc2136.php*
29
##|-PRIV
30

    
31
require_once("guiconfig.inc");
32

    
33
if ($_POST['act'] == "del") {
34
	config_del_path("dnsupdates/dnsupdate/{$_POST['id']}");
35

    
36
	write_config("RFC 2136 client deleted");
37

    
38
	header("Location: services_rfc2136.php");
39
	exit;
40
} else if ($_POST['act'] == "toggle") {
41
	if (config_get_path("dnsupdates/dnsupdate/{$_POST['id']}")) {
42
		if (config_path_enabled("dnsupdates/dnsupdate/{$_POST['id']}")) {
43
			config_del_path("dnsupdates/dnsupdate/{$_POST['id']}/enable");
44
			$action = "disabled";
45
		} else {
46
			config_set_path("dnsupdates/dnsupdate/{$_POST['id']}/enable", true);
47
			$action = "enabled";
48
		}
49
		write_config("RFC 2136 {$action}");
50

    
51
		header("Location: services_rfc2136.php");
52
		exit;
53
	}
54
}
55

    
56
$pgtitle = array(gettext("Services"), gettext("Dynamic DNS"), gettext("RFC 2136 Clients"));
57
$pglinks = array("", "services_dyndns.php", "@self");
58
include("head.inc");
59

    
60
$tab_array = array();
61
$tab_array[] = array(gettext("Dynamic DNS Clients"), false, "services_dyndns.php");
62
$tab_array[] = array(gettext("RFC 2136 Clients"), true, "services_rfc2136.php");
63
$tab_array[] = array(gettext("Check IP Services"), false, "services_checkip.php");
64
display_top_tabs($tab_array);
65

    
66
if ($input_errors) {
67
	print_input_errors($input_errors);
68
}
69
?>
70

    
71
<form action="services_rfc2136.php" method="post" name="iform" id="iform">
72
	<div class="panel panel-default">
73
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('RFC2136 Clients')?></h2></div>
74
		<div class="panel-body">
75
			<div class="table-responsive">
76
				<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
77
					<thead>
78
						<tr>
79
							<th><?=gettext("Status")?></th>
80
							<th><?=gettext("Interface")?></th>
81
							<th><?=gettext("Server")?></th>
82
							<th><?=gettext("Hostname")?></th>
83
							<th><?=gettext("Cached IP")?></th>
84
							<th><?=gettext("Description")?></th>
85
							<th><?=gettext("Actions")?></th>
86
						</tr>
87
					</thead>
88
					<tbody>
89
<?php
90

    
91

    
92
$iflist = get_configured_interface_with_descr();
93
$groupslist = return_gateway_groups_array();
94

    
95
$i = 0;
96
foreach (config_get_path('dnsupdates/dnsupdate', []) as $rfc2136):
97
	if (!is_array($rfc2136) || empty($rfc2136)) {
98
		continue;
99
	}
100
	$filename = "{$g['conf_path']}/dyndns_{$rfc2136['interface']}_rfc2136_" . escapeshellarg($rfc2136['host']) . "_{$rfc2136['server']}.cache";
101
	$filename_v6 = "{$g['conf_path']}/dyndns_{$rfc2136['interface']}_rfc2136_" . escapeshellarg($rfc2136['host']) . "_{$rfc2136['server']}_v6.cache";
102
	$if = get_failover_interface($rfc2136['interface']);
103

    
104
	if (file_exists($filename)) {
105
		if (isset($rfc2136['usepublicip'])) {
106
			$ipaddr = dyndnsCheckIP($if);
107
		} else {
108
			$ipaddr = get_interface_ip($if);
109
		}
110

    
111
		$cached_ip_s = explode("|", file_get_contents($filename));
112
		$cached_ip = $cached_ip_s[0];
113

    
114
		if ($ipaddr == $cached_ip) {
115
			$icon_class = "fa-solid fa-check-circle";
116
			$text_class = "text-success";
117
			$icon_title = "Updated";
118
		} else {
119
			$icon_class = "fa-solid fa-times-circle";
120
			$text_class = "text-danger";
121
			$icon_title = "Failed";
122
		}
123
	} elseif (file_exists($filename_v6)) {
124
		$ipv6addr = get_interface_ipv6($if);
125
		$cached_ipv6_s = explode("|", file_get_contents($filename_v6));
126
		$cached_ipv6 = $cached_ip_s[0];
127

    
128
		if ($ipv6addr == $cached_ipv6) {
129
			$icon_class = "fa-solid fa-check-circle";
130
			$text_class = "text-success";
131
			$icon_title = "Updated";
132
		} else {
133
			$icon_class = "fa-solid fa-times-circle";
134
			$text_class = "text-danger";
135
			$icon_title = "Failed";
136
		}
137
	}
138
?>
139
						<tr<?=(isset($rfc2136['enable']) ? '' : ' class="disabled"')?>>
140
							<td>
141
							<i class="<?=$icon_class?> <?=$text_class?>" title="<?=$icon_title?>"></i>
142
							</td>
143
							<td>
144
<?php
145
	foreach ($iflist as $if => $ifdesc) {
146
		if ($rfc2136['interface'] == $if) {
147
			print($ifdesc);
148
			break;
149
		}
150
	}
151
	foreach ($groupslist as $if => $group) {
152
		if ($rfc2136['interface'] == $if) {
153
			print($if);
154
			break;
155
		}
156
	}
157
?>
158
							</td>
159
							<td>
160
								<?=htmlspecialchars($rfc2136['server'])?>
161
							</td>
162
							<td>
163
								<?=htmlspecialchars($rfc2136['host'])?>
164
							</td>
165
							<td>
166
<?php
167
	if (file_exists($filename)) {
168
		print('IPv4: ');
169
		print("<span class='{$text_class}'>");
170
		print(htmlspecialchars($cached_ip));
171
		print('</span>');
172
	} elseif (file_exists($filename_v6)) {
173
		print("<span class='{$text_class}'>");
174
		print(htmlspecialchars($cached_ipv6));
175
		print('</span>');
176
	} else {
177
		print('IPv4: N/A');
178
	}
179

    
180
	print('<br />');
181

    
182
	if (file_exists($filename_v6)) {
183
		print('IPv6: ');
184
		$ipaddr = get_interface_ipv6($if);
185
		$cached_ip_s = explode("|", file_get_contents($filename_v6));
186
		$cached_ip = $cached_ip_s[0];
187

    
188
		if ($ipaddr != $cached_ip) {
189
			print('<span class="text-danger">');
190
		} else {
191
			print('<span class="text-success">');
192
		}
193

    
194
		print(htmlspecialchars($cached_ip));
195
		print('</span>');
196
	} else {
197
		print('IPv6: N/A');
198
	}
199

    
200
?>
201
					</td>
202
					<td>
203
						<?=htmlspecialchars($rfc2136['descr'])?>
204
					</td>
205
					<td>
206
						<a class="fa-solid fa-pencil" title="<?=gettext('Edit client')?>" href="services_rfc2136_edit.php?id=<?=$i?>"></a>
207
					<?php if (isset($rfc2136['enable'])) {
208
					?>
209
						<a	class="fa-solid fa-ban" title="<?=gettext('Disable client')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
210
					<?php } else {
211
					?>
212
						<a class="fa-regular fa-square-check" title="<?=gettext('Enable client')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
213
					<?php }
214
					?>
215
						<a class="fa-regular fa-clone" title="<?=gettext('Copy client')?>" href="services_rfc2136_edit.php?dup=<?=$i?>"></a>
216
						<a class="fa-solid fa-trash-can" title="<?=gettext('Delete client')?>" href="services_rfc2136.php?act=del&amp;id=<?=$i?>" usepost></a>
217
					</td>
218
					</tr>
219
<?php
220
	$i++;
221
endforeach; ?>
222

    
223
					</tbody>
224
				</table>
225
			</div>
226
		</div>
227
	</div>
228
</form>
229

    
230
<nav class="action-buttons">
231
	<a href="services_rfc2136_edit.php" class="btn btn-sm btn-success btn-sm">
232
		<i class="fa-solid fa-plus icon-embed-btn"></i>
233
		<?=gettext('Add')?>
234
	</a>
235
</nav>
236

    
237
<div>
238
	<?=sprintf(gettext('Entries with a %3$s status column icon and IP address appearing in %1$sgreen%2$s are up to date with Dynamic DNS provider. '), '<span class="text-success">', '</span>', '<i class="fa-solid fa-check-circle text-success"></i>')?>
239
	<?=gettext('An update can be forced on the edit page for an entry.')?>
240
</div>
241

    
242
<?php
243
include("foot.inc");
(142-142/232)