Skip to content

Commit

Permalink
add presets for local MMDB
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeboboliu committed Nov 15, 2023
1 parent a912002 commit a9b320e
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 17 deletions.
13 changes: 11 additions & 2 deletions PreferencesDialog.xeto
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,24 @@
</TableRow>
<TableRow>
<Label Text=""></Label>
<Button Text="{x:Static resource:Resources.LOCAL_MMDB_SELECT}" Click="HandleSelectMMDB"></Button>
<Button Text="{x:Static resource:Resources.LOCAL_MMDB_SELECT}" Click="HandleMMDBSelect"></Button>
</TableRow>
<TableRow>
<Label Text="{x:Static resource:Resources.LOCAL_MMDB_PREVIEW_IP}"></Label>
<TextBox x:Name="testMMDBIP" Text="223.5.5.5"></TextBox>
</TableRow>
<TableRow>
<Label Text=""></Label>
<Button Text="{x:Static resource:Resources.LOCAL_MMDB_PREVIEW}" Click="HandlePreviewMMDB"></Button>
<Button Text="{x:Static resource:Resources.LOCAL_MMDB_PREVIEW}" Click="HandleMMDBPreview"></Button>
</TableRow>
<TableRow>
<Label Text="{x:Static resource:Resources.LOCAL_MMDB_PRESETS}"></Label>
<DropDown x:Name="localDBPreset" SelectedIndex="0" DropDownClosed="HandleMMDBPreset">
<ListItem Text="" Key="none"></ListItem>
<ListItem Text="GeoIP2 City" Key="geoip2-city"></ListItem>
<ListItem Text="IPInfo.io Location" Key="ipinfo-loc"></ListItem>
<ListItem Text="IPInfo.io Org" Key="ipinfo-org"></ListItem>
</DropDown>
</TableRow>
<TableRow>
<Label Text="{x:Static resource:Resources.LOCAL_MMDB_ADDR}"></Label>
Expand Down
45 changes: 43 additions & 2 deletions PreferencesDialog.xeto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public partial class PreferencesDialog : Dialog
public PreferencesDialog()
{
XamlReader.Load(this);
ApplyUserSettings();
}

private void ApplyUserSettings()
{
foreach (var setting in userSettings.GetType().GetProperties())
{
TextBox settingTextBox = this.FindChild<TextBox>(setting.Name);
Expand Down Expand Up @@ -81,7 +86,7 @@ private void SaveButton_Click(object sender, EventArgs e)
Close();
}

private void HandleSelectMMDB(object sender, EventArgs e)
private void HandleMMDBSelect(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filters.Add(new FileFilter("MaxMind DB", ".mmdb"));
Expand All @@ -97,7 +102,7 @@ private void HandleSelectMMDB(object sender, EventArgs e)
}
}

private void HandlePreviewMMDB(object sender, EventArgs e)
private void HandleMMDBPreview(object sender, EventArgs e)
{
TextBox settingTextBox = this.FindChild<TextBox>("localDBPath");
if (settingTextBox == null || settingTextBox.Text == "")
Expand Down Expand Up @@ -163,5 +168,41 @@ private void reduceResult(int depth, List<object> result)
i++;
}
}

