# Path: ss/core/pac.py
# class ProxyAutoConfig(object):
# 
#     content = ""
#     URI = "/pac?t="
# 
#     def __str__(self):
#         s = "HTTP/1.1 200 OK\r\n"\
#         "Server: myss\r\n"\
#         "Connection: Close\r\n"\
#         "Content-Type: application/x-ns-proxy-autoconfig\r\n"\
#         "Content-Length: %d\r\n"\
#         "\r\n"\
#         "%s\r\n" % (len(self.content), self.content)
#         return s
# 
#     @classmethod
#     def load(cls):
#         path = settings["pac"]
#         with open(path, "r") as f:
#             data = f.read()
#         host = settings["local_address"]
#         socks5_port = settings.get("local_port", 1080)
#         http_port = settings.get("local_http_port", 1081)
#         proxy = ' proxy = "PROXY %s:%d; SOCKS %s:%d; ";\n' %\
#             (host, http_port, host, socks5_port)
#         data = re.sub("proxy *= *[\s\S]+?\n", proxy, data, 1)
#         cls.content = data
#         cls.URI = "/pac?t=%d" % int(time.time())
#         logging.info("reload pac file : %s" % path)
# 
# Path: ss/wrapper.py
# def onexit(func):
#     onexit_callbacks.append(func)
#     return func
# 
# Path: ss/settings.py
# class Settings(object):
#     DEFAULT_TIMEOUT = 300
#     _LOCK = RLock()
#     def __init__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, val):
#     def get(self, name, default=None):
#     def __contains__(self, name):
#     def update(self, config):
#     def dict(self):
#     def __repr__(self):


import logging
import os
from ss.core.pac import ProxyAutoConfig
from ss.wrapper import onexit
from ss.settings import settings
                "networksetup -setsecurewebproxystate %s off" % eth,
            ])
            logging.warn("set proxy mode to `off`")
        elif mode == self.MODE_PAC:
            host = "http://%(local_address)s:%(local_port)d" % settings
            url = host + ProxyAutoConfig.URI
            logging.info("set proxy mode to `pac`, pac url: %s" % url)
            cmd = "\n".join([
                "networksetup -setautoproxyurl %s %s" % (eth, url),
                "networksetup -setwebproxystate %s off" % eth,
                "networksetup -setsocksfirewallproxystate %s off" % eth,
                "networksetup -setsecurewebproxystate %s off" % eth,
                ])
        else:
            logging.warn("set proxy mode to `global`")
            socks5 = "networksetup -setsocksfirewallproxy %s %s %d" % (
                eth, settings["local_address"], settings["local_port"]
            )
            cmd = "\n".join([
                socks5, 
                "networksetup -setwebproxystate %s off" % eth,
                "networksetup -setautoproxystate %s off" % eth,
                "networksetup -setsecurewebproxystate %s off" % eth,
            ])
        os.system(cmd)

    def update_pac(self):
        if settings.get("proxy_mode", "off") != "pac":
            return
        host = "http://%(local_address)s:%(local_port)d" % settings

# Path: ss/core/pac.py
# class ProxyAutoConfig(object):
# 
#     content = ""
#     URI = "/pac?t="
# 
#     def __str__(self):
#         s = "HTTP/1.1 200 OK\r\n"\
#         "Server: myss\r\n"\
#         "Connection: Close\r\n"\
#         "Content-Type: application/x-ns-proxy-autoconfig\r\n"\
#         "Content-Length: %d\r\n"\
#         "\r\n"\
#         "%s\r\n" % (len(self.content), self.content)
#         return s
# 
#     @classmethod
#     def load(cls):
#         path = settings["pac"]
#         with open(path, "r") as f:
#             data = f.read()
#         host = settings["local_address"]
#         socks5_port = settings.get("local_port", 1080)
#         http_port = settings.get("local_http_port", 1081)
#         proxy = ' proxy = "PROXY %s:%d; SOCKS %s:%d; ";\n' %\
#             (host, http_port, host, socks5_port)
#         data = re.sub("proxy *= *[\s\S]+?\n", proxy, data, 1)
#         cls.content = data
#         cls.URI = "/pac?t=%d" % int(time.time())
#         logging.info("reload pac file : %s" % path)
# 
# Path: ss/wrapper.py
# def onexit(func):
#     onexit_callbacks.append(func)
#     return func
# 
# Path: ss/settings.py
# class Settings(object):
#     DEFAULT_TIMEOUT = 300
#     _LOCK = RLock()
#     def __init__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, val):
#     def get(self, name, default=None):
#     def __contains__(self, name):
#     def update(self, config):
#     def dict(self):
#     def __repr__(self):


# Path: ss/config/darwin.py
import logging
import os
from ss.core.pac import ProxyAutoConfig
from ss.wrapper import onexit
from ss.settings import settings

                "networksetup -setsecurewebproxystate %s off" % eth,
            ])
            logging.warn("set proxy mode to `off`")
        elif mode == self.MODE_PAC:
            host = "http://%(local_address)s:%(local_port)d" % settings
            url = host + ProxyAutoConfig.URI
            logging.info("set proxy mode to `pac`, pac url: %s" % url)
            cmd = "\n".join([
                "networksetup -setautoproxyurl %s %s" % (eth, url),
                "networksetup -setwebproxystate %s off" % eth,
                "networksetup -setsocksfirewallproxystate %s off" % eth,
                "networksetup -setsecurewebproxystate %s off" % eth,
                ])
        else:
            logging.warn("set proxy mode to `global`")
            socks5 = "networksetup -setsocksfirewallproxy %s %s %d" % (
                eth, settings["local_address"], settings["local_port"]
            )
            cmd = "\n".join([
                socks5, 
                "networksetup -setwebproxystate %s off" % eth,
                "networksetup -setautoproxystate %s off" % eth,
                "networksetup -setsecurewebproxystate %s off" % eth,
            ])
        os.system(cmd)

    def update_pac(self):
        if settings.get("proxy_mode", "off") != "pac":
            return
        host = "http://%(local_address)s:%(local_port)d" % settings

        url = host + ProxyAutoConfig.URI