2011-04-27 15:44:19 +00:00
< ? php
2017-10-11 09:58:04 +00:00
/*
----------------------------------------------------------------------
LICENSE
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License ( GPL )
as published by the Free Software Foundation ; either version 2
of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
To read the license please visit http :// www . gnu . org / copyleft / gpl . html
----------------------------------------------------------------------
*/
/**
* List and edit IP - Authentication list for this account
*
* @ copyright AlternC - Team 2000 - 2017 https :// alternc . com /
*/
2011-04-27 15:44:19 +00:00
require_once ( " ../class/config.php " );
include_once ( " head.php " );
$fields = array (
2016-05-23 13:03:13 +00:00
" delete_id " => array ( " request " , " integer " , " " ),
" delete_affected_id " => array ( " request " , " integer " , " " ),
" id " => array ( " request " , " integer " , 0 ),
2011-05-03 19:03:43 +00:00
" ipsub " => array ( " post " , " string " , " " ),
" infos " => array ( " post " , " string " , " " ),
" s_ipsub " => array ( " post " , " integer " , " " ),
" s_protocol " => array ( " post " , " string " , " " ),
2011-04-27 15:44:19 +00:00
);
getFields ( $fields );
2011-05-03 07:25:51 +00:00
if ( ! empty ( $s_protocol )) {
$val = " s_affect_ " . $s_protocol ;
$fields = array ( $val => Array ( 'post' , 'string' , '' ) );
getFields ( $fields );
if ( ! $authip -> ip_affected_save ( $s_ipsub , $s_protocol , $$val ) ) {
2017-10-06 16:04:36 +00:00
$msg -> raise ( " ERROR " , " ftp " , _ ( " Error during ip_affected_save " ));
2011-05-03 07:25:51 +00:00
}
}
2011-05-03 19:03:43 +00:00
if ( ! empty ( $delete_affected_id )) {
if ( ! $authip -> ip_affected_delete ( $delete_affected_id )) {
2017-10-06 16:04:36 +00:00
$msg -> raise ( " ERROR " , " ftp " , _ ( " Error during deletion " ));
2011-05-03 19:03:43 +00:00
}
}
2011-04-27 15:44:19 +00:00
if ( ! empty ( $delete_id )) {
if ( ! $authip -> ip_delete ( $delete_id )) {
2017-10-06 16:04:36 +00:00
$msg -> raise ( " ERROR " , " ftp " , _ ( " Error during deletion " ));
2011-04-27 15:44:19 +00:00
}
}
2011-05-03 07:25:51 +00:00
if ( ! empty ( $ipsub )) {
if ( ! $authip -> ip_save ( $id , $ipsub , $infos )) {
2017-10-06 16:04:36 +00:00
$msg -> raise ( " ERROR " , " ftp " , _ ( " Error during recording " ));
2011-04-27 15:44:19 +00:00
}
}
2011-05-03 07:25:51 +00:00
$list_ip = $authip -> list_ip ();
$ac = $authip -> get_auth_class ();
$lac = $authip -> list_affected ();
2011-04-27 15:44:19 +00:00
?>
2015-06-16 12:37:22 +00:00
< h3 >< ? php __ ( " FTP Access Security " ); ?> </h3>
2011-04-27 15:44:19 +00:00
< hr id = " topbar " />
< br />
2017-08-17 01:32:18 +00:00
< ? php
echo $msg -> msg_html_all ();
?>
2011-04-27 15:44:19 +00:00
2013-01-21 16:31:38 +00:00
< 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>
2012-04-06 10:10:36 +00:00
< h3 >< ? php __ ( " Enabled rules " ); ?> </h3>
< table class = " tlist " >
2011-05-03 07:25:51 +00:00
< tr >
2013-01-28 10:01:09 +00:00
< th >< ? php __ ( " Authorised IP address or network " ); ?> </th>
< th >< ? php __ ( " Access type " ); ?> </th>
< th ></ th >
2011-05-03 07:25:51 +00:00
</ tr >
< ? php
foreach ( $lac as $ll ) {
2013-05-23 16:18:56 +00:00
echo " <tr class='lst' > " ;
2013-04-19 07:18:25 +00:00
echo " <td><span title= \" { $list_ip [ $ll [ 'authorised_ip_id' ]][ 'ip_human' ] } \" > " . $list_ip [ $ll [ 'authorised_ip_id' ]][ 'infos' ];
2013-01-28 10:01:09 +00:00
//echo "<br/>".$list_ip[$ll['authorised_ip_id']]['ip_human'];
echo " </span></td> " ;
2013-01-30 18:11:58 +00:00
echo " <td> " .@ $ac [ $ll [ 'protocol' ]][ 'name' ];
2013-01-28 10:01:09 +00:00
if ( isset ( $ac [ $ll [ 'protocol' ]][ 'values' ][ $ll [ 'parameters' ]]) && $ac [ $ll [ 'protocol' ]][ 'values' ][ $ll [ 'parameters' ]]) {
echo " " . _ ( " for " ) . " " . $ac [ $ll [ 'protocol' ]][ 'values' ][ $ll [ 'parameters' ]];
}
echo " </td> " ;
2013-04-25 12:39:24 +00:00
echo '<td><div class="ina delete"><a href="ip_main.php?delete_affected_id=' . urlencode ( $ll [ " id " ]) . '">' . _ ( " Delete " ) . '</a></div></td>' ;
2011-05-03 07:25:51 +00:00
echo " </tr> " ;
}
?>
</ table >
2012-04-06 10:10:36 +00:00
< hr />
< h3 >< ? php __ ( " Add a new rule " ); ?> </h3>
2013-02-05 08:27:11 +00:00
< ? php if ( empty ( $list_ip )) { ?>
< p >< ? php __ ( " You need to have some 'Known IP and networks' defined below to define a new rule. " ) ?> </p>
< ? php } else { ?>
2011-05-03 07:25:51 +00:00
< form method = " post " action = " ip_main.php " name = " main " id = " main " >
2016-05-20 12:21:47 +00:00
< ? php csrf_get (); ?>
2013-01-28 10:01:09 +00:00
< table class = " tlistb " >
2011-05-03 07:25:51 +00:00
< tbody >
< tr valign = " top " >
2013-01-28 10:01:09 +00:00
< th >< ? php __ ( " Access type " ); ?> </th>
< td class = " lst2 " >
2011-05-03 07:25:51 +00:00
< ? php foreach ( $ac as $a ) { ?>
< p >
2016-05-22 18:14:26 +00:00
< input type = " radio " name = " s_protocol " id = " s_protocol_<?php ehe( $a['protocol'] );?> " value = " <?php ehe( $a['protocol'] );?> " />
< label for = " s_protocol_<?php ehe( $a['protocol'] );?> " >< ? php ehe ( $a [ 'name' ]); ?> </label>
2011-06-03 17:08:44 +00:00
< ? php if ( sizeof ( $a [ 'values' ]) > 1 ) { ?>
2016-05-22 18:14:26 +00:00
< select name = " s_affect_<?php ehe( $a['protocol'] );?> " id = " s_affect_<?php ehe( $a['protocol'] );?> " >
2011-06-03 17:08:44 +00:00
< ? php foreach ( $a [ 'values' ] as $k => $v ) { ?>
2016-05-22 18:14:26 +00:00
< option value = " <?php ehe( $k ); ?> " >< ? php ehe ( $v ); ?> </option>
2011-06-03 17:08:44 +00:00
< ? php } ?>
</ select >
< ? php } else { ?>
2011-05-03 07:25:51 +00:00
< ? php foreach ( $a [ 'values' ] as $k => $v ) { ?>
2016-05-22 18:14:26 +00:00
< label >< b >< ? php ehe ( $v ); ?> </b></label>
< input type = " hidden " name = " s_affect_<?php ehe( $a['protocol'] );?> " id = " s_affect_<?php ehe( $a['protocol'] );?> " value = " <?php ehe( $k ); ?> " readonly = " readonly " />
2011-05-03 07:25:51 +00:00
< ? php } ?>
2011-06-03 17:08:44 +00:00
< ? php } ?>
2011-05-03 07:25:51 +00:00
</ p >
< ? php } ?>
2013-01-28 10:01:09 +00:00
</ td >
</ tr >
< tr >
< th >< ? php __ ( " Authorized IP address or network " ); ?> </th>
< td valign = " middle " class = " lst2 " >
2011-05-03 07:25:51 +00:00
< p >
< select name = " s_ipsub " >
2011-06-03 17:08:44 +00:00
< ? php foreach ( $list_ip as $li ) { ?>
2016-05-22 18:14:26 +00:00
< option value = " <?php echo $li['id'] ; ?> " >< ? php ehe ( $li [ 'infos' ]);
2013-01-28 10:01:09 +00:00
//echo " - ".$li['ip'] ; if (!($li['subnet']==32 || $li['subnet'] == 128)) echo "/".$li['subnet'];
?> </option>
2011-05-03 07:25:51 +00:00
< ? php } ?>
</ select >
</ p >
</ td >
2013-01-28 10:01:09 +00:00
</ tr >
< tr >
< th >& nbsp ; </ th >
2013-04-19 07:18:25 +00:00
< td valign = 'middle' class = " lst2 " >
2013-04-25 16:06:50 +00:00
< input type = " submit " class = " inb ok " value = " <?php __( " Save " )?> " onclick = 'return check_accesstype_selected();' />
2011-05-03 07:25:51 +00:00
</ td >
</ tr >
</ tbody >
</ table >
</ form >
2013-02-05 08:27:11 +00:00
< ? php } // empty $list_ip ?>
2013-01-28 10:01:09 +00:00
< br />
2012-04-06 10:10:36 +00:00
< hr />
2012-10-17 08:00:35 +00:00
< h3 >< ? php __ ( " Known IP and networks " ); ?> </h3>
2012-04-06 10:10:36 +00:00
< table class = " tlist " >
2013-04-19 07:18:25 +00:00
< tr >< th >< ? php __ ( " Name " ); ?> </th><th><?php __("IP or network"); ?></th><th><?php __("Type"); ?></th><th colspan='2'></th></tr>
2013-01-28 10:01:09 +00:00
< ? php
foreach ( $list_ip as $i ) {
if ( checkip ( $i [ 'ip' ])) {
if ( $i [ 'subnet' ] == 32 ) {
2014-03-20 09:35:11 +00:00
$txt = _ ( " Address IPv4 " );
2013-01-28 10:01:09 +00:00
} else {
2014-03-20 09:35:11 +00:00
$txt = _ ( " Subnet IPv4 " );
2013-01-28 10:01:09 +00:00
}
} elseif ( checkipv6 ( $i [ 'ip' ])) {
if ( $i [ 'subnet' ] == 128 ) {
2014-03-20 09:35:11 +00:00
$txt = _ ( " Address IPv6 " );
2013-01-28 10:01:09 +00:00
} else {
2014-03-20 09:35:11 +00:00
$txt = _ ( " Subnet IPv6 " );
2013-01-28 10:01:09 +00:00
}
2014-03-20 09:35:11 +00:00
} else {
$txt = _ ( " Error with this IP " );
}
2013-05-23 16:18:56 +00:00
echo " <tr class='lst' ><td> { $i [ 'infos' ] } </td><td> { $i [ 'ip_human' ] } </td><td> $txt </td> " ;
2013-01-28 10:01:09 +00:00
?>
2017-08-17 01:32:18 +00:00
< 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>
2013-04-25 12:39:24 +00:00
< td >< div class = " ina delete " >< a href = " ip_main.php?delete_id=<?php echo urlencode( $i["id"] ) ?> " >< ? php __ ( " Delete " ); ?> </a></div></td>
2011-04-27 15:44:19 +00:00
</ tr >
2013-01-28 10:01:09 +00:00
< ? php } ?>
2011-04-27 15:44:19 +00:00
</ table >
2013-01-28 10:01:09 +00:00
< br />
< hr />
< h3 >< ? php __ ( " Add an IP or a networks " ); ?> </h3>
2017-08-17 01:32:18 +00:00
< p >< a href = " javascript:edit_ip('','<?php ehe(get_remote_ip(). " ',' Home IP ' " );?>); " >< ? php echo __ ( " Add my current IP " ); ?> </a></p>
2013-01-28 10:01:09 +00:00
< span id = " form_add_ip " >
2013-04-19 07:18:25 +00:00
< form method = " post " action = " ip_main.php " name = " main " >
2016-05-20 12:21:47 +00:00
< ? php csrf_get (); ?>
2013-01-28 10:01:09 +00:00
< p id = " reset_edit_ip " style = " display:none; " >< a href = " javascript:reset_edit_ip(); " >< ? php __ ( " Cancel edit " ) ?> </a></p>
2013-04-19 07:18:25 +00:00
< input type = " hidden " name = " id " value = " " id = " edit_id " />
2013-01-28 10:01:09 +00:00
< table class = " tlistb " >
< tr >< th >< ? php __ ( " Name " ); ?> </th><th><?php __("IP or network. <i>IPv4, IPv6 and subnet allowed</i>"); ?></th><th></th></tr>
< tr class = " lst2 " >
2016-05-22 18:14:26 +00:00
< td >< input type = " text " size = " 20 " maxlength = " 39 " name = " ipsub " id = " edit_ip " /></ td >
< td >< input type = " text " size = " 25 " maxlength = " 200 " name = " infos " id = " edit_infos " /></ td >
2013-04-25 16:06:50 +00:00
< td >< input type = " submit " class = " inb ok " value = " <?php __( " Save " )?> " /></ td >
2013-01-28 10:01:09 +00:00
</ tr >
2013-04-19 07:18:25 +00:00
</ table >
2013-01-28 10:01:09 +00:00
</ form >
</ span >
2011-04-27 15:44:19 +00:00
< script type = " text/javascript " >
2011-05-03 07:25:51 +00:00
function reset_edit_ip () {
$ ( " #reset_edit_ip " ) . hide ();
$ ( " #edit_id " ) . val ( '' );
$ ( " #edit_ip " ) . val ( '' );
$ ( " #edit_infos " ) . val ( '' );
2011-04-27 15:44:19 +00:00
}
2011-05-03 07:25:51 +00:00
function edit_ip ( id , iph , infos ) {
if ( id != '' ) {
$ ( " #reset_edit_ip " ) . show ();
}
2011-04-27 15:44:19 +00:00
$ ( " #edit_id " ) . val ( id );
$ ( " #edit_infos " ) . val ( infos );
2011-05-03 07:25:51 +00:00
$ ( " #edit_ip " ) . val ( iph );
2011-04-27 15:44:19 +00:00
}
2013-01-28 10:05:08 +00:00
function check_accesstype_selected () {
if ( $ ( 'input[name=s_protocol]:radio:checked' ) . val () ) {
// there is a value
return true ;
}
alert ( " <?php __( " Please select an access type " ); ?> " );
return false ;
}
2011-04-27 15:44:19 +00:00
</ script >
< ? php include_once ( " foot.php " ); ?>