GUI development

This commit is contained in:
BarsTiger
2022-01-26 20:43:25 +02:00
parent 88be80a4af
commit 9872f20ad5
3 changed files with 98 additions and 76 deletions

View File

@@ -20,6 +20,9 @@ MainWindow.show()
# Functions # Functions
def refresh_gui():
installed_apps()
def installed_apps(): def installed_apps():
from modules.manager import apps_list from modules.manager import apps_list
ui.installed_table.clear() ui.installed_table.clear()
@@ -30,21 +33,27 @@ def installed_apps():
ui.installed_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(apps[i]))) ui.installed_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(apps[i])))
def update_app(): def update_app():
app_name = ui.installed_table.currentItem().text() try:
if app_name == "": app_name = ui.installed_table.currentItem().text()
if app_name == "":
return
else:
from modules.manager import install
install(app_name, True)
except:
return return
else:
from modules.manager import install
install(app_name)
def uninstall_app(): def uninstall_app():
app_name = ui.installed_table.currentItem().text() try:
if app_name == "": app_name = ui.installed_table.currentItem().text()
if app_name == "":
return
else:
from modules.manager import uninstall
uninstall(app_name)
installed_apps()
except:
return return
else:
from modules.manager import uninstall
uninstall(app_name)
installed_apps()
def search_gui(): def search_gui():
from modules.search import search from modules.search import search
@@ -59,13 +68,38 @@ def search_gui():
for i in range(len(found)): for i in range(len(found)):
ui.search_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(found[i]))) ui.search_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(found[i])))
def install_app():
from modules.manager import install
try:
app_name = ui.search_table.currentItem().text()
if app_name == "":
return
else:
install(app_name, True)
except:
return
def get_source_gui():
from modules.source import get_source
try:
app_name = ui.search_table.currentItem().text()
if app_name == "":
return
else:
get_source(app_name)
except:
return
# Run functions on startup # Run functions on startup
installed_apps() installed_apps()
# Binds # Binds
ui.tabWidget.currentChanged.connect(refresh_gui)
ui.update_button.clicked.connect(update_app) ui.update_button.clicked.connect(update_app)
ui.delete_button.clicked.connect(uninstall_app) ui.delete_button.clicked.connect(uninstall_app)
ui.search_button.clicked.connect(search_gui) ui.search_button.clicked.connect(search_gui)
ui.install_button.clicked.connect(install_app)
ui.source_button.clicked.connect(get_source_gui)
# Handle GUI exiting to exit whole program # Handle GUI exiting to exit whole program

View File

@@ -201,13 +201,7 @@ class Ui_MainWindow(object):
self.manage_packages_table.setDragDropOverwriteMode(False) self.manage_packages_table.setDragDropOverwriteMode(False)
self.manage_packages_table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection) self.manage_packages_table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.manage_packages_table.setShowGrid(False) self.manage_packages_table.setShowGrid(False)
self.manage_packages_table.setRowCount(1)
self.manage_packages_table.setColumnCount(4)
self.manage_packages_table.setObjectName("manage_packages_table") self.manage_packages_table.setObjectName("manage_packages_table")
item = QtWidgets.QTableWidgetItem()
self.manage_packages_table.setItem(0, 0, item)
item = QtWidgets.QTableWidgetItem()
self.manage_packages_table.setItem(0, 1, item)
self.manage_packages_table.horizontalHeader().setVisible(False) self.manage_packages_table.horizontalHeader().setVisible(False)
self.manage_packages_table.horizontalHeader().setDefaultSectionSize(203) self.manage_packages_table.horizontalHeader().setDefaultSectionSize(203)
self.manage_packages_table.horizontalHeader().setHighlightSections(False) self.manage_packages_table.horizontalHeader().setHighlightSections(False)
@@ -344,13 +338,7 @@ class Ui_MainWindow(object):
self.search_table.setDragDropOverwriteMode(False) self.search_table.setDragDropOverwriteMode(False)
self.search_table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection) self.search_table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.search_table.setShowGrid(False) self.search_table.setShowGrid(False)
self.search_table.setRowCount(1)
self.search_table.setColumnCount(4)
self.search_table.setObjectName("search_table") self.search_table.setObjectName("search_table")
item = QtWidgets.QTableWidgetItem()
self.search_table.setItem(0, 0, item)
item = QtWidgets.QTableWidgetItem()
self.search_table.setItem(0, 1, item)
self.search_table.horizontalHeader().setVisible(False) self.search_table.horizontalHeader().setVisible(False)
self.search_table.horizontalHeader().setDefaultSectionSize(203) self.search_table.horizontalHeader().setDefaultSectionSize(203)
self.search_table.horizontalHeader().setHighlightSections(False) self.search_table.horizontalHeader().setHighlightSections(False)

