Cleaning tmp
This commit is contained in:
parent
46b68a17b8
commit
9c090991c0
10
README.md
10
README.md
@ -6,16 +6,17 @@ This too has several functions:
|
|||||||
|
|
||||||
## To-Do
|
## To-Do
|
||||||
|
|
||||||
* Auto-clean files/tmp/ folder
|
|
||||||
* Prettier code
|
* Prettier code
|
||||||
* Only update once per day, except if `-u` `--update`
|
* Only update once per day, except if `-u` `--update`
|
||||||
* Adding more services to listen to ?
|
* Adding more services to listen to ?
|
||||||
|
|
||||||
## Dependencies
|
## Pre-requisites
|
||||||
|
|
||||||
* requests python module
|
* requests python module
|
||||||
|
* rpmfile python module
|
||||||
* impacket smbserver.py must be in PATH
|
* impacket smbserver.py must be in PATH
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
[Create a Github personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token), and create the file `credz.json`:
|
[Create a Github personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token), and create the file `credz.json`:
|
||||||
@ -33,3 +34,8 @@ This too has several functions:
|
|||||||
|
|
||||||
Simply add the informations to [config.json](./config.json), for a release set "local_version" to a random value and run the script.
|
Simply add the informations to [config.json](./config.json), for a release set "local_version" to a random value and run the script.
|
||||||
The file is gonna be automatically downloaded.
|
The file is gonna be automatically downloaded.
|
||||||
|
|
||||||
|
## Share a file temporarly
|
||||||
|
|
||||||
|
You can add a file you wish to share once in `files/tmp`.
|
||||||
|
Every time you start the script, you will be asked if you want to clear the folder (if not empty).
|
@ -1,5 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import pathlib
|
from pathlib import Path
|
||||||
import hashlib
|
import hashlib
|
||||||
import requests
|
import requests
|
||||||
import base64
|
import base64
|
||||||
@ -62,7 +62,7 @@ def extract_bin(archtype, binpath, destpath, content):
|
|||||||
|
|
||||||
def githubmastersync(reponame, filepaths, credz):
|
def githubmastersync(reponame, filepaths, credz):
|
||||||
for filepath in filepaths:
|
for filepath in filepaths:
|
||||||
localfile = pathlib.Path('files').joinpath(pathlib.Path(filepath).name)
|
localfile = Path('files').joinpath(Path(filepath).name)
|
||||||
print(f" * {localfile} ", end='')
|
print(f" * {localfile} ", end='')
|
||||||
lastsha, content = get_master_info(reponame, filepath, credz)
|
lastsha, content = get_master_info(reponame, filepath, credz)
|
||||||
|
|
||||||
@ -96,14 +96,14 @@ def githubreleasesync(reponame, repoinfo, credz):
|
|||||||
binpath = filename['binpath']
|
binpath = filename['binpath']
|
||||||
filename = filename['filename']
|
filename = filename['filename']
|
||||||
filename = filename.replace('{last_version}', last_version).replace('{short_version}', short_version)
|
filename = filename.replace('{last_version}', last_version).replace('{short_version}', short_version)
|
||||||
localfile = pathlib.Path('files').joinpath(pathlib.Path(binpath).name)
|
localfile = Path('files').joinpath(Path(binpath).name)
|
||||||
if filename.endswith('.gz'):
|
if filename.endswith('.gz'):
|
||||||
is_gz = True
|
is_gz = True
|
||||||
print(f" * {localfile} ", end='')
|
print(f" * {localfile} ", end='')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
filename = filename.replace('{last_version}', last_version).replace('{short_version}', short_version)
|
filename = filename.replace('{last_version}', last_version).replace('{short_version}', short_version)
|
||||||
localfile = pathlib.Path('files').joinpath(pathlib.Path(filename).name)
|
localfile = Path('files').joinpath(Path(filename).name)
|
||||||
print(f" * {localfile} ", end='')
|
print(f" * {localfile} ", end='')
|
||||||
|
|
||||||
urldl = f'https://github.com/{reponame}/releases/download/{last_version}/{filename}'
|
urldl = f'https://github.com/{reponame}/releases/download/{last_version}/{filename}'
|
||||||
@ -145,7 +145,7 @@ def ncatsync(conf):
|
|||||||
local_version = conf['local_version']
|
local_version = conf['local_version']
|
||||||
|
|
||||||
for filename in conf['files']:
|
for filename in conf['files']:
|
||||||
localfile = pathlib.Path('files').joinpath(pathlib.Path(filename).name)
|
localfile = Path('files').joinpath(Path(filename).name)
|
||||||
print(f" * {localfile} ", end='')
|
print(f" * {localfile} ", end='')
|
||||||
|
|
||||||
if filename == "ncat.exe":
|
if filename == "ncat.exe":
|
||||||
@ -208,12 +208,52 @@ def update(config):
|
|||||||
|
|
||||||
|
|
||||||
def make_executable():
|
def make_executable():
|
||||||
path = pathlib.Path('files')
|
path = Path('files')
|
||||||
for fpath in path.glob("*"):
|
for fpath in path.glob("*"):
|
||||||
if fpath.name != '.gitkeep':
|
if fpath.name != '.gitkeep':
|
||||||
fpath.chmod(0o777)
|
fpath.chmod(0o777)
|
||||||
|
|
||||||
|
|
||||||
|
def yes_or_no(question, default="yes"):
|
||||||
|
"""Ask a yes/no question via input() and return their answer.
|
||||||
|
|
||||||
|
"question" is a string that is presented to the user.
|
||||||
|
"default" is the presumed answer if the user just hits <Enter>.
|
||||||
|
It must be "yes" (the default), "no" or None (meaning
|
||||||
|
an answer is required of the user).
|
||||||
|
|
||||||
|
The "answer" return value is True for "yes" or False for "no".
|
||||||
|
"""
|
||||||
|
valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
|
||||||
|
if default is None:
|
||||||
|
prompt = " [y/n] "
|
||||||
|
elif default == "yes":
|
||||||
|
prompt = " [Y/n] "
|
||||||
|
elif default == "no":
|
||||||
|
prompt = " [y/N] "
|
||||||
|
else:
|
||||||
|
raise ValueError("invalid default answer: '%s'" % default)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print(question + prompt)
|
||||||
|
choice = input().lower()
|
||||||
|
if default is not None and choice == "":
|
||||||
|
return valid[default]
|
||||||
|
elif choice in valid:
|
||||||
|
return valid[choice]
|
||||||
|
else:
|
||||||
|
print("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n")
|
||||||
|
|
||||||
|
|
||||||
|
def rmtree(root):
|
||||||
|
for p in root.iterdir():
|
||||||
|
if p.is_dir():
|
||||||
|
rmtree(p)
|
||||||
|
else:
|
||||||
|
p.unlink()
|
||||||
|
root.rmdir()
|
||||||
|
|
||||||
|
|
||||||
def print_menu(menu_options):
|
def print_menu(menu_options):
|
||||||
for key in menu_options.keys():
|
for key in menu_options.keys():
|
||||||
print(key, '->', menu_options[key])
|
print(key, '->', menu_options[key])
|
||||||
@ -317,7 +357,7 @@ def menu_choice(menu_options):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
print('Wrong input. Please enter a number ...')
|
print('Wrong input. Please enter a number ...')
|
||||||
|
|
||||||
files_dir = pathlib.Path.cwd().joinpath('files')
|
files_dir = Path.cwd().joinpath('files')
|
||||||
|
|
||||||
if option == 1:
|
if option == 1:
|
||||||
listen_http(files_dir)
|
listen_http(files_dir)
|
||||||
@ -336,6 +376,11 @@ if __name__ == '__main__':
|
|||||||
config = json.load(jsonfile)
|
config = json.load(jsonfile)
|
||||||
|
|
||||||
update(config)
|
update(config)
|
||||||
|
tmp = Path('files/tmp')
|
||||||
|
is_empty = not any(tmp.iterdir())
|
||||||
|
if not is_empty:
|
||||||
|
if yes_or_no("The folder 'files/tmp' is not empty. Would you like to remove the content ?", default="no"):
|
||||||
|
rmtree(tmp)
|
||||||
|
|
||||||
print('Choose a service to start a listener:')
|
print('Choose a service to start a listener:')
|
||||||
menu_options = {
|
menu_options = {
|
||||||
|
Loading…
Reference in New Issue
Block a user