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