2018-10-27 18:58:52 +05:30
|
|
|
import os
|
|
|
|
|
import tempfile
|
2018-11-15 15:41:01 +05:30
|
|
|
|
2018-11-12 14:06:45 +05:30
|
|
|
from core.config import defaultEditor
|
2019-01-21 04:57:55 +05:30
|
|
|
from core.colors import white, yellow
|
|
|
|
|
from core.log import setup_logger
|
2018-12-20 03:01:00 +02:00
|
|
|
|
2019-01-21 04:57:55 +05:30
|
|
|
logger = setup_logger(__name__)
|
2018-10-27 18:58:52 +05:30
|
|
|
|
2018-11-16 21:13:45 +05:30
|
|
|
|
2018-10-27 18:58:52 +05:30
|
|
|
def prompt(default=None):
|
2018-11-16 21:13:45 +05:30
|
|
|
# try assigning default editor, if fails, use default
|
2018-11-12 14:06:45 +05:30
|
|
|
editor = os.environ.get('EDITOR', defaultEditor)
|
2018-11-16 21:13:45 +05:30
|
|
|
# create a temporary file and open it
|
2018-10-27 18:58:52 +05:30
|
|
|
with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
|
2018-11-16 21:13:45 +05:30
|
|
|
if default: # if prompt should have some predefined text
|
2018-10-27 18:58:52 +05:30
|
|
|
tmpfile.write(default)
|
|
|
|
|
tmpfile.flush()
|
|
|
|
|
child_pid = os.fork()
|
|
|
|
|
is_child = child_pid == 0
|
|
|
|
|
if is_child:
|
2018-11-16 21:13:45 +05:30
|
|
|
# opens the file in the editor
|
2018-12-20 03:01:00 +02:00
|
|
|
try:
|
|
|
|
|
os.execvp(editor, [editor, tmpfile.name])
|
|
|
|
|
except FileNotFoundError:
|
2019-01-21 04:57:55 +05:30
|
|
|
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))
|
2018-12-20 03:01:00 +02:00
|
|
|
exit(1)
|
2018-10-27 18:58:52 +05:30
|
|
|
else:
|
2018-11-16 21:13:45 +05:30
|
|
|
os.waitpid(child_pid, 0) # wait till the editor gets closed
|
2018-10-27 18:58:52 +05:30
|
|
|
tmpfile.seek(0)
|
2018-11-16 21:13:45 +05:30
|
|
|
return tmpfile.read().strip() # read the file
|