Skip to content

Commit 4306e7a

Browse files
committed
Add fakeip filter
1 parent d43cd23 commit 4306e7a

File tree

3 files changed

+54
-15
lines changed

3 files changed

+54
-15
lines changed

YtFlowApp/NewProfilePage.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ namespace winrt::YtFlowApp::implementation
3030
hstring RuleResolver;
3131
hstring OutboundType;
3232
std::string CustomRules;
33+
std::string FakeIpFilter;
3334
std::vector<NewProfileConfigRuleset> Rulesets{};
3435
};
3536
void CreatePresetPlugins(uint32_t profileId, NewProfileConfig config);
37+
std::vector<std::string_view> SplitLines(std::string_view sv);
3638

3739
NewProfilePage::NewProfilePage()
3840
{
@@ -90,6 +92,7 @@ namespace winrt::YtFlowApp::implementation
9092
.RuleResolver = RuleResolverComboBox().SelectedItem().as<ComboBoxItem>().Tag().as<hstring>(),
9193
.OutboundType = m_selectedOutboundType,
9294
.CustomRules = to_string(CustomRuleTextBox().Text()),
95+
.FakeIpFilter = to_string(FakeIpFilterTextBox().Text()),
9396
.Rulesets =
9497
std::views::transform(
9598
RulesetListView().Items(),
@@ -314,7 +317,6 @@ namespace winrt::YtFlowApp::implementation
314317
void CreatePresetPlugins(uint32_t profileId, NewProfileConfig config)
315318
{
316319
using namespace std::string_literals;
317-
using namespace std::string_view_literals;
318320
try
319321
{
320322
auto doc = NewProfilePage::GenPresetDoc();
@@ -407,19 +409,20 @@ namespace winrt::YtFlowApp::implementation
407409
{"plugin_version", 0},
408410
{"param",
409411
{{"resolver", ruleResolver},
410-
{"source",
411-
{{"format", "quanx-filter"},
412-
{"text", std::views::split(std::string_view(config.CustomRules), "\r"sv) |
413-
std::views::transform([](auto const sr) {
414-
std::string_view const sv(sr);
415-
auto const rpos = sv.find_last_not_of('\r');
416-
return sv.substr(0, rpos == std::string_view::npos ? sv.size() : rpos + 1);
417-
}) |
418-
std::ranges::to<std::vector>()}}},
412+
{"source", {{"format", "quanx-filter"}, {"text", SplitLines(config.CustomRules)}}},
419413
{"actions", availableActions()},
420414
{"rules", {{"proxy", "proxy"}, {"direct", "direct"}, {"reject", "reject"}, {"next", "next"}}},
421-
{"fallback", makeAction(SplitRoutingRuleDecision::Next)}}}};
415+
{"fallback", makeAction(SplitRoutingRuleDecision::Next)}}}},
416+
fakeipFilterDoc{
417+
{"desc", "Generate real IP addresses instead of Fake IPs for specified domain names."},
418+
{"plugin", "list-dispatcher"},
419+
{"plugin_version", 0},
420+
{"param",
421+
{{"source", {{"format", "surge-domain-set"}, {"text", SplitLines(config.FakeIpFilter)}}},
422+
{"action", {{"resolver", "phy.resolver"}}},
423+
{"fallback", {{"resolver", "fake-ip.resolver"}}}}}};
422424
doc["custom-rule-dispatcher"] = std::move(customRuleDoc);
425+
doc["fakeip-filter"] = std::move(fakeipFilterDoc);
423426

424427
// Adjust outbound
425428
if (config.OutboundType == L"ss")
@@ -542,4 +545,15 @@ namespace winrt::YtFlowApp::implementation
542545
L"ip6-cidr, 2001:4860:4860::8800/120, proxy, no-resolve\r\n");
543546
CustomRuleTextBox().Visibility(Visibility::Visible);
544547
}
548+
549+
std::vector<std::string_view> SplitLines(std::string_view sv)
550+
{
551+
using namespace std::string_view_literals;
552+
return std::views::split(std::string_view(sv), "\r"sv) | std::views::transform([](auto const sr) {
553+
std::string_view const sv(sr);
554+
auto const rpos = sv.find_last_not_of('\r');
555+
return sv.substr(0, rpos == std::string_view::npos ? sv.size() : rpos + 1);
556+
}) |
557+
std::ranges::to<std::vector>();
558+
}
545559
}

