2010-01-20 16:55:27 +00:00
< ? php
/**
2010-01-25 10:06:34 +00:00
* This file is part of the Froxlor project .
2010-01-20 16:55:27 +00:00
* Copyright ( c ) 2003 - 2009 the SysCP Team ( see authors ) .
2010-01-25 10:06:34 +00:00
* Copyright ( c ) 2010 the Froxlor Team ( see authors ) .
2010-01-20 16:55:27 +00:00
*
* For the full copyright and license information , please view the COPYING
* file that was distributed with this source code . You can also view the
2010-01-25 10:06:34 +00:00
* COPYING file online at http :// files . froxlor . org / misc / COPYING . txt
2010-01-20 16:55:27 +00:00
*
* @ copyright ( c ) the authors
2010-01-25 10:06:34 +00:00
* @ author Florian Lippert < flo @ syscp . org > ( 2003 - 2009 )
* @ author Froxlor team < team @ froxlor . org > ( 2010 - )
* @ license GPLv2 http :// files . froxlor . org / misc / COPYING . txt
2010-01-20 16:55:27 +00:00
* @ package Panel
2011-05-04 09:59:20 +00:00
*
2010-01-20 16:55:27 +00:00
*/
define ( 'AREA' , 'admin' );
2013-11-18 11:53:33 +00:00
require './lib/init.php' ;
2010-01-20 16:55:27 +00:00
2018-12-19 15:57:03 +00:00
use Froxlor\Database\Database ;
use Froxlor\Settings ;
2018-12-18 12:45:05 +00:00
use Froxlor\Api\Commands\IpsAndPorts as IpsAndPorts ;
2013-10-31 07:01:50 +00:00
if ( isset ( $_POST [ 'id' ])) {
2010-01-20 16:55:27 +00:00
$id = intval ( $_POST [ 'id' ]);
2018-02-15 06:48:03 +00:00
} elseif ( isset ( $_GET [ 'id' ])) {
2010-01-20 16:55:27 +00:00
$id = intval ( $_GET [ 'id' ]);
}
2018-02-15 06:48:03 +00:00
if ( $page == 'ipsandports' || $page == 'overview' ) {
2016-02-15 21:37:46 +00:00
// Do not display attributes that are not used by the current webserver
$websrv = Settings :: Get ( 'system.webserver' );
$is_nginx = ( $websrv == 'nginx' );
$is_apache = ( $websrv == 'apache2' );
2016-09-24 19:58:20 +00:00
$is_apache24 = $is_apache && ( Settings :: Get ( 'system.apache24' ) === '1' );
2018-12-21 11:24:07 +00:00
2013-10-31 07:01:50 +00:00
if ( $action == '' ) {
2018-12-21 11:24:07 +00:00
2010-01-20 16:55:27 +00:00
$log -> logAction ( ADM_ACTION , LOG_NOTICE , " viewed admin_ipsandports " );
$fields = array (
2018-12-22 07:15:31 +00:00
'ip' => $lng [ 'admin' ][ 'ipsandports' ][ 'ip' ],
'port' => $lng [ 'admin' ][ 'ipsandports' ][ 'port' ]
2010-01-20 16:55:27 +00:00
);
2018-12-21 19:31:17 +00:00
$paging = new \Froxlor\UI\Paging ( \Froxlor\User :: getAll (), TABLE_PANEL_IPSANDPORTS , $fields );
2010-01-20 16:55:27 +00:00
$ipsandports = '' ;
2013-10-31 07:01:50 +00:00
$result_stmt = Database :: prepare ( " SELECT * FROM ` " . TABLE_PANEL_IPSANDPORTS . " ` " . $paging -> getSqlWhere ( false ) . " " . $paging -> getSqlOrderBy () . " " . $paging -> getSqlLimit ());
Database :: pexecute ( $result_stmt );
$paging -> setEntries ( Database :: num_rows ());
2010-01-20 16:55:27 +00:00
$sortcode = $paging -> getHtmlSortCode ( $lng );
$arrowcode = $paging -> getHtmlArrowCode ( $filename . '?page=' . $page . '&s=' . $s );
$searchcode = $paging -> getHtmlSearchCode ( $lng );
$pagingcode = $paging -> getHtmlPagingCode ( $filename . '?page=' . $page . '&s=' . $s );
$i = 0 ;
$count = 0 ;
2018-12-21 11:24:07 +00:00
2013-10-31 07:01:50 +00:00
while ( $row = $result_stmt -> fetch ( PDO :: FETCH_ASSOC )) {
2018-12-21 11:24:07 +00:00
2013-10-31 07:01:50 +00:00
if ( $paging -> checkDisplay ( $i )) {
2018-12-21 16:41:22 +00:00
$row = \Froxlor\PhpHelper :: htmlentities_array ( $row );
2013-10-31 07:01:50 +00:00
if ( filter_var ( $row [ 'ip' ], FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 )) {
2010-01-20 16:55:27 +00:00
$row [ 'ip' ] = '[' . $row [ 'ip' ] . ']' ;
}
2018-12-21 10:22:03 +00:00
eval ( " \$ ipsandports.= \" " . \Froxlor\UI\Template :: getTemplate ( " ipsandports/ipsandports_ipandport " ) . " \" ; " );
2018-02-15 06:48:03 +00:00
$count ++ ;
2010-01-20 16:55:27 +00:00
}
2018-02-15 06:48:03 +00:00
$i ++ ;
2010-01-20 16:55:27 +00:00
}
2018-12-21 10:22:03 +00:00
eval ( " echo \" " . \Froxlor\UI\Template :: getTemplate ( " ipsandports/ipsandports " ) . " \" ; " );
2018-02-15 06:48:03 +00:00
} elseif ( $action == 'delete' && $id != 0 ) {
try {
2018-12-21 19:31:17 +00:00
$json_result = IpsAndPorts :: getLocal ( \Froxlor\User :: getAll (), array (
2018-02-15 06:48:03 +00:00
'id' => $id
)) -> get ();
} catch ( Exception $e ) {
2018-12-21 10:22:03 +00:00
\Froxlor\UI\Response :: dynamic_error ( $e -> getMessage ());
2018-02-15 06:48:03 +00:00
}
$result = json_decode ( $json_result , true )[ 'data' ];
2018-12-21 11:24:07 +00:00
2018-02-15 06:48:03 +00:00
if ( isset ( $result [ 'id' ]) && $result [ 'id' ] == $id ) {
if ( isset ( $_POST [ 'send' ]) && $_POST [ 'send' ] == 'send' ) {
2018-12-21 11:24:07 +00:00
2018-02-15 06:48:03 +00:00
try {
2018-12-21 19:31:17 +00:00
IpsAndPorts :: getLocal ( \Froxlor\User :: getAll (), array (
2018-02-15 06:48:03 +00:00
'id' => $id
)) -> delete ();
} catch ( Exception $e ) {
2018-12-21 10:22:03 +00:00
\Froxlor\UI\Response :: dynamic_error ( $e -> getMessage ());
2010-01-20 16:55:27 +00:00
}
2018-12-21 11:24:07 +00:00
2018-12-21 10:22:03 +00:00
\Froxlor\UI\Response :: redirectTo ( $filename , array (
2018-02-15 06:48:03 +00:00
'page' => $page ,
's' => $s
));
2013-10-31 07:01:50 +00:00
} else {
2018-12-21 17:31:06 +00:00
\Froxlor\UI\HTML :: ask_yesno ( 'admin_ip_reallydelete' , $filename , array (
2018-02-15 06:48:03 +00:00
'id' => $id ,
'page' => $page ,
'action' => $action
), $result [ 'ip' ] . ':' . $result [ 'port' ]);
2010-01-20 16:55:27 +00:00
}
}
2018-02-15 06:48:03 +00:00
} elseif ( $action == 'add' ) {
if ( isset ( $_POST [ 'send' ]) && $_POST [ 'send' ] == 'send' ) {
try {
2018-12-21 19:31:17 +00:00
IpsAndPorts :: getLocal ( \Froxlor\User :: getAll (), $_POST ) -> add ();
2018-02-15 06:48:03 +00:00
} catch ( Exception $e ) {
2018-12-21 10:22:03 +00:00
\Froxlor\UI\Response :: dynamic_error ( $e -> getMessage ());
2010-01-20 16:55:27 +00:00
}
2018-12-21 10:22:03 +00:00
\Froxlor\UI\Response :: redirectTo ( $filename , array (
2018-02-15 06:48:03 +00:00
'page' => $page ,
's' => $s
));
2013-10-31 07:01:50 +00:00
} else {
2018-12-21 11:24:07 +00:00
2018-02-15 06:48:03 +00:00
$ipsandports_add_data = include_once dirname ( __FILE__ ) . '/lib/formfields/admin/ipsandports/formfield.ipsandports_add.php' ;
2018-12-21 10:22:03 +00:00
$ipsandports_add_form = \Froxlor\UI\HtmlForm :: genHTMLForm ( $ipsandports_add_data );
2018-12-21 11:24:07 +00:00
2015-06-10 12:59:38 +00:00
$title = $ipsandports_add_data [ 'ipsandports_add' ][ 'title' ];
$image = $ipsandports_add_data [ 'ipsandports_add' ][ 'image' ];
2018-12-21 11:24:07 +00:00
2018-12-21 10:22:03 +00:00
eval ( " echo \" " . \Froxlor\UI\Template :: getTemplate ( " ipsandports/ipsandports_add " ) . " \" ; " );
2010-01-20 16:55:27 +00:00
}
2018-02-15 06:48:03 +00:00
} elseif ( $action == 'edit' && $id != 0 ) {
try {
2018-12-21 19:31:17 +00:00
$json_result = IpsAndPorts :: getLocal ( \Froxlor\User :: getAll (), array (
2018-02-15 06:48:03 +00:00
'id' => $id
)) -> get ();
} catch ( Exception $e ) {
2018-12-21 10:22:03 +00:00
\Froxlor\UI\Response :: dynamic_error ( $e -> getMessage ());
2018-02-15 06:48:03 +00:00
}
$result = json_decode ( $json_result , true )[ 'data' ];
2018-12-21 11:24:07 +00:00
2013-10-31 07:01:50 +00:00
if ( $result [ 'ip' ] != '' ) {
2018-12-21 11:24:07 +00:00
2018-02-15 06:48:03 +00:00
if ( isset ( $_POST [ 'send' ]) && $_POST [ 'send' ] == 'send' ) {
try {
2018-12-21 19:31:17 +00:00
IpsAndPorts :: getLocal ( \Froxlor\User :: getAll (), $_POST ) -> update ();
2018-02-15 06:48:03 +00:00
} catch ( Exception $e ) {
2018-12-21 10:22:03 +00:00
\Froxlor\UI\Response :: dynamic_error ( $e -> getMessage ());
2018-12-21 11:24:07 +00:00
}
2018-12-21 10:22:03 +00:00
\Froxlor\UI\Response :: redirectTo ( $filename , array (
2018-02-15 06:48:03 +00:00
'page' => $page ,
's' => $s
));
2013-10-31 07:01:50 +00:00
} else {
2018-12-21 11:24:07 +00:00
2018-12-21 16:41:22 +00:00
$result = \Froxlor\PhpHelper :: htmlentities_array ( $result );
2018-12-21 11:24:07 +00:00
2018-02-15 06:48:03 +00:00
$ipsandports_edit_data = include_once dirname ( __FILE__ ) . '/lib/formfields/admin/ipsandports/formfield.ipsandports_edit.php' ;
2018-12-21 10:22:03 +00:00
$ipsandports_edit_form = \Froxlor\UI\HtmlForm :: genHTMLForm ( $ipsandports_edit_data );
2018-12-21 11:24:07 +00:00
2015-06-10 12:59:38 +00:00
$title = $ipsandports_edit_data [ 'ipsandports_edit' ][ 'title' ];
$image = $ipsandports_edit_data [ 'ipsandports_edit' ][ 'image' ];
2018-12-21 11:24:07 +00:00
2018-12-21 10:22:03 +00:00
eval ( " echo \" " . \Froxlor\UI\Template :: getTemplate ( " ipsandports/ipsandports_edit " ) . " \" ; " );
2010-01-20 16:55:27 +00:00
}
}
}
}