Project

General

Profile

Download (7.38 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_dyndns.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-dynamicdnsclients
26
##|*NAME=Services: Dynamic DNS clients
27
##|*DESCR=Allow access to the 'Services: Dynamic DNS clients' page.
28
##|*MATCH=services_dyndns.php*
29
##|-PRIV
30

    
31
require_once("guiconfig.inc");
32

    
33
init_config_arr(array('dyndnses', 'dyndns'));
34
$a_dyndns = &$config['dyndnses']['dyndns'];
35
global $dyndns_split_domain_types;
36

    
37
if ($_POST['act'] == "del") {
38
	$conf = $a_dyndns[$_POST['id']];
39
	if (in_array($conf['type'], $dyndns_split_domain_types)) {
40
		$hostname = $conf['host'] . "." . $conf['domainname'];
41
	} else {
42
		$hostname = $conf['host'];
43
	}
44
	@unlink("{$g['conf_path']}/dyndns_{$conf['interface']}{$conf['type']}" . escapeshellarg($hostname) . "{$conf['id']}.cache");
45
	unset($a_dyndns[$_POST['id']]);
46

    
47
	write_config(gettext("Dynamic DNS client deleted."));
48
	services_dyndns_configure();
49

    
50
	header("Location: services_dyndns.php");
51
	exit;
52
} else if ($_POST['act'] == "toggle") {
53
	if ($a_dyndns[$_POST['id']]) {
54
		if (isset($a_dyndns[$_POST['id']]['enable'])) {
55
			unset($a_dyndns[$_POST['id']]['enable']);
56
			$wc_msg = gettext('Dynamic DNS client disabled.');
57
		} else {
58
			$a_dyndns[$_POST['id']]['enable'] = true;
59
			$wc_msg = gettext('Dynamic DNS client enabled.');
60
		}
61
		write_config($wc_msg);
62
		services_dyndns_configure();
63

    
64
		header("Location: services_dyndns.php");
65
		exit;
66
	}
67
}
68

    
69
$pgtitle = array(gettext("Services"), gettext("Dynamic DNS"), gettext("Dynamic DNS Clients"));
70
$pglinks = array("", "@self", "@self");
71
include("head.inc");
72

    
73
if ($input_errors) {
74
	print_input_errors($input_errors);
75
}
76

    
77
$tab_array = array();
78
$tab_array[] = array(gettext("Dynamic DNS Clients"), true, "services_dyndns.php");
79
$tab_array[] = array(gettext("RFC 2136 Clients"), false, "services_rfc2136.php");
80
$tab_array[] = array(gettext("Check IP Services"), false, "services_checkip.php");
81
display_top_tabs($tab_array);
82
?>
83
<form action="services_dyndns.php" method="post" name="iform" id="iform">
84
	<div class="panel panel-default">
85
		<div class="panel-heading"><h2 class="panel-title"><?=gettext('Dynamic DNS Clients')?></h2></div>
86
		<div class="panel-body">
87
			<div class="table-responsive">
88
				<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
89
					<thead>
90
						<tr>
91
							<th><?=gettext("Status")?></th>
92
							<th><?=gettext("Interface")?></th>
93
							<th><?=gettext("Service")?></th>
94
							<th><?=gettext("Hostname")?></th>
95
							<th><?=gettext("Cached IP")?></th>
96
							<th><?=gettext("Description")?></th>
97
							<th><?=gettext("Actions")?></th>
98
						</tr>
99
					</thead>
100
					<tbody>
101
<?php
102

    
103
$iflist = get_configured_interface_with_descr();
104
$groupslist = return_gateway_groups_array();
105

    
106
$i = 0;
107
foreach ($a_dyndns as $dyndns):
108
	if (!is_array($dyndns) || empty($dyndns)) {
109
		continue;
110
	}
111
	if (in_array($dyndns['type'], $dyndns_split_domain_types)) {
112
		$hostname = $dyndns['host'] . "." . $dyndns['domainname'];
113
	} else {
114
		$hostname = $dyndns['host'];
115
	}
116
	$filename = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($hostname) . "{$dyndns['id']}.cache";
117
	$filename_v6 = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($hostname) . "{$dyndns['id']}_v6.cache";
118
	if (file_exists($filename)) {
119
		$ipaddr = dyndnsCheckIP($dyndns['interface']);
120
		$cached_ip_s = explode("|", file_get_contents($filename));
121
		$cached_ip = $cached_ip_s[0];
122

    
123
		if ($ipaddr == $cached_ip) {
124
			$icon_class = "fa-solid fa-check-circle";
125
			$text_class = "text-success";
126
			$icon_title = "Updated";
127
		} else {
128
			$icon_class = "fa-solid fa-times-circle";
129
			$text_class = "text-danger";
130
			$icon_title = "Failed";
131
		}
132
	} else if (file_exists($filename_v6)) {
133
		$ipv6addr = get_interface_ipv6($dyndns['interface']);
134
		$cached_ipv6_s = explode("|", file_get_contents($filename_v6));
135
		$cached_ipv6 = $cached_ipv6_s[0];
136

    
137
		if ($ipv6addr == $cached_ipv6) {
138
			$icon_class = "fa-solid fa-check-circle";
139
			$text_class = "text-success";
140
			$icon_title = "Updated";
141
		} else {
142
			$icon_class = "fa-solid fa-times-circle";
143
			$text_class = "text-danger";
144
			$icon_title = "Failed";
145
		}
146
	}
147
?>
148
						<tr<?=!isset($dyndns['enable'])?' class="disabled"':''?>>
149
							<td>
150
							<i class="<?=$icon_class?> <?=$text_class?>" title="<?=$icon_title?>"></i>
151
							</td>
152
							<td>
153
<?php
154
	foreach ($iflist as $if => $ifdesc) {
155
		if (str_replace('_stf', '', $dyndns['interface']) == $if) {
156
			print($ifdesc);
157

    
158
			break;
159
		}
160
	}
161

    
162
	foreach ($groupslist as $if => $group) {
163
		if ($dyndns['interface'] == $if) {
164
			print($if);
165
			break;
166
		}
167
	}
168
?>
169
							</td>
170
							<td>
171
<?php
172
	$types = explode(",", DYNDNS_PROVIDER_DESCRIPTIONS);
173
	$vals = explode(" ", DYNDNS_PROVIDER_VALUES);
174

    
175
	for ($j = 0; $j < count($vals); $j++) {
176
		if ($vals[$j] == $dyndns['type']) {
177
			print(htmlspecialchars($types[$j]));
178

    
179
			break;
180
		}
181
	}
182
?>
183
							</td>
184
							<td>
185
<?php
186
	print(insert_word_breaks_in_domain_name(htmlspecialchars($hostname)));
187
?>
188
							</td>
189
							<td>
190
<?php
191
	if (file_exists($filename)) {
192
		print("<span class='{$text_class}'>");
193
		print(htmlspecialchars($cached_ip));
194
		print('</span>');
195
	} elseif (file_exists($filename_v6)) {
196
		print("<span class='{$text_class}'>");
197
		print(htmlspecialchars($cached_ipv6));
198
		print('</span>');
199
	} else {
200
		print('N/A');
201
	}
202
?>
203
							</td>
204
							<td>
205
<?php
206
	print(htmlspecialchars($dyndns['descr']));
207
?>
208
							</td>
209
							<td>
210
								<a class="fa-solid fa-pencil" title="<?=gettext('Edit service')?>" href="services_dyndns_edit.php?id=<?=$i?>"></a>
211
<?php if (isset($dyndns['enable'])) {
212
?>
213
								<a class="fa-solid fa-ban" title="<?=gettext('Disable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
214
<?php } else {
215
?>
216
								<a class="fa-regular fa-square-check" title="<?=gettext('Enable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
217
<?php }
218
?>
219
								<a class="fa-regular fa-clone" title="<?=gettext('Copy service')?>"	href="services_dyndns_edit.php?dup=<?=$i?>"></a>
220
								<a class="fa-solid fa-trash-can" title="<?=gettext('Delete service')?>"	href="services_dyndns.php?act=del&amp;id=<?=$i?>" usepost></a>
221
							</td>
222
						</tr>
223
<?php
224
	$i++;
225
	endforeach;
226
?>
227
					</tbody>
228
			  </table>
229
			</div>
230
		</div>
231
	</div>
232
</form>
233

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

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

    
246
<?php
247
include("foot.inc");
(127-127/228)