# coding=utf-8
# 这是为Google和中文维基(无缝整合)镜像配置的示例配置文件
#
# 使用方法:
#   1. 复制本文件到 zmirror 根目录(wsgi.py所在目录), 并重命名为 config.py
#   2. 修改 my_host_name 为你自己的域名
#
# 各项设置选项的详细介绍请看 config_default.py 中对应的部分
# 本配置文件假定你的服务器本身在墙外
# 如果服务器本身在墙内(或者在本地环境下测试, 请修改`Proxy Settings`中的设置
#
# 由于google搜索结果经常会出现中文维基, 所以顺便把它也加入了.
# google跟中文维基之间使用了本程序的镜像隔离功能, 可以保证中文维基站的正常使用
#
# 本配置文件试图还原出一个功能完整的google.
#   但是由于程序本身所限, 还是不能[完整]镜像过来整个[google站群]
#   在后续版本会不断增加可用的网站
#
# 以下google服务完全可用:
#   google网页搜索/学术/图片/新闻/图书/视频(搜索)/财经/APP搜索/翻译/网页快照/...
#   google搜索与中文维基百科无缝结合
# 以下服务部分可用:
#     gg地图(地图可看, 左边栏显示不正常)/G+(不能登录)
# 以下服务暂不可用(因为目前无法解决登录的问题):
#     所有需要登录的东西, docs之类的
#

# Github: https://github.com/aploium/zmirror

# ############## Local Domain Settings ##############
my_host_name = 'ggb123.cn'
my_host_scheme = 'https://'
my_host_port = None  # None表示使用默认端口, 可以设置成非标准端口, 比如 81

# ############## Target Domain Settings ##############
target_domain = 'www.geogebra.org'
target_scheme = 'https://'

# 这里面大部分域名都是通过 `enable_automatic_domains_whitelist` 自动采集的, 我只是把它们复制黏贴到了这里
# 实际镜像一个新的站时, 手动只需要添加很少的几个域名就可以了.
# 自动采集(如果开启的话)会不断告诉你新域名
external_domains = (
    "accounts-beta.geogebra.org",
    "accounts.geogebra.org",
    "api.geogebra.org",
    "autotest2.geogebra.org",
    "beta.geogebra.org",
    "cdn.geogebra.org",
    "community.geogebra.org",
    "data-logger.geogebra.org",
    "dev.geogebra.org",
    "download.geogebra.org",
    #"help.geogebra.org",
    #"live.geogebra.org",
    "stage.geogebra.org",
    "static.geogebra.org",
    "tube.geogebra.org",
    "web.geogebra.org",
    #"wiki.geogebra.org",
    "static.hotjar.com",
    "script.hotjar.com",
    "vars.hotjar.com",
    "cdnjs.cloudflare.com",
    "fonts.gstatic.com",
    "forum.gstatic.com",
    "geogebra.github.io",
    #"c60708c831e2.edge.captcha-sdk.awswaf.com",
)

# 强制所有Google站点使用HTTPS
force_https_domains = 'ALL'

# 自动动态添加域名
enable_automatic_domains_whitelist = True
domains_whitelist_auto_add_glob_list = (
#    "*.awswaf.com",
)

# ############## Proxy Settings ##############
# 如果你在墙内使用本配置文件, 请指定一个墙外的http代理
is_use_proxy = False
# 代理的格式及SOCKS代理, 请看 http://docs.python-requests.org/en/latest/user/advanced/#proxies
requests_proxies = dict(
    http='http://127.0.0.1:8123',
    https='https://127.0.0.1:8123',
)

# ############## Sites Isolation ##############
enable_individual_sites_isolation = True

# 镜像隔离, 用于支持Google和维基共存
isolated_domains = {
        #'api.geogebra.org',
        #'www.google-analytics.com', 
        #'zh.m.wikipedia.org'
}

# ############## URL Custom Redirect ##############
url_custom_redirect_enable = True
url_custom_redirect_list = {
    # 这是一个方便的设置, 如果你访问 /wiki ,程序会自动重定向到后面这个长长的wiki首页
    #'/wiki': '/extdomains/https-zh.wikipedia.org/',
    # 这是gmail
    #'/gmail': '/extdomains/mail.google.com/mail/u/0/h/girbaeneuj90/',
    #'/tencent5487524491536532369.txt': '/extdomains/ali.ggb123.cn/tencent5487524491536532369.txt',
    '/m/dfJGV6Jw': '/extdomains/www.geogebra.org/',
    '/m/utjBZfbe': '/extdomains/www.geogebra.org/',
    '/search/%E5%9C%8B%E6%97%97': '/extdomains/www.geogebra.org/',
}

