plugin manager detect old installation file

This commit is contained in:
Ibnu Maksum 2024-08-02 10:24:11 +07:00
parent 9578006e11
commit c2fffdab88
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -62,19 +62,38 @@ switch ($action) {
$zip->open($_FILES['zip_plugin']['tmp_name']);
$zip->extractTo($cache);
$zip->close();
$plugin = basename($_FILES['zip_plugin']['name']);
unlink($_FILES['zip_plugin']['tmp_name']);
$success = 0;
//moving
if (file_exists($cache . 'plugin')) {
File::copyFolder($cache . 'plugin' . DIRECTORY_SEPARATOR, $PLUGIN_PATH . DIRECTORY_SEPARATOR);
$success++;
}
if (file_exists($cache . 'paymentgateway')) {
File::copyFolder($cache . 'paymentgateway' . DIRECTORY_SEPARATOR, $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR);
$success++;
}
if (file_exists($cache . 'theme')) {
File::copyFolder($cache . 'theme' . DIRECTORY_SEPARATOR, $UI_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR);
$success++;
}
if (file_exists($cache . 'device')) {
File::copyFolder($cache . 'device' . DIRECTORY_SEPARATOR, $DEVICE_PATH . DIRECTORY_SEPARATOR);
$success++;
}
if ($success == 0) {
// old plugin and theme using this
$check = strtolower($ghUrl);
if (strpos($check, 'plugin') !== false) {
File::copyFolder($folder, $PLUGIN_PATH . DIRECTORY_SEPARATOR);
} else if (strpos($check, 'payment') !== false) {
File::copyFolder($folder, $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR);
} else if (strpos($check, 'theme') !== false) {
rename($folder, $UI_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $plugin);
} else if (strpos($check, 'device') !== false) {
File::copyFolder($folder, $DEVICE_PATH . DIRECTORY_SEPARATOR);
}
}
//Cleaning
File::deleteFolder($cache);
@ -102,17 +121,35 @@ switch ($action) {
$zip->extractTo($cache);
$zip->close();
$folder = $cache . DIRECTORY_SEPARATOR . $plugin . '-main' . DIRECTORY_SEPARATOR;
$success = 0;
if (file_exists($folder . 'plugin')) {
File::copyFolder($folder . 'plugin' . DIRECTORY_SEPARATOR, $PLUGIN_PATH . DIRECTORY_SEPARATOR);
$success++;
}
if (file_exists($folder . 'paymentgateway')) {
File::copyFolder($folder . 'paymentgateway' . DIRECTORY_SEPARATOR, $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR);
$success++;
}
if (file_exists($folder . 'theme')) {
File::copyFolder($folder . 'theme' . DIRECTORY_SEPARATOR, $UI_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR);
$success++;
}
if (file_exists($folder . 'device')) {
File::copyFolder($folder . 'device' . DIRECTORY_SEPARATOR, $DEVICE_PATH . DIRECTORY_SEPARATOR);
$success++;
}
if ($success == 0) {
// old plugin and theme using this
$check = strtolower($ghUrl);
if (strpos($check, 'plugin') !== false) {
File::copyFolder($folder, $PLUGIN_PATH . DIRECTORY_SEPARATOR);
} else if (strpos($check, 'payment') !== false) {
File::copyFolder($folder, $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR);
} else if (strpos($check, 'theme') !== false) {
rename($folder, $UI_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $plugin);
} else if (strpos($check, 'device') !== false) {
File::copyFolder($folder, $DEVICE_PATH . DIRECTORY_SEPARATOR);
}
}
File::deleteFolder($cache);
r2(U . "pluginmanager", 's', 'Installation success');
@ -257,6 +294,43 @@ switch ($action) {
}
}
break;
} else if ($tipe == 'device') {
foreach ($json['devices'] as $d) {
if ($d['id'] == $plugin) {
if (!empty($config['github_token']) && !empty($config['github_username'])) {
$d['github'] = str_replace('https://github.com', 'https://' . $config['github_username'] . ':' . $config['github_token'] . '@github.com', $d['github']);
}
$fp = fopen($file, 'w+');
$ch = curl_init($d['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');
}
File::copyFolder($folder, $DEVICE_PATH . DIRECTORY_SEPARATOR, ['README.md', 'LICENSE']);
File::deleteFolder($folder);
unlink($file);
r2(U . "paymentgateway", 's', 'Payment Gateway ' . $plugin . ' has been installed');
break;
}
}
break;
}
default:
if (class_exists('ZipArchive')) {