private void HandleMMDBPreset(object sender, EventArgs e)
{

var setting = this.FindChild<DropDown>("localDBPreset");
switch (setting.SelectedKey)
{
case "geoip2-city":
UserSettings.localDBAddr = "{.country.names.zh-CN} {.subdivisions.0.names.zh-CN} {.city.names.zh-CN}";
UserSettings.localDBOrg = "";
UserSettings.localDBLat = "{.location.latitude}";
UserSettings.localDBLon = "{.location.longitude}";
UserSettings.localDBASN = "";
UserSettings.localDBHostname = "";
break;
case "ipinfo-loc":
UserSettings.localDBAddr = "{.country} {.region} {.city}";
UserSettings.localDBOrg = "";
UserSettings.localDBLat = "{.lat}";
UserSettings.localDBLon = "{.lng}";
UserSettings.localDBASN = "";
UserSettings.localDBHostname = "";
break;
case "ipinfo-org":
UserSettings.localDBAddr = "";
UserSettings.localDBOrg = "{.name} {.hosting} {.domain}";
UserSettings.localDBLat = "";
UserSettings.localDBLon = "";
UserSettings.localDBASN = "";
UserSettings.localDBHostname = "";
break;
default:
return;
}
ApplyUserSettings();
}
}
}
16 changes: 13 additions & 3 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Would you like to add a firewall rule to allow needed ICMP for NextTrace?</value
<value>Link-local Address</value>
</data>
<data name="LOCAL_MMDB" xml:space="preserve">
<value>Local MMDB</value>
<value>Local MMDB Overwrite</value>
</data>
<data name="LOCAL_MMDB_ADDR" xml:space="preserve">
<value>Address Template</value>
Expand All @@ -282,6 +282,9 @@ Would you like to add a firewall rule to allow needed ICMP for NextTrace?</value
<data name="LOCAL_MMDB_PATH" xml:space="preserve">
<value>Local MMDB Path</value>
</data>
<data name="LOCAL_MMDB_PRESETS" xml:space="preserve">
<value>Presets</value>
</data>
<data name="LOCAL_MMDB_PREVIEW" xml:space="preserve">
<value>Preview MMDB File</value>
</data>
Expand All @@ -292,8 +295,9 @@ Would you like to add a firewall rule to allow needed ICMP for NextTrace?</value
<value>Select MMDB File</value>
</data>
<data name="LOCAL_MMDB_TIPS" xml:space="preserve">
<value>Template Example: {.country}-{.city}
Leave empty to avoid overwrite field</value>
<value>Use MMDB query result overwrite original result
Leave empty to avoid overwrite field
Template Example: {.country}-{.city}</value>
</data>
<data name="LOOPBACK_ADDR" xml:space="preserve">
<value>Loopback Address</value>
Expand Down
11 changes: 8 additions & 3 deletions Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
<value>链路本地地址</value>
</data>
<data name="LOCAL_MMDB" xml:space="preserve">
<value>本地 MMDB</value>
<value>本地 MMDB 覆写</value>
</data>
<data name="LOCAL_MMDB_ADDR" xml:space="preserve">
<value>地理位置模板</value>
Expand All @@ -278,6 +278,9 @@
<data name="LOCAL_MMDB_PATH" xml:space="preserve">
<value>本地 MMDB 路径</value>
</data>
<data name="LOCAL_MMDB_PRESETS" xml:space="preserve">
<value>预设配置</value>
</data>
<data name="LOCAL_MMDB_PREVIEW" xml:space="preserve">
<value>预览 MMDB</value>
</data>
Expand All @@ -288,8 +291,10 @@
<value>选择 MMDB 文件</value>
</data>
<data name="LOCAL_MMDB_TIPS" xml:space="preserve">
<value>模板举例: {.country}-{.city}
留空以避免覆写对应字段</value>
<value>此功能用本地 MMDB 查询的结果覆盖原查询结果
留空以避免覆写对应字段
模板举例: {.country}-{.city}
</value>
</data>
<data name="LOOPBACK_ADDR" xml:space="preserve">
<value>本地回环地址</value>
Expand Down
8 changes: 6 additions & 2 deletions Properties/Resources.zh-HK.resx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@
<data name="LOCAL_MMDB_PATH" xml:space="preserve">
<value>本地 MMDB 路徑</value>
</data>
<data name="LOCAL_MMDB_PRESETS" xml:space="preserve">
<value>預設配置</value>
</data>
<data name="LOCAL_MMDB_PREVIEW" xml:space="preserve">
<value>預覽 MMDB</value>
</data>
Expand All @@ -288,8 +291,9 @@
<value>選擇 MMDB 文件</value>
</data>
<data name="LOCAL_MMDB_TIPS" xml:space="preserve">
<value>模板舉例: {.country}-{.city}
留空以避免覆寫對應字段</value>
<value>此功能用本地 MMDB 查詢的結果覆蓋原查詢結果
留空以避免覆寫對應字段
模板舉例: {.country}-{.city}</value>
</data>
<data name="LOOPBACK_ADDR" xml:space="preserve">
<value>本地迴環地址</value>
Expand Down
8 changes: 6 additions & 2 deletions Properties/Resources.zh-TW.resx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@
<data name="LOCAL_MMDB_PATH" xml:space="preserve">
<value>本地 MMDB 路徑</value>
</data>
<data name="LOCAL_MMDB_PRESETS" xml:space="preserve">
<value>預設配置</value>
</data>
<data name="LOCAL_MMDB_PREVIEW" xml:space="preserve">
<value>預覽 MMDB</value>
</data>
Expand All @@ -288,8 +291,9 @@
<value>選擇 MMDB 檔案</value>
</data>
<data name="LOCAL_MMDB_TIPS" xml:space="preserve">
<value>模板舉例: {.country}-{.city}
留空以避免覆寫對應欄位</value>
<value>此功能用本地 MMDB 查詢的結果覆蓋原查詢結果
留空以避免覆寫對應欄位
模板舉例: {.country}-{.city}</value>
</data>
<data name="LOOPBACK_ADDR" xml:space="preserve">
<value>本地迴環地址</value>
Expand Down

0 comments on commit a9b320e

Please sign in to comment.