# Path: persepolis/scripts/useful_tools.py
# def osAndDesktopEnvironment():
#     desktop_env = None
#     if os_type in OS.UNIX_LIKE:
#         # find desktop environment('KDE', 'GNOME', ...)
#         desktop_env = os.environ.get('XDG_CURRENT_DESKTOP')
# 
#     return os_type, desktop_env
# 
# Path: persepolis/scripts/logger.py
# def sendToLog(text="", type="INFO"):
# 
# Path: persepolis/constants/Os.py
# class OS:
#     LINUX = 'Linux'
#     WINDOWS = 'Windows'
#     FREE_BSD = 'FreeBSD'
#     OPEN_BSD = 'OpenBSD'
#     OSX = DARWIN = 'Darwin'
#     BSD_FAMILY = [FREE_BSD, OPEN_BSD]
#     UNIX_LIKE = BSD_FAMILY + [LINUX]
#     LIST = [LINUX, WINDOWS, FREE_BSD, OPEN_BSD, OSX]


import re
import subprocess
import requests
import urllib
import os
from persepolis.scripts.useful_tools import osAndDesktopEnvironment
from persepolis.scripts import logger
from persepolis.constants import OS
        # get ftp proxy
        try:
            proxy['ftp_proxy_ip'] = proxysource['ftp'].split(':')[1].replace('//', '')
            proxy['ftp_proxy_port'] = proxysource['ftp'].split(':')[2].replace("/", "").replace("\n", "")
        except:
            logger.sendToLog('no ftp proxy detected', 'INFO')

        # get socks proxy
        try:
            # if it is unity
            if desktop == 'Unity7':
                socks_proxy = proxysource['all'].split(':')[1].replace('//', '')
            # if it is Mac OS
            elif os_type == OS.OSX:

                validKeys = ['SOCKSEnable']

                # get proxies list using scutil command and parse it in tmp list
                mac_tmp_proxies_list = {}
                proxyList = subprocess.run(['scutil', '--proxy'], stdout=subprocess.PIPE)
                for line in proxyList.stdout.decode('utf-8').split('\n'):
                    words = line.split()
                    if len(words) == 3 and words[0] in validKeys:
                        mac_tmp_proxies_list[words[0]] = words[2]

                if mac_tmp_proxies_list['SOCKSEnable'] == '1':
                    socks_proxy = True
                else:
                    socks_proxy = False
            # others except KDE,Mac OS,gnome,unity7

# Path: persepolis/scripts/useful_tools.py
# def osAndDesktopEnvironment():
#     desktop_env = None
#     if os_type in OS.UNIX_LIKE:
#         # find desktop environment('KDE', 'GNOME', ...)
#         desktop_env = os.environ.get('XDG_CURRENT_DESKTOP')
# 
#     return os_type, desktop_env
# 
# Path: persepolis/scripts/logger.py
# def sendToLog(text="", type="INFO"):
# 
# Path: persepolis/constants/Os.py
# class OS:
#     LINUX = 'Linux'
#     WINDOWS = 'Windows'
#     FREE_BSD = 'FreeBSD'
#     OPEN_BSD = 'OpenBSD'
#     OSX = DARWIN = 'Darwin'
#     BSD_FAMILY = [FREE_BSD, OPEN_BSD]
#     UNIX_LIKE = BSD_FAMILY + [LINUX]
#     LIST = [LINUX, WINDOWS, FREE_BSD, OPEN_BSD, OSX]


# Path: persepolis/scripts/check_proxy.py
import re
import subprocess
import requests
import urllib
import os
from persepolis.scripts.useful_tools import osAndDesktopEnvironment
from persepolis.scripts import logger
from persepolis.constants import OS

        # get ftp proxy
        try:
            proxy['ftp_proxy_ip'] = proxysource['ftp'].split(':')[1].replace('//', '')
            proxy['ftp_proxy_port'] = proxysource['ftp'].split(':')[2].replace("/", "").replace("\n", "")
        except:
            logger.sendToLog('no ftp proxy detected', 'INFO')

        # get socks proxy
        try:
            # if it is unity
            if desktop == 'Unity7':
                socks_proxy = proxysource['all'].split(':')[1].replace('//', '')
            # if it is Mac OS
            elif os_type == OS.OSX:

                validKeys = ['SOCKSEnable']

                # get proxies list using scutil command and parse it in tmp list
                mac_tmp_proxies_list = {}
                proxyList = subprocess.run(['scutil', '--proxy'], stdout=subprocess.PIPE)
                for line in proxyList.stdout.decode('utf-8').split('\n'):
                    words = line.split()
                    if len(words) == 3 and words[0] in validKeys:
                        mac_tmp_proxies_list[words[0]] = words[2]

                if mac_tmp_proxies_list['SOCKSEnable'] == '1':
                    socks_proxy = True
                else:
                    socks_proxy = False
            # others except KDE,Mac OS,gnome,unity7

            else: