Merge branch 'Development' into feature/radius
This commit is contained in:
@ -33,6 +33,63 @@ class File
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
public static function resizeCropImage($source_file, $dst_dir, $max_width, $max_height, $quality = 80)
|
||||
{
|
||||
$imgsize = getimagesize($source_file);
|
||||
$width = $imgsize[0];
|
||||
$height = $imgsize[1];
|
||||
$mime = $imgsize['mime'];
|
||||
|
||||
switch ($mime) {
|
||||
case 'image/gif':
|
||||
$image_create = "imagecreatefromgif";
|
||||
$image = "imagegif";
|
||||
break;
|
||||
|
||||
case 'image/png':
|
||||
$image_create = "imagecreatefrompng";
|
||||
$image = "imagepng";
|
||||
$quality = 7;
|
||||
break;
|
||||
|
||||
case 'image/jpeg':
|
||||
$image_create = "imagecreatefromjpeg";
|
||||
$image = "imagejpeg";
|
||||
$quality = 80;
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($max_width == 0) {
|
||||
$max_width = $width;
|
||||
}
|
||||
|
||||
if ($max_height == 0) {
|
||||
$max_height = $height;
|
||||
}
|
||||
|
||||
$widthRatio = $max_width / $width;
|
||||
$heightRatio = $max_height / $height;
|
||||
$ratio = min($widthRatio, $heightRatio);
|
||||
$nwidth = (int)$width * $ratio;
|
||||
$nheight = (int)$height * $ratio;
|
||||
|
||||
$dst_img = imagecreatetruecolor($nwidth, $nheight);
|
||||
$white = imagecolorallocate($dst_img, 255, 255, 255);
|
||||
imagefill($dst_img, 0, 0, $white);
|
||||
$src_img = $image_create($source_file);
|
||||
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nwidth, $nheight, $width, $height);
|
||||
|
||||
$image($dst_img, $dst_dir, $quality);
|
||||
|
||||
if ($dst_img) imagedestroy($dst_img);
|
||||
if ($src_img) imagedestroy($src_img);
|
||||
return file_exists($dst_dir);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* file path fixer
|
||||
|
@ -12,11 +12,14 @@ class Mikrotik
|
||||
|
||||
public static function getClient($ip, $user, $pass)
|
||||
{
|
||||
global $ui;
|
||||
try {
|
||||
$iport = explode(":", $ip);
|
||||
return new RouterOS\Client($iport[0], $user, $pass, ($iport[1]) ? $iport[1] : null);
|
||||
} catch (Exception $e) {
|
||||
die("Unable to connect to the router.<br>" . $e->getMessage());
|
||||
$ui->assign("error_meesage","Unable to connect to the router.<br>" . $e->getMessage());
|
||||
$ui->display('router-error.tpl');
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,17 +219,17 @@ class Mikrotik
|
||||
|
||||
public static function removePpoeUser($client, $username)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ppp secret print .proplist=name',
|
||||
RouterOS\Query::where('name', $username)
|
||||
);
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/secret/remove');
|
||||
$client(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $id)
|
||||
);
|
||||
$printRequest = new RouterOS\Request('/ppp/secret/print');
|
||||
$printRequest->setArgument('.proplist', '.id');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $username));
|
||||
$id = $client->sendSync($printRequest)->getProperty('.id');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ppp/secret/remove');
|
||||
$client(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $id)
|
||||
);
|
||||
}
|
||||
|
||||
public static function addPpoeUser($client, $plan, $customer)
|
||||
|
@ -22,6 +22,7 @@ class Package
|
||||
global $_c, $_L, $_notifmsg;
|
||||
$date_now = date("Y-m-d H:i:s");
|
||||
$date_only = date("Y-m-d");
|
||||
$time_only = date("H:i:s");
|
||||
$time = date("H:i:s");
|
||||
|
||||
if ($id_customer == '' or $router_name == '' or $plan_id == '') {
|
||||
@ -40,6 +41,7 @@ class Package
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->recharged_time = date("H:i:s");
|
||||
$t->expiration = $date_only;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
@ -100,11 +102,29 @@ class Package
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
}
|
||||
|
||||
if ($b['namebp'] == $p['name_plan']) {
|
||||
// if it same internet plan, expired will extend
|
||||
if ($p['validity_unit'] == 'Months') {
|
||||
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
|
||||
} else if ($p['validity_unit'] == 'Days') {
|
||||
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days'));
|
||||
} else if ($p['validity_unit'] == 'Hrs') {
|
||||
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime($b['expiration'] . ' ' . $b['time'] . ' +' . $p['validity'] . ' hours')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
} else if ($p['validity_unit'] == 'Mins') {
|
||||
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime($b['expiration'] . ' ' . $b['time'] . ' +' . $p['validity'] . ' minutes')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
}
|
||||
}
|
||||
|
||||
$b->customer_id = $id_customer;
|
||||
$b->username = $c['username'];
|
||||
$b->plan_id = $plan_id;
|
||||
$b->namebp = $p['name_plan'];
|
||||
$b->recharged_on = $date_only;
|
||||
$b->recharged_time = $time_only;
|
||||
$b->expiration = $date_exp;
|
||||
$b->time = $time;
|
||||
$b->status = "on";
|
||||
@ -120,6 +140,7 @@ class Package
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->recharged_time = $time_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
@ -139,6 +160,7 @@ class Package
|
||||
$d->plan_id = $plan_id;
|
||||
$d->namebp = $p['name_plan'];
|
||||
$d->recharged_on = $date_only;
|
||||
$d->recharged_time = $time_only;
|
||||
$d->expiration = $date_exp;
|
||||
$d->time = $time;
|
||||
$d->status = "on";
|
||||
@ -154,6 +176,7 @@ class Package
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->recharged_time = $time_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
@ -176,11 +199,30 @@ class Package
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
|
||||
|
||||
if ($b['namebp'] == $p['name_plan']) {
|
||||
// if it same internet plan, expired will extend
|
||||
if ($p['validity_unit'] == 'Months') {
|
||||
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
|
||||
} else if ($p['validity_unit'] == 'Days') {
|
||||
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days'));
|
||||
} else if ($p['validity_unit'] == 'Hrs') {
|
||||
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime($b['expiration'] . ' ' . $b['time'] . ' +' . $p['validity'] . ' hours')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
} else if ($p['validity_unit'] == 'Mins') {
|
||||
$datetime = explode(' ', date("Y-m-d H:i:s", strtotime($b['expiration'] . ' ' . $b['time'] . ' +' . $p['validity'] . ' minutes')));
|
||||
$date_exp = $datetime[0];
|
||||
$time = $datetime[1];
|
||||
}
|
||||
}
|
||||
|
||||
$b->customer_id = $id_customer;
|
||||
$b->username = $c['username'];
|
||||
$b->plan_id = $plan_id;
|
||||
$b->namebp = $p['name_plan'];
|
||||
$b->recharged_on = $date_only;
|
||||
$b->recharged_time = $time_only;
|
||||
$b->expiration = $date_exp;
|
||||
$b->time = $time;
|
||||
$b->status = "on";
|
||||
@ -196,6 +238,7 @@ class Package
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->recharged_time = $time_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
@ -206,6 +249,7 @@ class Package
|
||||
if (!$_c['radius_mode']) {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
|
||||
@ -215,6 +259,7 @@ class Package
|
||||
$d->plan_id = $plan_id;
|
||||
$d->namebp = $p['name_plan'];
|
||||
$d->recharged_on = $date_only;
|
||||
$d->recharged_time = $time_only;
|
||||
$d->expiration = $date_exp;
|
||||
$d->time = $time;
|
||||
$d->status = "on";
|
||||
@ -230,6 +275,7 @@ class Package
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
$t->recharged_on = $date_only;
|
||||
$t->recharged_time = $time_only;
|
||||
$t->expiration = $date_exp;
|
||||
$t->time = $time;
|
||||
$t->method = "$gateway - $channel";
|
||||
@ -282,11 +328,14 @@ class Package
|
||||
if (!$_c['radius_mode']) {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
}
|
||||
} else {
|
||||
if (!$_c['radius_mode']) {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
Mikrotik::addHotspotUser($client, $p, $c);
|
||||
}
|
||||
}
|
||||
@ -294,12 +343,15 @@ class Package
|
||||
if ($b) {
|
||||
if (!$_c['radius_mode']) {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
} else {
|
||||
if (!$_c['radius_mode']) {
|
||||
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
||||
Mikrotik::removeHotspotUser($client, $c['username']);
|
||||
Mikrotik::removePpoeUser($client, $c['username']);
|
||||
Mikrotik::addPpoeUser($client, $p, $c);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user