Add login Internet from User account

This commit is contained in:
Ibnu Maksum
2023-06-15 15:26:38 +07:00
parent a256e1eb42
commit c1c3ce08cd
6 changed files with 144 additions and 10 deletions

View File

@ -19,6 +19,38 @@ class Mikrotik
}
}
public static function isUserLogin($client, $username){
$printRequest = new RouterOS\Request(
'/ip hotspot active print',
RouterOS\Query::where('user', $username)
);
return $client->sendSync($printRequest)->getProperty('.id');
}
public static function logMeIn($client, $user, $pass, $ip, $mac){
$addRequest = new RouterOS\Request('/ip/hotspot/active/login');
$client->sendSync(
$addRequest
->setArgument('user', $user)
->setArgument('password', $pass)
->setArgument('ip', $ip)
->setArgument('mac-address', $mac)
);
}
public static function logMeOut($client, $user){
$printRequest = new RouterOS\Request(
'/ip hotspot active print',
RouterOS\Query::where('user', $user)
);
$id = $client->sendSync($printRequest)->getProperty('.id');
$removeRequest = new RouterOS\Request('/ip/hotspot/active/remove');
$client(
$removeRequest
->setArgument('numbers', $id)
);
}
public static function addHotspotPlan($client, $name, $sharedusers, $rate){
$addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add');
$client->sendSync(

View File

@ -1,17 +1,22 @@
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
Class User{
public static function _info(){
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
class User
{
public static function _info()
{
$id = $_SESSION['uid'];
$d = ORM::for_table('tbl_customers')->find_one($id);
return $d;
}
public static function _billing(){
public static function _billing()
{
$id = $_SESSION['uid'];
$d = ORM::for_table('tbl_user_recharges')->where('customer_id',$id)->find_one();
$d = ORM::for_table('tbl_user_recharges')->where('customer_id', $id)->find_one();
return $d;
}
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* used for ajax
**/
_auth();
$action = $routes['1'];
$user = User::_info();
$bill = User::_billing();
switch ($action) {
case 'isLogin':
if ($bill['type'] == 'Hotspot' && $bill['status'] == 'on') {
$m = Mikrotik::info($bill['routers']);
$client = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
if (Mikrotik::isUserLogin($client, $user['username'])) {
die('<a href="' . U . 'home&mikrotik=logout" onclick="return confirm(\''.Lang::T('Disconnect Internet?').'\')" class="btn btn-success btn-xs btn-block">'.Lang::T('You are Online, Logout?').'</a>');
} else {
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
die('<a href="' . U . 'home&mikrotik=login" onclick="return confirm(\''.Lang::T('Connect to Internet?').'\')" class="btn btn-danger btn-xs btn-block">'.Lang::T('Not Online, Login now?').'</a>');
}else{
die(Lang::T('Your account not connected to internet'));
}
}
} else {
die('--');
}
break;
default:
echo 'action not defined';
}

View File

@ -13,6 +13,21 @@ $ui->assign('_user', $user);
$bill = User::_billing();
$ui->assign('_bill', $bill);
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
$ui->assign('nux_mac', $_SESSION['nux-mac']);
$ui->assign('nux_ip', $_SESSION['nux-ip']);
if ($_GET['mikrotik'] == 'login') {
$m = Mikrotik::info($bill['routers']);
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::logMeIn($c, $user['username'], $user['password'], $_SESSION['nux-ip'], $_SESSION['nux-mac']);
r2(U . 'home', 's', Lang::T('Login Request successfully'));
}else if ($_GET['mikrotik'] == 'logout') {
$m = Mikrotik::info($bill['routers']);
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
Mikrotik::logMeOut($c, $user['username']);
r2(U . 'home', 's', Lang::T('Logout Request successfully'));
}
}
$ui->assign('unpaid', ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])