Project

General

Profile

Download (7.31 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-2023 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
$i = 0;
103
foreach ($a_dyndns as $dyndns):
104
	if (!is_array($dyndns) || empty($dyndns)) {
105
		continue;
106
	}
107
	if (in_array($dyndns['type'], $dyndns_split_domain_types)) {
108
		$hostname = $dyndns['host'] . "." . $dyndns['domainname'];
109
	} else {
110
		$hostname = $dyndns['host'];
111
	}
112
	$filename = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($hostname) . "{$dyndns['id']}.cache";
113
	$filename_v6 = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($hostname) . "{$dyndns['id']}_v6.cache";
114
	if (file_exists($filename)) {
115
		$ipaddr = dyndnsCheckIP($dyndns['interface']);
116
		$cached_ip_s = explode("|", file_get_contents($filename));
117
		$cached_ip = $cached_ip_s[0];
118

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

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

    
155
			break;
156
		}
157
	}
158

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

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

    
177
			break;
178
		}
179
	}
180
?>
181
							</td>
182
							<td>
183
<?php
184
	print(insert_word_breaks_in_domain_name(htmlspecialchars($hostname)));
185
?>
186
							</td>
187
							<td>
188
<?php
189
	if (file_exists($filename)) {
190
		print("<span class='{$text_class}'>");
191
		print(htmlspecialchars($cached_ip));
192
		print('</span>');
193
	} elseif (file_exists($filename_v6)) {
194
		print("<span class='{$text_class}'>");
195
		print(htmlspecialchars($cached_ipv6));
196
		print('</span>');
197
	} else {
198
		print('N/A');
199
	}
200
?>
201
							</td>
202
							<td>
203
<?php
204
	print(htmlspecialchars($dyndns['descr']));
205
?>
206
							</td>
207
							<td>
208
								<a class="fa fa-pencil" title="<?=gettext('Edit service')?>" href="services_dyndns_edit.php?id=<?=$i?>"></a>
209
<?php if (isset($dyndns['enable'])) {
210
?>
211
								<a class="fa fa-ban" title="<?=gettext('Disable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
212
<?php } else {
213
?>
214
								<a class="fa fa-check-square-o" title="<?=gettext('Enable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
215
<?php }
216
?>
217
								<a class="fa fa-clone" title="<?=gettext('Copy service')?>"	href="services_dyndns_edit.php?dup=<?=$i?>"></a>
218
								<a class="fa fa-trash" title="<?=gettext('Delete service')?>"	href="services_dyndns.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_dyndns_edit.php" class="btn btn-sm btn-success btn-sm">
234
		<i class="fa 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 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");
(127-127/228)