# =============================================================================
# Clash Client Configuration — Campus VPN
# =============================================================================
# Compatible with: Clash Premium, Clash Meta (Mihomo), Clash Verge
#
# Architecture:
#   🌐 Internet  (port 10443) → Trojan-Go → direct internet egress from VPS
#   🎓 Campus    (port 8443)  → Trojan-Go → frp tunnel → gost SOCKS5 → campus network
#
# How to use:
#   1. Replace <PASSWORD> with the Trojan password from the public server
#   2. Import into Clash client
#   3. Select proxy mode: "Rule" (recommended) or "Global"
# =============================================================================

# ── General Settings ─────────────────────────────────────────────────────────
mixed-port: 7890          # HTTP(S) + SOCKS5 mixed port
allow-lan: false          # Set to true to share proxy on LAN
bind-address: "127.0.0.1"
mode: rule                # rule / global / direct
log-level: info
ipv6: false
external-controller: "127.0.0.1:9090"
secret: ""                # Set a password for external controller access

# ── DNS ──────────────────────────────────────────────────────────────────────
dns:
  enable: true
  listen: 0.0.0.0:1053
  ipv6: false
  default-nameserver:
    - 223.5.5.5       # Ali DNS
    - 114.114.114.114  # 114 DNS
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - "*.lan"
    - "*.local"
    - "*.localhost"
    - "*.home"
    - "*.arpa"
    - "time.*.com"
    - "ntp.*.com"
  nameserver:
    - 223.5.5.5
    - 114.114.114.114
    - https://doh.pub/dns-query         # DNSPod DoH
    - https://dns.alidns.com/dns-query   # Ali DoH
  fallback:
    - https://8.8.8.8/dns-query          # Google DoH
    - https://1.1.1.1/dns-query          # Cloudflare DoH
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 240.0.0.0/4
    domain:
      - "+.google.com"
      - "+.googleapis.com"
      - "+.youtube.com"
      - "+.github.com"

# ── Proxies ──────────────────────────────────────────────────────────────────
proxies:
  # Proxy #1: Internet egress via public server port 10443
  # Use this for: general browsing, Google, YouTube, GitHub, etc.
  - name: "🌐 Internet"
    type: trojan
    server: proxy.bi7khi.xyz
    port: 10443
    password: "wnYbT8rvHISg+s5paRiOQIbaJR6fswPb"
    sni: "proxy.bi7khi.xyz"
    skip-cert-verify: false
    udp: true

  # Proxy #2: Campus resource access via public server port 8443
  # Use this for: library databases, journals, campus internal services
  - name: "🎓 Campus"
    type: trojan
    server: proxy.bi7khi.xyz
    port: 8443
    password: "wnYbT8rvHISg+s5paRiOQIbaJR6fswPb"
    sni: "proxy.bi7khi.xyz"
    skip-cert-verify: false
    udp: true

# ── Proxy Groups ─────────────────────────────────────────────────────────────
proxy-groups:
  # Main selector — choose your routing mode
  - name: "🚀 Select"
    type: select
    proxies:
      - "♻️ Auto"
      - "🎓 Campus"
      - "🌐 Internet"
      - "DIRECT"

  # Auto mode: intelligent routing based on destination
  - name: "♻️ Auto"
    type: url-test
    proxies:
      - "🌐 Internet"
      - "🎓 Campus"
    url: "https://www.gstatic.com/generate_204"
    interval: 300

  # Fallback group for robustness
  - name: "🛡 Fallback"
    type: fallback
    proxies:
      - "🌐 Internet"
      - "🎓 Campus"
      - "DIRECT"
    url: "https://www.gstatic.com/generate_204"
    interval: 300

