# Path: ptp/libptp/parser.py
# class LineParser(AbstractParser):
# 
#     """Specialized parser for generic report files.
# 
#     Define the special :func:`handle_file` function in order to process the generic report file.
# 
#     .. note::
# 
#         Contrary to :class:`FileParser`, this class reads the file line by line and return a :class:`list`, instead of
#         a :class:`str`.
# 
#     """
# 
#     @classmethod
#     def handle_file(cls, pathname='./', filename='*', skip_empty=True, first=True):
#         """Return a list of the lines of the file.
# 
#         :param str pathname: Path to the report directory.
#         :param str filename: Regex matching the report file.
#         :param bool first: Stop the search as soon as a file has been matched.
#         :param bool skip_empty: skip the empty lines that can occur in the file if `True`, otherwise keep them.
# 
#         :raises IOError: when the report file cannot be found or an error occurs when opening/reading.
#         :raises OSError: when an error occurs when opening/reading the report file.
# 
#         :return: all the data from the file, line by line.
#         :rtype: list
# 
#         """
#         fullpath = cls._recursive_find(pathname, filename, first=first)
#         if not len(fullpath):
#             raise IOError("Report matching '%s' cannot be found." % filename)
#         data = []
#         for current_file in fullpath:
#             with open(current_file, 'r') as f:
#                 if skip_empty:
#                     data.extend([line.rstrip('\n\r') for line in f.readlines() if line.rstrip('\n\r')])
#                 else:
#                     data.extend([line.rstrip('\n\r') for line in f.readlines()])
#         return data
# 
# Path: ptp/tools/dirbuster/signatures.py
# DIRECTORIES = {
#     r'.*/manager/html/.*': LOW,
#     r'.*/admin/.*': LOW,
#     r'.*/conf/server.xml/.*': LOW,
#     r'.*/phpmyadmin/.*': LOW,
#     r'.*/phpMyAdmin/.*': LOW}
# 
# FILES = {
#     r'.*/config\.php': HIGH,
#     r'.*/c99\.php': HIGH,
#     r'.*/c99shell\.php': HIGH,
#     r'.*/r57\.php': HIGH,
#     r'.*/r58\.php': HIGH,
#     r'.*/dra\.php': HIGH,
#     r'.*/cmd\.php': HIGH,
#     r'.*/cmd\.asp': HIGH,
#     r'.*/\.htaccess': HIGH,
#     r'.*/\.htpasswd': HIGH,
# 
#     r'.*/phpinfo\.php': LOW,
#     r'.*/info\.php': LOW,
#     r'.*/php\.ini': LOW,
#     r'.*/WEB-INF/web\.xml': LOW,
#     r'.*/jmx-console': LOW,
#     r'.*/web-console': LOW,
#     r'.*/web-console/Invoker': LOW,
#     r'.*/invoker/JMXInvokerServlet': LOW,
# 
#     r'.*/server-info': INFO,
#     r'.*/server-status': INFO,
#     r'.*/status': INFO}


import re
from ptp.libptp.parser import LineParser
from ptp.tools.dirbuster.signatures import DIRECTORIES, FILES

