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 os
|
||||||
import sys
|
import sys
|
||||||
import ftplib
|
import ftplib
|
||||||
|
import stat
|
||||||
|
import re
|
||||||
|
|
||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
@ -93,3 +95,14 @@ def ftp_downloadFile(ftp, downloadPath, fileToDownload):
|
|||||||
ftp.retrbinary('RETR '+fileToDownload, filedata.write)
|
ftp.retrbinary('RETR '+fileToDownload, filedata.write)
|
||||||
filedata.close()
|
filedata.close()
|
||||||
ftp.quit()
|
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 os
|
||||||
import pysftp
|
import pysftp
|
||||||
import paramiko
|
import paramiko
|
||||||
|
import stat
|
||||||
|
import re
|
||||||
|
|
||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
@ -27,14 +29,16 @@ def createSFTPConnection():
|
|||||||
|
|
||||||
|
|
||||||
def sftp_showPlugins(sftp):
|
def sftp_showPlugins(sftp):
|
||||||
sftp.cd('plugins')
|
configValues = configurationValues()
|
||||||
|
sftp.cd(configValues.sftp_folderPath)
|
||||||
for attr in sftp.listdir_attr():
|
for attr in sftp.listdir_attr():
|
||||||
print(attr.filename, attr)
|
print(attr.filename, attr)
|
||||||
|
|
||||||
|
|
||||||
def sftp_upload_file(sftp, itemPath):
|
def sftp_upload_file(sftp, itemPath):
|
||||||
|
configValues = configurationValues()
|
||||||
try:
|
try:
|
||||||
sftp.chdir('plugins')
|
sftp.chdir(configValues.sftp_folderPath)
|
||||||
sftp.put(itemPath)
|
sftp.put(itemPath)
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@ -54,8 +58,9 @@ def sftp_upload_server_jar(sftp, itemPath):
|
|||||||
|
|
||||||
|
|
||||||
def sftp_listAll(sftp):
|
def sftp_listAll(sftp):
|
||||||
|
configValues = configurationValues()
|
||||||
try:
|
try:
|
||||||
sftp.chdir('plugins')
|
sftp.chdir(configValues.sftp_folderPath)
|
||||||
installedPlugins = sftp.listdir()
|
installedPlugins = sftp.listdir()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(oColors.brightRed + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
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()
|
sftp.close()
|
||||||
os.chdir(currentDirectory)
|
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"]
|
ressourceId = packageName[ressourceSelected]["id"]
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
try:
|
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:
|
except HTTPError as err:
|
||||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
getSpecificPackage(ressourceId, configValues.pathToPluginFolder)
|
if configValues.seperateDownloadPath is True:
|
||||||
|
getSpecificPackage(ressourceId, configValues.pathToPluginFolder)
|
||||||
|
else:
|
||||||
|
getSpecificPackage(ressourceId, configValues.pathToSeperateDownloadPath)
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
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)
|
versionId = getVersionID(ressourceId, inputPackageVersion)
|
||||||
packageVersion = getVersionName(ressourceId, versionId)
|
packageVersion = getVersionName(ressourceId, versionId)
|
||||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||||
#if not configValues.localPluginFolder:
|
|
||||||
#downloadPackagePath = f"{downloadPath}/{packageDownloadName}"
|
|
||||||
#else:
|
|
||||||
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
|
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
|
||||||
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
||||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import io
|
import io
|
||||||
|
import stat
|
||||||
|
import pysftp
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -9,8 +11,8 @@ from rich.progress import track
|
|||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from utils.web_request import doAPIRequest
|
from utils.web_request import doAPIRequest
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
from handlers.handle_sftp import createSFTPConnection, sftp_listAll, sftp_downloadFile
|
from handlers.handle_sftp import createSFTPConnection, sftp_listAll, sftp_downloadFile, sftp_validateFileAttributes
|
||||||
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile
|
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile, ftp_validateFileAttributes
|
||||||
from plugin.plugin_downloader import getSpecificPackage
|
from plugin.plugin_downloader import getSpecificPackage
|
||||||
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder
|
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder
|
||||||
|
|
||||||
@ -133,11 +135,25 @@ def checkInstalledPackage(inputSelectedObject="all"):
|
|||||||
print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
|
print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
|
||||||
try:
|
try:
|
||||||
for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="bright_yellow"):
|
for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="bright_yellow"):
|
||||||
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
|
if not configValues.localPluginFolder:
|
||||||
continue
|
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):
|
if configValues.sftp_useSftp:
|
||||||
continue
|
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:
|
try:
|
||||||
fileName = getFileName(plugin)
|
fileName = getFileName(plugin)
|
||||||
@ -223,11 +239,25 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
print("└─────┴────────────────────────────────┴────────────┴──────────┘")
|
print("└─────┴────────────────────────────────┴────────────┴──────────┘")
|
||||||
try:
|
try:
|
||||||
for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="bright_magenta"):
|
for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="bright_magenta"):
|
||||||
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
|
if not configValues.localPluginFolder:
|
||||||
continue
|
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):
|
if configValues.sftp_useSftp:
|
||||||
continue
|
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:
|
try:
|
||||||
fileName = getFileName(plugin)
|
fileName = getFileName(plugin)
|
||||||
|
Loading…
Reference in New Issue
Block a user