YtFlowApp/NewProfilePage.xaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,39 @@
6262
<RadioButton Tag="fake">UWP VPN, Fake IP range</RadioButton>
6363
<RadioButton Tag="full">UWP VPN, Full IP range</RadioButton>
6464
</muxc:RadioButtons>
65-
<TextBlock Margin="{StaticResource SubheaderMargin}" Style="{ThemeResource BaseTextBlockStyle}">
65+
66+
<muxc:Expander
67+
HorizontalAlignment="Stretch"
68+
HorizontalContentAlignment="Stretch"
69+
Padding="0"
70+
Margin="0, 8, 0, 0"
71+
>
72+
<muxc:Expander.Header>
73+
<TextBlock Style="{ThemeResource BaseTextBlockStyle}">
74+
Exclude domains from Fake IP
75+
</TextBlock>
76+
</muxc:Expander.Header>
77+
<TextBox
78+
x:Name="FakeIpFilterTextBox"
79+
Height="250"
80+
AcceptsReturn="True"
81+
TextWrapping="Wrap"
82+
IsSpellCheckEnabled="False"
83+
Text=".msftconnecttest.com&#13;.msftncsi.com&#13;.lan&#13;localhost.ptlogin2.qq.com"
84+
></TextBox>
85+
</muxc:Expander>
86+
87+
88+
<!-- Inbound connections from localhost will be blocked by sandbox. No plan for now. -->
89+
<!-- TextBlock Margin="{StaticResource SubheaderMargin}" Style="{ThemeResource BaseTextBlockStyle}">
6690
Additional Inbound ports
6791
</TextBlock>
6892
<CheckBox IsEnabled="False">
6993
<StackPanel Orientation="Horizontal" VerticalAlignment="Stretch">
7094
<TextBlock VerticalAlignment="Center" Margin="0, 0, 10, 0">SOCKS5</TextBlock>
7195
<TextBox PlaceholderText="Port" Text="9080" InputScope="Number" MaxLength="5" />
7296
</StackPanel>
73-
</CheckBox>
97+
</CheckBox -->
7498
</StackPanel>
7599

76100
<StackPanel x:Name="MiddlePanel" Grid.Row="2" Grid.Column="0">
@@ -186,6 +210,7 @@
186210
AcceptsReturn="True"
187211
Visibility="Collapsed"
188212
TextWrapping="Wrap"
213+
IsSpellCheckEnabled="False"
189214
></TextBox>
190215
<TextBlock
191216
Margin="24, 8, 24, 16"
@@ -287,7 +312,7 @@
287312
<Setter Target="MiddlePanel.(Grid.Column)" Value="1" />
288313
<Setter Target="MiddlePanel.(Grid.Row)" Value="1" />
289314
<Setter Target="MiddlePanel.(Grid.RowSpan)" Value="3" />
290-
<Setter Target="RightPanel.Margin" Value="8, 0, 0, 0" />
315+
<Setter Target="MiddlePanel.Margin" Value="12, 0, 12, 0" />
291316
<Setter Target="RightPanel.(Grid.Column)" Value="2" />
292317
<Setter Target="RightPanel.(Grid.Row)" Value="1" />
293318
<Setter Target="RightPanel.(Grid.RowSpan)" Value="3" />

YtFlowApp/NewProfilePagePresets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ namespace winrt::YtFlowApp::implementation
242242
{"plugin_version", 0},
243243
{"param",
244244
{{"concurrency_limit", 64},
245-
{"resolver", "fake-ip.resolver"},
245+
{"resolver", "fakeip-filter.resolver"},
246246
{"tcp_map_back", {"udp-proxy-switch.tcp"}},
247247
{"udp_map_back", {"udp-proxy-switch.udp"}},
248248
{"ttl", 60}}}},

0 commit comments

Comments
 (0)