commit
f9e7a8dbb4
@ -284,7 +284,7 @@ switch ($action) {
|
|||||||
if ($_app_stage != 'demo') {
|
if ($_app_stage != 'demo') {
|
||||||
if (file_exists($dvc)) {
|
if (file_exists($dvc)) {
|
||||||
require_once $dvc;
|
require_once $dvc;
|
||||||
(new $p['device'])->add_customer($c, $p);
|
(new $p['device'])->sync_customer($c, $p);
|
||||||
} else {
|
} else {
|
||||||
new Exception(Lang::T("Devices Not Found"));
|
new Exception(Lang::T("Devices Not Found"));
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ if (isset($_GET['sync']) && !empty($_GET['sync'])) {
|
|||||||
if ($_app_stage != 'demo') {
|
if ($_app_stage != 'demo') {
|
||||||
if (file_exists($dvc)) {
|
if (file_exists($dvc)) {
|
||||||
require_once $dvc;
|
require_once $dvc;
|
||||||
(new $p['device'])->add_customer($c, $p);
|
(new $p['device'])->sync_customer($c, $p);
|
||||||
} else {
|
} else {
|
||||||
new Exception(Lang::T("Devices Not Found"));
|
new Exception(Lang::T("Devices Not Found"));
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ switch ($action) {
|
|||||||
if ($_app_stage != 'demo') {
|
if ($_app_stage != 'demo') {
|
||||||
if (file_exists($dvc)) {
|
if (file_exists($dvc)) {
|
||||||
require_once $dvc;
|
require_once $dvc;
|
||||||
(new $p['device'])->add_customer($c, $p);
|
(new $p['device'])->sync_customer($c, $p);
|
||||||
} else {
|
} else {
|
||||||
new Exception(Lang::T("Devices Not Found"));
|
new Exception(Lang::T("Devices Not Found"));
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,31 @@ class MikrotikHotspot
|
|||||||
}
|
}
|
||||||
$this->addHotspotUser($client, $plan, $customer);
|
$this->addHotspotUser($client, $plan, $customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sync_customer($customer, $plan)
|
||||||
|
{
|
||||||
|
$mikrotik = $this->info($plan['routers']);
|
||||||
|
$client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||||
|
$t = ORM::for_table('tbl_user_recharges')->where('username', $customer['username'])->where('status', 'on')->find_one();
|
||||||
|
if ($t) {
|
||||||
|
$printRequest = new RouterOS\Request('/ip/hotspot/user/print');
|
||||||
|
$printRequest->setArgument('.proplist', '.id,limit-uptime,limit-bytes-total');
|
||||||
|
$printRequest->setQuery(RouterOS\Query::where('name', $customer['username']));
|
||||||
|
$userInfo = $client->sendSync($printRequest);
|
||||||
|
$id = $userInfo->getProperty('.id');
|
||||||
|
$uptime = $userInfo->getProperty('limit-uptime');
|
||||||
|
$data = $userInfo->getProperty('limit-bytes-total');
|
||||||
|
if (!empty($id) && (!empty($uptime) || !empty($data))) {
|
||||||
|
$setRequest = new RouterOS\Request('/ip/hotspot/user/set');
|
||||||
|
$setRequest->setArgument('numbers', $id);
|
||||||
|
$setRequest->setArgument('profile', $t['namebp']);
|
||||||
|
$client->sendSync($setRequest);
|
||||||
|
} else {
|
||||||
|
$this->add_customer($customer, $plan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function remove_customer($customer, $plan)
|
function remove_customer($customer, $plan)
|
||||||
{
|
{
|
||||||
|
@ -77,6 +77,11 @@ class MikrotikPppoe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sync_customer($customer, $plan)
|
||||||
|
{
|
||||||
|
$this->add_customer($customer, $plan);
|
||||||
|
}
|
||||||
|
|
||||||
function remove_customer($customer, $plan)
|
function remove_customer($customer, $plan)
|
||||||
{
|
{
|
||||||
|
@ -57,6 +57,11 @@ class MikrotikVpn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sync_customer($customer, $plan)
|
||||||
|
{
|
||||||
|
$this->add_customer($customer, $plan);
|
||||||
|
}
|
||||||
|
|
||||||
function remove_customer($customer, $plan)
|
function remove_customer($customer, $plan)
|
||||||
{
|
{
|
||||||
|
@ -50,18 +50,42 @@ class Radius
|
|||||||
|
|
||||||
if ($p['validity_unit'] == 'Months') {
|
if ($p['validity_unit'] == 'Months') {
|
||||||
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month'));
|
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month'));
|
||||||
|
$time = date("H:i:s");
|
||||||
} else if ($p['validity_unit'] == 'Period') {
|
} else if ($p['validity_unit'] == 'Period') {
|
||||||
$date_tmp = date("Y-m-$day_exp", strtotime('+' . $p['validity'] . ' month'));
|
$current_date = new DateTime($date_only);
|
||||||
$dt1 = new DateTime("$date_only");
|
$exp_date = clone $current_date;
|
||||||
$dt2 = new DateTime("$date_tmp");
|
$exp_date->modify('first day of next month');
|
||||||
$diff = $dt2->diff($dt1);
|
$exp_date->setDate($exp_date->format('Y'), $exp_date->format('m'), $day_exp);
|
||||||
$sum = $diff->format("%a"); // => 453
|
|
||||||
if ($sum >= 35 * $p['validity']) {
|
$min_days = 7 * $p['validity'];
|
||||||
$date_exp = date("Y-m-$day_exp", strtotime('+0 month'));
|
$max_days = 35 * $p['validity'];
|
||||||
} else {
|
|
||||||
$date_exp = date("Y-m-$day_exp", strtotime('+' . $p['validity'] . ' month'));
|
$days_until_exp = $exp_date->diff($current_date)->days;
|
||||||
};
|
|
||||||
$time = date("23:59:00");
|
// If less than min_days away, move to the next period
|
||||||
|
while ($days_until_exp < $min_days) {
|
||||||
|
$exp_date->modify('+1 month');
|
||||||
|
$days_until_exp = $exp_date->diff($current_date)->days;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If more than max_days away, move to the previous period
|
||||||
|
while ($days_until_exp > $max_days) {
|
||||||
|
$exp_date->modify('-1 month');
|
||||||
|
$days_until_exp = $exp_date->diff($current_date)->days;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Final check to ensure we're not less than min_days or in the past
|
||||||
|
if ($days_until_exp < $min_days || $exp_date <= $current_date) {
|
||||||
|
$exp_date->modify('+1 month');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust for multiple periods
|
||||||
|
if ($p['validity'] > 1) {
|
||||||
|
$exp_date->modify('+' . ($p['validity'] - 1) . ' months');
|
||||||
|
}
|
||||||
|
|
||||||
|
$date_exp = $exp_date->format('Y-m-d');
|
||||||
|
$time = "23:59:59";
|
||||||
} else if ($p['validity_unit'] == 'Days') {
|
} else if ($p['validity_unit'] == 'Days') {
|
||||||
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' day')));
|
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime('+' . $p['validity'] . ' day')));
|
||||||
$date_exp = $datetime[0];
|
$date_exp = $datetime[0];
|
||||||
@ -80,6 +104,14 @@ class Radius
|
|||||||
$this->customerAddPlan($customer, $plan, $date_exp . ' ' . $time);
|
$this->customerAddPlan($customer, $plan, $date_exp . ' ' . $time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sync_customer($customer, $plan)
|
||||||
|
{
|
||||||
|
$t = ORM::for_table('tbl_user_recharges')->where('username', $customer['username'])->where('status', 'on')->findOne();
|
||||||
|
$date_exp = $t['expiration'];
|
||||||
|
$time = $t['time'];
|
||||||
|
$this->customerAddPlan($customer, $plan, $date_exp . ' ' . $time);
|
||||||
|
}
|
||||||
|
|
||||||
function remove_customer($customer, $plan)
|
function remove_customer($customer, $plan)
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,11 @@ class RadiusRest {
|
|||||||
function add_customer($customer, $plan)
|
function add_customer($customer, $plan)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sync_customer($customer, $plan)
|
||||||
|
{
|
||||||
|
$this->add_customer($customer, $plan);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove Customer to Mikrotik/Device
|
// Remove Customer to Mikrotik/Device
|
||||||
function remove_customer($customer, $plan)
|
function remove_customer($customer, $plan)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user