Project

General

Profile

Download (6.54 KB) Statistics
| Branch: | Tag: | Revision:
1 39d2f39d NOYB
<?php
2
/*
3 c5d81585 Renato Botelho
 * services_checkip.php
4 39d2f39d NOYB
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 a68f7a3d Luiz Otavio O Souza
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 39d2f39d NOYB
 *
11 b12ea3fb Renato Botelho
 * 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 39d2f39d NOYB
 *
15 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
16 39d2f39d NOYB
 *
17 b12ea3fb Renato Botelho
 * 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 39d2f39d NOYB
 */
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 63d6bb4f Marcos Mendoza
config_init_path('checkipservices/checkipservice');
34 39d2f39d NOYB
35
$dirty = false;
36 c946d721 Steve Beaver
if ($_POST['act'] == "del") {
37 63d6bb4f Marcos Mendoza
	config_del_path("checkipservices/checkipservice/{$_POST['id']}");
38 9178eadc doktornotor
	$wc_msg = gettext('Deleted a check IP service.');
39 39d2f39d NOYB
	$dirty = true;
40 c946d721 Steve Beaver
} else if ($_POST['act'] == "toggle") {
41 63d6bb4f Marcos Mendoza
	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 9178eadc doktornotor
			$wc_msg = gettext('Disabled a check IP service.');
45 39d2f39d NOYB
		} else {
46 63d6bb4f Marcos Mendoza
			config_set_path("checkipservices/checkipservice/{$_POST['id']}/enable", true);
47 9178eadc doktornotor
			$wc_msg = gettext('Enabled a check IP service.');
48 39d2f39d NOYB
		}
49
		$dirty = true;
50 4b9165e5 Marcos Mendoza
	} else if ($_POST['id'] == count(config_get_path('checkipservices/checkipservice', []))) {
51 63d6bb4f Marcos Mendoza
		if (config_path_enabled('checkipservices', 'disable_factory_default')) {
52 6e081414 Christian McDonald
			config_del_path('checkipservices/disable_factory_default');
53 9178eadc doktornotor
			$wc_msg = gettext('Enabled the default check IP service.');
54 39d2f39d NOYB
		} else {
55 721fafba Christian McDonald
			config_set_path('checkipservices/disable_factory_default', true);
56 9178eadc doktornotor
			$wc_msg = gettext('Disabled the default check IP service.');
57 39d2f39d NOYB
		}
58
		$dirty = true;
59
	}
60
}
61
if ($dirty) {
62 9178eadc doktornotor
	write_config($wc_msg);
63 39d2f39d NOYB
64
	header("Location: services_checkip.php");
65
	exit;
66
}
67
68
$pgtitle = array(gettext("Services"), gettext("Dynamic DNS"), gettext("Check IP Services"));
69 edcd7535 Phil Davis
$pglinks = array("", "services_dyndns.php", "@self");
70 39d2f39d NOYB
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 f764f63a jim-p
							<th><?=gettext("Verify SSL/TLS Peer")?></th>
94 39d2f39d NOYB
							<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 63d6bb4f Marcos Mendoza
if (config_path_enabled('checkipservices/checkipservice', 'disable_factory_default')) {
102 39d2f39d NOYB
	unset($factory_default_checkipservice['enable']);
103
}
104
105
// Append the factory default check IP service to the list.
106 63d6bb4f Marcos Mendoza
$a_checkipservice = config_get_path('checkipservices/checkipservice');
107 39d2f39d NOYB
$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 e0cb987c Marcos Mendoza
							<i<?=(isset($checkipservice['verifysslpeer'])) ? ' class="fa-solid fa-check"' : '';?>></i>
129 39d2f39d NOYB
						</td>
130
						<td>
131
							<?=htmlspecialchars($checkipservice['descr'])?>
132
						</td>
133
						<td>
134 e0cb987c Marcos Mendoza
							<a class="fa-solid fa-pencil <?=$visibility?>" title="<?=gettext('Edit service')?>" href="services_checkip_edit.php?id=<?=$i?>"></a>
135 39d2f39d NOYB
						<?php if (isset($checkipservice['enable'])) {
136
						?>
137 e0cb987c Marcos Mendoza
							<a	class="fa-solid fa-ban" title="<?=gettext('Disable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
138 39d2f39d NOYB
						<?php } else {
139
						?>
140 c1d304b3 Marcos Mendoza
							<a class="fa-regular fa-square-check" title="<?=gettext('Enable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
141 39d2f39d NOYB
						<?php }
142
						?>
143 c1d304b3 Marcos Mendoza
							<a class="fa-solid fa-trash-can <?=$visibility?>" title="<?=gettext('Delete service')?>" href="services_checkip.php?act=del&amp;id=<?=$i?>" usepost></a>
144 39d2f39d NOYB
						</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 e0cb987c Marcos Mendoza
		<i class="fa-solid fa-plus icon-embed-btn"></i>
160 39d2f39d NOYB
		<?=gettext('Add')?>
161
	</a>
162
</nav>
163
164 6f3ac947 NOYB
<div class="infoblock">
165 186c7a6c jim-p
	<?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 c946d721 Steve Beaver
	'The first (highest in list) enabled check ip service will be used to ' .
170 6f3ac947 NOYB
	'check IP addresses for Dynamic DNS services, and ' .
171 186c7a6c jim-p
	'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 6f3ac947 NOYB
</div>
192
193
<?php include("foot.inc");