Project

General

Profile

Download (6.37 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'])) {
32
	$config['checkipservices'] = array();
33
}
34

    
35
if (!is_array($config['checkipservices']['checkipservice'])) {
36
	$config['checkipservices']['checkipservice'] = array();
37
}
38

    
39
$a_checkipservice = &$config['checkipservices']['checkipservice'];
40

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

    
70
	header("Location: services_checkip.php");
71
	exit;
72
}
73

    
74
$pgtitle = array(gettext("Services"), gettext("Dynamic DNS"), gettext("Check IP Services"));
75
$pglinks = array("", "services_dyndns.php", "@self");
76
include("head.inc");
77

    
78
$tab_array = array();
79
$tab_array[] = array(gettext("Dynamic DNS Clients"), false, "services_dyndns.php");
80
$tab_array[] = array(gettext("RFC 2136 Clients"), false, "services_rfc2136.php");
81
$tab_array[] = array(gettext("Check IP Services"), true, "services_checkip.php");
82
display_top_tabs($tab_array);
83

    
84
if ($input_errors) {
85
	print_input_errors($input_errors);
86
}
87
?>
88

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

    
111
// Append the factory default check IP service to the list.
112
$a_checkipservice[] = $factory_default_checkipservice;
113
$factory_default = count($a_checkipservice) - 1;
114

    
115
$i = 0;
116
foreach ($a_checkipservice as $checkipservice):
117

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

    
155
					</tbody>
156
				</table>
157
			</div>
158
		</div>
159
	</div>
160
</form>
161

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

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

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

    
198
<?php include("foot.inc");
(122-122/234)