2023-06-15 15:26:38 +07:00
< ? php
2024-06-20 14:16:09 +07:00
2023-10-12 15:55:42 +07:00
/**
* PHP Mikrotik Billing ( https :// github . com / hotspotbilling / phpnuxbill / )
* by https :// t . me / ibnux
**/
2023-06-15 15:26:38 +07:00
/**
* used for ajax
**/
_auth ();
$action = $routes [ '1' ];
$user = User :: _info ();
switch ( $action ) {
case 'isLogin' :
2023-11-15 11:45:29 +07:00
$bill = ORM :: for_table ( 'tbl_user_recharges' ) -> where ( 'id' , $routes [ '2' ]) -> where ( 'username' , $user [ 'username' ]) -> findOne ();
2023-06-15 15:26:38 +07:00
if ( $bill [ 'type' ] == 'Hotspot' && $bill [ 'status' ] == 'on' ) {
2024-06-20 11:33:15 +07:00
$p = ORM :: for_table ( 'tbl_plans' ) -> find_one ( $bill [ 'plan_id' ]);
$dvc = Package :: getDevice ( $p );
2024-06-20 14:16:09 +07:00
if ( $_app_stage != 'demo' ) {
2024-08-15 15:33:44 +07:00
try {
2024-08-01 11:08:01 +07:00
if ( file_exists ( $dvc )) {
require_once $dvc ;
if (( new $p [ 'device' ]) -> online_customer ( $user , $bill [ 'routers' ])) {
2025-01-31 16:22:58 +07:00
die ( '<a href="' . getUrl ( 'home&mikrotik=logout&id=' . $bill [ 'id' ]) . '" onclick="return confirm(\'' . Lang :: T ( 'Disconnect Internet?' ) . '\')" class="btn btn-success btn-xs btn-block">' . Lang :: T ( 'You are Online, Logout?' ) . '</a>' );
2024-06-20 14:16:09 +07:00
} else {
2024-08-01 11:08:01 +07:00
if ( ! empty ( $_SESSION [ 'nux-mac' ]) && ! empty ( $_SESSION [ 'nux-ip' ])) {
2025-01-31 16:22:58 +07:00
die ( '<a href="' . getUrl ( 'home&mikrotik=login&id=' . $bill [ 'id' ]) . '" onclick="return confirm(\'' . Lang :: T ( 'Connect to Internet?' ) . '\')" class="btn btn-danger btn-xs btn-block">' . Lang :: T ( 'Not Online, Login now?' ) . '</a>' );
2024-08-01 11:08:01 +07:00
} else {
die ( Lang :: T ( '-' ));
}
2024-06-20 14:16:09 +07:00
}
2024-08-01 11:08:01 +07:00
} else {
die ( Lang :: T ( '-' ));
2024-06-07 17:21:29 +07:00
}
2024-08-15 15:33:44 +07:00
} catch ( Exception $e ) {
2024-08-01 11:08:01 +07:00
die ( Lang :: T ( 'Failed to connect to device' ));
2023-06-15 15:26:38 +07:00
}
}
2024-08-01 11:08:01 +07:00
die ( Lang :: T ( '-' ));
2023-06-15 15:26:38 +07:00
} else {
die ( '--' );
}
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-08-02 17:22:42 +07:00
case 'inbox_unread' :
$count = ORM :: for_table ( 'tbl_customers_inbox' ) -> where ( 'customer_id' , $user [ 'id' ]) -> whereRaw ( 'date_read is null' ) -> count ( 'id' );
2024-08-15 15:33:44 +07:00
if ( $count > 0 ) {
2024-08-02 17:22:42 +07:00
echo $count ;
}
die ();
case 'inbox' :
$inboxs = ORM :: for_table ( 'tbl_customers_inbox' ) -> selects ([ 'id' , 'subject' , 'date_created' ]) -> where ( 'customer_id' , $user [ 'id' ]) -> whereRaw ( 'date_read is null' ) -> order_by_desc ( 'date_created' ) -> limit ( 10 ) -> find_many ();
2024-08-15 15:33:44 +07:00
foreach ( $inboxs as $inbox ) {
2025-01-31 16:22:58 +07:00
echo '<li><a href="' . getUrl ( 'mail/view/' . $inbox [ 'id' ]) . '">' . $inbox [ 'subject' ] . '<br><sub class="text-muted">' . Lang :: dateTimeFormat ( $inbox [ 'date_created' ]) . '</sub></a></li>' ;
2024-08-15 15:33:44 +07:00
}
die ();
case 'language' :
$select = _get ( 'select' );
$folders = [];
$files = scandir ( 'system/lan/' );
foreach ( $files as $file ) {
if ( is_file ( 'system/lan/' . $file ) && ! in_array ( $file , [ 'index.html' , 'country.json' , '.DS_Store' ])) {
$file = str_replace ( " .json " , " " , $file );
if ( ! empty ( $file )){
2025-01-31 16:22:58 +07:00
echo '<li><a href="' . getUrl ( 'accounts/language-update-post&lang=' . $file ) . '">' ;
2024-08-15 15:33:44 +07:00
if ( $select == $file ){
echo '<span class="glyphicon glyphicon-ok"></span> ' ;
}
echo ucwords ( $file ) . '</a></li>' ;
}
}
2024-08-02 17:22:42 +07:00
}
die ();
2023-06-15 15:26:38 +07:00
default :
2025-02-04 17:22:11 +07:00
die ();
2023-06-15 15:26:38 +07:00
}