# Path: core/io.py
# def query_yes_no(question, default="yes"):
#     """Ask a yes/no question via raw_input() and return their answer.
# 
#     "question" is a string that is presented to the user.
#     "default" is the presumed answer if the user just hits <Enter>.
#         It must be "yes" (the default), "no" or None (meaning
#         an answer is required of the user).
# 
#     The "answer" return value is True for "yes" or False for "no".
#     """
#     valid = {"yes": True, "y": True, "ye": True,
#              "no": False, "n": False}
#     if default is None:
#         prompt = " [y/n] "
#     elif default == "yes":
#         prompt = " [Y/n] "
#     elif default == "no":
#         prompt = " [y/N] "
#     else:
#         raise ValueError("invalid default answer: '%s'" % default)
# 
#     while True:
#         print_info(question + prompt)
#         choice = input().lower()
#         if default is not None and choice == '':
#             return valid[default]
#         elif choice in valid:
#             return valid[choice]
#         else:
#             print_error("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n")
# 
# Path: interface/messages.py
# def print_failed(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# def print_warning(*args, **kwargs):
#     print(Color.YELLOW + Color.BOLD + "[!]" + Color.ENDC, *args, **kwargs)
# 
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)
# 
# def print_help(*args, **kwargs):
#     print(Color.PURPLE + Color.BOLD + "[?]" + Color.ENDC, *args, **kwargs)


import core.Exploit
import interface.utils
import requests
import requests.exceptions
import re
from core.io import query_yes_no
from interface.messages import print_failed, print_success, print_warning, print_error, print_info, print_help
                   ]
        core.Exploit.RextExploit.__init__(self)

    def do_list(self, e):
        counter = 0
        print_info("ID\tManufacturer\tModel\tFirmware")
        for device in self.devices:
            print_info("%d %s" % (counter, self.devices[counter]['name']))
            counter += 1

    def do_set(self, e):
        args = e.split(' ')
        try:
            if args[0] == "host":
                if interface.utils.validate_ipv4(args[1]):
                    self.host = args[1]
                else:
                    print_error("Please provide valid IPv4 address")
            elif args[0] == "port":
                if str.isdigit(args[1]):
                    self.port = args[1]
                else:
                    print_error("Port value must be integer")
            elif args[0] == 'device':
                if not str.isdigit(args[1]):
                    print_error("Invalid device ID")
                elif int(args[1]) < 0 or int(args[1]) > len(self.devices):
                    print_error("Invalid device ID")
                else:
                    index = int(args[1])

# Path: core/io.py
# def query_yes_no(question, default="yes"):
#     """Ask a yes/no question via raw_input() and return their answer.
# 
#     "question" is a string that is presented to the user.
#     "default" is the presumed answer if the user just hits <Enter>.
#         It must be "yes" (the default), "no" or None (meaning
#         an answer is required of the user).
# 
#     The "answer" return value is True for "yes" or False for "no".
#     """
#     valid = {"yes": True, "y": True, "ye": True,
#              "no": False, "n": False}
#     if default is None:
#         prompt = " [y/n] "
#     elif default == "yes":
#         prompt = " [Y/n] "
#     elif default == "no":
#         prompt = " [y/N] "
#     else:
#         raise ValueError("invalid default answer: '%s'" % default)
# 
#     while True:
#         print_info(question + prompt)
#         choice = input().lower()
#         if default is not None and choice == '':
#             return valid[default]
#         elif choice in valid:
#             return valid[choice]
#         else:
#             print_error("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n")
# 
# Path: interface/messages.py
# def print_failed(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# def print_warning(*args, **kwargs):
#     print(Color.YELLOW + Color.BOLD + "[!]" + Color.ENDC, *args, **kwargs)
# 
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)
# 
# def print_help(*args, **kwargs):
#     print(Color.PURPLE + Color.BOLD + "[?]" + Color.ENDC, *args, **kwargs)


# Path: modules/exploits/allegrosoft/misfortune_auth_bypass.py
import core.Exploit
import interface.utils
import requests
import requests.exceptions
import re
from core.io import query_yes_no
from interface.messages import print_failed, print_success, print_warning, print_error, print_info, print_help

                   ]
        core.Exploit.RextExploit.__init__(self)

    def do_list(self, e):
        counter = 0
        print_info("ID\tManufacturer\tModel\tFirmware")
        for device in self.devices:
            print_info("%d %s" % (counter, self.devices[counter]['name']))
            counter += 1

    def do_set(self, e):
        args = e.split(' ')
        try:
            if args[0] == "host":
                if interface.utils.validate_ipv4(args[1]):
                    self.host = args[1]
                else:
                    print_error("Please provide valid IPv4 address")
            elif args[0] == "port":
                if str.isdigit(args[1]):
                    self.port = args[1]
                else:
                    print_error("Port value must be integer")
            elif args[0] == 'device':
                if not str.isdigit(args[1]):
                    print_error("Invalid device ID")
                elif int(args[1]) < 0 or int(args[1]) > len(self.devices):
                    print_error("Invalid device ID")
                else:
                    index = int(args[1])

                    print_info("Device: %s" % self.devices[index]['name'])