Alternc
latest
Alternc logiel libre pour l'hébergement
ip_main.php
Go to the documentation of this file.
1
<?php
2
3
/*
4
----------------------------------------------------------------------
5
LICENSE
6
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License (GPL)
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
To read the license please visit http://www.gnu.org/copyleft/gpl.html
18
----------------------------------------------------------------------
19
*/
20
21
/**
22
* List and edit IP-Authentication list for this account
23
*
24
* @copyright AlternC-Team 2000-2017 https://alternc.com/
25
*/
26
27
require_once(
"../class/config.php"
);
28
include_once(
"head.php"
);
29
30
31
$fields
= array (
32
"delete_id"
=> array (
"request"
,
"integer"
,
""
),
33
"delete_affected_id"
=> array (
"request"
,
"integer"
,
""
),
34
"id"
=> array (
"request"
,
"integer"
, 0),
35
"ipsub"
=> array (
"post"
,
"string"
,
""
),
36
"infos"
=> array (
"post"
,
"string"
,
""
),
37
"s_ipsub"
=> array (
"post"
,
"integer"
,
""
),
38
"s_protocol"
=> array (
"post"
,
"string"
,
""
),
39
);
40
getFields
(
$fields
);
41
42
if
(!empty($s_protocol)) {
43
$val
=
"s_affect_"
.$s_protocol;
44
$fields
= array(
$val
=> Array(
'post'
,
'string'
,
''
) );
45
getFields
(
$fields
);
46
47
if
(!
$authip
->ip_affected_save($s_ipsub, $s_protocol, $
$val
) ) {
48
$msg
->raise(
"ERROR"
,
"ftp"
, _(
"Error during ip_affected_save"
));
49
}
50
}
51
52
if
(!empty($delete_affected_id)) {
53
if
(!
$authip
->ip_affected_delete($delete_affected_id)) {
54
$msg
->raise(
"ERROR"
,
"ftp"
, _(
"Error during deletion"
));
55
}
56
}
57
58
if
(!empty($delete_id)) {
59
if
(!
$authip
->ip_delete($delete_id)) {
60
$msg
->raise(
"ERROR"
,
"ftp"
, _(
"Error during deletion"
));
61
}
62
}
63
64
if
(!empty($ipsub)) {
65
if
(!
$authip
->ip_save(
$id
, $ipsub,
$infos
)) {
66
$msg
->raise(
"ERROR"
,
"ftp"
, _(
"Error during recording"
));
67
}
68
}
69
70
$list_ip
=
$authip
->list_ip();
71
$ac
=
$authip
->get_auth_class();
72
$lac
=
$authip
->list_affected();
73
?>
74
75
<h3><?php
__
(
"FTP Access Security"
); ?></h3>
76
<hr
id
=
"topbar"
/>
77
<br />
78
79
<?php
80
echo
$msg
->msg_html_all();
81
?>
82
83
<p><?php
__
(
"Here you can add rules to restrict access to AlternC's services, filtered by IP. First, add trusted IPs in the 'Known IP and networks' list. Then, add rules to grant access on services to the chosen IPs from this list."
) ?></p>
84
85
<h3><?php
__
(
"Enabled rules"
); ?></h3>
86
87
<table
class
=
"tlist"
>
88
<tr>
89
<th><?php
__
(
"Authorised IP address or network"
);?></th>
90
<th><?php
__
(
"Access type"
);?></th>
91
<th></th>
92
</tr>
93
<?php
94
foreach
(
$lac
as $ll) {
95
echo
"<tr class='lst' >"
;
96
echo
"<td><span title=\"{$list_ip[$ll['authorised_ip_id']]['ip_human']}\">"
.$list_ip[$ll[
'authorised_ip_id'
]][
'infos'
];
97
//echo "<br/>".$list_ip[$ll['authorised_ip_id']]['ip_human'];
98
echo
"</span></td>"
;
99
echo
"<td>"
.@
$ac
[$ll[
'protocol'
]][
'name'
];
100
if
(isset(
$ac
[$ll[
'protocol'
]][
'values'
][$ll[
'parameters'
]]) &&
$ac
[$ll[
'protocol'
]][
'values'
][$ll[
'parameters'
]]) {
101
echo
" "
._(
"for"
).
" "
.
$ac
[$ll[
'protocol'
]][
'values'
][$ll[
'parameters'
]];
102
}
103
echo
"</td>"
;
104
echo
'<td><div class="ina delete"><a href="ip_main.php?delete_affected_id='
.urlencode($ll[
"id"
]).
'">'
._(
"Delete"
).
'</a></div></td>'
;
105
echo
"</tr>"
;
106
}
107
?>
108
</table>
109
110
<hr/>
111
<h3><?php
__
(
"Add a new rule"
); ?></h3>
112
113
<?php
if
(empty(
$list_ip
)) { ?>
114
<p><?php
__
(
"You need to have some 'Known IP and networks' defined below to define a new rule."
) ?></p>
115
<?php }
else
{ ?>
116
<form method=
"post"
action=
"ip_main.php"
name=
"main"
id
=
"main"
>
117
<?php
csrf_get
(); ?>
118
<table
class
=
"tlistb"
>
119
<tbody>
120
<tr valign=
"top"
>
121
<th><?php
__
(
"Access type"
); ?></th>
122
<td
class
=
"lst2"
>
123
<?php
foreach
(
$ac
as $a) { ?>
124
<p>
125
<input type=
"radio"
name=
"s_protocol"
id
=
"s_protocol_<?php ehe($a['protocol']);?>"
value=
"<?php ehe($a['protocol']);?>"
/>
126
<label
for
=
"s_protocol_<?php ehe($a['protocol']);?>"
><?php
ehe
($a[
'name'
]); ?></label>
127
128
<?php
if
(
sizeof
($a[
'values'
]) > 1 ) { ?>
129
<select name=
"s_affect_<?php ehe($a['protocol']);?>"
id
=
"s_affect_<?php ehe($a['protocol']);?>"
>
130
<?php
foreach
($a[
'values'
] as $k => $v) { ?>
131
<option value=
"<?php ehe($k); ?>"
><?php
ehe
($v); ?></option>
132
<?php } ?>
133
</select>
134
<?php }
else
{ ?>
135
<?php
foreach
($a[
'values'
] as $k => $v) { ?>
136
<label><b><?php
ehe
($v); ?></b></label>
137
<input type=
"hidden"
name=
"s_affect_<?php ehe($a['protocol']);?>"
id
=
"s_affect_<?php ehe($a['protocol']);?>"
value=
"<?php ehe($k); ?>"
readonly=
"readonly"
/>
138
<?php } ?>
139
<?php } ?>
140
</p>
141
<?php } ?>
142
</td>
143
</tr>
144
<tr>
145
<th><?php
__
(
"Authorized IP address or network"
); ?></th>
146
<td valign=
"middle"
class
=
"lst2"
>
147
<p>
148
<select name=
"s_ipsub"
>
149
<?php
foreach
(
$list_ip
as $li) { ?>
150
<option value=
"<?php echo $li['id']; ?>"
><?php
ehe
($li[
'infos'
]);
151
//echo " - ".$li['ip'] ; if (!($li['subnet']==32 || $li['subnet'] == 128)) echo "/".$li['subnet'];
152
?></option>
153
<?php } ?>
154
</select>
155
</p>
156
</td>
157
</tr>
158
<tr>
159
<th> </th>
160
<td valign=
'middle'
class
=
"lst2"
>
161
<input type=
"submit"
class
=
"inb ok"
value=
"<?php __("
Save
")?>"
onclick=
'return check_accesstype_selected();'
/>
162
</td>
163
</tr>
164
</tbody>
165
</table>
166
</form>
167
<?php }
// empty $list_ip ?>
168
<br/>
169
<hr/>
170
<h3><?php
__
(
"Known IP and networks"
);?></h3>
171
<table
class
=
"tlist"
>
172
<tr><th><?php
__
(
"Name"
); ?></th><th><?php
__
(
"IP or network"
); ?></th><th><?php
__
(
"Type"
); ?></th><th colspan=
'2'
></th></tr>
173
<?php
174
foreach
(
$list_ip
as
$i
) {
175
if
(
checkip
(
$i
[
'ip'
])) {
176
if
(
$i
[
'subnet'
]==32) {
177
$txt=_(
"Address IPv4"
);
178
}
else
{
179
$txt=_(
"Subnet IPv4"
);
180
}
181
}
elseif
(
checkipv6
(
$i
[
'ip'
])) {
182
if
(
$i
[
'subnet'
]==128) {
183
$txt=_(
"Address IPv6"
);
184
}
else
{
185
$txt=_(
"Subnet IPv6"
);
186
}
187
}
else
{
188
$txt=_(
"Error with this IP"
);
189
}
190
echo
"<tr class='lst' ><td>{$i['infos']}</td><td>{$i['ip_human']}</td><td>$txt</td>"
;
191
?>
192
<td><div
class
=
"ina edit"
><a href=
"javascript:edit_ip(<?php echo "
'".htmlentities($i['
id
'])."'
,
'".htmlentities($i['
ip_human
'])."'
,
".htmlentities($i['infos']); ?>);"
><?php
__
(
"Edit"
); ?></a></div></td>
193
<td><div
class
=
"ina delete"
><a href=
"ip_main.php?delete_id=<?php echo urlencode($i["
id
"]) ?>"
><?php
__
(
"Delete"
); ?></a></div></td>
194
</tr>
195
196
<?php } ?>
197
</table>
198
<br/>
199
<hr/>
200
<h3><?php
__
(
"Add an IP or a networks"
);?></h3>
201
202
<p><a href=
"javascript:edit_ip('','<?php ehe(get_remote_ip()."
','
Home IP
'");?>);" ><?php echo __("Add my current IP"); ?></a></p>
203
<span id="form_add_ip">
204
<form method="post" action="ip_main.php" name="main" >
205
<?php csrf_get(); ?>
206
<p id="reset_edit_ip" style="display:none;"><a href="javascript:reset_edit_ip();"><?php __("Cancel edit")?></a></p>
207
208
<input type="hidden" name="id" value="" id="edit_id" />
209
<table class="tlistb">
210
<tr><th><?php __("IP or network. <i>IPv4, IPv6 and subnet allowed</i>"); ?></th><th><?php __("Name"); ?></th><th></th></tr>
211
212
<tr class="lst2">
213
<td><input type="text" size="20" maxlength="39" name="ipsub" id="edit_ip" /></td>
214
<td><input type="text" size="25" maxlength="200" name="infos" id="edit_infos" /></td>
215
<td><input type="submit" class="inb ok" value="<?php __("Save")?>" /></td>
216
</tr>
217
</table>
218
</form>
219
</span>
220
221
<script type="text/javascript">
222
function reset_edit_ip() {
223
$("#reset_edit_ip").hide();
224
$("#edit_id").val('
');
225
$("#edit_ip").val('
');
226
$("#edit_infos").val('
');
227
}
228
229
function edit_ip(id, iph, infos) {
230
if ( id != '
' ) {
231
$("#reset_edit_ip").show();
232
}
233
$("#edit_id").val(id);
234
$("#edit_infos").val(infos);
235
$("#edit_ip").val(iph);
236
}
237
238
function check_accesstype_selected() {
239
if ( $('
input[name=s_protocol]:radio:checked
').val() ) {
240
// there is a value
241
return true;
242
}
243
alert("<?php __("Please select an access type"); ?>");
244
return false;
245
}
246
247
</script>
248
<?php include_once("foot.php"); ?>
$msg
$msg
Definition:
bootstrap.php:75
$authip
$authip
Definition:
bootstrap.php:73
checkipv6
checkipv6($ip)
Check that $ip is a correct ipv6 ip.
Definition:
functions.php:221
ehe
ehe($str, $display=TRUE)
Echo the HTMLSpecialChars version of a value.
Definition:
functions.php:647
__
__($str)
Definition:
functions.php:404
getFields
getFields($fields, $requestOnly=false)
Get the Fields of the posted form from $_REQUEST or POST or GET and check their type.
Definition:
functions.php:688
checkip
checkip($ip)
Check that $ip is a correct 4 Dotted ip.
Definition:
functions.php:210
csrf_get
csrf_get($return=false)
Give a new CSRF uniq token for a form the session must be up since the CSRF is linked to the session ...
Definition:
functions.php:1159
$list_ip
if(!empty($s_protocol)) if(!empty($delete_affected_id)) if(!empty($delete_id)) if(!empty($ipsub)) $list_ip
Definition:
ip_main.php:70
$ac
$ac
Definition:
ip_main.php:71
$lac
$lac
Definition:
ip_main.php:72
$fields
$fields
List and edit IP-Authentication list for this account.
Definition:
ip_main.php:31
elseif
if(empty($site_name)) elseif($piwik->site_add( $site_name, $site_urls))
Definition:
piwik_addsites.php:39
$i
$i
Definition:
sql_getparam.php:55
$id
if(!isset($is_include)) if(! $key &&! $crt) $id
Definition:
ssl_doimport.php:44
$val
$val
Definition:
tempovars.php:15
$infos
if(in_array($action, array('start', 'stop', 'monit'))) switch($action) if($lxc->error &&! $script) $infos
Definition:
vm.php:32
bureau
admin
ip_main.php
Generated on Sat Sep 16 2023 12:00:03 for Alternc by
1.9.1