Project

General

Profile

Download (6.22 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
init_config_arr(array('checkipservices', 'checkipservice'));
32
$a_checkipservice = &$config['checkipservices']['checkipservice'];
33

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

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

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

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

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

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

    
104
// Append the factory default check IP service to the list.
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 fa-check"' : '';?>></i>
127
						</td>
128
						<td>
129
							<?=htmlspecialchars($checkipservice['descr'])?>
130
						</td>
131
						<td>
132
							<a class="fa 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 fa-ban" title="<?=gettext('Disable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
136
						<?php } else {
137
						?>
138
							<a class="fa fa-check-square-o" title="<?=gettext('Enable service')?>" href="?act=toggle&amp;id=<?=$i?>" usepost></a>
139
						<?php }
140
						?>
141
							<a class="fa fa-trash <?=$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 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");
(122-122/234)