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
No known key found for this signature in database
GPG key ID: 7FC82848810579E5
6 changed files with 144 additions and 10 deletions

View file

@ -2,6 +2,15 @@
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
session_start();
require ('system/boot.php');
if(isset($_GET['nux-mac']) && !empty($_GET['nux-mac'])){
$_SESSION['nux-mac'] = $_GET['nux-mac'];
}
if(isset($_GET['nux-ip']) && !empty($_GET['nux-ip'])){
$_SESSION['nux-ip'] = $_GET['nux-ip'];
}
require_once 'system/vendor/autoload.php';
require_once 'system/boot.php';
App::_run();

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'])

View file

@ -41,7 +41,7 @@
<div class="box-header">
<h3 class="box-title">{$_L['Announcement']}</h3>
</div>
<div class="box-body" style="max-height:296px;overflow:scroll;">
<div class="box-body" style="max-height:296px;overflow:auto;">
{include file="$_path/../pages/Announcement.html"}
</div>
</div>
@ -56,6 +56,12 @@
<td class="small text-success text-uppercase text-normal">{$_L['Username']}</td>
<td class="small mb15">{$_bill['username']}</td>
</tr>
<tr>
<td class="small text-success text-uppercase text-normal">{$_L['Password']}</td>
<td class="small mb15"><input type="text" value="{$_user['password']}"
style="background-color: black; color:black; width:100%; border: 0px;"
onclick="this.select()"></td>
</tr>
<tr>
<td class="small text-primary text-uppercase text-normal">{$_L['Plan_Name']}</td>
<td class="small mb15">{$_bill['namebp']}</td>
@ -72,8 +78,41 @@
{if $_bill['time'] ne ''}{date($_c['date_format'], strtotime($_bill['expiration']))}
{$_bill['time']}{/if}&nbsp;</td>
</tr>
{if $_bill['type'] == 'Hotspot' && $_bill['status'] == 'on'}
{if $nux_ip}
<tr>
<td class="small text-primary text-uppercase text-normal">{Lang::T('Current IP')}</td>
<td class="small mb15">{$nux_ip}</td>
</tr>
{/if}
{if $nux_mac}
<tr>
<td class="small text-primary text-uppercase text-normal">{Lang::T('Current MAC')}</td>
<td class="small mb15">{$nux_mac}</td>
</tr>
{/if}
<tr>
<td class="small text-primary text-uppercase text-normal">{Lang::T('Login Status')}</td>
<td class="small mb15" id="login_status">
Loading....
</td>
</tr>
{/if}
</table>
</div>
{if $_bill['type'] == 'Hotspot' && $_bill['status'] == 'on'}
<script>
setTimeout(() => {
$.ajax({
url: "index.php?_route=autoload_user/isLogin",
cache: false,
success: function(msg) {
$("#login_status").html(msg);
}
});
}, 2000);
</script>
{/if}
<br>
<div class="box box-primary box-solid mb30">
<div class="box-header">