Skip to content

Commit

Permalink
separate rules into a standalone file
Browse files Browse the repository at this point in the history
  • Loading branch information
URenko committed Oct 24, 2024
1 parent 503c972 commit c721a30
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
pip install -r requirements.txt
- name: Package Application
run: |
sed -i 's/^ \+\"https/# \"https/' accesser/config.toml
sed -i 's/^ \+\"https/# \"https/' accesser/rules.toml
pyinstaller accesser.spec
env:
PYTHONOPTIMIZE: 1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ jobs:
python-version: ">=3.11"
- run: |
python3 -c 'import tomllib; tomllib.load(open("accesser/config.toml", "rb"))'
- run: |
python3 -c 'import tomllib; tomllib.load(open("accesser/rules.toml", "rb"))'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ hosts
*.exe
.1
config.toml
rules.toml
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ In addition, for Windows, by default (without specifying `--notimportca`) the ce
*You can use, for example, [pyenv](https://github.com/pyenv/pyenv) to install the required version of Python (Python 3.11+ is recommended).

## Configuration
After starting Accesser once, `config.toml` will be generated in the **working directory**. See the comments therein. After saving, reopen the program.
After starting Accesser once, `config.toml` and `rules.toml` will be generated in the **working directory**. See the comments therein. After saving, reopen the program.

## Advanced Usage 1: Use with other proxy software such as v2ray
Accesser is a local HTTP proxy with a default proxy address of `http://localhost:7654`, which can be used in combination with other proxy software as long as the network traffic can be exported as HTTP proxy.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ accesser
*可以使用例如[pyenv](https://github.com/pyenv/pyenv)来安装所需的Python版本(推荐Python 3.11+)。

## 设置
启动一次Accesser后,会在 **工作目录** 下生成`config.toml`,具体含义见其中注释,保存后重新打开程序。
启动一次Accesser后,会在 **工作目录** 下生成`config.toml``rules.toml`,具体含义见其中注释,保存后重新打开程序。

## 进阶1: 与v2ray等其他代理软件一起使用
Accesser是一个本地HTTP代理,默认代理地址为`http://localhost:7654`,只要网络流量能从其他代理软件以HTTP代理导出就能联合使用。
Expand Down
1 change: 1 addition & 0 deletions accesser.spec
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ block_cipher = None

datas=[
('accesser/config.toml', 'accesser'),
('accesser/rules.toml', 'accesser'),
('accesser/pac', 'accesser'),
(os.path.dirname(tld.__file__)+'/res/effective_tld_names.dat.txt', 'tld/res'),
]
Expand Down
180 changes: 0 additions & 180 deletions accesser/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,183 +44,3 @@ port = 7654
pac_host = "127.0.0.1"


[DNS]

# DNS服务器地址。可于下方 hosts 字段指定DNS服务器 host 对应的 IP 地址。
# DNS server address. You can specify bootstrap IP address in the [hosts] field below.
nameserver = [
"https://185.222.222.222/dns-query",# https://host|IP[:port]/path # DNS-over-HTTPS (DoH)
"https://45.11.45.11/dns-query",
"https://149.112.112.112/dns-query",
"https://149.112.112.10/dns-query",
"tls://149.112.112.112", # tls://host|IP[:port] # DNS-overTLS (DoT)
"tls://149.112.112.10",
"tls://dot.sb",
# "quic://dns.adguard-dns.com", # quic://host|IP[:port] # DNS-over-QUIC (DoQ)
# "localhost" # host|IP[:port] # 传统 UDP DNS | traditional UDP DNS
]


[http_redirect]

# 如果一个HTTP(无TLS)请求的URL以下面某个键开头,则会被重定向到其值对应的URL(通过HTTPS请求)。
# If the URL of an HTTP (no TLS) request starts with one of the following keys, it will be redirected to the URL corresponding to its value (via HTTPS request).

"pixiv.net/" = "www.pixiv.net/"
"www.google.com/recaptcha/" = "www.recaptcha.net/recaptcha/"
"instagram.com/" = "www.instagram.com/"
"nicovideo.jp/" = "www.nicovideo.jp/"
"twitch.tv/" = "www.twitch.tv/"


[alter_hostname]

# 与键对应的域名的TLS连接会使用其值对应的域名作为server_name字段,并且校验证书时也使用这一域名。键支持Unix shell风格的通配符。
# A TLS connection to the domain corresponding to the key will use the domain name corresponding to its value as the server_name field, and this domain name is also used when verifying the certificate. The key supports Unix shell-style wildcards.

"www.quora.com" = "fs.quoracdn.net"
"nyaa.si" = "ddos-guard.net"
"steamcommunity.com" = "www.valvesoftware.com"
"gn-web-assets.api.bbc.com" = "static-web-assets.gnl-common.bbcverticals.com"


[cert_verify]

# 为域名分别设置证书校验策略,其值可以是一个包含用于校验的域名的列表(有一个匹配就通过),也可以是 false 表示不校验
# 这比 [alter_hostname] 和全局的 check_hostname 的优先级高,但不会在 Client Hello 中作为 server_name 发送。
# Set the certificate validation policy for domains individually. The values can be a array contain strings which represent the domain name used to verify the certificate (pass if there is a match), or false which means disabling the verification.
# It has as a higher priority than [alter_hostname] and the global check_hostname, but will not be sent as server_name in Client Hello.

"1lib.sk" = ["1lib.pm", "1lib.sk", "singlelogin.re"]
"*.1lib.sk" = ["1lib.pm", "1lib.sk", "singlelogin.re"]
"singlelogin.re" = ["1lib.pm", "1lib.sk", "singlelogin.re"]
"*.singlelogin.re" = ["1lib.pm", "1lib.sk", "singlelogin.re"]
"scratch.mit.edu" = ["d.sni-645-default.ssl.fastly.net"]
"*.scratch.mit.edu" = ["d.sni-645-default.ssl.fastly.net"]
"mega.io" = ["static.mega.co.nz"]
"*.nytimes.com" = ["fastly.com", "cloudfront.net"]
"*.twitch.tv" = ["twitch.tv", "cloudfront.net","twitch.a2z.com", "fastly.com", "visioncritical.com", "imgix.net", "discourse.org", "bit.ly"]
"nicovideo.jp" = ["cloudfront.net"]
"*.nicovideo.jp" = ["cloudfront.net", "nicovideo.jp"]
"onedrive.live.com" = ["azureedge.net"]
"*.github.com" = ["github.com", "githubassets.com", "githubusercontent.com"]
"*.pixiv.net" = ["pixiv.net", "firebaseapp.com", "cloudfront.net", "tumblr.com"]


[hosts]

# 自定义 域名-IP 映射,即用于与网站建立连接,也用于与DNS服务器建立连接。
# Customize domain-IP mapping, which is used to establish a connection with the website and the DNS server.

# example for DNS server bootstrap address
"dot.sb" = "185.222.222.222"
# "dns.adguard-dns.com" = "94.140.14.14"

"pixiv.net" = "pixiv.me"
"www.pixiv.net" = "pixiv.me"
"sketch.pixiv.net" = "pixiv.me"
"accounts.pixiv.net" = "pixiv.me"
"imp.pixiv.net" = "pixiv.me"
"oauth.secure.pixiv.net" = "pixiv.me"
"factory.pixiv.net" = "pixiv.me"
"embed.pixiv.net" = "pixiv.me"
"engineering.pixiv.net" = "pixiv.me"
"app-api.pixiv.net" = "pixiv.me"
"sensei.pixiv.net" = "pixiv.me"
"goods.pixiv.net" = "pixiv.me"
"link.pixiv.net" = "pixiv.me"
"dic.pixiv.net" = "pixiv.me"
"en-dic.pixiv.net" = "pixiv.me"
"market.pixiv.net" = "pixiv.me"
"comic.pixiv.net" = "210.140.131.153"
"source.pixiv.net" = "210.140.131.153"
"i.pximg.net" = "pximg.net"
"fanbox.cc" = "pixiv.me"
".fanbox.cc" = "pixiv.me"
"www.bbc.co.uk" = "212.58.233.252"
"count.wenxuecity.com" = "0.0.0.0"
"adserver.wenxuecity.com" = "0.0.0.0"
"www.dropbox.com" = "162.125.69.1"
".appledaily.com" = "60.254.170.127"
"e-hentai.org" = "e-hentai.org.cdn.cloudflare.net"
".e-hentai.org" = "e-hentai.org.cdn.cloudflare.net"
"exhentai.org" = "178.175.128.252"
"v2ex.com" = "v2ex.com.cdn.cloudflare.net"
".v2ex.com" = "v2ex.com.cdn.cloudflare.net"
"discord.com" = "discord.com.cdn.cloudflare.net"
".discord.com" = "discord.com.cdn.cloudflare.net"
"discordapp.com" = "discordapp.com.cdn.cloudflare.net"
".discordapp.com" = "discordapp.com.cdn.cloudflare.net"
"discord.gg" = "discord.gg.cdn.cloudflare.net"
".discord.gg" = "discord.gg.cdn.cloudflare.net"
"media.discordapp.net" = "media.discordapp.net.cdn.cloudflare.net"
"nicovideo.jp" = "futuregadget-lab.com"
"qa.nicovideo.jp" = "124.146.170.109"
".nicovideo.jp" = "futuregadget-lab.com"
"cn.nytimes.com" = "futuregadget-lab.com"
"www.bbc.com" = "151.101.128.81"
"disqus.com" = "151.101.64.134"
"i.imgur.com" = "151.101.196.193"
"i.stack.imgur.com" = "151.101.196.193"
".theepochtimes.com" = "151.139.128.13"
"donate.epochtimes.com" = "151.139.128.13"
"i.epochtimes.com" = "151.139.128.13"
"mediawiki.org" = "text-lb.codfw.wikimedia.org"
".mediawiki.org" = "text-lb.codfw.wikimedia.org"
"wikipedia.org" = "text-lb.codfw.wikimedia.org"
".wikipedia.org" = "text-lb.codfw.wikimedia.org"
"wikiquote.org" = "text-lb.codfw.wikimedia.org"
".wikiquote.org" = "text-lb.codfw.wikimedia.org"
"wikinews.org" = "text-lb.codfw.wikimedia.org"
".wikinews.org" = "text-lb.codfw.wikimedia.org"
"wikiversity.org" = "text-lb.codfw.wikimedia.org"
".wikiversity.org" = "text-lb.codfw.wikimedia.org"
"wiktionary.org" = "text-lb.codfw.wikimedia.org"
".wiktionary.org" = "text-lb.codfw.wikimedia.org"
"wikibooks.org" = "text-lb.codfw.wikimedia.org"
".wikibooks.org" = "text-lb.codfw.wikimedia.org"
"wikivoyage.org" = "text-lb.codfw.wikimedia.org"
".wikivoyage.org" = "text-lb.codfw.wikimedia.org"
"wikisource.org" = "text-lb.codfw.wikimedia.org"
".wikisource.org" = "text-lb.codfw.wikimedia.org"
"wikidata.org" = "text-lb.codfw.wikimedia.org"
".wikidata.org" = "text-lb.codfw.wikimedia.org"
"wikimedia.org" = "text-lb.codfw.wikimedia.org"
"upload.wikimedia.org" = "upload-lb.codfw.wikimedia.org"
"maps.wikimedia.org" = "upload-lb.codfw.wikimedia.org"
".wikimedia.org" = "text-lb.codfw.wikimedia.org"
"scratch.mit.edu" = "scratchfoundation.map.fastly.net"
".scratch.mit.edu" = "scratchfoundation.map.fastly.net"
"archive.org" = "207.241.224.27"
"assets.twitch.tv" = "futuregadget-lab.com"
"vod-secure.twitch.tv" = "futuregadget-lab.com"
"vod-metro.twitch.tv" = "futuregadget-lab.com"
"vod-storyboards.twitch.tv" = "futuregadget-lab.com"
"extension-files.twitch.tv" = "futuregadget-lab.com"
"panels.twitch.tv" = "futuregadget-lab.com"
"clips-media-assets2.twitch.tv" = "futuregadget-lab.com"
"extensions-discovery-images.twitch.tv" = "futuregadget-lab.com"
"passport.twitch.tv" = "futuregadget-lab.com"
"brand.twitch.tv" = "futuregadget-lab.com"
"meetups.twitch.tv" = "futuregadget-lab.com"
"affiliate.twitch.tv" = "futuregadget-lab.com"
"ttv-redirect.m7g.twitch.tv" = "futuregadget-lab.com"
"blog.twitch.tv" = "futuregadget-lab.com"
"streamon.twitch.tv" = "futuregadget-lab.com"
"rivals.twitch.tv" = "futuregadget-lab.com"
"bits.twitch.tv" = "futuregadget-lab.com"
"mew.twitch.tv" = "futuregadget-lab.com"
"mobile.twitch.tv" = "futuregadget-lab.com"
".event-engineering.twitch.tv" = "futuregadget-lab.com"
"mi.twitch.tv" = "futuregadget-lab.com"
"costream.twitch.tv" = "futuregadget-lab.com"
"id-cdn.twitch.tv" = "futuregadget-lab.com"
"cvp.twitch.tv" = "futuregadget-lab.com"
"sings.twitch.tv" = "futuregadget-lab.com"
"discuss.dev.twitch.tv" = "futuregadget-lab.com"
"singlelogin.re" = "176.123.7.105"
".singlelogin.re" = "176.123.7.105"
# "singlelogin.re" = "176.123.7.228"
# ".singlelogin.re" = "176.123.7.228"
# "singlelogin.re" = "176.123.7.252"
# ".singlelogin.re" = "176.123.7.252"
7 changes: 6 additions & 1 deletion accesser/utils/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

basepath = Path(__file__).parent.parent

if not Path('rules.toml').exists():
shutil.copyfile(basepath / 'rules.toml', 'rules.toml')
with open('rules.toml', 'rb') as f:
config = tomllib.load(f)

if not Path('config.toml').exists():
shutil.copyfile(basepath / 'config.toml', 'config.toml')
with open('config.toml', 'rb') as f:
config = tomllib.load(f)
config |= tomllib.load(f)

def parse_args():
parser = argparse.ArgumentParser()
Expand Down

0 comments on commit c721a30

Please sign in to comment.