This commit is contained in:
BarsTiger
2022-01-24 13:17:49 +02:00
parent e5e216ca75
commit cce55d434a
4 changed files with 35 additions and 27 deletions

View File

@@ -8,6 +8,7 @@ from modules.manager import install, uninstall
from modules.virustotal import add_to_cfg from modules.virustotal import add_to_cfg
from modules.uploader import upload from modules.uploader import upload
from modules.source import get_source from modules.source import get_source
import modules.vars as horsy_vars
# Getting the arguments # Getting the arguments
parser = argparse.ArgumentParser(description='horsy - the best package manager') parser = argparse.ArgumentParser(description='horsy - the best package manager')
@@ -24,10 +25,10 @@ option = args.option
app = args.app app = args.app
# Checking directories and files # Checking directories and files
if not os.path.exists('apps'): if not os.path.exists(horsy_vars.horsypath + 'apps'):
os.makedirs('apps') os.makedirs(horsy_vars.horsypath + 'apps')
if not os.path.isfile('config.cfg'): if not os.path.isfile(horsy_vars.horsypath + 'config.cfg'):
with open('config.cfg', 'w') as f: with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
f.write('{}') f.write('{}')
# Displaying the logo # Displaying the logo
@@ -49,7 +50,9 @@ isNoArgs = False
if args.vt_key: if args.vt_key:
if args.vt_key != 'disable': if args.vt_key != 'disable':
add_to_cfg(args.vt_key) add_to_cfg(args.vt_key)
print('VT key updated')
else: else:
print('VT disabled')
add_to_cfg(None) add_to_cfg(None)
sys.exit() sys.exit()

View File

@@ -10,7 +10,6 @@ from modules.virustotal import get_key, scan_file, get_report
def install(package, is_gui=False): def install(package, is_gui=False):
horsypath = os.popen('echo %HORSYPATH%').read().replace('\n', '') + '/'
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text
try: try:
r = json.loads(r) r = json.loads(r)
@@ -30,15 +29,15 @@ def install(package, is_gui=False):
try: try:
print(f"[green]App {r['name']} found, information loaded[/]") print(f"[green]App {r['name']} found, information loaded[/]")
if not os.path.exists('{1}apps/{0}'.format(r['name'], horsypath)): if not os.path.exists('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath)):
os.makedirs('{1}apps/{0}'.format(r['name'], 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], 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:
@@ -54,9 +53,9 @@ def install(package, is_gui=False):
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], 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], horsypath)) analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], 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")
@@ -69,8 +68,8 @@ def install(package, is_gui=False):
if r['url'].split('.')[-1] == 'zip': if r['url'].split('.')[-1] == 'zip':
print(f"Extracting {r['url'].split('/')[-1]}") print(f"Extracting {r['url'].split('/')[-1]}")
unzip('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsypath), unzip('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath),
'{1}apps/{0}'.format(r['name'], horsypath)) '{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
if r['download']: if r['download']:
print(f"Found dependency") print(f"Found dependency")
@@ -79,7 +78,8 @@ def install(package, is_gui=False):
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], horsypath), "wb") as f: with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].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:
@@ -93,9 +93,10 @@ def install(package, is_gui=False):
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], 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], horsypath)) analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1],
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:
@@ -105,14 +106,14 @@ def install(package, is_gui=False):
if r['install']: if r['install']:
print(f"Found install option") print(f"Found install option")
threading.Thread(target=os.system, args=('{2}apps/{0}/{1}'.format(r['name'], r['install'], horsypath),)) \ threading.Thread(target=os.system, args=('{2}apps/{0}/{1}'.format(r['name'], r['install'],
.start() horsy_vars.horsypath),)).start()
print(f"Generating launch script") print(f"Generating launch script")
with open('{1}apps/{0}.bat'.format(r['name'], horsypath), 'w') as f: with open('{1}apps/{0}.bat'.format(r['name'], horsy_vars.horsypath), 'w') as f:
f.write(f"@ECHO off\n") f.write(f"@ECHO off\n")
f.write(f"{horsypath}apps/{r['name']}/{r['run']} %*\n") f.write(f"{horsy_vars.horsypath}apps/{r['name']}/{r['run']} %*\n")
print(f"[green][OK] All done![/]") print(f"[green][OK] All done![/]")
print(f"[green]You can run your app by entering [italic white]{r['name']}[/] in terminal[/]") print(f"[green]You can run your app by entering [italic white]{r['name']}[/] in terminal[/]")
@@ -124,15 +125,14 @@ def install(package, is_gui=False):
def uninstall(package, is_gui=False): def uninstall(package, is_gui=False):
horsypath = os.popen('echo %HORSYPATH%').read().replace('\n', '') + '/'
if not is_gui: if not is_gui:
if os.path.exists('{1}apps/{0}'.format(package, horsypath)): if os.path.exists('{1}apps/{0}'.format(package, horsy_vars.horsypath)):
os.system('rmdir /s /q "{1}apps/{0}"'.format(package, horsypath)) os.system('rmdir /s /q "{1}apps/{0}"'.format(package, horsy_vars.horsypath))
print(f"[green][OK] Files deleted[/]") print(f"[green][OK] Files deleted[/]")
else: else:
print(f"[red]App {package} is not installed or doesn't have files[/]") print(f"[red]App {package} is not installed or doesn't have files[/]")
if os.path.isfile('{1}apps/{0}.bat'.format(package, horsypath)): if os.path.isfile('{1}apps/{0}.bat'.format(package, horsy_vars.horsypath)):
os.remove("{1}apps/{0}.bat".format(package, horsypath)) os.remove("{1}apps/{0}.bat".format(package, horsy_vars.horsypath))
print(f"[green][OK] Launch script deleted[/]") print(f"[green][OK] Launch script deleted[/]")
else: else:
print(f"[red]App {package} is not installed or doesn't have launch script[/]") print(f"[red]App {package} is not installed or doesn't have launch script[/]")

View File

@@ -1,2 +1,6 @@
import os
protocol = "http://" protocol = "http://"
server_url = 'localhost:60666' server_url = 'localhost:60666'
horsypath = os.popen('echo %HORSYPATH%').read().replace('\n', '') + '/'

View File

@@ -2,20 +2,21 @@ import json
import requests import requests
import os import os
import hashlib import hashlib
import modules.vars as horsy_vars
def add_to_cfg(key): def add_to_cfg(key):
with open('config.cfg') as f: with open(horsy_vars.horsypath + 'config.cfg') as f:
config = json.load(f) config = json.load(f)
config['vt-key'] = key config['vt-key'] = key
with open('config.cfg', 'w') as f: with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
json.dump(config, f) json.dump(config, f)
def get_key(): def get_key():
with open('config.cfg') as f: with open(horsy_vars.horsypath + 'config.cfg') as f:
config = json.load(f) config = json.load(f)
try: try: