feat: support custom bypass rules and mesh routing policies
This commit is contained in:
@@ -4,6 +4,14 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meshport_client_core/meshport_client_core.dart';
|
||||
|
||||
String routingPolicyLabel(Object? action) => switch (action) {
|
||||
'proxy' => '代理',
|
||||
'direct' => '直连',
|
||||
'mesh' => '组网',
|
||||
'reject' => '拒绝',
|
||||
_ => '$action',
|
||||
};
|
||||
|
||||
Future<bool> confirmDiscard(BuildContext context) async =>
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
@@ -130,6 +138,13 @@ class _RuleEditorState extends State<RuleEditor> {
|
||||
setState(() => error = '请输入有效域名或 CIDR,不接受星号语法');
|
||||
return;
|
||||
}
|
||||
if (action == 'mesh' &&
|
||||
type == 'ip_cidr' &&
|
||||
InternetAddress.tryParse(v.split('/').first)?.type !=
|
||||
InternetAddressType.IPv4) {
|
||||
setState(() => error = '组网目前仅支持 IPv4 网段');
|
||||
return;
|
||||
}
|
||||
Navigator.pop(context, {
|
||||
'type': type,
|
||||
'value': v,
|
||||
@@ -159,18 +174,28 @@ class _RuleEditorState extends State<RuleEditor> {
|
||||
),
|
||||
TextField(
|
||||
controller: value,
|
||||
decoration: const InputDecoration(labelText: '匹配值'),
|
||||
decoration: InputDecoration(
|
||||
labelText: '匹配值',
|
||||
hintText: type == 'ip_cidr'
|
||||
? '例如 192.168.50.0/24'
|
||||
: '例如 example.com',
|
||||
),
|
||||
),
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: action,
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'proxy', child: Text('所选代理')),
|
||||
DropdownMenuItem(value: 'proxy', child: Text('代理')),
|
||||
DropdownMenuItem(value: 'direct', child: Text('直连')),
|
||||
DropdownMenuItem(value: 'mesh', child: Text('组网')),
|
||||
DropdownMenuItem(value: 'reject', child: Text('拒绝')),
|
||||
],
|
||||
onChanged: (v) => setState(() => action = v!),
|
||||
),
|
||||
if (action == 'mesh')
|
||||
const Text(
|
||||
'需启用代理+组网。目标必须属于已接入的 IPv4 组网网段;未接入时拒绝访问,不回退到代理或直连。此规则不会自动发布远端网段。',
|
||||
),
|
||||
const Text('按列表顺序匹配;组网优先,然后普通规则,最后规则集。'),
|
||||
],
|
||||
),
|
||||
@@ -264,7 +289,11 @@ class _RulesPageState extends State<RulesPage> {
|
||||
subtitle: Text('有效目标走组网;已知失效目标拒绝。不能移动或关闭。'),
|
||||
),
|
||||
Text(
|
||||
widget.profile.mode == 'rule' && widget.profile.feature != 'mesh'
|
||||
widget.profile.feature == 'mesh'
|
||||
? '仅组网模式暂停普通规则'
|
||||
: widget.profile.mode == 'bypass_cn'
|
||||
? '自定义规则和规则集优先,其后执行私网及中国大陆 IP 直连,其余走代理'
|
||||
: widget.profile.mode == 'rule'
|
||||
? '普通规则按顺序执行'
|
||||
: '当前模式暂停普通规则',
|
||||
),
|
||||
@@ -272,7 +301,9 @@ class _RulesPageState extends State<RulesPage> {
|
||||
Card(
|
||||
child: ListTile(
|
||||
title: Text('${entry.$1 + 1}. ${entry.$2['value']}'),
|
||||
subtitle: Text('${entry.$2['type']} → ${entry.$2['action']}'),
|
||||
subtitle: Text(
|
||||
'${entry.$2['type']} → ${routingPolicyLabel(entry.$2['action'])}',
|
||||
),
|
||||
onTap: () => edit(entry.$1),
|
||||
trailing: Wrap(
|
||||
children: [
|
||||
@@ -303,7 +334,9 @@ class _RulesPageState extends State<RulesPage> {
|
||||
const Text('规则集 · 普通规则之后按顺序匹配'),
|
||||
for (final e in sets.indexed)
|
||||
ListTile(
|
||||
title: Text('${e.$2['tag']} → ${e.$2['action']}'),
|
||||
title: Text(
|
||||
'${e.$2['tag']} → ${routingPolicyLabel(e.$2['action'])}',
|
||||
),
|
||||
subtitle: Text(
|
||||
e.$2['url'] == null
|
||||
? '内联规则'
|
||||
@@ -341,20 +374,25 @@ class _RulesPageState extends State<RulesPage> {
|
||||
),
|
||||
),
|
||||
OutlinedButton(onPressed: () => editSet(), child: const Text('添加规则集')),
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: outlet,
|
||||
decoration: const InputDecoration(labelText: '固定默认出口'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'proxy', child: Text('所选代理')),
|
||||
DropdownMenuItem(value: 'direct', child: Text('直连')),
|
||||
DropdownMenuItem(value: 'reject', child: Text('拒绝')),
|
||||
],
|
||||
onChanged: (v) => setState(() {
|
||||
outlet = v!;
|
||||
dirty = true;
|
||||
}),
|
||||
),
|
||||
if (widget.profile.mode == 'bypass_cn')
|
||||
const Text('预设默认出口:所选代理(未匹配自定义规则、私网及中国大陆 IP 时)'),
|
||||
if (widget.profile.mode == 'rule')
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: outlet,
|
||||
decoration: const InputDecoration(labelText: '固定默认出口'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'proxy', child: Text('代理')),
|
||||
DropdownMenuItem(value: 'direct', child: Text('直连')),
|
||||
DropdownMenuItem(value: 'mesh', child: Text('组网')),
|
||||
DropdownMenuItem(value: 'reject', child: Text('拒绝')),
|
||||
],
|
||||
onChanged: (v) => setState(() {
|
||||
outlet = v!;
|
||||
dirty = true;
|
||||
}),
|
||||
),
|
||||
if (outlet == 'mesh') const Text('组网默认策略仅允许已接入的组网目标,其他目标拒绝访问。'),
|
||||
const Text('保存不改变当前会话;应用时需要重连。'),
|
||||
],
|
||||
),
|
||||
@@ -1066,8 +1104,9 @@ class _RuleSetEditorState extends State<RuleSetEditor> {
|
||||
initialValue: action,
|
||||
decoration: const InputDecoration(labelText: '匹配后执行'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'proxy', child: Text('代理')),
|
||||
DropdownMenuItem(value: 'direct', child: Text('直连')),
|
||||
DropdownMenuItem(value: 'proxy', child: Text('所选代理')),
|
||||
DropdownMenuItem(value: 'mesh', child: Text('组网')),
|
||||
DropdownMenuItem(value: 'reject', child: Text('拒绝')),
|
||||
],
|
||||
onChanged: (v) => setState(() {
|
||||
@@ -1075,7 +1114,11 @@ class _RuleSetEditorState extends State<RuleSetEditor> {
|
||||
dirty = true;
|
||||
}),
|
||||
),
|
||||
const Text('远程集在规则模式连接期间自动更新并缓存;首次下载失败会阻止连接,后续失败保留已缓存版本。保存后重连生效。'),
|
||||
if (action == 'mesh')
|
||||
const Text('需启用代理+组网;规则集匹配到的目标仅在已有组网路由时可达,否则拒绝访问。'),
|
||||
const Text(
|
||||
'远程集在自定义规则或绕过中国大陆模式连接期间自动更新并缓存;首次下载失败会阻止连接,后续失败保留已缓存版本。保存后重连生效。',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user