diff --git a/config/niri/.config/niri/config/envs.kdl b/config/niri/.config/niri/config/envs.kdl index 7803b80..eee5e66 100644 --- a/config/niri/.config/niri/config/envs.kdl +++ b/config/niri/.config/niri/config/envs.kdl @@ -15,8 +15,12 @@ environment { LIBVA_DRIVER_NAME "nvidia" __GLX_VENDOR_LIBRARY_NAME "nvidia" NVD_BACKEND "nvidia" - GBM_BACKEND "nvidia-drm"; - WLR_NO_HARDWARE_CURSORS "1"; + GBM_BACKEND "nvidia-drm" + WLR_NO_HARDWARE_CURSORS "1" + + // Nvidia Prime + // __NV_PRIME_RENDER_OFFLOAD "1"; + // __VK_LAYER_NV_optimus "NVIDIA_only" // Fix Swing _JAVA_AWT_WM_NONREPARENTING "1" diff --git a/config/niri/.config/niri/config/misc.kdl b/config/niri/.config/niri/config/misc.kdl index 8c18b91..db5af45 100644 --- a/config/niri/.config/niri/config/misc.kdl +++ b/config/niri/.config/niri/config/misc.kdl @@ -1,7 +1,7 @@ screenshot-path "~/Pictures/Screenshots/niri_screenshot_%Y-%m-%d_%H-%M-%S.png" debug { - render-drm-device "/dev/dri/renderD129" + render-drm-device "/dev/dri/renderD128" } // gestures { diff --git a/config/scripts/.local/snippets/set_display b/config/scripts/.local/snippets/set_display index 648487c..991e8b3 100644 --- a/config/scripts/.local/snippets/set_display +++ b/config/scripts/.local/snippets/set_display @@ -9,7 +9,7 @@ # Constants niri_config_file="$HOME/.config/niri/config/misc.kdl" -prefer_order=(amd nvidia intel) # AMD -> Nvidia -> Intel +prefer_order=(intel amd nvidia) # AMD -> Nvidia -> Intel # Get vendor and path of each GPU default_card_path="$(find /dev/dri/card* 2>/dev/null | head -n 1)" @@ -24,49 +24,49 @@ nvidia_render_path="" amd_render_path="" for link in /dev/dri/by-path/*-card; do - [[ -e "$link" ]] || continue - card="$(readlink -f "$link")" - vfile="/sys/class/drm/$(basename "$card")/device/vendor" - [[ -r "$vfile" ]] || continue - vendor="$(cat "$vfile")" - case "$vendor" in - 0x10de) nvidia_card_path="$card" ;; - 0x8086) intel_card_path="$card" ;; - 0x1002) amd_card_path="$card" ;; - esac + [[ -e "$link" ]] || continue + card="$(readlink -f "$link")" + vfile="/sys/class/drm/$(basename "$card")/device/vendor" + [[ -r "$vfile" ]] || continue + vendor="$(cat "$vfile")" + case "$vendor" in + 0x10de) nvidia_card_path="$card" ;; + 0x8086) intel_card_path="$card" ;; + 0x1002) amd_card_path="$card" ;; + esac done for link in /dev/dri/by-path/*-render; do - [[ -e "$link" ]] || continue - render="$(readlink -f "$link")" - vfile="/sys/class/drm/$(basename "$render")/device/vendor" - [[ -r "$vfile" ]] || continue - vendor="$(cat "$vfile")" - case "$vendor" in - 0x10de) nvidia_render_path="$render" ;; - 0x8086) intel_render_path="$render" ;; - 0x1002) amd_render_path="$render" ;; - esac + [[ -e "$link" ]] || continue + render="$(readlink -f "$link")" + vfile="/sys/class/drm/$(basename "$render")/device/vendor" + [[ -r "$vfile" ]] || continue + vendor="$(cat "$vfile")" + case "$vendor" in + 0x10de) nvidia_render_path="$render" ;; + 0x8086) intel_render_path="$render" ;; + 0x1002) amd_render_path="$render" ;; + esac done # Specify device for brightnessctl # Only tested on my laptop with Intel iGPU & Nvidia dGPU BRIGHTNESSCTL_DEVICE="auto" if [[ -n "$intel_card_path" ]]; then - BRIGHTNESSCTL_DEVICE="intel_backlight" + BRIGHTNESSCTL_DEVICE="intel_backlight" elif [[ -n "$nvidia_card_path" ]]; then - BRIGHTNESSCTL_DEVICE="nvidia_0" + BRIGHTNESSCTL_DEVICE="nvidia_0" fi export BRIGHTNESSCTL_DEVICE # AQ_DRM_DEVICES allows multiple entries separated by colon devices="" for who in "${prefer_order[@]}"; do - case "$who" in - nvidia) [[ -n "$nvidia_card_path" ]] && devices="${devices:+$devices:}$nvidia_card_path" ;; - intel) [[ -n "$intel_card_path" ]] && devices="${devices:+$devices:}$intel_card_path" ;; - amd) [[ -n "$amd_card_path" ]] && devices="${devices:+$devices:}$amd_card_path" ;; - esac + case "$who" in + nvidia) [[ -n "$nvidia_card_path" ]] && devices="${devices:+$devices:}$nvidia_card_path" ;; + intel) [[ -n "$intel_card_path" ]] && devices="${devices:+$devices:}$intel_card_path" ;; + amd) [[ -n "$amd_card_path" ]] && devices="${devices:+$devices:}$amd_card_path" ;; + esac done HYPR_AQ_DRM_DEVICES="${devices:-$default_card_path}" export HYPR_AQ_DRM_DEVICES @@ -74,37 +74,37 @@ export HYPR_AQ_DRM_DEVICES # But niri only supports choosing one preferred render device primary_render_device="$default_render_path" for who in "${prefer_order[@]}"; do - case "$who" in - nvidia) [[ -n "$nvidia_render_path" ]] && { - primary_render_device="$nvidia_render_path" - break - } ;; - intel) [[ -n "$intel_render_path" ]] && { - primary_render_device="$intel_render_path" - break - } ;; - amd) [[ -n "$amd_render_path" ]] && { - primary_render_device="$amd_render_path" - break - } ;; - esac + case "$who" in + nvidia) [[ -n "$nvidia_render_path" ]] && { + primary_render_device="$nvidia_render_path" + break + } ;; + intel) [[ -n "$intel_render_path" ]] && { + primary_render_device="$intel_render_path" + break + } ;; + amd) [[ -n "$amd_render_path" ]] && { + primary_render_device="$amd_render_path" + break + } ;; + esac done # Update niri config function update_niri_config() { - local config_file="$1" - local device_path="$2" + local config_file="$1" + local device_path="$2" - [[ -f "$config_file" ]] || return + [[ -f "$config_file" ]] || return - if grep -qE '^\s*render-drm-device\s+"[^"]+"' "$config_file"; then - local current - current="$(grep -E '^\s*render-drm-device\s+"[^"]+"' "$config_file" | sed -E 's/^\s*render-drm-device\s+"([^"]+)".*/\1/')" - [[ "$current" == "$device_path" ]] && return - sed -i -E "s|^(\s*render-drm-device\s+)\"[^\"]+\"|\1\"$device_path\"|" "$config_file" - else - printf '\ndebug {\nrender-drm-device "%s"\n}\n' "$device_path" >>"$config_file" - fi + if grep -qE '^\s*render-drm-device\s+"[^"]+"' "$config_file"; then + local current + current="$(grep -E '^\s*render-drm-device\s+"[^"]+"' "$config_file" | sed -E 's/^\s*render-drm-device\s+"([^"]+)".*/\1/')" + [[ "$current" == "$device_path" ]] && return + sed -i -E "s|^(\s*render-drm-device\s+)\"[^\"]+\"|\1\"$device_path\"|" "$config_file" + else + printf '\ndebug {\nrender-drm-device "%s"\n}\n' "$device_path" >>"$config_file" + fi } update_niri_config "$niri_config_file" "$primary_render_device" diff --git a/memo/mail-service.md b/memo/mail-service.md index 8fe3c89..2afb630 100644 --- a/memo/mail-service.md +++ b/memo/mail-service.md @@ -8,6 +8,7 @@ - [目录](#目录) - [概览](#概览) + - [一些术语和缩写](#一些术语和缩写) - [要做什么](#要做什么) - [需要什么](#需要什么) - [前置准备](#前置准备) @@ -42,9 +43,64 @@ ## 概览 -### 要做什么 +### 一些术语和缩写 -一个概览. +> 看不懂没关系, 遇到了再回来翻就好 :) + +- M\*A + + | 简写 | 全称 | 中文名称 | 说明 | + | ---- | --------------------- | ------------ | ---------------------------------------------------------- | + | MTA | Mail Transfer Agent | 邮件传输代理 | 负责在邮件服务器之间传输邮件. 例如 Postfix. | + | MDA | Mail Delivery Agent | 邮件投递代理 | 负责将邮件存储到用户邮箱中. 例如 Dovecot. | + | MSA | Mail Submission Agent | 邮件提交代理 | 负责接收来自邮件客户端的邮件并将其传递给 MTA. 例如 Postfix | + | MUA | Mail User Agent | 邮件用户代理 | 即邮件客户端. 例如 Thunderbird | + +- 协议 + + | 简写 | 全称 | 中文名称 | 说明 | + | --------------- | -------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | + | SMTP | Simple Mail Transfer Protocol | 简单邮件传输协议 | 用于 MTA 之间的服务器通信. 通常运行在 25 端口. | + | SMTP Submission | SMTP Submission | SMTP 提交协议 | 用于 MUA 向 MSA 提交邮件. 通常运行在 587 端口, 支持 `STARTTLS` 加密通信. | + | SMTPS | SMTP over SSL/TLS | 基于 SSL/TLS 的 SMTP | 用于 MUA 提交邮件给 MSA, 使用独立端口(465)进行加密通信, 支持 `Implicit TLS`, 与 `STARTTLS` 不同的是其在连接建立时便立即进行 SSL/TLS 握手, 降低中间人攻击的风险. | + | IMAP | Internet Message Access Protocol | 互联网消息访问协议 | 用于 MUA 从 MDA 拉取邮件. | + | IMAPS | IMAP over SSL/TLS | 基于 SSL/TLS 的 IMAP | 使用独立端口(993)进行加密通信. | + | POP3 | Post Office Protocol version 3 | 邮局协议版本 3 | 另一种用于 MUA 接收邮件的协议, 不同的是一旦某个 MUA 取走邮件, 该邮件会在服务器上删除, 其他 MUA 将不再能收到这封邮件. 本文不会涉及此协议. | + | LMTP | Local Mail Transfer Protocol | 本地邮件传输协议 | 简化的 SMTP, 用于 MTA 在服务器内部将邮件传递给 MDA. | + +- 安全策略 + + | 简写 | 全称 | 中文名称 | 说明 | + | --------------- | --------------------------------------------------------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------- | + | rDNS | Reverse DNS | 反向域名解析 | 将 IP 地址映射回域名的特殊 DNS 记录. 多个 ip 可以同时映射到同一个域名, 但一个 ip 只能映射到一个域名. | + | SPF | Sender Policy Framework | 发件人策略框架 | 用于防止伪造发件人的技术. | + | DKIM | DomainKeys Identified Mail | 域名密钥识别邮件 | 用于验证邮件的完整性和真实性的技术. | + | DMARC | Domain-based Message Authentication, Reporting, and Conformance | 基于域的消息认证, 报告和一致性 | 用于指定邮件在目标服务的处理策略. | + | DMARC Alignment | DMARC Alignment | DMARC 对齐 | 用于确保发件人域名与 SPF 和 DKIM 认证域名一致的策略. | + | MTA-STS | Mail Transfer Agent Strict Transport Security | 邮件传输代理严格传输安全 | 用于防止中间人攻击的技术. | + | TLS-RPT | Transport Layer Security Reporting | 传输层安全报告 | 一方向另一方反馈 TLS 相关报告的方式. | + | SRS | Sender Rewriting Scheme | 发件人重写方案 | 用于确保在邮件转发后保持 SPF 通过的技术, 通过改写 Envelope From 地址实现. | + | ARC | Authenticated Received Chain | 认证接收链 | 用于在邮件转发过程中保持认证信息的技术. | + +- 邮件数据 + + | 名称 | 中文名称 | 说明 | + | ------------------ | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | + | Envelope From | 信封发件人 | 邮件传输过程中使用的发件人地址. 通常在接受到的邮件头部中以 `Return-Path` 字段显示. | + | Header From / From | 邮件头部发件人 | 邮件头部中显示的发件人地址, 也是在邮件客户端中能清晰看到的最醒目的发件人地址. | + | Return-Path | 退信路径 | 邮件头部中的一个字段, 用于指定邮件的回执地址, 通常由接受方 MTA 根据 Envelope sender 生成. | + | DKIM-Signature | DKIM 签名 | 邮件头部中的一个字段, 包含用于验证邮件完整性和真实性的签名信息. | + | Content-Type | 内容类型 | 邮件头部中的一个字段, 用于指定邮件内容的格式和编码方式. 文本为主的邮件通常使用 `text/plain; charset="UTF-8"` 或 `text/html; charset="UTF-8"`, 二者在收件方的垃圾邮件过滤策略中可能会有不同的检测标准和权重. | + +- 反垃圾与声誉 + + | 简写 | 全称 | 中文名称 | 说明 | + | ---- | ------------------------------------------- | -------------------- | ----------------------------------------------------------------------------------------------- | + | RBL | Real-time Blackhole List | 实时黑洞列表 | 由第三方维护的黑名单数据库. | + | - | Greylisting | 灰名单 | 一种反垃圾邮件技术, 通过拒绝第一次发送的邮件并要求重试来过滤垃圾邮件. | + | BIMI | Brand Indicators for Message Identification | 邮件识别的品牌指示符 | 允许在收件人的列表页显示自定义品牌 Logo 的标准. ~~因为我没有品牌也没有 Logo 所以~~本文不会涉及. | + +### 要做什么 1. 在自己的服务器上配置邮件服务器, 直接接收邮件; @@ -108,6 +164,10 @@ 下文中将使用 `1.14.5.14` 作为服务器的公网 IP 地址. +> [!IMPORTANT] +> +> 在网络工程和状态防火墙的语境中, 当提到"封锁端口 X 的出站流量"时, 通常指的是"禁止从本地服务器发起到外部服务器的连接请求, 目标端口为 X". 相反, "封锁端口 X 的入站流量"则意味着"禁止外部服务器发起到本地服务器的连接请求, 目标端口为 X". 策略中用于识别流量的是目标端口, 而非源端口. 例如即使"25 端口的出站流量被封", 如果强行用 25 端口连接外部服务器的其他开放端口如 80, 这种连接请求仍然是允许的. 当然策略中也可以通过源端口进行过滤, 不过这么做通常意义不大. + ## 前置准备 ### 放开那个端口! @@ -192,6 +252,12 @@ > [!TIP] > > 如果乐意的话可以把收信域名, 发信域名, 乃至退信域名等等都拆分开来配置, 但这超过了本文的讨论范围且配置大同小异, 因此不做另外说明 ~~主要是懒~~ :) +> +> 在使用 SMTP 中继服务的情况下, 这个域名只作为收信服务器存在, 发信时使用的域名通常是 SMTP 服务商提供的子域名. + +> [!NOTE] +> +> 优先级数值越小, 优先级越高. 如果同一个域名下有多个 MX 记录, 那么邮件服务器会优先选择优先级最高的记录进行连接. - A 记录: - 主机名: `mail` @@ -360,7 +426,7 @@ docker exec -it mailserver setup email add me@domain.tld <密码> ### 配置 SPF -SPF 记录用于指定哪些服务器被允许代表该域名发送邮件. +SPF 记录用于指定哪些服务器被允许代表该域名发送邮件. 它会检查信件 "Envelope sender" (也就是 `Return-Path` 头部) 中的域名是否与对应域名的 SPF 记录匹配, 从而防止伪造发件人. > [!IMPORTANT] > @@ -812,14 +878,7 @@ docker exec -it mailserver setup alias add @domain.tld me@domain.tld ### 邮件传输链路 -> 一些术语简写: -> -> - `MTA`: Mail Transfer Agent, 邮件传输代理, 负责在邮件服务器之间传输邮件. 例如 Postfix. -> - `MDA`: Mail Delivery Agent, 邮件投递代理, 负责将邮件存储到用户邮箱中. 例如 Dovecot. -> - `MSA`: Mail Submission Agent, 邮件提交代理, 负责接收来自邮件客户端的邮件并将其传递给 MTA. 例如 Postfix. -> - `MUA`: Mail User Agent, 邮件用户代理, 即邮件客户端. 例如 Thunderbird. -> -> 以及位置: +> 一些关于服务器位置描述的解释: > > - `Local`: 自建邮件服务器. > - `Source`: 外部邮件服务器, 发送方.