# ── Rules ────────────────────────────────────────────────────────────────────
# Rules are evaluated TOP TO BOTTOM. First match wins.
rules:
  # ═══════════════════════════════════════════════════════════════════
  # Campus & Academic Resources → 🎓 Campus (through campus network)
  # ═══════════════════════════════════════════════════════════════════

  # Chinese academic TLD
  - DOMAIN-SUFFIX,edu.cn,🎓 Campus

  # Library and academic keywords
  - DOMAIN-KEYWORD,library,🎓 Campus
  - DOMAIN-KEYWORD,lib.,🎓 Campus
  - DOMAIN-KEYWORD,librar,🎓 Campus

  # CNKI (中国知网)
  - DOMAIN-SUFFIX,cnki.net,🎓 Campus
  - DOMAIN-KEYWORD,cnki,🎓 Campus
  - DOMAIN-SUFFIX,cnki.com.cn,🎓 Campus

  # Wanfang Data (万方数据)
  - DOMAIN-SUFFIX,wanfangdata.com.cn,🎓 Campus
  - DOMAIN-SUFFIX,wanfangdata.com,🎓 Campus
  - DOMAIN-KEYWORD,wanfang,🎓 Campus

  # CQVIP (维普)
  - DOMAIN-SUFFIX,cqvip.com,🎓 Campus
  - DOMAIN-SUFFIX,cqvip.com.cn,🎓 Campus
  - DOMAIN-KEYWORD,cqvip,🎓 Campus

  # Other common Chinese academic databases
  - DOMAIN-SUFFIX,nssd.cn,🎓 Campus
  - DOMAIN-SUFFIX,csdl.ac.cn,🎓 Campus
  - DOMAIN-SUFFIX,nlc.cn,🎓 Campus
  - DOMAIN-SUFFIX,readcube.com,🎓 Campus
  - DOMAIN-SUFFIX,sciencedirect.com,🎓 Campus
  - DOMAIN-SUFFIX,springer.com,🎓 Campus
  - DOMAIN-SUFFIX,ieee.org,🎓 Campus
  - DOMAIN-SUFFIX,acm.org,🎓 Campus
  - DOMAIN-SUFFIX,wiley.com,🎓 Campus
  - DOMAIN-SUFFIX,tandfonline.com,🎓 Campus
  - DOMAIN-SUFFIX,jstor.org,🎓 Campus
  - DOMAIN-SUFFIX,nature.com,🎓 Campus
  - DOMAIN-SUFFIX,sci-hub.se,🎓 Campus
  - DOMAIN-SUFFIX,sci-hub.ru,🎓 Campus

  # Chinese university portals
  - DOMAIN-KEYWORD,university,🎓 Campus
  - DOMAIN-KEYWORD,college,🎓 Campus
  - DOMAIN-KEYWORD,campus,🎓 Campus

  # Campus internal IP ranges
  - IP-CIDR,10.0.0.0/8,🎓 Campus
  - IP-CIDR,172.16.0.0/12,🎓 Campus
  - IP-CIDR,100.64.0.0/10,🎓 Campus

  # ═══════════════════════════════════════════════════════════════════
  # LAN & Private Networks → DIRECT
  # ═══════════════════════════════════════════════════════════════════
  - IP-CIDR,127.0.0.0/8,DIRECT
  - IP-CIDR,192.168.0.0/16,DIRECT
  - IP-CIDR,224.0.0.0/4,DIRECT
  - DOMAIN-SUFFIX,local,DIRECT
  - DOMAIN-SUFFIX,localhost,DIRECT
  - DOMAIN-SUFFIX,lan,DIRECT
  - DOMAIN-SUFFIX,home.arpa,DIRECT

  # ═══════════════════════════════════════════════════════════════════
  # Chinese Domestic Sites → DIRECT (faster, no proxy needed)
  # ═══════════════════════════════════════════════════════════════════
  - GEOIP,CN,DIRECT
  - DOMAIN-SUFFIX,cn,DIRECT

  # Chinese major websites (direct for speed)
  - DOMAIN-SUFFIX,baidu.com,DIRECT
  - DOMAIN-SUFFIX,bilibili.com,DIRECT
  - DOMAIN-SUFFIX,zhihu.com,DIRECT
  - DOMAIN-SUFFIX,taobao.com,DIRECT
  - DOMAIN-SUFFIX,jd.com,DIRECT
  - DOMAIN-SUFFIX,qq.com,DIRECT
  - DOMAIN-SUFFIX,weixin.com,DIRECT
  - DOMAIN-SUFFIX,weibo.com,DIRECT
  - DOMAIN-SUFFIX,douyin.com,DIRECT
  - DOMAIN-SUFFIX,alipay.com,DIRECT
  - DOMAIN-SUFFIX,163.com,DIRECT
  - DOMAIN-SUFFIX,sina.com.cn,DIRECT
  - DOMAIN-SUFFIX,csdn.net,DIRECT
  - DOMAIN-SUFFIX,aliyun.com,DIRECT
  - DOMAIN-SUFFIX,cloud.tencent.com,DIRECT

  # ═══════════════════════════════════════════════════════════════════
  # Apple Services → Internet (prefer proxy for App Store speed)
  # ═══════════════════════════════════════════════════════════════════
  - DOMAIN-SUFFIX,apple.com,🌐 Internet
  - DOMAIN-SUFFIX,icloud.com,🌐 Internet
  - DOMAIN-SUFFIX,mzstatic.com,DIRECT

  # ═══════════════════════════════════════════════════════════════════
  # Default → Internet proxy
  # ═══════════════════════════════════════════════════════════════════
  - MATCH,🌐 Internet

# ── Proxy Group Display (cosmetic, Clash Verge / Meta) ───────────────────────
# proxy-groups remain as configured above, but some clients support
# additional display metadata. This section is optional.

# ═══════════════════════════════════════════════════════════════════════════
# Rule Categories Reference — Customize for Your Campus
# ═══════════════════════════════════════════════════════════════════════════
#
# Add your campus-specific domains below. Common patterns:
#
#   - DOMAIN-SUFFIX,<your-university>.edu.cn,🎓 Campus
#   - DOMAIN-SUFFIX,lib.<your-university>.edu.cn,🎓 Campus
#   - IP-CIDR,<your-campus-subnet>/24,🎓 Campus
#
# To find your campus IP ranges while on the campus network:
#   Windows: ipconfig
#   macOS:   ifconfig | grep inet
#   Linux:   ip addr show
#
# Look for IPs like 10.x.x.x, 172.16-31.x.x, or the school's public IP range.
# ═══════════════════════════════════════════════════════════════════════════