# If you want more complicated regex redirect, please add then in this dict.
# If url FULLY MATCH the first regex, the second regex for re.sub  will be applied
# Same as above, only the url PATH will be applied (maybe change in later version)
# Please see https://docs.python.org/3.5/library/re.html#re.sub for more rules
#
# Dependency: url_custom_redirect_enable == True
url_custom_redirect_regex = (
    # v0.18.0+ because the new sites isolation mechanism, these redirect are NO LONGER NEEDED FOR WIKIPEDIA
    # now, they are for sample only.
    #
    # This example fix mobile wikipedia's search bug
    # will redirect /wiki/Some_wiki_page to /extdomains/https-zh.m.wikipedia.org/wiki/Some_wiki_page
    # (r'^/wiki/(?P<name>.*)$', '/extdomains/https-zh.m.wikipedia.org/wiki/\g<name>'),
    # (r'.*recaptcha__zh_cn\.js$', '/extdomains/www.ggb123.cn/recaptcha.ggb123.js'),
    (r'^/extdomains/accounts\.geogebra\.org/scripts/create\.js.*$', '/extdomains/www.ggb123.cn/create.js'),
    (r'^/c60708c831e2/jsapi\.js.*$', '/extdomains/www.ggb123.cn/jsapi.js'),
    (r'^/extdomains/www\.google\.com/recaptcha/api\.js.*$', '/extdomains/accounts.geogebra.org/scripts/gt.js?v=0.2'),
    (r'^/$', '/extdomains/www.ggb123.cn/geogebra.html'),
    (r'^/sp-assets/_next/static/chunks/571-69291bd65ab08f61\.js$', '/extdomains/www.ggb123.cn/571-69291bd65ab08f61.js?v=20240705004'),
)

# ############## Misc ##############
# v0.18.5+
# eg: {'access-control-max-age', 'access-control-allow-origin', 'x-connection-hash'}
# must be lower case
# 在默认允许的headers以外添加一些允许被传送到用户的http响应头, 一般不需要添加自定义的. 内置的够用了
# 必须全部小写
custom_allowed_remote_headers = {'access-control-allow-origin',}
custom_allowed_origin = '*'

#custom_text_rewriter_enable = True
#url_custom_redirect_enable = False

plain_replace_domain_alias = [
    ('www.googletagmanager.com', 'www.ggb123.cn'),
    ('www.google-analytics.com', 'www.ggb123.cn'),
    ('domain=geogebra.org', 'domain=ggb123.cn'),
]

#domains_alias_to_target_domain = ['api.geogebra.org']

enable_connection_keep_alive = True

# ############## Output Settings ##############
# Verbose level (0~4) 0:important and error 1:info 2:warning 3/4:debug. Default is 3 (for first time runner)
# 注意: 在正式部署到服务器后, 请把这个值修改为2, 如果设置为3或4,会产生非常大量的debug输出
verbose_level = 1
custom_inject_content = {
    "head_first": [
        {
            "content": r"""<script>Node.prototype.insertBefore=function(b){return function(){if(arguments[0].type=="text/javascript"&&arguments[0].integrity&&arguments[0].src.indexOf("recaptcha__zh_cn.js")>0){arguments[0].removeAttribute("integrity");return b.apply(this,arguments)}else{return b.apply(this,arguments)}}}(Node.prototype.insertBefore);</script>""",
            "url_regex": r"^.*user\/create",
	},
    ],
    "head_last": [
        {               "content": r"""<script>var cct=0;document.title="GeoGebra免费的数学应用全球学生与教师用户超过一亿";function addicp(){cct++;var footdiv=document.getElementsByClassName('mx-a-s w-360px my-1 tc-white vertical-align-middle');if(footdiv.length>0){var pos=footdiv[0].getElementsByTagName("li");if(pos.length>=1&&pos[pos.length-1].innerHTML.indexOf("18027985")<0)pos[pos.length-1].innerHTML='<a style="hover{color: var(--theme-hover);" href="https://beian.miit.gov.cn/" target="_blank" rel="noopener">鄂ICP备18027985号-2</a>'}if(document.title.indexOf("镜像")<0)document.title=document.title.replace(/^GeoGebra|GeoGebra$/,"Geogebra镜像站");if(cct<=1000)setTimeout(addicp,100)}addicp();</script>""",
            "url_regex": r"^[^\/]+[^.]*$",
        },
    ]
}

developer_temporary_disable_ssrf_prevention = True
local_cache_enable = False
#developer_dump_all_traffics = True
developer_do_not_verify_ssl=True
