Project

General

Profile

Download (7.19 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
config_init_path('dnsupdates/dnsupdate');
34

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

    
38
	write_config("RFC 2136 client deleted");
39

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

    
53
		header("Location: services_rfc2136.php");
54
		exit;
55
	}
56
}
57

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

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

    
68
if ($input_errors) {
69
	print_input_errors($input_errors);
70
}
71
?>
72

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

    
93

    
94
$iflist = get_configured_interface_with_descr();
95
$groupslist = return_gateway_groups_array();
96

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

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

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

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

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

    
182
	print('<br />');
183

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

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

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

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

    
225
					</tbody>
226
				</table>
227
			</div>
228
		</div>
229
	</div>
230
</form>
231

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

    
239
<div>
240
	<?=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>')?>
241
	<?=gettext('An update can be forced on the edit page for an entry.')?>
242
</div>
243

    
244
<?php
245
include("foot.inc");
(142-142/232)