View File

@@ -32,33 +32,33 @@ def install(package, is_gui=False):
if not os.path.exists('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath)): if not os.path.exists('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath)):
os.makedirs('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath)) os.makedirs('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
if not is_gui: # if not is_gui:
print(f"Downloading {r['url'].split('/')[-1]}") print(f"Downloading {r['url'].split('/')[-1]}")
chunk_size = 1024 chunk_size = 1024
file_r = requests.get(r['url'], stream=True) file_r = requests.get(r['url'], stream=True)
with open('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath), "wb") as f: with open('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath), "wb") as f:
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length'])) pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
for chunk in file_r.iter_content(chunk_size=chunk_size): for chunk in file_r.iter_content(chunk_size=chunk_size):
if chunk: if chunk:
pbar.update(len(chunk)) pbar.update(len(chunk))
f.write(chunk) f.write(chunk)
pbar.close() pbar.close()
print(f"Starting virustotal scan") print(f"Starting virustotal scan")
if not get_key(): if not get_key():
print(f"[red]Virustotal api key not found[/]") print(f"[red]Virustotal api key not found[/]")
print(f"You can add it by entering [bold]horsy --vt \[your key][/] in terminal") print(f"You can add it by entering [bold]horsy --vt \[your key][/] in terminal")
else: else:
print(f"[green]Virustotal api key found[/]") print(f"[green]Virustotal api key found[/]")
print(f"[italic white]If you want to disable scan, type [/][bold]horsy --vt disable[/]" print(f"[italic white]If you want to disable scan, type [/][bold]horsy --vt disable[/]"
f"[italic white] in terminal[/]") f"[italic white] in terminal[/]")
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath)) scan_file('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
print(f"[green]Virustotal scan finished[/]") print(f"[green]Virustotal scan finished[/]")
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1],
horsy_vars.horsypath)) horsy_vars.horsypath))
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]") print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious") print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
print(f"[green][OK] Done[/]") print(f"[green][OK] Done[/]")
@@ -74,36 +74,36 @@ def install(package, is_gui=False):
if r['download']: if r['download']:
print(f"Found dependency") print(f"Found dependency")
if not is_gui: # if not is_gui:
print(f"Downloading {r['download'].split('/')[-1]}") print(f"Downloading {r['download'].split('/')[-1]}")
chunk_size = 1024 chunk_size = 1024
file_r = requests.get(r['download'], stream=True) file_r = requests.get(r['download'], stream=True)
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath), with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath),
"wb") as f: "wb") as f:
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length'])) pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
for chunk in file_r.iter_content(chunk_size=chunk_size): for chunk in file_r.iter_content(chunk_size=chunk_size):
if chunk: if chunk:
pbar.update(len(chunk)) pbar.update(len(chunk))
f.write(chunk) f.write(chunk)
pbar.close() pbar.close()
print(f"Starting virustotal scan") print(f"Starting virustotal scan")
if not get_key(): if not get_key():
print(f"[red]Virustotal api key not found[/]") print(f"[red]Virustotal api key not found[/]")
print(f"You can add it by entering [italic white]horsy --vt \[your key][/] in terminal") print(f"You can add it by entering [italic white]horsy --vt \[your key][/] in terminal")
else: else:
print(f"[green]Virustotal api key found[/]") print(f"[green]Virustotal api key found[/]")
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath)) scan_file('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath))
print(f"[green]Virustotal scan finished[/]") print(f"[green]Virustotal scan finished[/]")
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1],
horsy_vars.horsypath)) horsy_vars.horsypath))
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]") print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious") print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
if analysis['detect']['malicious'] > 0: if analysis['detect']['malicious'] > 0:
print(f"[red]Dependency can be malicious. It may run now, if this added to installation " print(f"[red]Dependency can be malicious. It may run now, if this added to installation "
f"config[/]") f"config[/]")
input("Press enter if you want continue, or ctrl+c to exit") input("Press enter if you want continue, or ctrl+c to exit")
if r['install']: if r['install']:
print(f"Found install option") print(f"Found install option")