Files
.github
admin
docs
install
pages_template
qrcode
scan
system
autoload
cache
controllers
accounts.php
admin.php
autoload.php
autoload_user.php
bandwidth.php
callback.php
community.php
customers.php
dashboard.php
default.php
export.php
home.php
index.html
login.php
logout.php
logs.php
map.php
message.php
order.php
page.php
pages.php
paymentgateway.php
plan.php
plugin.php
pluginmanager.php
pool.php
radius.php
register.php
reports.php
routers.php
services.php
settings.php
voucher.php
devices
lan
paymentgateway
plugin
uploads
vendor
.htaccess
api.php
boot.php
composer.json
composer.lock
cron.php
cron_reminder.php
index.html
orm.php
updates.json
ui
.gitignore
.htaccess_firewall
CHANGELOG.md
Dockerfile
LICENSE
README.md
composer.json
config.sample.php
docker-compose.example.yml
favicon.ico
index.php
init.php
radius.php
update.php
version.json
mitrobill/system/controllers/pluginmanager.php

281 lines
12 KiB
PHP
Raw Normal View History

2023-01-31 14:26:49 +07:00
<?php
2024-02-26 14:38:04 +07:00
2023-01-31 14:26:49 +07:00
/**
2023-10-12 15:55:42 +07:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
2023-01-31 14:26:49 +07:00
**/
2023-10-12 15:55:42 +07:00
2023-01-31 14:26:49 +07:00
_admin();
2024-01-18 17:24:21 +07:00
$ui->assign('_title', 'Plugin Manager');
2023-01-31 14:26:49 +07:00
$ui->assign('_system_menu', 'settings');
2023-03-08 11:08:56 +07:00
$plugin_repository = 'https://hotspotbilling.github.io/Plugin-Repository/repository.json';
2023-01-31 14:26:49 +07:00
$action = $routes['1'];
$ui->assign('_admin', $admin);
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
2024-02-26 14:38:04 +07:00
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2023-01-31 14:26:49 +07:00
}
2024-02-26 14:38:04 +07:00
$cache = $CACHE_PATH . File::pathFixer('/plugin_repository.json');
2023-07-28 15:38:52 +07:00
if (file_exists($cache) && time() - filemtime($cache) < (24 * 60 * 60)) {
2023-09-13 10:07:58 +07:00
$txt = file_get_contents($cache);
$json = json_decode($txt, true);
2024-02-26 14:38:04 +07:00
if (empty($json['plugins']) && empty($json['payment_gateway'])) {
2023-09-13 10:07:58 +07:00
unlink($cache);
2024-06-19 14:00:04 +07:00
r2(U . 'pluginmanager');
2023-09-13 10:07:58 +07:00
}
2023-03-08 11:08:56 +07:00
} else {
$data = Http::getData($plugin_repository);
2023-03-08 11:08:56 +07:00
file_put_contents($cache, $data);
$json = json_decode($data, true);
}
2023-01-31 14:26:49 +07:00
switch ($action) {
2024-06-19 14:00:04 +07:00
case 'refresh':
if (file_exists($cache)) unlink($cache);
r2(U . "pluginmanager", 's', 'Refresh success');
break;
2024-06-12 17:02:52 +07:00
case 'dlinstall':
if($_app_stage == 'demo'){
r2(U . "pluginmanager", 'e', 'Demo Mode cannot install as it Security risk');
}
2024-06-12 17:02:52 +07:00
if (!is_writeable($CACHE_PATH)) {
r2(U . "pluginmanager", 'e', 'Folder cache/ is not writable');
}
if (!is_writeable($PLUGIN_PATH)) {
r2(U . "pluginmanager", 'e', 'Folder plugin/ is not writable');
}
if (!is_writeable($DEVICE_PATH)) {
r2(U . "pluginmanager", 'e', 'Folder devices/ is not writable');
}
if (!is_writeable($UI_PATH . DIRECTORY_SEPARATOR . 'themes')) {
r2(U . "pluginmanager", 'e', 'Folder themes/ is not writable');
}
$cache = $CACHE_PATH . DIRECTORY_SEPARATOR . 'installer' . DIRECTORY_SEPARATOR;
if (!file_exists($cache)) {
mkdir($cache);
}
if (file_exists($_FILES['zip_plugin']['tmp_name'])) {
$zip = new ZipArchive();
$zip->open($_FILES['zip_plugin']['tmp_name']);
$zip->extractTo($cache);
$zip->close();
unlink($_FILES['zip_plugin']['tmp_name']);
//moving
if (file_exists($cache . 'plugin')) {
File::copyFolder($cache . 'plugin' . DIRECTORY_SEPARATOR, $PLUGIN_PATH . DIRECTORY_SEPARATOR);
}
if (file_exists($cache . 'paymentgateway')) {
File::copyFolder($cache . 'paymentgateway' . DIRECTORY_SEPARATOR, $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR);
}
if (file_exists($cache . 'theme')) {
File::copyFolder($cache . 'theme' . DIRECTORY_SEPARATOR, $UI_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR);
}
if (file_exists($cache . 'device')) {
File::copyFolder($cache . 'device' . DIRECTORY_SEPARATOR, $DEVICE_PATH . DIRECTORY_SEPARATOR);
}
//Cleaning
File::deleteFolder($cache);
r2(U . "pluginmanager", 's', 'Installation success');
} else if (_post('gh_url', '') != '') {
$ghUrl = _post('gh_url', '');
$plugin = basename($ghUrl);
$file = $cache . $plugin . '.zip';
$fp = fopen($file, 'w+');
$ch = curl_init($ghUrl . '/archive/refs/heads/master.zip');
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
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);
$zip = new ZipArchive();
$zip->open($file);
$zip->extractTo($cache);
$zip->close();
$folder = $cache . DIRECTORY_SEPARATOR . $plugin . '-main' . DIRECTORY_SEPARATOR;
if (file_exists($folder . 'plugin')) {
File::copyFolder($folder . 'plugin' . DIRECTORY_SEPARATOR, $PLUGIN_PATH . DIRECTORY_SEPARATOR);
}
if (file_exists($folder . 'paymentgateway')) {
File::copyFolder($folder . 'paymentgateway' . DIRECTORY_SEPARATOR, $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR);
}
if (file_exists($folder . 'theme')) {
File::copyFolder($folder . 'theme' . DIRECTORY_SEPARATOR, $UI_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR);
}
if (file_exists($folder . 'device')) {
File::copyFolder($folder . 'device' . DIRECTORY_SEPARATOR, $DEVICE_PATH . DIRECTORY_SEPARATOR);
}
File::deleteFolder($cache);
r2(U . "pluginmanager", 's', 'Installation success');
} else {
r2(U . 'pluginmanager', 'e', 'Nothing Installed');
}
break;
2024-03-12 10:42:42 +07:00
case 'delete':
2024-02-26 14:38:04 +07:00
if (!is_writeable($CACHE_PATH)) {
r2(U . "pluginmanager", 'e', 'Folder cache/ is not writable');
2023-03-08 11:08:56 +07:00
}
2024-02-26 14:38:04 +07:00
if (!is_writeable($PLUGIN_PATH)) {
r2(U . "pluginmanager", 'e', 'Folder plugin/ is not writable');
2023-03-08 11:08:56 +07:00
}
set_time_limit(-1);
$tipe = $routes['2'];
$plugin = $routes['3'];
2024-03-12 10:42:42 +07:00
$file = $CACHE_PATH . DIRECTORY_SEPARATOR . $plugin . '.zip';
if (file_exists($file)) unlink($file);
if ($tipe == 'plugin') {
foreach ($json['plugins'] as $plg) {
if ($plg['id'] == $plugin) {
$fp = fopen($file, 'w+');
$ch = curl_init($plg['github'] . '/archive/refs/heads/master.zip');
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
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);
$zip = new ZipArchive();
$zip->open($file);
$zip->extractTo($CACHE_PATH);
$zip->close();
$folder = $CACHE_PATH . File::pathFixer('/' . $plugin . '-main/');
if (!file_exists($folder)) {
$folder = $CACHE_PATH . File::pathFixer('/' . $plugin . '-master/');
}
if (!file_exists($folder)) {
r2(U . "pluginmanager", 'e', 'Extracted Folder is unknown');
}
scanAndRemovePath($folder, $PLUGIN_PATH . DIRECTORY_SEPARATOR);
File::deleteFolder($folder);
unlink($file);
r2(U . "pluginmanager", 's', 'Plugin ' . $plugin . ' has been deleted');
break;
}
}
break;
}
break;
case 'install':
if (!is_writeable($CACHE_PATH)) {
r2(U . "pluginmanager", 'e', 'Folder cache/ is not writable');
}
if (!is_writeable($PLUGIN_PATH)) {
r2(U . "pluginmanager", 'e', 'Folder plugin/ is not writable');
}
2024-03-13 09:37:45 +07:00
set_time_limit(-1);
$tipe = $routes['2'];
$plugin = $routes['3'];
2024-03-12 10:42:42 +07:00
$file = $CACHE_PATH . DIRECTORY_SEPARATOR . $plugin . '.zip';
2023-03-08 11:08:56 +07:00
if (file_exists($file)) unlink($file);
if ($tipe == 'plugin') {
foreach ($json['plugins'] as $plg) {
if ($plg['id'] == $plugin) {
$fp = fopen($file, 'w+');
2024-02-26 14:38:04 +07:00
$ch = curl_init($plg['github'] . '/archive/refs/heads/master.zip');
2023-03-08 11:08:56 +07:00
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
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);
$zip = new ZipArchive();
$zip->open($file);
2024-02-26 14:38:04 +07:00
$zip->extractTo($CACHE_PATH);
2023-03-08 11:08:56 +07:00
$zip->close();
2024-02-26 14:38:04 +07:00
$folder = $CACHE_PATH . File::pathFixer('/' . $plugin . '-main/');
if (!file_exists($folder)) {
$folder = $CACHE_PATH . File::pathFixer('/' . $plugin . '-master/');
2023-03-08 11:08:56 +07:00
}
2024-02-26 14:38:04 +07:00
if (!file_exists($folder)) {
2023-03-08 11:08:56 +07:00
r2(U . "pluginmanager", 'e', 'Extracted Folder is unknown');
}
2024-02-26 14:38:04 +07:00
File::copyFolder($folder, $PLUGIN_PATH . DIRECTORY_SEPARATOR, ['README.md', 'LICENSE']);
2023-03-08 11:08:56 +07:00
File::deleteFolder($folder);
unlink($file);
2024-03-13 09:37:45 +07:00
r2(U . "pluginmanager", 's', 'Plugin ' . $plugin . ' has been installed');
2023-03-08 11:08:56 +07:00
break;
}
}
break;
} else if ($tipe == 'payment') {
foreach ($json['payment_gateway'] as $plg) {
if ($plg['id'] == $plugin) {
$fp = fopen($file, 'w+');
2024-02-26 14:38:04 +07:00
$ch = curl_init($plg['github'] . '/archive/refs/heads/master.zip');
2023-03-08 11:08:56 +07:00
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
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);
$zip = new ZipArchive();
$zip->open($file);
2024-02-26 14:38:04 +07:00
$zip->extractTo($CACHE_PATH);
2023-03-08 11:08:56 +07:00
$zip->close();
2024-02-26 14:38:04 +07:00
$folder = $CACHE_PATH . File::pathFixer('/' . $plugin . '-main/');
if (!file_exists($folder)) {
$folder = $CACHE_PATH . File::pathFixer('/' . $plugin . '-master/');
2023-03-08 11:08:56 +07:00
}
2024-02-26 14:38:04 +07:00
if (!file_exists($folder)) {
2023-03-08 11:08:56 +07:00
r2(U . "pluginmanager", 'e', 'Extracted Folder is unknown');
}
2024-02-26 14:38:04 +07:00
File::copyFolder($folder, $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR, ['README.md', 'LICENSE']);
2023-03-08 11:08:56 +07:00
File::deleteFolder($folder);
unlink($file);
2024-02-26 14:38:04 +07:00
r2(U . "paymentgateway", 's', 'Payment Gateway ' . $plugin . ' has been installed');
2023-03-08 11:08:56 +07:00
break;
}
}
break;
}
2023-01-31 14:26:49 +07:00
default:
2023-03-08 11:08:56 +07:00
if (class_exists('ZipArchive')) {
$zipExt = true;
} else {
$zipExt = false;
2023-01-31 14:26:49 +07:00
}
2023-03-08 11:08:56 +07:00
$ui->assign('zipExt', $zipExt);
2023-01-31 14:26:49 +07:00
$ui->assign('plugins', $json['plugins']);
$ui->assign('pgs', $json['payment_gateway']);
$ui->display('plugin-manager.tpl');
}
2024-03-12 10:42:42 +07:00
function scanAndRemovePath($source, $target)
{
$files = scandir($source);
foreach ($files as $file) {
if (is_file($source . $file)) {
2024-06-12 17:02:52 +07:00
if (file_exists($target . $file)) {
2024-03-12 10:42:42 +07:00
unlink($target . $file);
}
} else if (is_dir($source . $file) && !in_array($file, ['.', '..'])) {
2024-06-12 17:02:52 +07:00
scanAndRemovePath($source . $file . DIRECTORY_SEPARATOR, $target . $file . DIRECTORY_SEPARATOR);
if (file_exists($target . $file)) {
2024-03-12 10:42:42 +07:00
rmdir($target . $file);
}
}
}
2024-06-12 17:02:52 +07:00
if (file_exists($target)) {
2024-03-12 10:42:42 +07:00
rmdir($target);
}
2024-06-12 17:02:52 +07:00
}