Spaces:
Sleeping
Sleeping
Download src/modules/utils.py from zundom/pentest-lab: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/spaces/zundom/pentest-lab/resolve/main/src/modules/utils.py
- Command line
-
hf download hf://spaces/zundom/pentest-lab/src/modules/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/zundom/pentest-lab/resolve/main/src/modules/utils.py
1.66 kB
| import os | |
| import time | |
| import tempfile | |
| import zipfile | |
| class Utils: | |
| def get_tempdir(): | |
| try: | |
| timestamp = int(time.time()) | |
| temp_dir = tempfile.mkdtemp() | |
| return timestamp, temp_dir | |
| except Exception as e: | |
| raise RuntimeError(f"Failed to create temporary directory: {str(e)}") | |
| def create_zip(filelist, tmp_fname, passwd=None): | |
| if not filelist: | |
| return None | |
| try: | |
| zip_name = os.path.abspath(tmp_fname) | |
| with zipfile.ZipFile(zip_name, "w", compression=zipfile.ZIP_DEFLATED) as f: | |
| for file in filelist: | |
| if os.path.isfile(file): | |
| f.write(file, os.path.relpath(file, os.path.dirname(filelist[0]))) | |
| elif os.path.isdir(file): | |
| for root, dirs, files in os.walk(file): | |
| for filename in files: | |
| filepath = os.path.join(root, filename) | |
| f.write(filepath, os.path.relpath(filepath, os.path.dirname(filelist[0]))) | |
| if passwd: | |
| zip_name_encrypted = zip_name + ".zip" | |
| with zipfile.ZipFile(zip_name_encrypted, "w", compression=zipfile.ZIP_DEFLATED) as f: | |
| f.setpassword(passwd) | |
| f.write(zip_name, os.path.basename(zip_name)) | |
| os.remove(zip_name) | |
| return zip_name_encrypted | |
| else: | |
| return zip_name | |
| except Exception as e: | |
| raise RuntimeError(f"Failed to create zip file: {str(e)}") | |