Skip to content

Commit

Permalink
Merge branch 'Development'
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnux committed Apr 23, 2024
2 parents 2a70236 + 8dc7707 commit 9712d41
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 166 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

# CHANGELOG

## 2024.4.23

- Fix Pagination Voucher
- Fix Languange Translation
- Fix Alert Confirmation for requesting Extend
- Send Telegram Notification when Customer request to extend expiration
- prepaid users export list by @freeispradius
- fix show voucher by @agstrxyz

## 2024.4.21

- Restore old cron
Expand Down
2 changes: 1 addition & 1 deletion init.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function Lang($key)

function alphanumeric($str, $tambahan = "")
{
return preg_replace("/[^a-zA-Z0-9" . $tambahan . "]+/", "", $str);
return Text::alphanumeric($str, $tambahan);
}

function showResult($success, $message = '', $result = [], $meta = [])
Expand Down
64 changes: 64 additions & 0 deletions system/autoload/Text.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
*
* This file is for Text Transformation
**/

class Text
{

public static function toHex($string)
{
return "\x" . implode("\x", str_split(array_shift(unpack('H*', $string)), 2));
}

public static function alphanumeric($str, $tambahan = "")
{
return preg_replace("/[^a-zA-Z0-9" . $tambahan . "]+/", "", $str);
}

public static function numeric($str)
{
return preg_replace("/[^0-9]+/", "", $str);
}

public static function ucWords($text)
{
return ucwords(str_replace('_', ' ', $text));
}

public static function randomUpLowCase($text)
{
$jml = strlen($text);
$result = '';
for ($i = 0; $i < $jml; $i++) {
if (rand(0, 99) % 2) {
$result .= strtolower(substr($text, $i, 1));
} else {
$result .= substr($text, $i, 1);
}
}
return $result;
}

public static function maskText($text){
$len = strlen($text);
if($len < 3){
return "***";
}else if($len<5){
return substr($text,0,1)."***".substr($text,-1,1);
}else if($len<8){
return substr($text,0,2)."***".substr($text,-2,2);
}else{
return substr($text,0,4)."******".substr($text,-3,3);
}
}

public static function sanitize($str)
{
return preg_replace("/[^A-Za-z0-9]/", '_', $str);;
}
}
113 changes: 100 additions & 13 deletions system/controllers/customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,126 @@
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}

$cs = ORM::for_table('tbl_customers')
->select('tbl_customers.id', 'id')
->select('tbl_customers.username', 'username')
->select('fullname')
->select('address')
->select('phonenumber')
->select('email')
->select('balance')
->select('service_type')
->order_by_asc('tbl_customers.id')
->find_array();

$h = false;
set_time_limit(-1);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-type: text/csv");
header('Content-Disposition: attachment;filename="phpnuxbill_customers_' . date('Y-m-d_H_i') . '.csv"');
header('Content-Transfer-Encoding: binary');

$headers = [
'id',
'username',
'fullname',
'address',
'phonenumber',
'email',
'balance',
'service_type',
];

if (!$h) {
echo '"' . implode('","', $headers) . "\"\n";
$h = true;
}

foreach ($cs as $c) {
$row = [
$c['id'],
$c['username'],
$c['fullname'],
$c['address'],
$c['phonenumber'],
$c['email'],
$c['balance'],
$c['service_type'],
];
echo '"' . implode('","', $row) . "\"\n";
}
break;
//case csv-prepaid can be moved later to (plan.php) php file dealing with prepaid users
case 'csv-prepaid':
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}

$cs = ORM::for_table('tbl_customers')
->select('tbl_customers.id', 'id')
->select('tbl_customers.username', 'username')
->select('fullname')
->select('address')
->select('phonenumber')
->select('email')
->select('balance')
->select('service_type')
->select('namebp')
->select('routers')
->select('status')
->select('method', 'Payment')
->join('tbl_user_recharges', array('tbl_customers.id', '=', 'tbl_user_recharges.customer_id'))
->order_by_asc('tbl_customers.id')->find_array();
->order_by_asc('tbl_customers.id')
->find_array();

$h = false;
set_time_limit(-1);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-type: text/csv");
header('Content-Disposition: attachment;filename="phpnuxbill_customers_' . date('Y-m-d_H_i') . '.csv"');
header('Content-Disposition: attachment;filename="phpnuxbill_prepaid_users' . date('Y-m-d_H_i') . '.csv"');
header('Content-Transfer-Encoding: binary');

$headers = [
'id',
'username',
'fullname',
'address',
'phonenumber',
'email',
'balance',
'service_type',
'namebp',
'routers',
'status',
'Payment'
];

if (!$h) {
echo '"' . implode('","', $headers) . "\"\n";
$h = true;
}

