<filename>src/controller.py
# -*- coding: utf-8 -*-

"""
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Development Team: <NAME>
"""

from src.lib import ArgumentsError
from src.lib import BrowserError
from src.lib import PackageError
from src.lib import ReporterError
from src.lib import TplError
from src.lib import args
from src.lib import browser
from src.lib import events
from src.lib import package
from src.lib import reporter
from src.lib import tpl
from . import execution_time
from .exceptions import SrcError


class Controller(object):
    """Controller class"""

    def __init__(self):
        """
        Init constructor
        :raise SrcError
        """

        events.terminate()

        try:

            interpreter = package.check_interpreter()
            
            if interpreter is not True:
                raise SrcError(tpl.error(key='unsupported', actual=interpreter.get('actual'),
                                         expected=interpreter.get('expected')))

            self.ioargs = args().get_arguments()
        except ArgumentsError as e:
            raise SrcError(tpl.error(e.message))

    @execution_time(log=tpl)
    def run(self):
        """
        Bootstrap action
        :raise SrcError
        :return: None
        """

        try:

            tpl.message(package.banner())

            if 'host' in self.ioargs:
                getattr(self, 'scan_action')(self.ioargs)
            else:
                for action in self.ioargs.keys():
                    if hasattr(self, '{0}_action'.format(action)) and callable(
                            getattr(self, '{0}_action'.format(action))):
                        getattr(self, '{func}_action'.format(func=action))()
                        break

        except (SrcError, PackageError, BrowserError, AttributeError) as e:
            raise SrcError(tpl.error(e.message))

    @staticmethod
    def examples_action():
        """
        Show examples action
        :return: None
        """

        tpl.message(package.examples())

    @staticmethod
    def update_action():
        """
        App update action
        :raise SrcError
        :return: None
        """

        try:
            tpl.message(package.update())
        except (AttributeError, PackageError) as e:
            raise SrcError(e)

    @staticmethod
    def version_action():
        """
        Show app version action

        :raise SrcError
        :return: None
        """

        try:
            tpl.message(package.version())
        except (AttributeError, PackageError) as e:
            raise SrcError(e)

    @staticmethod
    def local_version():
        """
        Show app local version
        :raise SrcError
        :return: None
        """

        try:
            tpl.message(package.local_version())
        except (AttributeError, PackageError) as e:
            raise SrcError(e)

    @classmethod
    def scan_action(cls, params):
        """
        URL scan action
        :param dict params: console input args
        :raise SrcError
        :return: None
        """

        try:
            brows = browser(params)
            if True is reporter.is_reported(params.get('host')):
                try:
                    tpl.prompt(key='logged')
                except KeyboardInterrupt:
                    tpl.cancel(key='abort')

            if reporter.default is params.get('reports'):
                tpl.info(key='use_reports')

            brows.ping()
            brows.scan()
            brows.done()

        except (AttributeError, BrowserError, ReporterError, TplError) as e:
            raise SrcError(e.message)
        except (KeyboardInterrupt, SystemExit):
            tpl.cancel(key='abort')

<filename>src/controller.py
# -*- coding: utf-8 -*-

"""
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Development Team: <NAME>
"""

from src.lib import ArgumentsError
from src.lib import BrowserError
from src.lib import PackageError
from src.lib import ReporterError
from src.lib import TplError
from src.lib import args
from src.lib import browser
from src.lib import events
from src.lib import package
from src.lib import reporter
from src.lib import tpl
from . import execution_time
from .exceptions import SrcError


class Controller(object):
    """Controller class"""

    def __init__(self):
        """
        Init constructor
        :raise SrcError
        """

        events.terminate()

        try:

            interpreter = package.check_interpreter()
            
            if interpreter is not True:
                raise SrcError(tpl.error(key='unsupported', actual=interpreter.get('actual'),
                                         expected=interpreter.get('expected')))

            self.ioargs = args().get_arguments()
        except ArgumentsError as e:
            raise SrcError(tpl.error(e.message))

    @execution_time(log=tpl)
    def run(self):
        """
        Bootstrap action
        :raise SrcError
        :return: None
        """

        try:

            tpl.message(package.banner())

            if 'host' in self.ioargs:
                getattr(self, 'scan_action')(self.ioargs)
            else:
                for action in self.ioargs.keys():
                    if hasattr(self, '{0}_action'.format(action)) and callable(
                            getattr(self, '{0}_action'.format(action))):
                        getattr(self, '{func}_action'.format(func=action))()
                        break

        except (SrcError, PackageError, BrowserError, AttributeError) as e:
            raise SrcError(tpl.error(e.message))

    @staticmethod
    def examples_action():
        """
        Show examples action
        :return: None
        """

        tpl.message(package.examples())

    @staticmethod
    def update_action():
        """
        App update action
        :raise SrcError
        :return: None
        """

        try:
            tpl.message(package.update())
        except (AttributeError, PackageError) as e:
            raise SrcError(e)

    @staticmethod
    def version_action():
        """
        Show app version action

        :raise SrcError
        :return: None
        """

        try:
            tpl.message(package.version())
        except (AttributeError, PackageError) as e:
            raise SrcError(e)

    @staticmethod
    def local_version():
        """
        Show app local version
        :raise SrcError
        :return: None
        """

        try:
            tpl.message(package.local_version())
        except (AttributeError, PackageError) as e:
            raise SrcError(e)

    @classmethod
    def scan_action(cls, params):
        """
        URL scan action
        :param dict params: console input args
        :raise SrcError
        :return: None
        """

        try:
            brows = browser(params)
            if True is reporter.is_reported(params.get('host')):
                try:
                    tpl.prompt(key='logged')
                except KeyboardInterrupt:
                    tpl.cancel(key='abort')

            if reporter.default is params.get('reports'):
                tpl.info(key='use_reports')

            brows.ping()
            brows.scan()
            brows.done()

        except (AttributeError, BrowserError, ReporterError, TplError) as e:
            raise SrcError(e.message)
        except (KeyboardInterrupt, SystemExit):
            tpl.cancel(key='abort')

# -*- coding: utf-8 -*- This program is free software: you can redistribute it and/or modify     it under the terms of the GNU General Public License as published by     the Free Software Foundation, either version 3 of the License.      This program is distributed in the hope that it will be useful,     but WITHOUT ANY WARRANTY; without even the implied warranty of     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     GNU General Public License for more details.      You should have received a copy of the GNU General Public License     along with this program.  If not, see <http://www.gnu.org/licenses/>.      Development Team: <NAME> Controller class Init constructor         :raise SrcError Bootstrap action         :raise SrcError         :return: None Show examples action         :return: None App update action         :raise SrcError         :return: None Show app version action          :raise SrcError         :return: None Show app local version         :raise SrcError         :return: None URL scan action         :param dict params: console input args         :raise SrcError         :return: None