Project

General

Profile

Download (7.25 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-2020 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 (in_array($dyndns['type'], $dyndns_split_domain_types)) {
105
		$hostname = $dyndns['host'] . "." . $dyndns['domainname'];
106
	} else {
107
		$hostname = $dyndns['host'];
108
	}
109
	$filename = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($hostname) . "{$dyndns['id']}.cache";
110
	$filename_v6 = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($hostname) . "{$dyndns['id']}_v6.cache";
111
	if (file_exists($filename)) {
112
		$ipaddr = dyndnsCheckIP($dyndns['interface']);
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 fa-check-circle";
118
			$text_class = "text-success";
119
			$icon_title = "Updated";
120
		} else {
121
			$icon_class = "fa fa-times-circle";
122
			$text_class = "text-danger";
123
			$icon_title = "Failed";
124
		}
125
	} else if (file_exists($filename_v6)) {
126
		$ipv6addr = get_interface_ipv6($dyndns['interface']);
127
		$cached_ipv6_s = explode("|", file_get_contents($filename_v6));
128
		$cached_ipv6 = $cached_ipv6_s[0];
129

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

    
152
			break;
153
		}
154
	}
155

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

    
170
	for ($j = 0; $j < count($vals); $j++) {
171
		if ($vals[$j] == $dyndns['type']) {
172
			print(htmlspecialchars($types[$j]));
173

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

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

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

    
241
<?php
242
include("foot.inc");
(129-129/229)