Upload files to "system/autoload"
Signed-off-by: nestict <icttechnest@gmail.com>
This commit is contained in:
parent
dbe54cb3d0
commit
585a7382f1
61
system/autoload/Admin.php
Normal file
61
system/autoload/Admin.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
||||
* by https://t.me/ibnux
|
||||
**/
|
||||
|
||||
|
||||
class Admin
|
||||
{
|
||||
|
||||
public static function getID()
|
||||
{
|
||||
global $db_password;
|
||||
if (isset($_SESSION['aid'])) {
|
||||
return $_SESSION['aid'];
|
||||
} else if (isset($_COOKIE['aid'])) {
|
||||
// id.time.sha1
|
||||
$tmp = explode('.', $_COOKIE['aid']);
|
||||
if (sha1($tmp[0] . '.' . $tmp[1] . '.' . $db_password) == $tmp[2]) {
|
||||
if (time() - $tmp[1] < 86400 * 7) {
|
||||
$_SESSION['aid'] = $tmp[0];
|
||||
return $tmp[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function setCookie($aid)
|
||||
{
|
||||
global $db_password;
|
||||
if (isset($aid)) {
|
||||
$time = time();
|
||||
$token = $aid . '.' . $time . '.' . sha1($aid . '.' . $time . '.' . $db_password);
|
||||
setcookie('aid', $token, time() + 86400 * 7);
|
||||
return $token;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
public static function removeCookie()
|
||||
{
|
||||
if (isset($_COOKIE['aid'])) {
|
||||
setcookie('aid', '', time() - 86400);
|
||||
}
|
||||
}
|
||||
|
||||
public static function _info($id = 0)
|
||||
{
|
||||
if (empty($id) && $id == 0) {
|
||||
$id = Admin::getID();
|
||||
}
|
||||
if ($id) {
|
||||
return ORM::for_table('tbl_users')->find_one($id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
29
system/autoload/App.php
Normal file
29
system/autoload/App.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
||||
* by https://t.me/ibnux
|
||||
**/
|
||||
|
||||
|
||||
class App{
|
||||
public static function _run(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getToken(){
|
||||
return md5(microtime());
|
||||
}
|
||||
|
||||
public static function setToken($token, $value){
|
||||
$_SESSION[$token] = $value;
|
||||
}
|
||||
|
||||
public static function getTokenValue($key){
|
||||
if(isset($_SESSION[$key])){
|
||||
return $_SESSION[$key];
|
||||
}else{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
64
system/autoload/Balance.php
Normal file
64
system/autoload/Balance.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
||||
* by https://t.me/ibnux
|
||||
**/
|
||||
/**
|
||||
* This script is for managing user balance
|
||||
**/
|
||||
|
||||
class Balance
|
||||
{
|
||||
|
||||
public static function plus($id_customer, $amount)
|
||||
{
|
||||
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
|
||||
$c->balance = $amount + $c['balance'];
|
||||
$c->save();
|
||||
}
|
||||
|
||||
public static function transfer($id_customer, $phoneTarget, $amount)
|
||||
{
|
||||
global $config;
|
||||
if (Balance::min($id_customer, $amount)) {
|
||||
return Balance::plusByPhone($phoneTarget, $amount);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function min($id_customer, $amount)
|
||||
{
|
||||
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
|
||||
if ($c && $c['balance'] >= $amount) {
|
||||
$c->balance = $c['balance'] - $amount;
|
||||
$c->save();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function plusByPhone($phone_customer, $amount)
|
||||
{
|
||||
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
|
||||
if ($c) {
|
||||
$c->balance = $amount + $c['balance'];
|
||||
$c->save();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function minByPhone($phone_customer, $amount)
|
||||
{
|
||||
$c = ORM::for_table('tbl_customers')->where('username', $phone_customer)->find_one();
|
||||
if ($c && $c['balance'] >= $amount) {
|
||||
$c->balance = $c['balance'] - $amount;
|
||||
$c->save();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
55
system/autoload/Csrf.php
Normal file
55
system/autoload/Csrf.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
||||
* by https://t.me/ibnux
|
||||
**/
|
||||
|
||||
|
||||
class Csrf
|
||||
{
|
||||
private static $tokenExpiration = 1800; // 30 minutes
|
||||
|
||||
public static function generateToken($length = 16)
|
||||
{
|
||||
return bin2hex(random_bytes($length));
|
||||
}
|
||||
|
||||
public static function validateToken($token, $storedToken)
|
||||
{
|
||||
return hash_equals($token, $storedToken);
|
||||
}
|
||||
|
||||
public static function check($token)
|
||||
{
|
||||
global $config;
|
||||
if($config['csrf_enabled'] == 'yes') {
|
||||
if (isset($_SESSION['csrf_token'], $_SESSION['csrf_token_time'], $token)) {
|
||||
$storedToken = $_SESSION['csrf_token'];
|
||||
$tokenTime = $_SESSION['csrf_token_time'];
|
||||
|
||||
if (time() - $tokenTime > self::$tokenExpiration) {
|
||||
self::clearToken();
|
||||
return false;
|
||||
}
|
||||
|
||||
return self::validateToken($token, $storedToken);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function generateAndStoreToken()
|
||||
{
|
||||
$token = self::generateToken();
|
||||
$_SESSION['csrf_token'] = $token;
|
||||
$_SESSION['csrf_token_time'] = time();
|
||||
return $token;
|
||||
}
|
||||
|
||||
public static function clearToken()
|
||||
{
|
||||
unset($_SESSION['csrf_token'], $_SESSION['csrf_token_time']);
|
||||
}
|
||||
}
|
108
system/autoload/File.php
Normal file
108
system/autoload/File.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
||||
* by https://t.me/ibnux
|
||||
**/
|
||||
class File
|
||||
{
|
||||
|
||||
public static function copyFolder($from, $to, $exclude = [])
|
||||
{
|
||||
$files = scandir($from);
|
||||
foreach ($files as $file) {
|
||||
if (is_file($from . $file) && !in_array($file, $exclude)) {
|
||||
if (file_exists($to . $file)) unlink($to . $file);
|
||||
rename($from . $file, $to . $file);
|
||||
} else if (is_dir($from . $file) && !in_array($file, ['.', '..'])) {
|
||||
if (!file_exists($to . $file)) {
|
||||
mkdir($to . $file);
|
||||
}
|
||||
File::copyFolder($from . $file . DIRECTORY_SEPARATOR, $to . $file . DIRECTORY_SEPARATOR, $exclude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteFolder($path)
|
||||
{
|
||||
$files = scandir($path);
|
||||
foreach ($files as $file) {
|
||||
if (is_file($path . $file)) {
|
||||
unlink($path . $file);
|
||||
} else if (is_dir($path . $file) && !in_array($file, ['.', '..'])) {
|
||||
File::deleteFolder($path . $file . DIRECTORY_SEPARATOR);
|
||||
rmdir($path . $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
|
||||
*
|
||||
* @access public
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public static function pathFixer($path)
|
||||
{
|
||||
return str_replace("/", DIRECTORY_SEPARATOR, $path);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user