Merge pull request #11 from hotspotbilling/Development

Add self Update Script
This commit is contained in:
iBNu Maksum 2023-08-01 16:30:31 +07:00 committed by GitHub
commit 11b54bdcc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 302 additions and 60 deletions

3
.gitignore vendored
View File

@ -17,3 +17,6 @@ system/paymentgateway/**
!system/plugin/ui/
system/plugin/ui/*
!system/plugin/ui/index.html
ui/ui_custom/**
!ui/ui_custom/index.html
!ui/ui_custom/README.md

View File

@ -2,6 +2,12 @@
# CHANGELOG
## 2023.8.1
- Add Update file script, one click updating PHPNuxBill
- Add Custom UI folder, to custome your own template
- Delete debug text
- Fix Vendor JS
## 2023.7.28
- Fix link buy Voucher

View File

@ -5,21 +5,16 @@ class File
public static function copyFolder($from, $to, $exclude = [])
{
echo "copyFolder($from, $to);<br>";
$files = scandir($from);
print_r($files);
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);
echo "rename($from$file, $to$file);<br>";
} else if (is_dir($from . $file) && !in_array($file, ['.', '..'])) {
if (!file_exists($to . $file)) {
echo "mkdir($to$file);;<br>";
mkdir($to . $file);
}
echo "File::copyFolder($from$file, $to$file);<br>";
File::copyFolder($from . $file . DIRECTORY_SEPARATOR, $to . $file . DIRECTORY_SEPARATOR);
File::copyFolder($from . $file . DIRECTORY_SEPARATOR, $to . $file . DIRECTORY_SEPARATOR, $exclude);
}
}
}
@ -29,15 +24,12 @@ class File
$files = scandir($path);
foreach ($files as $file) {
if (is_file($path . $file)) {
echo "unlink($path$file);<br>";
unlink($path . $file);
} else if (is_dir($path . $file) && !in_array($file, ['.', '..'])) {
File::deleteFolder($path . $file . DIRECTORY_SEPARATOR);
echo "rmdir($path$file);<br>";
rmdir($path . $file);
}
}
echo "rmdir($path);<br>";
rmdir($path);
}

View File

@ -55,7 +55,7 @@ ORM::configure('username', $db_user);
ORM::configure('password', $db_password);
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
ORM::configure('return_result_sets', true);
if($_app_stage != 'Live'){
if ($_app_stage != 'Live') {
ORM::configure('logging', true);
}
@ -67,7 +67,7 @@ foreach ($result as $value) {
date_default_timezone_set($config['timezone']);
$_c = $config;
if($config['radius_mode']){
if ($config['radius_mode']) {
ORM::configure("mysql:host=$radius_host;dbname=$radius_name", null, 'radius');
ORM::configure('username', $radius_user, 'radius');
ORM::configure('password', $radius_password, 'radius');
@ -84,7 +84,7 @@ function _notify($msg, $type = 'e')
$lan_file = 'system/lan/' . $config['language'] . '/common.lan.php';
require($lan_file);
$ui = new Smarty();
$ui->setTemplateDir('ui/ui/');
$ui->setTemplateDir(['custom' => 'ui/ui_custom/', 'default' => 'ui/ui/']);
$ui->addTemplateDir('system/paymentgateway/ui/', 'pg');
$ui->addTemplateDir('system/plugin/ui/', 'plugin');
$ui->setCompileDir('ui/compiled/');
@ -130,8 +130,7 @@ include "autoload/Hookers.php";
//register all plugin
foreach (glob("system/plugin/*.php") as $filename)
{
foreach (glob("system/plugin/*.php") as $filename) {
include $filename;
}
@ -290,25 +289,25 @@ if (file_exists($sys_render)) {
// "function" => $function
$ui->assign('_system_menu', $routes[0]);
foreach ($menu_registered as $menu) {
if($menu['admin'] && _admin(false)) {
$menus[$menu['position']] .= '<li'.(($routes[1]==$menu['function'])?' class="active"':'').'><a href="'.U.'plugin/'.$menu['function'].'">';
if(!empty($menu['icon'])){
$menus[$menu['position']] .= '<i class="'.$menu['icon'].'"></i>';
if ($menu['admin'] && _admin(false)) {
$menus[$menu['position']] .= '<li' . (($routes[1] == $menu['function']) ? ' class="active"' : '') . '><a href="' . U . 'plugin/' . $menu['function'] . '">';
if (!empty($menu['icon'])) {
$menus[$menu['position']] .= '<i class="' . $menu['icon'] . '"></i>';
}
$menus[$menu['position']] .= '<span class="text">'.$menu['name'].'</span></a></li>';
}else if(!$menu['admin'] && _auth(false)) {
$menus[$menu['position']] .= '<li'.(($routes[1]==$menu['function'])?' class="active"':'').'><a href="'.U.'plugin/'.$menu['function'].'">';
if(!empty($menu['icon'])){
$menus[$menu['position']] .= '<i class="'.$menu['icon'].'"></i>';
$menus[$menu['position']] .= '<span class="text">' . $menu['name'] . '</span></a></li>';
} else if (!$menu['admin'] && _auth(false)) {
$menus[$menu['position']] .= '<li' . (($routes[1] == $menu['function']) ? ' class="active"' : '') . '><a href="' . U . 'plugin/' . $menu['function'] . '">';
if (!empty($menu['icon'])) {
$menus[$menu['position']] .= '<i class="' . $menu['icon'] . '"></i>';
}
$menus[$menu['position']] .= '<span class="text">'.$menu['name'].'</span></a></li>';
$menus[$menu['position']] .= '<span class="text">' . $menu['name'] . '</span></a></li>';
}
}
foreach ($menus as $k => $v) {
$ui->assign('_MENU_'.$k, $v);
$ui->assign('_MENU_' . $k, $v);
}
unset($menus, $menu_registered);
include($sys_render);
} else {
r2(U.'dashboard', 'e', 'not found');
r2(U . 'dashboard', 'e', 'not found');
}

View File

@ -8,10 +8,13 @@
</div>
<div class="box-body">Get help from community</div>
<div class="box-footer">
<a href="https://github.com/hotspotbilling/phpnuxbill/discussions" target="_blank"
class="btn btn-primary btn-lg btn-block"><i class="ion ion-chatboxes"></i> Github Discussions</a>
<a href="https://t.me/phpnuxbill" target="_blank"
class="btn btn-primary btn-lg btn-block"><i class="ion ion-chatboxes"></i> Telegram Group</a>
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<a href="https://github.com/hotspotbilling/phpnuxbill/discussions" target="_blank"
class="btn btn-primary btn-lg btn-block"><i class="ion ion-chatboxes"></i> Github
Discussions</a>
<a href="https://t.me/phpnuxbill" target="_blank" class="btn btn-primary btn-lg btn-block"><i
class="ion ion-chatboxes"></i> Telegram Group</a>
</div>
</div>
</div>
</div>
@ -58,10 +61,12 @@
</table>
</div>
<div class="box-footer">
<a href="https://trakteer.id/ibnux" target="_blank"
class="btn btn-primary btn-lg btn-block">Trakteer</a>
<a href="https://karyakarsa.com/ibnux/support" target="_blank"
class="btn btn-primary btn-lg btn-block">karyakarsa</a>
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<a href="https://trakteer.id/ibnux" target="_blank"
class="btn btn-primary btn-lg btn-block">Trakteer</a>
<a href="https://karyakarsa.com/ibnux/support" target="_blank"
class="btn btn-primary btn-lg btn-block">karyakarsa</a>
</div>
</div>
</div>
</div>
@ -107,14 +112,21 @@
<div class="box-header">
<h3 class="box-title">Chat with me</h3>
</div>
<div class="box-body">Paid Support?<br>donation confirmation?<br>Or ask any Donation Alternative</div>
<div class="box-body">$50 Paid Support<br>donation confirmation?<br>Or ask any Donation Alternative</div>
<div class="box-footer">
<a href="https://t.me/ibnux" target="_blank" class="btn btn-primary btn-lg btn-block">Telegram</a>
<a href="https://twitter.com/messages/compose?recipient_id=20653807&text=Hello+i+am+phpnuxbill+user"
target="_blank" class="btn btn-primary btn-lg btn-block">Twitter</a>
<a href="https://m.me/ibnumaksum" target="_blank" class="btn btn-primary btn-lg btn-block">Facebook
Messenger</a>
<a href="https://keybase.io/ibnux" target="_blank" class="btn btn-primary btn-lg btn-block">Keybase</a>
</div>
</div>
<div class="box box-primary box-hovered mb20 activities">
<div class="box-header">
<h3 class="box-title">Free WhatsApp Gateway and Telegram Bot creater</h3>
</div>
<div class="box-body">
There is a Telegram bot wizard in here
</div>
<div class="box-footer">
<a href="https://wa.nux.my.id/login" target="_blank"
class="btn btn-primary btn-lg btn-block">wa.nux.my.id</a>
</div>
</div>
</div>
@ -129,20 +141,12 @@
<div class="box-footer" id="currentVersion">ver</div>
<div class="box-footer" id="latestVersion">ver</div>
<div class="box-footer">
<a href="https://github.com/hotspotbilling/phpnuxbill/" target="_blank"
class="btn btn-primary btn-lg btn-block">Get Latest Version</a>
</div>
</div>
<div class="box box-primary box-hovered mb20 activities">
<div class="box-header">
<h3 class="box-title">Free WhatsApp Gateway and Telegram Bot creater</h3>
</div>
<div class="box-body">
There is a Telegram bot wizard in here
</div>
<div class="box-footer">
<a href="https://wa.nux.my.id/login" target="_blank"
class="btn btn-primary btn-lg btn-block">wa.nux.my.id</a>
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<a href="./update.php" target="_blank"
class="btn btn-success btn-lg btn-block">Install Latest Version</a>
<a href="https://github.com/hotspotbilling/phpnuxbill/archive/refs/heads/master.zip" target="_blank"
class="btn btn-warning btn-lg btn-block">Download Latest Version</a>
</div>
</div>
</div>
</div>

View File

@ -117,7 +117,7 @@
</script>
<!--End of Tawk.to Script-->
{/if}
<script src="scripts/vendors.js"></script>
<script src="ui/ui/scripts/vendors.js"></script>
</body>
</html>

View File

@ -93,7 +93,7 @@
</script>
<!--End of Tawk.to Script-->
{/if}
<script src="scripts/vendors.js"></script>
<script src="ui/ui/scripts/vendors.js"></script>
</body>
</html>

View File

@ -115,7 +115,7 @@
</script>
<!--End of Tawk.to Script-->
{/if}
<script src="scripts/vendors.js"></script>
<script src="ui/ui/scripts/vendors.js"></script>
</body>
</html>

View File

@ -74,7 +74,7 @@
</div>
</div>
</div>
<script src="scripts/vendors.js"></script>
<script src="ui/ui/scripts/vendors.js"></script>
</body>
</html>

5
ui/ui_custom/README.md Normal file
View File

@ -0,0 +1,5 @@
# CUSTOM DESIGN
If you want to change the UI, copy the file from UI, to here, and edit as you need, so it will not be overwrite when updating
Jika mau mengubah tampilan UI, salin filenya dari folder UI kesini, lalu ubah sesuai keinginan, sehingga tidak akan ditimpa saat ada update

0
ui/ui_custom/index.html Normal file
View File

233
update.php Normal file
View File

@ -0,0 +1,233 @@
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
*
* This script is for updating PHPNuxBill
**/
session_start();
$download_url = 'https://github.com/hotspotbilling/phpnuxbill/archive/refs/heads/master.zip';
if (!isset($_SESSION['aid']) || empty($_SESSION['aid'])) {
r2("./?_route=login&You_are_not_admin", 'e', 'You are not admin');
}
set_time_limit(-1);
if (!is_writeable(pathFixer('system/cache/'))) {
r2("./?_route=community", 'e', 'Folder system/cache/ is not writable');
}
if (!is_writeable(pathFixer('.'))) {
r2("./?_route=community", 'e', 'Folder web is not writable');
}
$step = $_GET['step'];
$continue = true;
if (!extension_loaded('zip')) {
$msg = "No PHP ZIP extension is available";
$msgType = "danger";
$continue = false;
}
$file = pathFixer('system/cache/phpnuxbill.zip');
$folder = pathFixer('system/cache/phpnuxbill-master/');
if (empty($step)) {
$step++;
} else if ($step == 1) {
if (file_exists($file)) unlink($file);
// Download update
$fp = fopen($file, 'w+');
$ch = curl_init($download_url);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 600);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
if (file_exists($file)) {
$step++;
} else {
$msg = "Failed to download Update file";
$msgType = "danger";
$continue = false;
}
} else if ($step == 2) {
$zip = new ZipArchive();
$zip->open($file);
$zip->extractTo(pathFixer('system/cache/'));
$zip->close();
if (file_exists($folder)) {
$step++;
} else {
$msg = "Failed to extract update file";
$msgType = "danger";
$continue = false;
}
// remove downloaded zip
if (file_exists($file)) unlink($file);
} else if ($step == 3) {
copyFolder($folder, pathFixer('./'));
deleteFolder('install/');
deleteFolder($folder);
if (!file_exists($folder . pathFixer('/system/'))) {
$step++;
} else {
$msg = "Failed to install update file.";
$msgType = "danger";
$continue = false;
}
} else {
$version = json_decode(file_get_contents('version.json'), true)['version'];
$continue = false;
}
function pathFixer($path)
{
return str_replace("/", DIRECTORY_SEPARATOR, $path);
}
function r2($to, $ntype = 'e', $msg = '')
{
if ($msg == '') {
header("location: $to");
exit;
}
$_SESSION['ntype'] = $ntype;
$_SESSION['notify'] = $msg;
header("location: $to");
exit;
}
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);
}
copyFolder($from . $file . DIRECTORY_SEPARATOR, $to . $file . DIRECTORY_SEPARATOR);
}
}
}
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, ['.', '..'])) {
deleteFolder($path . $file . DIRECTORY_SEPARATOR);
rmdir($path . $file);
}
}
rmdir($path);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>PHPNuxBill Updater</title>
<link rel="shortcut icon" href="ui/ui/images/logo.png" type="image/x-icon" />
<link rel="stylesheet" href="ui/ui/styles/bootstrap.min.css">
<link rel="stylesheet" href="ui/ui/fonts/ionicons/css/ionicons.min.css">
<link rel="stylesheet" href="ui/ui/fonts/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="ui/ui/fonts/MaterialDesign/css/materialdesignicons.min.css">
<link rel="stylesheet" href="ui/ui/styles/adminlte.min.css">
<link rel="stylesheet" href="ui/ui/styles/skin-blue.min.css">
<?php if ($continue) { ?>
<meta http-equiv="refresh" content="1; ./update.php?step=<?= $step ?>">
<?php } ?>
<style>
::-moz-selection {
/* Code for Firefox */
color: red;
background: yellow;
}
::selection {
color: red;
background: yellow;
}
</style>
</head>
<body class="hold-transition skin-blue">
<div class="container">
<section class="content-header">
<h1 class="text-center">
Update PHP NuxBill
</h1>
</section>
<section class="content">
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<?php if (!empty($msgType) && !empty($msg)) { ?>
<div class="alert alert-<?= $msgType ?>" role="alert">
<?= $msg ?>
</div>
<?php } ?>
<?php if ($continue || $step == 4) { ?>
<?php if ($step == 1) { ?>
<div class="panel panel-primary">
<div class="panel-heading">Step 1</div>
<div class="panel-body">
Downloading update<br>
Please wait....
</div>
</div>
<?php } else if ($step == 2) { ?>
<div class="panel panel-primary">
<div class="panel-heading">Step 2</div>
<div class="panel-body">
extracting<br>
Please wait....
</div>
</div>
<?php } else if ($step == 3) { ?>
<div class="panel panel-primary">
<div class="panel-heading">Step 3</div>
<div class="panel-body">
Installing<br>
Please wait....
</div>
</div>
<?php } else if ($step == 4) { ?>
<div class="panel panel-primary">
<div class="panel-success">Update Finished</div>
<div class="panel-body">
PHPNuxBill has been updated to Version <b><?= $version ?></b>
</div>
</div>
<meta http-equiv="refresh" content="5; ./index.php?_route=dashboard">
<?php } ?>
<?php } ?>
</div>
</div>
</section>
<footer class="footer text-center">
PHPNuxBill by <a href="https://github.com/hotspotbilling/phpnuxbill" rel="nofollow noreferrer noopener" target="_blank">iBNuX</a>
</footer>
</div>
</body>
</html>

View File

@ -1,3 +1,3 @@
{
"version": "2023.7.28"
"version": "2023.8.1"
}