Project

General

Profile

Download (6.48 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_checkip.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-2025 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-checkipservices
26
##|*NAME=Services: Check IP Service
27
##|*DESCR=Allow access to the 'Services: Check IP Service' page.
28
##|*MATCH=services_checkip.php*
29
##|-PRIV
30

    
31
require_once("guiconfig.inc");
32

    
33
$dirty = false;
34
if ($_POST['act'] == "del") {
35
	config_del_path("checkipservices/checkipservice/{$_POST['id']}");
36
	$wc_msg = gettext('Deleted a check IP service.');
37
	$dirty = true;
38
} else if ($_POST['act'] == "toggle") {
39
	if (config_get_path("checkipservices/checkipservice/{$_POST['id']}")) {
40
		if (config_path_enabled("checkipservices/checkipservice/{$_POST['id']}")) {
41
			config_del_path("checkipservices/checkipservice/{$_POST['id']}/enable");
42
			$wc_msg = gettext('Disabled a check IP service.');
43
		} else {
44
			config_set_path("checkipservices/checkipservice/{$_POST['id']}/enable", true);
45
			$wc_msg = gettext('Enabled a check IP service.');
46
		}
47
		$dirty = true;
48
	} else if ($_POST['id'] == count(config_get_path('checkipservices/checkipservice', []))) {
49
		if (config_path_enabled('checkipservices', 'disable_factory_default')) {
50
			config_del_path('checkipservices/disable_factory_default');
51
			$wc_msg = gettext('Enabled the default check IP service.');
52
		} else {
53
			config_set_path('checkipservices/disable_factory_default', true);
54
			$wc_msg = gettext('Disabled the default check IP service.');
55
		}
56
		$dirty = true;
57
	}
58
}
59
if ($dirty) {
60
	write_config($wc_msg);
61

    
62
	header("Location: services_checkip.php");
63
	exit;
64
}
65

    
66
$pgtitle = array(gettext("Services"), gettext("Dynamic DNS"), gettext("Check IP Services"));
67
$pglinks = array("", "services_dyndns.php", "@self");
68
include("head.inc");
69

    
70
$tab_array = array();
71
$tab_array[] = array(gettext("Dynamic DNS Clients"), false, "services_dyndns.php");
72
$tab_array[] = array(gettext("RFC 2136 Clients"), false, "services_rfc2136.php");
73
$tab_array[] = array(gettext("Check IP Services"), true, "services_checkip.php");
74
display_top_tabs($tab_array);
75

    
76
if ($input_errors) {
77
	print_input_errors($input_errors);
78
}
79
?>
80

    
81
<form action="services_checkip.php" method="post" name="iform" id="iform">
82
	<div class="panel panel-default">
83
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Check IP Services')?></h2></div>
84
		<div class="panel-body">
85
			<div class="table-responsive">
86
				<table class="table table-striped table-hover table-condensed">
87
					<thead>
88
						<tr>
89
							<th><?=gettext("Name")?></th>
90
							<th><?=gettext("URL")?></th>
91
							<th><?=gettext("Verify SSL/TLS Peer")?></th>
92
							<th><?=gettext("Description")?></th>
93
							<th><?=gettext("Actions")?></th>
94
						</tr>
95
					</thead>
96
					<tbody>
97
<?php
98
// Is the factory default check IP service disabled?
99
if (config_path_enabled('checkipservices', 'disable_factory_default')) {
100
	unset($factory_default_checkipservice['enable']);
101
}
102

    
103
// Append the factory default check IP service to the list.
104
$a_checkipservice = config_get_path('checkipservices/checkipservice', []);
105
$a_checkipservice[] = $factory_default_checkipservice;
106
$factory_default = count($a_checkipservice) - 1;
107

    
108
$i = 0;
109
foreach ($a_checkipservice as $checkipservice):
110

    
111
	// Hide edit and delete controls on the factory default check IP service entry (last one; id = count-1), and retain layout positioning.
112
	if ($i == $factory_default) {
113
		$visibility = 'invisible';
114
	} else {
115
		$visibility = 'visible';
116
	}
117
?>
118
						<tr<?=(isset($checkipservice['enable']) ? '' : ' class="disabled"')?>>
119
						<td>
120
							<?=htmlspecialchars($checkipservice['name'])?>
121
						</td>
122
						<td>
123
							<?=htmlspecialchars($checkipservice['url'])?>
124
						</td>
125
						<td class="text-center">
126
							<i<?=(isset($checkipservice['verifysslpeer'])) ? ' class="fa-solid fa-check"' : '';?>></i>
127
						</td>
128
						<td>
129
							<?=htmlspecialchars($checkipservice['descr'])?>
130
						</td>
131
						<td>
132
							<a class="fa-solid fa-pencil <?=$visibility?>" title="<?=gettext('Edit service')?>" href="services_checkip_edit.php?id=<?=$i?>"></a>
133
						<?php if (isset($checkipservice['enable'])) {
134
						?>
135
							<a	class="fa-solid fa-ban" title="<?=gettext('Disable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
136
						<?php } else {
137
						?>
138
							<a class="fa-regular fa-square-check" title="<?=gettext('Enable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
139
						<?php }
140
						?>
141
							<a class="fa-solid fa-trash-can <?=$visibility?>" title="<?=gettext('Delete service')?>" href="services_checkip.php?act=del&amp;id=<?=$i?>" usepost></a>
142
						</td>
143
					</tr>
144
<?php
145
	$i++;
146
endforeach; ?>
147

    
148
					</tbody>
149
				</table>
150
			</div>
151
		</div>
152
	</div>
153
</form>
154

    
155
<nav class="action-buttons">
156
	<a href="services_checkip_edit.php" class="btn btn-sm btn-success btn-sm">
157
		<i class="fa-solid fa-plus icon-embed-btn"></i>
158
		<?=gettext('Add')?>
159
	</a>
160
</nav>
161

    
162
<div class="infoblock">
163
	<?php print_info_box(gettext('The server must return the client IP address ' .
164
	'as a string in the following format: ') .
165
	'<pre>Current IP Address: x.x.x.x</pre>' .
166
	gettext(
167
	'The first (highest in list) enabled check ip service will be used to ' .
168
	'check IP addresses for Dynamic DNS services, and ' .
169
	'RFC 2136 entries that have the "Use public IP" option enabled.') .
170
	'<br/><br/>'
171
	, 'info', false);
172

    
173
	print_info_box(gettext('Sample Server Configurations') .
174
	'<br/>' .
175
	gettext('nginx with LUA') . ':' .
176
	'<pre> location = /ip {
177
	default_type text/html;
178
	content_by_lua \'
179
		ngx.say("' . htmlspecialchars('<html><head><title>Current IP Check</title></head><body>') . 'Current IP Address: ")
180
		ngx.say(ngx.var.remote_addr)
181
		ngx.say("' . htmlspecialchars('</body></html>') . '")
182
	\';
183
	}</pre>' .
184
	gettext('PHP') .
185
	'<pre>' .
186
	htmlspecialchars('<html><head><title>Current IP Check</title></head><body>Current IP Address: <?=$_SERVER[\'REMOTE_ADDR\']?></body></html>') .
187
	'</pre>'
188
	, 'info', false); ?>
189
</div>
190

    
191
<?php include("foot.inc");
(119-119/233)