Project

General

Profile

Download (6.28 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-2018 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 * http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21

    
22
##|+PRIV
23
##|*IDENT=page-services-checkipservices
24
##|*NAME=Services: Check IP Service
25
##|*DESCR=Allow access to the 'Services: Check IP Service' page.
26
##|*MATCH=services_checkip.php*
27
##|-PRIV
28

    
29
require_once("guiconfig.inc");
30

    
31
if (!is_array($config['checkipservices']['checkipservice'])) {
32
	$config['checkipservices']['checkipservice'] = array();
33
}
34

    
35
$a_checkipservice = &$config['checkipservices']['checkipservice'];
36

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

    
66
	header("Location: services_checkip.php");
67
	exit;
68
}
69

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

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

    
80
if ($input_errors) {
81
	print_input_errors($input_errors);
82
}
83
?>
84

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

    
107
// Append the factory default check IP service to the list.
108
$a_checkipservice[] = $factory_default_checkipservice;
109
$factory_default = count($a_checkipservice) - 1;
110

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

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

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

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

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

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

    
194
<?php include("foot.inc");
(121-121/232)