foreach ($cs as $c) {
$ks = [];
$vs = [];
foreach ($c as $k => $v) {
$ks[] = $k;
$vs[] = $v;
}
if (!$h) {
echo '"' . implode('";"', $ks) . "\"\n";
$h = true;
}
echo '"' . implode('";"', $vs) . "\"\n";
$row = [
$c['id'],
$c['username'],
$c['fullname'],
$c['address'],
$c['phonenumber'],
$c['email'],
$c['balance'],
$c['service_type'],
$c['namebp'],
$c['routers'],
$c['status'],
$c['Payment']
];
echo '"' . implode('","', $row) . "\"\n";
}
break;
case 'add':
Expand Down
18 changes: 12 additions & 6 deletions system/controllers/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,18 @@
$router = $tur['routers'];
}
$p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
$c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
if(!$p){
r2(U . 'home', '3', "Plan Not Found");
}
if ($tur['routers'] == 'radius') {
Radius::customerAddPlan($c, $p, $tur['expiration'] . ' ' . $tur['time']);
Radius::customerAddPlan($user, $p, $tur['expiration'] . ' ' . $tur['time']);
} else {
if ($tur['type'] == 'Hotspot') {
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::addHotspotUser($client, $p, $c);
Mikrotik::removeHotspotUser($client, $user['username']);
Mikrotik::addHotspotUser($client, $p, $user);
} else if ($tur['type'] == 'PPPOE') {
Mikrotik::removePpoeUser($client, $c['username']);
Mikrotik::addPpoeUser($client, $p, $c);
Mikrotik::removePpoeUser($client, $user['username']);
Mikrotik::addPpoeUser($client, $p, $user);
}
}
// make customer cannot extend again
Expand All @@ -169,6 +171,10 @@
App::setToken(_get('stoken'), $id);
file_put_contents($path, $m);
_log("Customer $tur[customer_id] $tur[username] extend for $days days", "Customer", $user['id']);
Message::sendTelegram("#u$user[username] #extend #".$p['type']." \n" . $p['name_plan'] .
"\nLocation: " . $p['routers'] .
"\nCustomer: " . $user['fullname'] .
"\nNew Expired: " . Lang::dateAndTimeFormat($expiration, $tur['time']));
r2(U . 'home', 's', "Extend until $expiration");
}else{
r2(U . 'home', 'e', "Plan is not expired");
Expand Down
48 changes: 19 additions & 29 deletions system/controllers/plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
$using = _post('using');
$stoken = _post('stoken');

if(!empty(App::getTokenValue($stoken))){
if (!empty(App::getTokenValue($stoken))) {
$username = App::getTokenValue($stoken);
$in = ORM::for_table('tbl_transactions')->where('username', $username)->order_by_desc('id')->find_one();
Package::createInvoice($in);
Expand Down Expand Up @@ -325,53 +325,42 @@

case 'voucher':
$ui->assign('_title', Lang::T('Vouchers'));
$limit = 10;
$page = _get('p', 0);
$pageNow = $page * $limit;
$search = _req('search');
if ($search != '') {
if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
$d = ORM::for_table('tbl_plans')->where('enabled', '1')
$query = ORM::for_table('tbl_plans')->where('enabled', '1')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where_like('tbl_voucher.code', '%' . $search . '%')
->offset($pageNow)
->limit($limit)
->findArray();
->where_like('tbl_voucher.code', '%' . $search . '%');
$d = Paginator::findMany($query, ["search" => $search]);
} else if ($admin['user_type'] == 'Agent') {
$sales = [];
$sls = ORM::for_table('tbl_users')->select('id')->where('root', $admin['id'])->findArray();
foreach ($sls as $s) {
$sales[] = $s['id'];
}
$sales[] = $admin['id'];
$d = ORM::for_table('tbl_plans')
$query = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where_in('generated_by', $sales)
->where_like('tbl_voucher.code', '%' . $search . '%')
->offset($pageNow)
->limit($limit)
->findArray();
->where_like('tbl_voucher.code', '%' . $search . '%');
$d = Paginator::findMany($query, ["search" => $search]);
}
} else {
if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
$d = ORM::for_table('tbl_plans')->where('enabled', '1')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->offset($pageNow)
->limit($limit)
->findArray();
$query = ORM::for_table('tbl_plans')->where('enabled', '1')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'));
$d = Paginator::findMany($query);
} else if ($admin['user_type'] == 'Agent') {
$sales = [];
$sls = ORM::for_table('tbl_users')->select('id')->where('root', $admin['id'])->findArray();
foreach ($sls as $s) {
$sales[] = $s['id'];
}
$sales[] = $admin['id'];
$d = ORM::for_table('tbl_plans')
$query = ORM::for_table('tbl_plans')
->join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan'))
->where_in('generated_by', $sales)
->offset($pageNow)
->limit($limit)
->findArray();
->where_in('generated_by', $sales);
$d = Paginator::findMany($query);
}
}
// extract admin
Expand Down Expand Up @@ -581,6 +570,7 @@
} else if ($voucher_format == 'rand') {
$code = Lang::randomUpLowCase($code);
}
die($code);
$d = ORM::for_table('tbl_voucher')->create();
$d->type = $type;
$d->routers = $server;
Expand Down Expand Up @@ -743,23 +733,23 @@
$id = $routes[2];
$days = $routes[3];
$stoken = $_GET['stoken'];
if(App::getTokenValue($stoken)){
if (App::getTokenValue($stoken)) {
r2(U . 'plan', 's', "Extend already done");
}
$tur = ORM::for_table('tbl_user_recharges')->find_one($id);
$status = $tur['status'];
if(strtotime($tur['expiration'].' '.$tur['time']) > time()){
if (strtotime($tur['expiration'] . ' ' . $tur['time']) > time()) {
// not expired
$expiration = date('Y-m-d', strtotime($tur['expiration']." +$days day"));
}else{
$expiration = date('Y-m-d', strtotime($tur['expiration'] . " +$days day"));
} else {
//expired
$expiration = date('Y-m-d', strtotime(" +$days day"));
}
$tur->expiration = $expiration;
$tur->status = "on";
$tur->save();
App::setToken($stoken, $id);
if($status=='off'){
if ($status == 'off') {
if ($tur['routers'] != 'radius') {
$mikrotik = Mikrotik::info($tur['routers']);
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Expand Down
Loading

0 comments on commit 9712d41

Please sign in to comment.