diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index 6b0a07c3..5e99aaef 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -330,4 +330,6 @@ ALTER TABLE `tbl_customers` ADD `status` ENUM('Active','Banned','Disabled') NOT ALTER TABLE `tbl_customers` CHANGE `status` `status` ENUM('Active','Banned','Disabled','Inactive','Limited','Suspended') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'Active'; ALTER TABLE `tbl_plans` ADD `price_old` VARCHAR(40) NOT NULL DEFAULT '' AFTER `price`; ALTER TABLE `tbl_plans` ADD `device` VARCHAR(32) NOT NULL DEFAULT '' AFTER `plan_type`; -ALTER TABLE `tbl_pool` ADD `local_ip` VARCHAR(40) NOT NULL DEFAULT '' AFTER `pool_name`; \ No newline at end of file +ALTER TABLE `tbl_pool` ADD `local_ip` VARCHAR(40) NOT NULL DEFAULT '' AFTER `pool_name`; +ALTER TABLE `tbl_plans` ADD `plan_expired` INT NOT NULL DEFAULT '0' AFTER `pool`; +ALTER TABLE `tbl_plans` DROP `pool_expired`, DROP `list_expired`; \ No newline at end of file diff --git a/system/controllers/services.php b/system/controllers/services.php index a4d21b0f..4ca9ea8d 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -15,10 +15,6 @@ if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } -use PEAR2\Net\RouterOS; - -require_once 'system/autoload/PEAR2/Autoload.php'; - switch ($action) { case 'sync': set_time_limit(-1); @@ -31,10 +27,6 @@ switch ($action) { if (file_exists($dvc)) { require_once $dvc; (new $p['device'])->add_plan($plan); - if (!empty($plan['pool_expired'])) { - $plan->name_plan = 'EXPIRED NUXBILL ' . $pool_expired; - (new $p['device'])->add_plan($plan); - } } else { new Exception(Lang::T("Devices Not Found")); } @@ -49,10 +41,6 @@ switch ($action) { if (file_exists($dvc)) { require_once $dvc; (new $p['device'])->add_plan($plan); - if (!empty($plan['pool_expired'])) { - $plan->name_plan = 'EXPIRED NUXBILL ' . $pool_expired; - (new $p['device'])->add_plan($plan); - } } else { new Exception(Lang::T("Devices Not Found")); } @@ -84,9 +72,9 @@ switch ($action) { $ui->assign('r', $r); $devices = []; $files = scandir($DEVICE_PATH); - foreach($files as $file){ + foreach ($files as $file) { $ext = pathinfo($file, PATHINFO_EXTENSION); - if($ext == 'php'){ + if ($ext == 'php') { $devices[] = pathinfo($file, PATHINFO_FILENAME); } } @@ -99,28 +87,33 @@ switch ($action) { $id = $routes['2']; $d = ORM::for_table('tbl_plans')->find_one($id); if ($d) { - if(empty($d['device'])){ - if($d['is_radius']){ + if (empty($d['device'])) { + if ($d['is_radius']) { $d->device = 'Radius'; - }else{ + } else { $d->device = 'MikrotikHotspot'; } $d->save(); } $ui->assign('d', $d); - $p = ORM::for_table('tbl_pool')->where('routers', $d['routers'])->find_many(); - $ui->assign('p', $p); $b = ORM::for_table('tbl_bandwidth')->find_many(); $ui->assign('b', $b); $devices = []; $files = scandir($DEVICE_PATH); - foreach($files as $file){ + foreach ($files as $file) { $ext = pathinfo($file, PATHINFO_EXTENSION); - if($ext == 'php'){ + if ($ext == 'php') { $devices[] = pathinfo($file, PATHINFO_FILENAME); } } $ui->assign('devices', $devices); + //select expired plan + if($d['is_radius']){ + $exps = ORM::for_table('tbl_plans')->selects('id','name_plan')->where("is_radius", 1)->findArray(); + }else{ + $exps = ORM::for_table('tbl_plans')->selects('id','name_plan')->where("routers", $d['routers'])->findArray(); + } + $ui->assign('exps', $exps); run_hook('view_edit_plan'); #HOOK $ui->display('hotspot-edit.tpl'); } else { @@ -164,8 +157,6 @@ switch ($action) { $validity_unit = _post('validity_unit'); $routers = _post('routers'); $device = _post('device'); - $pool_expired = _post('pool_expired'); - $list_expired = _post('list_expired'); $enabled = _post('enabled'); $prepaid = _post('prepaid'); @@ -215,8 +206,6 @@ switch ($action) { $d->is_radius = 0; $d->routers = $routers; } - $d->pool_expired = $pool_expired; - $d->list_expired = $list_expired; $d->enabled = $enabled; $d->prepaid = $prepaid; $d->device = $device; @@ -226,14 +215,6 @@ switch ($action) { if (file_exists($dvc)) { require_once $dvc; (new $p['device'])->add_plan($d); - if (!empty($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")); } @@ -260,8 +241,7 @@ switch ($action) { $sharedusers = _post('sharedusers'); $validity = _post('validity'); $validity_unit = _post('validity_unit'); - $pool_expired = _post('pool_expired'); - $list_expired = _post('list_expired'); + $plan_expired = _post('plan_expired', '0'); $device = _post('device'); $enabled = _post('enabled'); $prepaid = _post('prepaid'); @@ -317,8 +297,7 @@ switch ($action) { $d->validity = $validity; $d->validity_unit = $validity_unit; $d->shared_users = $sharedusers; - $d->pool_expired = $pool_expired; - $d->list_expired = $list_expired; + $d->plan_expired = $plan_expired; $d->enabled = $enabled; $d->prepaid = $prepaid; $d->device = $device; @@ -328,15 +307,6 @@ switch ($action) { 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")); } @@ -373,9 +343,9 @@ switch ($action) { $ui->assign('r', $r); $devices = []; $files = scandir($DEVICE_PATH); - foreach($files as $file){ + foreach ($files as $file) { $ext = pathinfo($file, PATHINFO_EXTENSION); - if($ext == 'php'){ + if ($ext == 'php') { $devices[] = pathinfo($file, PATHINFO_FILENAME); } } @@ -389,10 +359,10 @@ switch ($action) { $id = $routes['2']; $d = ORM::for_table('tbl_plans')->find_one($id); if ($d) { - if(empty($d['device'])){ - if($d['is_radius']){ + if (empty($d['device'])) { + if ($d['is_radius']) { $d->device = 'Radius'; - }else{ + } else { $d->device = 'MikrotikPppoe'; } $d->save(); @@ -409,13 +379,20 @@ switch ($action) { $ui->assign('r', $r); $devices = []; $files = scandir($DEVICE_PATH); - foreach($files as $file){ + foreach ($files as $file) { $ext = pathinfo($file, PATHINFO_EXTENSION); - if($ext == 'php'){ + if ($ext == 'php') { $devices[] = pathinfo($file, PATHINFO_FILENAME); } } $ui->assign('devices', $devices); + //select expired plan + if($d['is_radius']){ + $exps = ORM::for_table('tbl_plans')->selects('id','name_plan')->where("is_radius", 1)->findArray(); + }else{ + $exps = ORM::for_table('tbl_plans')->selects('id','name_plan')->where("routers", $d['routers'])->findArray(); + } + $ui->assign('exps', $exps); run_hook('view_edit_ppoe'); #HOOK $ui->display('pppoe-edit.tpl'); } else { @@ -454,8 +431,6 @@ switch ($action) { $routers = _post('routers'); $device = _post('device'); $pool = _post('pool_name'); - $pool_expired = _post('pool_expired'); - $list_expired = _post('list_expired'); $enabled = _post('enabled'); $prepaid = _post('prepaid'); @@ -516,8 +491,6 @@ switch ($action) { $d->is_radius = 0; $d->routers = $routers; } - $d->pool_expired = $pool_expired; - $d->list_expired = $list_expired; $d->enabled = $enabled; $d->prepaid = $prepaid; $d->device = $device; @@ -527,10 +500,6 @@ switch ($action) { if (file_exists($dvc)) { require_once $dvc; (new $p['device'])->add_plan($d); - if (!empty($pool_expired)) { - $d->name_plan = 'EXPIRED NUXBILL ' . $pool_expired; - (new $p['device'])->add_plan($d); - } } else { new Exception(Lang::T("Devices Not Found")); } @@ -552,8 +521,7 @@ switch ($action) { $routers = _post('routers'); $device = _post('device'); $pool = _post('pool_name'); - $pool_expired = _post('pool_expired'); - $list_expired = _post('list_expired'); + $plan_expired = _post('plan_expired'); $enabled = _post('enabled'); $prepaid = _post('prepaid'); @@ -603,8 +571,7 @@ switch ($action) { $d->validity_unit = $validity_unit; $d->routers = $routers; $d->pool = $pool; - $d->pool_expired = $pool_expired; - $d->list_expired = $list_expired; + $d->plan_expired = $plan_expired; $d->enabled = $enabled; $d->prepaid = $prepaid; $d->device = $device; @@ -614,15 +581,6 @@ switch ($action) { 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")); } diff --git a/system/devices/MikrotikHotspot.php b/system/devices/MikrotikHotspot.php index 5968401d..03117646 100644 --- a/system/devices/MikrotikHotspot.php +++ b/system/devices/MikrotikHotspot.php @@ -34,8 +34,9 @@ class MikrotikHotspot } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - if (!empty($plan['pool_expired'])) { - $this->setHotspotUserPackage($client, $customer['username'], 'EXPIRED NUXBILL ' . $plan['pool_expired']); + if (!empty($plan['plan_expired'])) { + $p = ORM::for_table("tbl_plans")->select("name_plan")->find_one($plan['plan_expired']); + $this->setHotspotUserPackage($client, $customer['username'], $p['name_plan']); } else { $this->removeHotspotUser($client, $customer['username']); } @@ -322,7 +323,7 @@ class MikrotikHotspot $client->sendSync($setRequest); } - function setHotspotUserPackage($client, $user, $plan) + function setHotspotUserPackage($client, $user, $plan_name) { global $_app_stage; if ($_app_stage == 'demo') { @@ -335,7 +336,7 @@ class MikrotikHotspot $setRequest = new RouterOS\Request('/ip/hotspot/user/set'); $setRequest->setArgument('numbers', $id); - $setRequest->setArgument('profile', $plan); + $setRequest->setArgument('profile', $plan_name); $client->sendSync($setRequest); } diff --git a/system/devices/MikrotikPppoe.php b/system/devices/MikrotikPppoe.php index 88715200..6ad8ba51 100644 --- a/system/devices/MikrotikPppoe.php +++ b/system/devices/MikrotikPppoe.php @@ -34,8 +34,9 @@ class MikrotikPppoe } $mikrotik = $this->info($plan['routers']); $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - if (!empty($plan['pool_expired'])) { - $this->setPpoeUserPlan($client, $customer['username'], 'EXPIRED NUXBILL ' . $plan['pool_expired']); + if (!empty($plan['plan_expired'])) { + $p = ORM::for_table("tbl_plans")->select("name_plan")->find_one($plan['plan_expired']); + $this->setPpoeUserPlan($client, $customer['username'], $p['plan_expired']); } else { $this->removePpoeUser($client, $customer['username']); } diff --git a/system/devices/radius.php b/system/devices/radius.php index 0d559674..2579b5f0 100644 --- a/system/devices/radius.php +++ b/system/devices/radius.php @@ -23,8 +23,10 @@ class Radius { if ($_app_stage == 'demo') { return; } - if (empty($plan['pool_expired'])) { + if (empty($plan['plan_expired'])) { + $p = ORM::for_table("tbl_plans")->find_one($plan['plan_expired']); $this->customerDeactivate($customer['username']); + $this->customerAddPlan($customer, $p); } else { $this->upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool_expired'], ':='); $this->disconnectCustomer($customer['username']); diff --git a/system/lan/english.json b/system/lan/english.json index ae5e1b4e..22dcb8d8 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -633,5 +633,7 @@ "Zip_Code": "Zip Code", "Local_IP": "Local IP", "": "", - "Device": "Device" + "Device": "Device", + "Expired_Internet_Plan": "Expired Internet Plan", + "When_Expired__customer_will_be_move_to_selected_internet_plan": "When Expired, customer will be move to selected internet plan" } \ No newline at end of file diff --git a/system/updates.json b/system/updates.json index 9bceb553..18b1f665 100644 --- a/system/updates.json +++ b/system/updates.json @@ -109,5 +109,9 @@ ], "2024.6.10" : [ "ALTER TABLE `tbl_pool` ADD `local_ip` VARCHAR(40) NOT NULL DEFAULT '' AFTER `pool_name`;" + ], + "2024.6.11" : [ + "ALTER TABLE `tbl_plans` ADD `plan_expired` INT NOT NULL DEFAULT '0' AFTER `pool`;", + "ALTER TABLE `tbl_plans` DROP `pool_expired`, DROP `list_expired`;" ] } \ No newline at end of file diff --git a/ui/ui/hotspot-add.tpl b/ui/ui/hotspot-add.tpl index 3b0021f6..0758acec 100644 --- a/ui/ui/hotspot-add.tpl +++ b/ui/ui/hotspot-add.tpl @@ -169,22 +169,6 @@ - -
{Lang::T('1 Period = 1 Month, Expires the 20th of each month')} -
+{Lang::T('1 Period = 1 Month, Expires the 20th of each month')}
{Lang::T('When Expired, customer will be move to selected internet plan')}
{Lang::T('When Expired, customer will be move to selected internet plan')}