diff --git a/index.php b/index.php index 8686af78..d1eac444 100644 --- a/index.php +++ b/index.php @@ -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(); diff --git a/system/autoload/Mikrotik.php b/system/autoload/Mikrotik.php index a5c4e346..0b98ecd4 100644 --- a/system/autoload/Mikrotik.php +++ b/system/autoload/Mikrotik.php @@ -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( diff --git a/system/autoload/User.php b/system/autoload/User.php index 68ebbf55..d3917b60 100644 --- a/system/autoload/User.php +++ b/system/autoload/User.php @@ -1,17 +1,22 @@ 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; } -} \ No newline at end of file +} diff --git a/system/controllers/autoload_user.php b/system/controllers/autoload_user.php new file mode 100644 index 00000000..4a02eca6 --- /dev/null +++ b/system/controllers/autoload_user.php @@ -0,0 +1,34 @@ +'.Lang::T('You are Online, Logout?').''); + } else { + if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) { + die(''.Lang::T('Not Online, Login now?').''); + }else{ + die(Lang::T('Your account not connected to internet')); + } + } + } else { + die('--'); + } + break; + default: + echo 'action not defined'; +} diff --git a/system/controllers/home.php b/system/controllers/home.php index edb65fee..89109404 100644 --- a/system/controllers/home.php +++ b/system/controllers/home.php @@ -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']) diff --git a/ui/ui/user-dashboard.tpl b/ui/ui/user-dashboard.tpl index 561c6cf4..37a05b20 100644 --- a/ui/ui/user-dashboard.tpl +++ b/ui/ui/user-dashboard.tpl @@ -41,7 +41,7 @@