# Path: interface/messages.py
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_help(*args, **kwargs):
#     print(Color.PURPLE + Color.BOLD + "[?]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)
# 
# Path: interface/utils.py
# def validate_mac(mac):
#     xr = re.compile(r'^([a-fA-F0-9]{2}([:-]?)[a-fA-F0-9]{2}(\2[a-fA-F0-9]{2}){4})$')
#     rr = xr.match(mac)
#     if rr:
#         return True
#     else:
#         return False
# 
# def lookup_mac(mac):
#     mac = mac.replace(":", "")
#     mac = mac.replace("-", "")
#     cursor = core.globals.ouidb_conn.cursor()
#     cursor.execute("SELECT name FROM oui WHERE oui == ?", [mac[:6]])
#     company_name = (cursor.fetchone())
#     if company_name is not None:
#         company_name = company_name[0]
#         return "(" + company_name + ")"
#     else:
#         return "(Unknown)"


import core.Misc
import core.io
import binascii
from interface.messages import print_success, print_error, print_help, print_info
from interface.utils import validate_mac, lookup_mac
    """
Name:Default WPA key generator for Sitecom WLR-4000/4004 routers
File:wlr-400X_mac2wpa.py
Author:Ján Trenčanský
License: GNU GPL v3
Created: 22.7.2015
Description: Generates default WPA key for Sitecom WLR-4000/4004 routers
Based on: Work of Roberto Paleari (@rpaleari) and Alessandro Di Pinto (@adipinto)
    http://blog.emaze.net/2014/04/sitecom-firmware-and-wifi.html

Options:
    Name        Description

    mac         MAC address used as input for WPA password generation
    """
    mac = "00:00:00:00:00"

    def __init__(self):
        core.Misc.RextMisc.__init__(self)

    def do_set(self, e):
        args = e.split(' ')
        if args[0] == "mac":
            if validate_mac(args[1]):
                self.mac = args[1]
                print_info("MAC set to: " + self.mac + " " + lookup_mac(self.mac))
            else:
                print_error("please provide valid MAC address")

    def do_mac(self, e):

# Path: interface/messages.py
# def print_success(*args, **kwargs):
#     print(Color.GREEN + Color.BOLD + "[+]" + Color.ENDC, *args, **kwargs)
# 
# def print_error(*args, **kwargs):
#     print(Color.RED + Color.BOLD + "[-]" + Color.ENDC, *args, **kwargs)
# 
# def print_help(*args, **kwargs):
#     print(Color.PURPLE + Color.BOLD + "[?]" + Color.ENDC, *args, **kwargs)
# 
# def print_info(*args, **kwargs):
#     print(Color.BLUE + Color.BOLD + "[*]" + Color.ENDC, *args, **kwargs)
# 
# Path: interface/utils.py
# def validate_mac(mac):
#     xr = re.compile(r'^([a-fA-F0-9]{2}([:-]?)[a-fA-F0-9]{2}(\2[a-fA-F0-9]{2}){4})$')
#     rr = xr.match(mac)
#     if rr:
#         return True
#     else:
#         return False
# 
# def lookup_mac(mac):
#     mac = mac.replace(":", "")
#     mac = mac.replace("-", "")
#     cursor = core.globals.ouidb_conn.cursor()
#     cursor.execute("SELECT name FROM oui WHERE oui == ?", [mac[:6]])
#     company_name = (cursor.fetchone())
#     if company_name is not None:
#         company_name = company_name[0]
#         return "(" + company_name + ")"
#     else:
#         return "(Unknown)"


# Path: modules/misc/sitecom/wlr-400X_mac2wpa.py
import core.Misc
import core.io
import binascii
from interface.messages import print_success, print_error, print_help, print_info
from interface.utils import validate_mac, lookup_mac

    """
Name:Default WPA key generator for Sitecom WLR-4000/4004 routers
File:wlr-400X_mac2wpa.py
Author:Ján Trenčanský
License: GNU GPL v3
Created: 22.7.2015
Description: Generates default WPA key for Sitecom WLR-4000/4004 routers
Based on: Work of Roberto Paleari (@rpaleari) and Alessandro Di Pinto (@adipinto)
    http://blog.emaze.net/2014/04/sitecom-firmware-and-wifi.html

Options:
    Name        Description

    mac         MAC address used as input for WPA password generation
    """
    mac = "00:00:00:00:00"

    def __init__(self):
        core.Misc.RextMisc.__init__(self)

    def do_set(self, e):
        args = e.split(' ')
        if args[0] == "mac":
            if validate_mac(args[1]):
                self.mac = args[1]
                print_info("MAC set to: " + self.mac + " " + lookup_mac(self.mac))
            else:
                print_error("please provide valid MAC address")

    def do_mac(self, e):

        print_info(self.mac)