2017-03-11 02:51:06 +07:00
< ? php
2024-08-21 17:05:46 +07:00
2023-10-12 15:55:42 +07:00
/**
* PHP Mikrotik Billing ( https :// github . com / hotspotbilling / phpnuxbill / )
* by https :// t . me / ibnux
**/
2023-08-23 12:11:07 +07:00
2017-03-11 02:51:06 +07:00
/**
2023-08-23 12:11:07 +07:00
* used for ajax
**/
2022-09-18 00:00:40 +07:00
2017-03-11 02:51:06 +07:00
_admin ();
2024-02-13 13:54:01 +07:00
$ui -> assign ( '_title' , Lang :: T ( 'Network' ));
2017-03-11 02:51:06 +07:00
$ui -> assign ( '_system_menu' , 'network' );
$action = $routes [ '1' ];
$ui -> assign ( '_admin' , $admin );
switch ( $action ) {
case 'pool' :
2023-08-23 12:11:07 +07:00
$routers = _get ( 'routers' );
2024-08-21 17:05:46 +07:00
if ( empty ( $routers )) {
2023-10-04 11:25:58 +07:00
$d = ORM :: for_table ( 'tbl_pool' ) -> find_many ();
2024-08-21 17:05:46 +07:00
} else {
2023-10-04 11:25:58 +07:00
$d = ORM :: for_table ( 'tbl_pool' ) -> where ( 'routers' , $routers ) -> find_many ();
}
$ui -> assign ( 'routers' , $routers );
2023-08-23 12:11:07 +07:00
$ui -> assign ( 'd' , $d );
2025-02-04 10:22:14 +07:00
$ui -> display ( 'admin/autoload/pool.tpl' );
2017-03-11 02:51:06 +07:00
break ;
2024-09-25 15:00:13 +07:00
case 'bw_name' :
$bw = ORM :: for_table ( 'tbl_bandwidth' ) -> select ( " name_bw " ) -> find_one ( $routes [ '2' ]);
echo $bw [ 'name_bw' ];
die ();
2024-10-23 14:04:11 +07:00
case 'balance' :
$balance = ORM :: for_table ( 'tbl_customers' ) -> select ( " balance " ) -> find_one ( $routes [ '2' ])[ 'balance' ];
2024-12-21 11:16:29 +01:00
if ( $routes [ '3' ] == '1' ) {
2024-10-23 14:04:11 +07:00
echo Lang :: moneyFormat ( $balance );
2024-12-21 11:16:29 +01:00
} else {
2024-10-23 14:04:11 +07:00
echo $balance ;
}
die ();
2017-03-11 02:51:06 +07:00
case 'server' :
2023-08-23 12:11:07 +07:00
$d = ORM :: for_table ( 'tbl_routers' ) -> where ( 'enabled' , '1' ) -> find_many ();
$ui -> assign ( 'd' , $d );
2022-09-01 14:52:32 +07:00
2025-02-04 10:22:14 +07:00
$ui -> display ( 'admin/autoload/server.tpl' );
2017-03-11 02:51:06 +07:00
break ;
2024-08-21 17:05:46 +07:00
case 'pppoe_ip_used' :
if ( ! empty ( _get ( 'ip' ))) {
$cs = ORM :: for_table ( 'tbl_customers' )
-> select ( " username " )
-> where_not_equal ( 'id' , _get ( 'id' ))
-> where ( " pppoe_ip " , _get ( 'ip' ))
-> findArray ();
if ( count ( $cs ) > 0 ) {
$c = array_column ( $cs , 'username' );
die ( Lang :: T ( " IP has been used by " ) . ' : ' . implode ( " , " , $c ));
}
}
die ();
case 'pppoe_username_used' :
if ( ! empty ( _get ( 'u' ))) {
$cs = ORM :: for_table ( 'tbl_customers' )
-> select ( " username " )
-> where_not_equal ( 'id' , _get ( 'id' ))
-> where ( " pppoe_username " , _get ( 'u' ))
-> findArray ();
if ( count ( $cs ) > 0 ) {
$c = array_column ( $cs , 'username' );
die ( Lang :: T ( " Username has been used by " ) . ' : ' . implode ( " , " , $c ));
}
}
die ();
2017-03-11 02:51:06 +07:00
case 'plan' :
2023-08-23 12:11:07 +07:00
$server = _post ( 'server' );
$jenis = _post ( 'jenis' );
2024-08-21 17:05:46 +07:00
if ( in_array ( $admin [ 'user_type' ], array ( 'SuperAdmin' , 'Admin' ))) {
2024-12-21 11:16:29 +01:00
switch ( $server ) {
case 'radius' :
$d = ORM :: for_table ( 'tbl_plans' ) -> where ( 'is_radius' , 1 ) -> where ( 'type' , $jenis ) -> find_many ();
break ;
case '' :
break ;
default :
$d = ORM :: for_table ( 'tbl_plans' ) -> where ( 'routers' , $server ) -> where ( 'type' , $jenis ) -> find_many ();
break ;
2024-03-12 13:58:42 +07:00
}
2024-08-21 17:05:46 +07:00
} else {
2024-12-21 11:16:29 +01:00
switch ( $server ) {
case 'radius' :
$d = ORM :: for_table ( 'tbl_plans' ) -> where ( 'is_radius' , 1 ) -> where ( 'type' , $jenis ) -> find_many ();
break ;
case '' :
break ;
default :
$d = ORM :: for_table ( 'tbl_plans' ) -> where ( 'routers' , $server ) -> where ( 'type' , $jenis ) -> find_many ();
break ;
2024-03-12 13:58:42 +07:00
}
2023-10-04 15:51:51 +07:00
}
2023-08-23 12:11:07 +07:00
$ui -> assign ( 'd' , $d );
2022-09-01 14:52:32 +07:00
2025-02-04 10:22:14 +07:00
$ui -> display ( 'admin/autoload/plan.tpl' );
2017-03-11 02:51:06 +07:00
break ;
2023-09-07 10:54:20 +07:00
case 'customer_is_active' :
2024-10-11 11:37:45 +07:00
if ( $config [ 'check_customer_online' ] == 'yes' ) {
$c = ORM :: for_table ( 'tbl_customers' ) -> where ( 'username' , $routes [ '2' ]) -> find_one ();
$p = ORM :: for_table ( 'tbl_plans' ) -> find_one ( $routes [ '3' ]);
$dvc = Package :: getDevice ( $p );
2024-12-21 11:16:29 +01:00
if ( $_app_stage != 'Demo' ) {
2024-10-11 11:37:45 +07:00
if ( file_exists ( $dvc )) {
require_once $dvc ;
try {
//don't wait more than 5 seconds for response from device, otherwise we get timeout error.
ini_set ( 'default_socket_timeout' , 5 );
if (( new $p [ 'device' ]) -> online_customer ( $c , $p [ 'routers' ])) {
2025-01-07 16:41:52 +07:00
echo '<span style="color: green;" title="online">•</span>' ;
} else {
echo '<span style="color: yellow;" title="offline">•</span>' ;
2024-10-11 11:37:45 +07:00
}
} catch ( Exception $e ) {
2025-01-07 16:41:52 +07:00
echo '<span style="color: red;" title="' . $e -> getMessage () . '">•</span>' ;
2024-10-07 14:50:11 +07:00
}
}
}
}
break ;
case 'plan_is_active' :
$ds = ORM :: for_table ( 'tbl_user_recharges' ) -> where ( 'customer_id' , $routes [ '2' ]) -> find_array ();
if ( $ds ) {
$ps = [];
$c = ORM :: for_table ( 'tbl_customers' ) -> find_one ( $routes [ '2' ]);
foreach ( $ds as $d ) {
if ( $d [ 'status' ] == 'on' ) {
2024-10-11 11:37:45 +07:00
if ( $config [ 'check_customer_online' ] == 'yes' ) {
$p = ORM :: for_table ( 'tbl_plans' ) -> find_one ( $d [ 'plan_id' ]);
$dvc = Package :: getDevice ( $p );
$status = " " ;
2024-12-21 11:16:29 +01:00
if ( $_app_stage != 'Demo' ) {
2024-10-11 11:37:45 +07:00
if ( file_exists ( $dvc )) {
require_once $dvc ;
try {
//don't wait more than 5 seconds for response from device, otherwise we get timeout error.
ini_set ( 'default_socket_timeout' , 5 );
if (( new $p [ 'device' ]) -> online_customer ( $c , $p [ 'routers' ])) {
2025-01-07 16:41:52 +07:00
$status = '<span style="color: green;" title="online">•</span>' ;
} else {
$status = '<span style="color: yellow;" title="offline">•</span>' ;
2024-10-11 11:37:45 +07:00
}
} catch ( Exception $e ) {
2025-01-07 16:41:52 +07:00
$status = '<span style="color: red;" title="' . $e -> getMessage () . '">•</span>' ;
2024-10-07 14:50:11 +07:00
}
}
}
}
$ps [] = ( '<span class="label label-primary m-1" title="Expired ' . Lang :: dateAndTimeFormat ( $d [ 'expiration' ], $d [ 'time' ]) . '">' . $d [ 'namebp' ] . ' ' . $status . '</span>' );
} else {
$ps [] = ( '<span class="label label-danger m-1" title="Expired ' . Lang :: dateAndTimeFormat ( $d [ 'expiration' ], $d [ 'time' ]) . '">' . $d [ 'namebp' ] . '</span>' );
}
2023-09-07 10:54:20 +07:00
}
2024-10-07 14:50:11 +07:00
echo implode ( " <br> " , $ps );
2023-09-07 10:54:20 +07:00
} else {
2024-10-07 14:50:11 +07:00
die ( '' );
2023-09-07 10:54:20 +07:00
}
2023-09-13 15:50:12 +07:00
break ;
2023-08-23 12:11:07 +07:00
case 'customer_select2' :
$s = addslashes ( _get ( 's' ));
if ( empty ( $s )) {
$c = ORM :: for_table ( 'tbl_customers' ) -> limit ( 30 ) -> find_many ();
} else {
2023-12-19 09:55:55 +07:00
$c = ORM :: for_table ( 'tbl_customers' ) -> where_raw ( " (`username` LIKE '% $s %' OR `fullname` LIKE '% $s %' OR `phonenumber` LIKE '% $s %' OR `email` LIKE '% $s %') " ) -> limit ( 30 ) -> find_many ();
2023-08-23 12:11:07 +07:00
}
header ( 'Content-Type: application/json' );
2023-08-23 15:00:34 +07:00
foreach ( $c as $cust ) {
2023-08-23 12:11:07 +07:00
$json [] = [
'id' => $cust [ 'id' ],
2023-08-23 15:00:34 +07:00
'text' => $cust [ 'username' ] . ' - ' . $cust [ 'fullname' ] . ' - ' . $cust [ 'email' ]
2023-08-23 12:11:07 +07:00
];
}
2023-08-23 15:00:34 +07:00
echo json_encode ([ 'results' => $json ]);
2023-08-23 12:11:07 +07:00
die ();
2017-03-11 02:51:06 +07:00
default :
2025-02-04 09:23:55 +07:00
$ui -> display ( 'admin/404.tpl' );
2023-08-23 12:11:07 +07:00
}