"""




class DirbusterParser(LineParser):
    """DirBuster specialized parser."""

    __tool__ = 'dirbuster'
    __format__ = 'dirbuster'
    __version__ = ['1.0-RC1']

    #: :class:`str` -- Regex matching DirBuster section separator.
    _re_sep = r"^-*$"
    #: :class:`str` -- Regex matching DirBuster version.
    _re_version = r"^DirBuster (?P<version>[0-9]+\.[0-9]+(-RC[0-9])?) - Report$"
    #: :class:`str` -- Regex matching DirBuster directories status code.
    _re_dir_status = r"^Dirs found with a (?P<status>[0-9]{3}) response:$"
    #: :class:`str` -- Regex matching DirBuster files status code.
    _re_file_status = r"^Files found with a (?P<status>[0-9]{3}) responce:$"

    def __init__(self, pathname, filename='DirBuster-Report*', light=False, first=True):
        """Initialize DirbusterParser.

        :param str pathname: Path to the report directory.
        :param str filename: Regex matching the report file.
        :param bool first: Only process first file (``True``) or each file that matched (``False``).

        """

# Path: ptp/libptp/parser.py
# class LineParser(AbstractParser):
# 
#     """Specialized parser for generic report files.
# 
#     Define the special :func:`handle_file` function in order to process the generic report file.
# 
#     .. note::
# 
#         Contrary to :class:`FileParser`, this class reads the file line by line and return a :class:`list`, instead of
#         a :class:`str`.
# 
#     """
# 
#     @classmethod
#     def handle_file(cls, pathname='./', filename='*', skip_empty=True, first=True):
#         """Return a list of the lines of the file.
# 
#         :param str pathname: Path to the report directory.
#         :param str filename: Regex matching the report file.
#         :param bool first: Stop the search as soon as a file has been matched.
#         :param bool skip_empty: skip the empty lines that can occur in the file if `True`, otherwise keep them.
# 
#         :raises IOError: when the report file cannot be found or an error occurs when opening/reading.
#         :raises OSError: when an error occurs when opening/reading the report file.
# 
#         :return: all the data from the file, line by line.
#         :rtype: list
# 
#         """
#         fullpath = cls._recursive_find(pathname, filename, first=first)
#         if not len(fullpath):
#             raise IOError("Report matching '%s' cannot be found." % filename)
#         data = []
#         for current_file in fullpath:
#             with open(current_file, 'r') as f:
#                 if skip_empty:
#                     data.extend([line.rstrip('\n\r') for line in f.readlines() if line.rstrip('\n\r')])
#                 else:
#                     data.extend([line.rstrip('\n\r') for line in f.readlines()])
#         return data
# 
# Path: ptp/tools/dirbuster/signatures.py
# DIRECTORIES = {
#     r'.*/manager/html/.*': LOW,
#     r'.*/admin/.*': LOW,
#     r'.*/conf/server.xml/.*': LOW,
#     r'.*/phpmyadmin/.*': LOW,
#     r'.*/phpMyAdmin/.*': LOW}
# 
# FILES = {
#     r'.*/config\.php': HIGH,
#     r'.*/c99\.php': HIGH,
#     r'.*/c99shell\.php': HIGH,
#     r'.*/r57\.php': HIGH,
#     r'.*/r58\.php': HIGH,
#     r'.*/dra\.php': HIGH,
#     r'.*/cmd\.php': HIGH,
#     r'.*/cmd\.asp': HIGH,
#     r'.*/\.htaccess': HIGH,
#     r'.*/\.htpasswd': HIGH,
# 
#     r'.*/phpinfo\.php': LOW,
#     r'.*/info\.php': LOW,
#     r'.*/php\.ini': LOW,
#     r'.*/WEB-INF/web\.xml': LOW,
#     r'.*/jmx-console': LOW,
#     r'.*/web-console': LOW,
#     r'.*/web-console/Invoker': LOW,
#     r'.*/invoker/JMXInvokerServlet': LOW,
# 
#     r'.*/server-info': INFO,
#     r'.*/server-status': INFO,
#     r'.*/status': INFO}


# Path: ptp/tools/dirbuster/parser.py
import re
from ptp.libptp.parser import LineParser
from ptp.tools.dirbuster.signatures import DIRECTORIES, FILES


"""




class DirbusterParser(LineParser):
    """DirBuster specialized parser."""

    __tool__ = 'dirbuster'
    __format__ = 'dirbuster'
    __version__ = ['1.0-RC1']

    #: :class:`str` -- Regex matching DirBuster section separator.
    _re_sep = r"^-*$"
    #: :class:`str` -- Regex matching DirBuster version.
    _re_version = r"^DirBuster (?P<version>[0-9]+\.[0-9]+(-RC[0-9])?) - Report$"
    #: :class:`str` -- Regex matching DirBuster directories status code.
    _re_dir_status = r"^Dirs found with a (?P<status>[0-9]{3}) response:$"
    #: :class:`str` -- Regex matching DirBuster files status code.
    _re_file_status = r"^Files found with a (?P<status>[0-9]{3}) responce:$"

    def __init__(self, pathname, filename='DirBuster-Report*', light=False, first=True):
        """Initialize DirbusterParser.

        :param str pathname: Path to the report directory.
        :param str filename: Regex matching the report file.
        :param bool first: Only process first file (``True``) or each file that matched (``False``).

        """

        LineParser.__init__(self, pathname, filename, first=first)