Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
127576b03f | |||
5d4cb4cce0 | |||
2c7d0a321e | |||
4196dbf591 | |||
4c8f0b27a1 | |||
5f6fc31344 | |||
e23b2464b8 |
@ -2,6 +2,11 @@
|
||||
|
||||
# CHANGELOG
|
||||
|
||||
## 2023.8.18
|
||||
|
||||
- Fix Auto Renewall Cronjob
|
||||
- Add comment to Mikrotik User
|
||||
|
||||
## 2023.8.16
|
||||
|
||||
- Admin Can Add Balance to Customer
|
||||
|
@ -55,7 +55,7 @@ CREATE TABLE
|
||||
`address` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
|
||||
`phonenumber` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0',
|
||||
`email` varchar(128) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '1',
|
||||
`balance` decimal(15,2) NOT NULL COMMENT 'For Money Deposit',
|
||||
`balance` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT 'For Money Deposit',
|
||||
`auto_renewal` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Auto renewal from balance',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`last_login` datetime DEFAULT NULL
|
||||
|
@ -38,7 +38,7 @@ class Balance
|
||||
{
|
||||
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
|
||||
if ($c && $c['balance'] >= $amount) {
|
||||
$c->balance = $amount - $c['balance'];
|
||||
$c->balance = $c['balance'] - $amount;
|
||||
$c->save();
|
||||
return true;
|
||||
} else {
|
||||
@ -61,7 +61,7 @@ class Balance
|
||||
{
|
||||
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
|
||||
if ($c && $c['balance'] >= $amount) {
|
||||
$c->balance = $amount - $c['balance'];
|
||||
$c->balance = $c['balance'] - $amount;
|
||||
$c->save();
|
||||
return true;
|
||||
} else {
|
||||
|
@ -4,7 +4,8 @@ use PEAR2\Net\RouterOS;
|
||||
|
||||
class Mikrotik
|
||||
{
|
||||
public static function info($name){
|
||||
public static function info($name)
|
||||
{
|
||||
$d = ORM::for_table('tbl_routers')->where('name', $name)->find_one();
|
||||
return $d;
|
||||
}
|
||||
@ -19,7 +20,8 @@ class Mikrotik
|
||||
}
|
||||
}
|
||||
|
||||
public static function isUserLogin($client, $username){
|
||||
public static function isUserLogin($client, $username)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot active print',
|
||||
RouterOS\Query::where('user', $username)
|
||||
@ -27,7 +29,8 @@ class Mikrotik
|
||||
return $client->sendSync($printRequest)->getProperty('.id');
|
||||
}
|
||||
|
||||
public static function logMeIn($client, $user, $pass, $ip, $mac){
|
||||
public static function logMeIn($client, $user, $pass, $ip, $mac)
|
||||
{
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/active/login');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
@ -38,7 +41,8 @@ class Mikrotik
|
||||
);
|
||||
}
|
||||
|
||||
public static function logMeOut($client, $user){
|
||||
public static function logMeOut($client, $user)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot active print',
|
||||
RouterOS\Query::where('user', $user)
|
||||
@ -51,7 +55,8 @@ class Mikrotik
|
||||
);
|
||||
}
|
||||
|
||||
public static function addHotspotPlan($client, $name, $sharedusers, $rate){
|
||||
public static function addHotspotPlan($client, $name, $sharedusers, $rate)
|
||||
{
|
||||
$addRequest = new RouterOS\Request('/ip/hotspot/user/profile/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
@ -61,7 +66,8 @@ class Mikrotik
|
||||
);
|
||||
}
|
||||
|
||||
public static function setHotspotPlan($client, $name, $sharedusers, $rate){
|
||||
public static function setHotspotPlan($client, $name, $sharedusers, $rate)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=name',
|
||||
RouterOS\Query::where('name', $name)
|
||||
@ -77,7 +83,8 @@ class Mikrotik
|
||||
);
|
||||
}
|
||||
|
||||
public static function removeHotspotPlan($client, $name){
|
||||
public static function removeHotspotPlan($client, $name)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip hotspot user profile print .proplist=name',
|
||||
RouterOS\Query::where('name', $name)
|
||||
@ -119,6 +126,8 @@ class Mikrotik
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('password', $customer['password'])
|
||||
->setArgument('comment', $customer['fullname'])
|
||||
->setArgument('email', $customer['email'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
);
|
||||
} else if ($plan['limit_type'] == "Data_Limit") {
|
||||
@ -131,6 +140,8 @@ class Mikrotik
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('password', $customer['password'])
|
||||
->setArgument('comment', $customer['fullname'])
|
||||
->setArgument('email', $customer['email'])
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
} else if ($plan['limit_type'] == "Both_Limit") {
|
||||
@ -147,6 +158,8 @@ class Mikrotik
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('password', $customer['password'])
|
||||
->setArgument('comment', $customer['fullname'])
|
||||
->setArgument('email', $customer['email'])
|
||||
->setArgument('limit-uptime', $timelimit)
|
||||
->setArgument('limit-bytes-total', $datalimit)
|
||||
);
|
||||
@ -156,12 +169,15 @@ class Mikrotik
|
||||
$addRequest
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('comment', $customer['fullname'])
|
||||
->setArgument('email', $customer['email'])
|
||||
->setArgument('password', $customer['password'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static function setHotspotUser($client, $user, $pass, $nuser= null){
|
||||
public static function setHotspotUser($client, $user, $pass, $nuser = null)
|
||||
{
|
||||
$printRequest = new RouterOS\Request('/ip/hotspot/user/print');
|
||||
$printRequest->setArgument('.proplist', '.id');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $user));
|
||||
@ -226,11 +242,13 @@ class Mikrotik
|
||||
->setArgument('name', $customer['username'])
|
||||
->setArgument('service', 'pppoe')
|
||||
->setArgument('profile', $plan['name_plan'])
|
||||
->setArgument('comment', $customer['fullname'] . ' | ' . $customer['email'])
|
||||
->setArgument('password', $pass)
|
||||
);
|
||||
}
|
||||
|
||||
public static function setPpoeUser($client, $user, $pass, $nuser= null){
|
||||
public static function setPpoeUser($client, $user, $pass, $nuser = null)
|
||||
{
|
||||
$printRequest = new RouterOS\Request('/ppp/secret/print');
|
||||
$printRequest->setArgument('.proplist', '.id');
|
||||
$printRequest->setQuery(RouterOS\Query::where('name', $user));
|
||||
@ -266,7 +284,8 @@ class Mikrotik
|
||||
$client->sendSync($removeRequest);
|
||||
}
|
||||
|
||||
public static function removePool($client, $name){
|
||||
public static function removePool($client, $name)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip pool print .proplist=name',
|
||||
RouterOS\Query::where('name', $name)
|
||||
@ -274,20 +293,24 @@ class Mikrotik
|
||||
$poolName = $client->sendSync($printRequest)->getProperty('name');
|
||||
|
||||
$removeRequest = new RouterOS\Request('/ip/pool/remove');
|
||||
$client($removeRequest
|
||||
$client(
|
||||
$removeRequest
|
||||
->setArgument('numbers', $poolName)
|
||||
);
|
||||
}
|
||||
|
||||
public static function addPool($client, $name, $ip_address){
|
||||
public static function addPool($client, $name, $ip_address)
|
||||
{
|
||||
$addRequest = new RouterOS\Request('/ip/pool/add');
|
||||
$client->sendSync($addRequest
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
->setArgument('name', $name)
|
||||
->setArgument('ranges', $ip_address)
|
||||
);
|
||||
}
|
||||
|
||||
public static function setPool($client, $name, $ip_address){
|
||||
public static function setPool($client, $name, $ip_address)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ip pool print .proplist=name',
|
||||
RouterOS\Query::where('name', $name)
|
||||
@ -307,7 +330,8 @@ class Mikrotik
|
||||
}
|
||||
|
||||
|
||||
public static function addPpoePlan($client, $name, $pool, $rate){
|
||||
public static function addPpoePlan($client, $name, $pool, $rate)
|
||||
{
|
||||
$addRequest = new RouterOS\Request('/ppp/profile/add');
|
||||
$client->sendSync(
|
||||
$addRequest
|
||||
@ -318,7 +342,8 @@ class Mikrotik
|
||||
);
|
||||
}
|
||||
|
||||
public static function setPpoePlan($client, $name, $pool, $rate){
|
||||
public static function setPpoePlan($client, $name, $pool, $rate)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ppp profile print .proplist=name',
|
||||
RouterOS\Query::where('name', $name)
|
||||
@ -338,7 +363,8 @@ class Mikrotik
|
||||
}
|
||||
}
|
||||
|
||||
public static function removePpoePlan($client, $name){
|
||||
public static function removePpoePlan($client, $name)
|
||||
{
|
||||
$printRequest = new RouterOS\Request(
|
||||
'/ppp profile print .proplist=name',
|
||||
RouterOS\Query::where('name', $name)
|
||||
|
@ -33,7 +33,7 @@ class Package
|
||||
|
||||
if ($router_name == 'balance') {
|
||||
// insert table transactions
|
||||
$inv = "INV-" . _raid(5);
|
||||
$inv = "INV-" . Package::_raid(5);
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = $inv;
|
||||
$t->username = $c['username'];
|
||||
@ -114,7 +114,7 @@ class Package
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->invoice = "INV-" . Package::_raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
@ -147,7 +147,7 @@ class Package
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->invoice = "INV-" . Package::_raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
@ -188,7 +188,7 @@ class Package
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->invoice = "INV-" . Package::_raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
@ -221,7 +221,7 @@ class Package
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->invoice = "INV-" . Package::_raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
@ -301,4 +301,10 @@ class Package
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function _raid($l)
|
||||
{
|
||||
return substr(str_shuffle(str_repeat('0123456789', $l)), 0, $l);
|
||||
}
|
||||
}
|
||||
|
@ -191,10 +191,6 @@ function _admin($login = true)
|
||||
}
|
||||
}
|
||||
|
||||
function _raid($l)
|
||||
{
|
||||
return substr(str_shuffle(str_repeat('0123456789', $l)), 0, $l);
|
||||
}
|
||||
|
||||
function _log($description, $type = '', $userid = '0')
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ $style
|
||||
$html
|
||||
EOF;
|
||||
$mpdf->WriteHTML($nhtml);
|
||||
$mpdf->Output(date('Y-m-d') . _raid(4) . '.pdf', 'D');
|
||||
$mpdf->Output(date('Y-m-d') . Package::_raid(4) . '.pdf', 'D');
|
||||
} else {
|
||||
echo 'No Data';
|
||||
}
|
||||
@ -340,7 +340,7 @@ $style
|
||||
$html
|
||||
EOF;
|
||||
$mpdf->WriteHTML($nhtml);
|
||||
$mpdf->Output(date('Y-m-d') . _raid(4) . '.pdf', 'D');
|
||||
$mpdf->Output(date('Y-m-d') . Package::_raid(4) . '.pdf', 'D');
|
||||
} else {
|
||||
echo 'No Data';
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ switch ($action) {
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->invoice = "INV-" . Package::_raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
@ -106,7 +106,7 @@ switch ($action) {
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->invoice = "INV-" . Package::_raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
@ -150,7 +150,7 @@ switch ($action) {
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->invoice = "INV-" . Package::_raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
@ -183,7 +183,7 @@ switch ($action) {
|
||||
|
||||
// insert table transactions
|
||||
$t = ORM::for_table('tbl_transactions')->create();
|
||||
$t->invoice = "INV-" . _raid(5);
|
||||
$t->invoice = "INV-" . Package::_raid(5);
|
||||
$t->username = $c['username'];
|
||||
$t->plan_name = $p['name_plan'];
|
||||
$t->price = $p['price'];
|
||||
|
@ -59,6 +59,9 @@ $result = ORM::for_table('tbl_appconfig')->find_many();
|
||||
foreach ($result as $value) {
|
||||
$config[$value['setting']] = $value['value'];
|
||||
}
|
||||
|
||||
$_c = $config;
|
||||
|
||||
date_default_timezone_set($config['timezone']);
|
||||
|
||||
$textExpired = $_notifmsg['expired'];
|
||||
@ -95,12 +98,20 @@ foreach ($d as $ds) {
|
||||
if (Package::rechargeUser($ds['customer_id'], $p['routers'], $p['id'], 'Customer', 'Balance')) {
|
||||
// if success, then get the balance
|
||||
Balance::min($ds['customer_id'], $p['price']);
|
||||
echo "plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n";
|
||||
echo "auto renewall Success\n";
|
||||
} else {
|
||||
echo "plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n";
|
||||
echo "auto renewall Failed\n";
|
||||
Message::sendTelegram("FAILED RENEWAL #cron\n\n#u$c[username] #buy #Hotspot \n" . $p['name_plan'] .
|
||||
"\nRouter: " . $router_name .
|
||||
"\nPrice: " . $p['price']);
|
||||
}
|
||||
}else{
|
||||
echo "no renewall | plan enabled: $p[enabled] | User balance: $c[balance] | price $p[price]\n";
|
||||
}
|
||||
}else{
|
||||
echo "no renewall | balance $config[enable_balance] auto_renewal $c[auto_renewal]\n";
|
||||
}
|
||||
} else echo " : ACTIVE \r\n";
|
||||
} else {
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"version": "2023.8.16"
|
||||
"version": "2023.8.18"
|
||||
}
|
Reference in New Issue
Block a user