Files
XSStrike/core/prompt.py
Somdev Sangwan 98c6b347b4 Logging functionality (#193)
* Add files via upload

* Add files via upload

* Logging functionality (Resolves #146)

* Created customized logger and setup file

* Start replacing prints

* Custom StreamHandler to allow '\r' as line terminator and updated more prints

* Remove setup.py

* Logger functionality to write red lines and records without format

* Possibility to set logging level when logging without format and usage of debug level instead of verboseOutput

* Replace utils logger function calls

* Fixes

* Import missing info color

* Move xsstrike.py imports to properly initialize loggers and add logger method to debug data using json

* Minor fix
2019-01-21 04:57:55 +05:30

35 lines
1.2 KiB
Python

import os
import tempfile
from core.config import defaultEditor
from core.colors import white, yellow
from core.log import setup_logger
logger = setup_logger(__name__)
def prompt(default=None):
# try assigning default editor, if fails, use default
editor = os.environ.get('EDITOR', defaultEditor)
# create a temporary file and open it
with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
if default: # if prompt should have some predefined text
tmpfile.write(default)
tmpfile.flush()
child_pid = os.fork()
is_child = child_pid == 0
if is_child:
# opens the file in the editor
try:
os.execvp(editor, [editor, tmpfile.name])
except FileNotFoundError:
logger.error('You don\'t have either a default $EDITOR \
value defined nor \'nano\' text editor')
logger.info('Execute %s`export EDITOR=/pat/to/your/editor` \
%sthen run XSStrike again.\n\n' % (yellow,white))
exit(1)
else:
os.waitpid(child_pid, 0) # wait till the editor gets closed
tmpfile.seek(0)
return tmpfile.read().strip() # read the file