forked from kevinowino869/mitrobill
Change to devices
This commit is contained in:
@ -41,22 +41,14 @@ switch ($action) {
|
||||
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username', $user['username'])->find_one();
|
||||
if ($c) {
|
||||
// if has active plan, change the password to devices
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $c['plan_id'])->find_one();
|
||||
if ($p['is_radius']) {
|
||||
if ($c['type'] == 'Hotspot' || ($c['type'] == 'PPPOE' && empty($d['pppoe_password']))) {
|
||||
Radius::customerUpsert($d, $p);
|
||||
}
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($c, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($c['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($c['type'] == 'Hotspot') {
|
||||
Mikrotik::setHotspotUser($client, $c['username'], $npass);
|
||||
Mikrotik::removeHotspotActiveUser($client, $user['username']);
|
||||
} else if (empty($d['pppoe_password'])) {
|
||||
// only change when pppoe_password empty
|
||||
Mikrotik::setPpoeUser($client, $c['username'], $npass);
|
||||
Mikrotik::removePpoeActive($client, $user['username']);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
$d->password = $npass;
|
||||
|
@ -212,18 +212,13 @@ switch ($action) {
|
||||
if ($b) {
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $b['plan_id'])->find_one();
|
||||
if ($p) {
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDeactivate($b['username']);
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $c['plan_id'])->find_one();
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->change_customer($c, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($b['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($b['type'] == 'Hotspot') {
|
||||
Mikrotik::removeHotspotUser($client, $b['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $b['username']);
|
||||
} else if ($b['type'] == 'PPPOE') {
|
||||
Mikrotik::removePpoeUser($client, $b['username']);
|
||||
Mikrotik::removePpoeActive($client, $b['username']);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$b->status = 'off';
|
||||
$b->expiration = date('Y-m-d');
|
||||
@ -246,16 +241,12 @@ switch ($action) {
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $b['plan_id'])->where('enabled', '1')->find_one();
|
||||
if ($p) {
|
||||
$routers[] = $b['routers'];
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerAddPlan($c, $p, $p['expiration'] . ' ' . $p['time']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($c, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($b['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($b['type'] == 'Hotspot') {
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
} else if ($b['type'] == 'PPPOE') {
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -337,43 +328,25 @@ switch ($action) {
|
||||
$c = ORM::for_table('tbl_user_recharges')->where('username', $d['username'])->find_one();
|
||||
if ($c) {
|
||||
$p = ORM::for_table('tbl_plans')->find_one($c['plan_id']);
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDelete($d['username']);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($c['routers']);
|
||||
if ($c['type'] == 'Hotspot') {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $d['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $d['username']);
|
||||
if($p){
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($d, $p);
|
||||
} else {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePpoeUser($client, $d['username']);
|
||||
Mikrotik::removePpoeActive($client, $d['username']);
|
||||
}
|
||||
try {
|
||||
$d->delete();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
try {
|
||||
$c->delete();
|
||||
} catch (Exception $e) {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$d->delete();
|
||||
$c->delete();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
try {
|
||||
if ($c)
|
||||
$c->delete();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$d->delete();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
r2(U . 'customers/list', 's', Lang::T('User deleted Successfully'));
|
||||
}
|
||||
break;
|
||||
@ -595,26 +568,13 @@ switch ($action) {
|
||||
$c->username = $username;
|
||||
$c->save();
|
||||
$p = ORM::for_table('tbl_plans')->find_one($c['plan_id']);
|
||||
if ($p['is_radius']) {
|
||||
if ($userDiff) {
|
||||
Radius::customerChangeUsername($oldusername, $username);
|
||||
}
|
||||
Radius::customerAddPlan($d, $p, $p['expiration'] . ' ' . $p['time']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($d, $p);
|
||||
new $p['device']->add_customer($d, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($c['routers']);
|
||||
if ($c['type'] == 'Hotspot') {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setHotspotUser($client, $c['username'], $password);
|
||||
Mikrotik::removeHotspotActiveUser($client, $d['username']);
|
||||
} else {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if (!empty($d['pppoe_password'])) {
|
||||
Mikrotik::setPpoeUser($client, $c['username'], $d['pppoe_password']);
|
||||
} else {
|
||||
Mikrotik::setPpoeUser($client, $c['username'], $password);
|
||||
}
|
||||
Mikrotik::removePpoeActive($client, $d['username']);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,26 +154,15 @@ if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
|
||||
}
|
||||
}
|
||||
if ($tur['status'] != 'on') {
|
||||
if ($tur['routers'] != 'radius') {
|
||||
$mikrotik = Mikrotik::info($tur['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $tur['routers'];
|
||||
}
|
||||
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
|
||||
if (!$p) {
|
||||
r2(U . 'home', '3', "Plan Not Found");
|
||||
}
|
||||
if ($tur['routers'] == 'radius') {
|
||||
Radius::customerAddPlan($user, $p, $tur['expiration'] . ' ' . $tur['time']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($user, $p);
|
||||
} else {
|
||||
if ($tur['type'] == 'Hotspot') {
|
||||
Mikrotik::removeHotspotUser($client, $user['username']);
|
||||
Mikrotik::addHotspotUser($client, $p, $user);
|
||||
} else if ($tur['type'] == 'PPPOE') {
|
||||
Mikrotik::removePpoeUser($client, $user['username']);
|
||||
Mikrotik::addPpoeUser($client, $p, $user);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
// make customer cannot extend again
|
||||
$days = $config['extend_days'];
|
||||
$expiration = date('Y-m-d', strtotime(" +$days day"));
|
||||
@ -198,22 +187,12 @@ if (isset($_GET['recharge']) && !empty($_GET['recharge'])) {
|
||||
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['deactivate'])->where('username', $user['username'])->findOne();
|
||||
if ($bill) {
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDeactivate($user['username']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($user, $p);
|
||||
} else {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($bill['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
if ($bill['type'] == 'Hotspot') {
|
||||
Mikrotik::removeHotspotUser($client, $bill['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $bill['username']);
|
||||
} else if ($bill['type'] == 'PPPOE') {
|
||||
Mikrotik::removePpoeUser($client, $bill['username']);
|
||||
Mikrotik::removePpoeActive($client, $bill['username']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
//ignore it maybe mikrotik has been deleted
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$bill->status = 'off';
|
||||
$bill->expiration = date('Y-m-d');
|
||||
@ -231,16 +210,19 @@ if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
|
||||
$ui->assign('nux_mac', $_SESSION['nux-mac']);
|
||||
$ui->assign('nux_ip', $_SESSION['nux-ip']);
|
||||
$bill = ORM::for_table('tbl_user_recharges')->where('id', $_GET['id'])->where('username', $user['username'])->findOne();
|
||||
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'));
|
||||
$p = ORM::for_table('tbl_plans')->where('id', $bill['plan_id'])->find_one();
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
if ($_GET['mikrotik'] == 'login') {
|
||||
new $p['device']->connect_customer($user, $_SESSION['nux-ip'], $_SESSION['nux-mac'], $bill['routers']);
|
||||
r2(U . 'home', 's', Lang::T('Login Request successfully'));
|
||||
} else if ($_GET['mikrotik'] == 'logout') {
|
||||
new $p['device']->disconnect_customer($user, $bill['routers']);
|
||||
r2(U . 'home', 's', Lang::T('Logout Request successfully'));
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,21 +41,14 @@ switch ($action) {
|
||||
$log = '';
|
||||
$router = '';
|
||||
foreach ($plans as $plan) {
|
||||
if ($router != $plan['routers'] && $plan['routers'] != 'radius') {
|
||||
$mikrotik = Mikrotik::info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $plan['routers'];
|
||||
}
|
||||
$p = ORM::for_table('tbl_plans')->findOne($plan['plan_id']);
|
||||
$c = ORM::for_table('tbl_customers')->findOne($plan['customer_id']);
|
||||
if ($plan['routers'] == 'radius') {
|
||||
Radius::customerAddPlan($c, $p, $plan['expiration'] . ' ' . $plan['time']);
|
||||
$dvc = Package::getDevice($plan);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($c, $p);
|
||||
} else {
|
||||
if ($plan['type'] == 'Hotspot') {
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
} else if ($plan['type'] == 'PPPOE') {
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$log .= "DONE : $plan[username], $plan[namebp], $plan[type], $plan[routers]<br>";
|
||||
}
|
||||
@ -265,19 +258,11 @@ switch ($action) {
|
||||
if ($d) {
|
||||
run_hook('delete_customer_active_plan'); #HOOK
|
||||
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
|
||||
if ($p['is_radius']) {
|
||||
Radius::customerDeactivate($d['username']);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_customer($c, $p);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
if ($d['type'] == 'Hotspot') {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $d['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $d['username']);
|
||||
} else {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePpoeUser($client, $d['username']);
|
||||
Mikrotik::removePpoeActive($client, $d['username']);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$d->delete();
|
||||
_log('[' . $admin['username'] . ']: ' . 'Delete Plan for Customer ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']);
|
||||
@ -786,25 +771,14 @@ switch ($action) {
|
||||
$tur->status = "on";
|
||||
$tur->save();
|
||||
App::setToken($stoken, $id);
|
||||
if ($tur['routers'] != 'radius') {
|
||||
$mikrotik = Mikrotik::info($tur['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $tur['routers'];
|
||||
}
|
||||
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
|
||||
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
|
||||
if ($tur['routers'] == 'radius') {
|
||||
Radius::customerAddPlan($c, $p, $tur['expiration'] . ' ' . $tur['time']);
|
||||
$p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
|
||||
$dvc = Package::getDevice($p);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_customer($c, $p);
|
||||
} else {
|
||||
if ($tur['type'] == 'Hotspot') {
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removeHotspotActiveUser($client, $c['username']);
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
} else if ($tur['type'] == 'PPPOE') {
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
Mikrotik::removePpoeActive($client, $c['username']);
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
_log("$admin[fullname] extend Customer $tur[customer_id] $tur[username] for $days days", $admin['user_type'], $admin['id']);
|
||||
r2(U . 'plan', 's', "Extend until $expiration");
|
||||
|
@ -13,9 +13,10 @@ $action = $routes['1'];
|
||||
$ui->assign('_admin', $admin);
|
||||
|
||||
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
|
||||
_alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard");
|
||||
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
|
||||
}
|
||||
|
||||
require_once $DEVICE_PATH . DIRECTORY_SEPARATOR . "MikrotikPppoe.php";
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
@ -60,15 +61,7 @@ switch ($action) {
|
||||
$d = ORM::for_table('tbl_pool')->find_one($id);
|
||||
if ($d) {
|
||||
if ($d['routers'] != 'radius') {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePool($client, $d['pool_name']);
|
||||
} catch (Exception $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
} catch(Throwable $e){
|
||||
//ignore exception, it means router has already deleted
|
||||
}
|
||||
(new MikrotikPppoe())->remove_pool($d);
|
||||
}
|
||||
$d->delete();
|
||||
|
||||
@ -81,9 +74,7 @@ switch ($action) {
|
||||
$log = '';
|
||||
foreach ($pools as $pool) {
|
||||
if ($pool['routers'] != 'radius') {
|
||||
$mikrotik = Mikrotik::info($pool['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::addPool($client, $pool['pool_name'], $pool['range_ip']);
|
||||
(new MikrotikPppoe())->update_pool($pool, $pool);
|
||||
$log .= 'DONE: ' . $pool['pool_name'] . ': ' . $pool['range_ip'] . '<br>';
|
||||
}
|
||||
}
|
||||
@ -108,9 +99,7 @@ switch ($action) {
|
||||
}
|
||||
if ($msg == '') {
|
||||
if ($routers != 'radius') {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::addPool($client, $name, $ip_address);
|
||||
(new MikrotikPppoe())->add_pool($pool);
|
||||
}
|
||||
|
||||
$b = ORM::for_table('tbl_pool')->create();
|
||||
@ -138,22 +127,20 @@ switch ($action) {
|
||||
|
||||
$id = _post('id');
|
||||
$d = ORM::for_table('tbl_pool')->find_one($id);
|
||||
if ($d) {
|
||||
} else {
|
||||
$old = ORM::for_table('tbl_pool')->find_one($id);
|
||||
if (!$d) {
|
||||
$msg .= Lang::T('Data Not Found') . '<br>';
|
||||
}
|
||||
|
||||
if ($msg == '') {
|
||||
if ($routers != 'radius') {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setPool($client, $d['pool_name'], $ip_address);
|
||||
}
|
||||
|
||||
$d->range_ip = $ip_address;
|
||||
$d->routers = $routers;
|
||||
$d->save();
|
||||
|
||||
if ($routers != 'radius') {
|
||||
(new MikrotikPppoe())->update_pool($old, $d);
|
||||
}
|
||||
|
||||
r2(U . 'pool/list', 's', Lang::T('Data Updated Successfully'));
|
||||
} else {
|
||||
r2(U . 'pool/edit/' . $id, 'e', $msg);
|
||||
|
@ -27,43 +27,20 @@ switch ($action) {
|
||||
$log = '';
|
||||
$router = '';
|
||||
foreach ($plans as $plan) {
|
||||
if ($plan['is_radius']) {
|
||||
if ($b['rate_down_unit'] == 'Kbps') {
|
||||
$raddown = '000';
|
||||
} else {
|
||||
$raddown = '000000';
|
||||
}
|
||||
if ($b['rate_up_unit'] == 'Kbps') {
|
||||
$radup = '000';
|
||||
} else {
|
||||
$radup = '000000';
|
||||
}
|
||||
$radiusRate = $plan['rate_up'] . $radup . '/' . $plan['rate_down'] . $raddown . '/' . $plan['burst'];
|
||||
Radius::planUpSert($plan['id'], $radiusRate);
|
||||
$log .= "DONE : Radius $plan[name_plan], $plan[shared_users], $radiusRate<br>";
|
||||
} else {
|
||||
if ($router != $plan['routers']) {
|
||||
$mikrotik = Mikrotik::info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $plan['routers'];
|
||||
}
|
||||
if ($plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
$unitdown = 'M';
|
||||
}
|
||||
if ($plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
||||
Mikrotik::addHotspotPlan($client, $plan['name_plan'], $plan['shared_users'], $rate);
|
||||
$log .= "DONE : $plan[name_plan], $plan[shared_users], $rate<br>";
|
||||
$dvc = Package::getDevice($plan);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_plan($plan);
|
||||
if (!empty($plan['pool_expired'])) {
|
||||
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired']);
|
||||
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
|
||||
$plan->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$plan->rate_down_unit = "Kbps";
|
||||
$plan->rate_up_unit == 'Kbps';
|
||||
$plan->rate_up = '512';
|
||||
$plan->rate_down = '512';
|
||||
new $p['device']->add_plan($plan);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
r2(U . 'services/hotspot', 's', $log);
|
||||
@ -72,43 +49,20 @@ switch ($action) {
|
||||
$log = '';
|
||||
$router = '';
|
||||
foreach ($plans as $plan) {
|
||||
if ($plan['is_radius']) {
|
||||
if ($b['rate_down_unit'] == 'Kbps') {
|
||||
$raddown = '000';
|
||||
} else {
|
||||
$raddown = '000000';
|
||||
}
|
||||
if ($b['rate_up_unit'] == 'Kbps') {
|
||||
$radup = '000';
|
||||
} else {
|
||||
$radup = '000000';
|
||||
}
|
||||
$radiusRate = $plan['rate_up'] . $radup . '/' . $plan['rate_down'] . $raddown . '/' . $plan['burst'];
|
||||
Radius::planUpSert($plan['id'], $radiusRate, $plan['pool']);
|
||||
$log .= "DONE : RADIUS $plan[name_plan], $plan[pool], $rate<br>";
|
||||
} else {
|
||||
if ($router != $plan['routers']) {
|
||||
$mikrotik = Mikrotik::info($plan['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
$router = $plan['routers'];
|
||||
}
|
||||
if ($plan['rate_down_unit'] == 'Kbps') {
|
||||
$unitdown = 'K';
|
||||
} else {
|
||||
$unitdown = 'M';
|
||||
}
|
||||
if ($plan['rate_up_unit'] == 'Kbps') {
|
||||
$unitup = 'K';
|
||||
} else {
|
||||
$unitup = 'M';
|
||||
}
|
||||
$rate = $plan['rate_up'] . $unitup . "/" . $plan['rate_down'] . $unitdown;
|
||||
Mikrotik::addPpoePlan($client, $plan['name_plan'], $plan['pool'], $rate);
|
||||
$log .= "DONE : $plan[name_plan], $plan[pool], $rate<br>";
|
||||
$dvc = Package::getDevice($plan);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_plan($plan);
|
||||
if (!empty($plan['pool_expired'])) {
|
||||
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $plan['pool_expired'], $plan['pool_expired'], '512K/512K');
|
||||
$log .= "DONE Expired : EXPIRED NUXBILL $plan[pool_expired]<br>";
|
||||
$plan->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$plan->rate_down_unit = "Kbps";
|
||||
$plan->rate_up_unit == 'Kbps';
|
||||
$plan->rate_up = '512';
|
||||
$plan->rate_down = '512';
|
||||
new $p['device']->add_plan($plan);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
}
|
||||
r2(U . 'services/pppoe', 's', $log);
|
||||
@ -162,20 +116,13 @@ switch ($action) {
|
||||
$d = ORM::for_table('tbl_plans')->find_one($id);
|
||||
if ($d) {
|
||||
run_hook('delete_plan'); #HOOK
|
||||
if ($d['is_radius']) {
|
||||
Radius::planDelete($d['id']);
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_plan($d);
|
||||
} else {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotPlan($client, $d['name_plan']);
|
||||
} catch (Exception $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
} catch (Throwable $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
$d->delete();
|
||||
|
||||
r2(U . 'services/hotspot', 's', Lang::T('Data Deleted Successfully'));
|
||||
@ -272,20 +219,23 @@ switch ($action) {
|
||||
$d->enabled = $enabled;
|
||||
$d->prepaid = $prepaid;
|
||||
$d->save();
|
||||
$plan_id = $d->id();
|
||||
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpSert($plan_id, $radiusRate);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate);
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_plan($d);
|
||||
if (!empty($pool_expired)) {
|
||||
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
|
||||
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$d->rate_down_unit = "Kbps";
|
||||
$d->rate_up_unit == 'Kbps';
|
||||
$d->rate_up = '512';
|
||||
$d->rate_down = '512';
|
||||
new $p['device']->add_plan($d);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
|
||||
r2(U . 'services/hotspot', 's', Lang::T('Data Created Successfully'));
|
||||
} else {
|
||||
r2(U . 'services/add', 'e', $msg);
|
||||
@ -324,6 +274,7 @@ switch ($action) {
|
||||
$msg .= Lang::T('All field is required') . '<br>';
|
||||
}
|
||||
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
|
||||
$old = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
|
||||
if ($d) {
|
||||
} else {
|
||||
$msg .= Lang::T('Data Not Found') . '<br>';
|
||||
@ -350,16 +301,6 @@ switch ($action) {
|
||||
|
||||
$rate = trim($rate . " " . $b['burst']);
|
||||
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpSert($id, $radiusRate);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate);
|
||||
if (!empty($pool_expired)) {
|
||||
Mikrotik::setHotspotExpiredPlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired);
|
||||
}
|
||||
}
|
||||
$d->name_plan = $name;
|
||||
$d->id_bw = $id_bw;
|
||||
$d->price = $price; // Set price with or without tax based on configuration
|
||||
@ -379,6 +320,23 @@ switch ($action) {
|
||||
$d->prepaid = $prepaid;
|
||||
$d->save();
|
||||
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $d['device']->update_plan($old, $d);
|
||||
if (!empty($pool_expired)) {
|
||||
$old->name_plan = 'EXPIRED NUXBILL ' . $old['pool_expired'];
|
||||
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$d->rate_down_unit = "Kbps";
|
||||
$d->rate_up_unit == 'Kbps';
|
||||
$d->rate_up = '512';
|
||||
$d->rate_down = '512';
|
||||
new $d['device']->update_plan($old, $d);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
r2(U . 'services/hotspot', 's', Lang::T('Data Updated Successfully'));
|
||||
} else {
|
||||
r2(U . 'services/edit/' . $id, 'e', $msg);
|
||||
@ -441,18 +399,13 @@ switch ($action) {
|
||||
$d = ORM::for_table('tbl_plans')->find_one($id);
|
||||
if ($d) {
|
||||
run_hook('delete_ppoe'); #HOOK
|
||||
if ($d['is_radius']) {
|
||||
Radius::planDelete($d['id']);
|
||||
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->remove_plan($d);
|
||||
} else {
|
||||
try {
|
||||
$mikrotik = Mikrotik::info($d['routers']);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removePpoePlan($client, $d['name_plan']);
|
||||
} catch (Exception $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
} catch (Throwable $e) {
|
||||
//ignore exception, it means router has already deleted
|
||||
}
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
$d->delete();
|
||||
|
||||
@ -537,17 +490,21 @@ switch ($action) {
|
||||
$d->enabled = $enabled;
|
||||
$d->prepaid = $prepaid;
|
||||
$d->save();
|
||||
$plan_id = $d->id();
|
||||
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpSert($plan_id, $radiusRate, $pool);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::addPpoePlan($client, $name, $pool, $rate);
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $p['device']->add_plan($d);
|
||||
if (!empty($pool_expired)) {
|
||||
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
|
||||
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$d->rate_down_unit = "Kbps";
|
||||
$d->rate_up_unit == 'Kbps';
|
||||
$d->rate_up = '512';
|
||||
$d->rate_down = '512';
|
||||
new $p['device']->add_plan($d);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
r2(U . 'services/pppoe', 's', Lang::T('Data Created Successfully'));
|
||||
@ -583,6 +540,7 @@ switch ($action) {
|
||||
}
|
||||
|
||||
$d = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
|
||||
$old = ORM::for_table('tbl_plans')->where('id', $id)->find_one();
|
||||
if ($d) {
|
||||
} else {
|
||||
$msg .= Lang::T('Data Not Found') . '<br>';
|
||||
@ -608,16 +566,6 @@ switch ($action) {
|
||||
$radiusRate = $b['rate_up'] . $radup . '/' . $b['rate_down'] . $raddown . '/' . $b['burst'];
|
||||
$rate = trim($rate . " " . $b['burst']);
|
||||
|
||||
if ($d['is_radius']) {
|
||||
Radius::planUpSert($id, $radiusRate, $pool);
|
||||
} else {
|
||||
$mikrotik = Mikrotik::info($routers);
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::setPpoePlan($client, $name, $pool, $rate);
|
||||
if (!empty($pool_expired)) {
|
||||
Mikrotik::setPpoePlan($client, 'EXPIRED NUXBILL ' . $pool_expired, $pool_expired, '512K/512K');
|
||||
}
|
||||
}
|
||||
$d->name_plan = $name;
|
||||
$d->id_bw = $id_bw;
|
||||
$d->price = $price;
|
||||
@ -632,6 +580,23 @@ switch ($action) {
|
||||
$d->prepaid = $prepaid;
|
||||
$d->save();
|
||||
|
||||
$dvc = Package::getDevice($d);
|
||||
if (file_exists($dvc)) {
|
||||
require_once $dvc;
|
||||
new $d['device']->update_plan($old, $d);
|
||||
if (!empty($pool_expired)) {
|
||||
$old->name_plan = 'EXPIRED NUXBILL ' . $old['pool_expired'];
|
||||
$d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired;
|
||||
$d->rate_down_unit = "Kbps";
|
||||
$d->rate_up_unit == 'Kbps';
|
||||
$d->rate_up = '512';
|
||||
$d->rate_down = '512';
|
||||
new $d['device']->update_plan($old, $d);
|
||||
}
|
||||
} else {
|
||||
new Exception(Lang::T("Devices Not Found"));
|
||||
}
|
||||
|
||||
r2(U . 'services/pppoe', 's', Lang::T('Data Updated Successfully'));
|
||||
} else {
|
||||
r2(U . 'services/pppoe-edit/' . $id, 'e', $msg);
|
||||
|
Reference in New Issue
Block a user