Project

General

Profile

Download (6.54 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-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-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
config_init_path('checkipservices/checkipservice');
34

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

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

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

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

    
78
if ($input_errors) {
79
	print_input_errors($input_errors);
80
}
81
?>
82

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

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

    
110
$i = 0;
111
foreach ($a_checkipservice as $checkipservice):
112

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

    
150
					</tbody>
151
				</table>
152
			</div>
153
		</div>
154
	</div>
155
</form>
156

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

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

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

    
193
<?php include("foot.inc");
(118-118/232)