mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Added .jar
validation to SFTP/FTP
Changes: - added `.jar` file validation to SFTP/FTP - cleanup of old code
This commit is contained in:
parent
3ad7753674
commit
2712bd5be6
@ -1,6 +1,8 @@
|
||||
import os
|
||||
import sys
|
||||
import ftplib
|
||||
import stat
|
||||
import re
|
||||
|
||||
from utils.consoleoutput import oColors
|
||||
from handlers.handle_config import configurationValues
|
||||
@ -93,3 +95,14 @@ def ftp_downloadFile(ftp, downloadPath, fileToDownload):
|
||||
ftp.retrbinary('RETR '+fileToDownload, filedata.write)
|
||||
filedata.close()
|
||||
ftp.quit()
|
||||
|
||||
|
||||
def ftp_validateFileAttributes(ftp, pluginPath):
|
||||
pluginFTPAttribute = ftp.lstat(pluginPath)
|
||||
if stat.S_ISDIR(pluginFTPAttribute.st_mode):
|
||||
return False
|
||||
if stat.S_ISDIR(pluginFTPAttribute.st_mode):
|
||||
if re.search(r'.jar$', pluginFTPAttribute.filename):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -2,6 +2,8 @@ import sys
|
||||
import os
|
||||
import pysftp
|
||||
import paramiko
|
||||
import stat
|
||||
import re
|
||||
|
||||
from utils.consoleoutput import oColors
|
||||
from handlers.handle_config import configurationValues
|
||||
@ -27,14 +29,16 @@ def createSFTPConnection():
|
||||
|
||||
|
||||
def sftp_showPlugins(sftp):
|
||||
sftp.cd('plugins')
|
||||
configValues = configurationValues()
|
||||
sftp.cd(configValues.sftp_folderPath)
|
||||
for attr in sftp.listdir_attr():
|
||||
print(attr.filename, attr)
|
||||
|
||||
|
||||
def sftp_upload_file(sftp, itemPath):
|
||||
configValues = configurationValues()
|
||||
try:
|
||||
sftp.chdir('plugins')
|
||||
sftp.chdir(configValues.sftp_folderPath)
|
||||
sftp.put(itemPath)
|
||||
|
||||
except FileNotFoundError:
|
||||
@ -54,8 +58,9 @@ def sftp_upload_server_jar(sftp, itemPath):
|
||||
|
||||
|
||||
def sftp_listAll(sftp):
|
||||
configValues = configurationValues()
|
||||
try:
|
||||
sftp.chdir('plugins')
|
||||
sftp.chdir(configValues.sftp_folderPath)
|
||||
installedPlugins = sftp.listdir()
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
@ -87,3 +92,13 @@ def sftp_downloadFile(sftp, downloadPath, fileToDownload):
|
||||
sftp.close()
|
||||
os.chdir(currentDirectory)
|
||||
|
||||
|
||||
def sftp_validateFileAttributes(sftp, pluginPath):
|
||||
pluginSFTPAttribute = sftp.lstat(pluginPath)
|
||||
if stat.S_ISDIR(pluginSFTPAttribute.st_mode):
|
||||
return False
|
||||
if stat.S_ISDIR(pluginSFTPAttribute.st_mode):
|
||||
if re.search(r'.jar$', pluginSFTPAttribute.filename):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -79,12 +79,18 @@ def searchPackage(ressourceName):
|
||||
ressourceId = packageName[ressourceSelected]["id"]
|
||||
if not configValues.localPluginFolder:
|
||||
try:
|
||||
getSpecificPackage(ressourceId, configValues.sftp_folderPath)
|
||||
if configValues.sftp_seperateDownloadPath is True:
|
||||
getSpecificPackage(ressourceId, configValues.sftp_pathToSeperateDownloadPath)
|
||||
else:
|
||||
getSpecificPackage(ressourceId, configValues.sftp_folderPath)
|
||||
except HTTPError as err:
|
||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||
else:
|
||||
try:
|
||||
getSpecificPackage(ressourceId, configValues.pathToPluginFolder)
|
||||
if configValues.seperateDownloadPath is True:
|
||||
getSpecificPackage(ressourceId, configValues.pathToPluginFolder)
|
||||
else:
|
||||
getSpecificPackage(ressourceId, configValues.pathToSeperateDownloadPath)
|
||||
except HTTPError as err:
|
||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||
|
||||
@ -134,9 +140,6 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
||||
versionId = getVersionID(ressourceId, inputPackageVersion)
|
||||
packageVersion = getVersionName(ressourceId, versionId)
|
||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||
#if not configValues.localPluginFolder:
|
||||
#downloadPackagePath = f"{downloadPath}/{packageDownloadName}"
|
||||
#else:
|
||||
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
|
||||
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
||||
|
@ -1,6 +1,8 @@
|
||||
import os
|
||||
import re
|
||||
import io
|
||||
import stat
|
||||
import pysftp
|
||||
from zipfile import ZipFile
|
||||
from urllib.error import HTTPError
|
||||
from pathlib import Path
|
||||
@ -9,8 +11,8 @@ from rich.progress import track
|
||||
from utils.consoleoutput import oColors
|
||||
from utils.web_request import doAPIRequest
|
||||
from handlers.handle_config import configurationValues
|
||||
from handlers.handle_sftp import createSFTPConnection, sftp_listAll, sftp_downloadFile
|
||||
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile
|
||||
from handlers.handle_sftp import createSFTPConnection, sftp_listAll, sftp_downloadFile, sftp_validateFileAttributes
|
||||
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile, ftp_validateFileAttributes
|
||||
from plugin.plugin_downloader import getSpecificPackage
|
||||
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder
|
||||
|
||||
@ -133,11 +135,25 @@ def checkInstalledPackage(inputSelectedObject="all"):
|
||||
print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
|
||||
try:
|
||||
for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="bright_yellow"):
|
||||
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
|
||||
continue
|
||||
if not configValues.localPluginFolder:
|
||||
if configValues.sftp_seperateDownloadPath is True:
|
||||
pluginFile = f"{configValues.sftp_pathToSeperateDownloadPath}/{plugin}"
|
||||
else:
|
||||
pluginFile = f"{configValues.sftp_folderPath}/{plugin}"
|
||||
|
||||
if not re.search(r'.jar$', plugin):
|
||||
continue
|
||||
if configValues.sftp_useSftp:
|
||||
pluginAttributes = sftp_validateFileAttributes(connection, pluginFile)
|
||||
if pluginAttributes == False:
|
||||
continue
|
||||
else:
|
||||
pluginAttributes = ftp_validateFileAttributes(connection, pluginFile)
|
||||
if pluginAttributes == False:
|
||||
continue
|
||||
else:
|
||||
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
|
||||
continue
|
||||
if not re.search(r'.jar$', plugin):
|
||||
continue
|
||||
|
||||
try:
|
||||
fileName = getFileName(plugin)
|
||||
@ -223,11 +239,25 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
||||
print("└─────┴────────────────────────────────┴────────────┴──────────┘")
|
||||
try:
|
||||
for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="bright_magenta"):
|
||||
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
|
||||
continue
|
||||
if not configValues.localPluginFolder:
|
||||
if configValues.sftp_seperateDownloadPath is True:
|
||||
pluginFile = f"{configValues.sftp_pathToSeperateDownloadPath}/{plugin}"
|
||||
else:
|
||||
pluginFile = f"{configValues.sftp_folderPath}/{plugin}"
|
||||
|
||||
if not re.search(r'.jar$', plugin):
|
||||
continue
|
||||
if configValues.sftp_useSftp:
|
||||
pluginAttributes = sftp_validateFileAttributes(connection, pluginFile)
|
||||
if pluginAttributes == False:
|
||||
continue
|
||||
else:
|
||||
pluginAttributes = ftp_validateFileAttributes(connection, pluginFile)
|
||||
if pluginAttributes == False:
|
||||
continue
|
||||
else:
|
||||
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
|
||||
continue
|
||||
if not re.search(r'.jar$', plugin):
|
||||
continue
|
||||
|
||||
try:
|
||||
fileName = getFileName(plugin)
|
||||
|
Loading…
Reference in New Issue
Block a user