mirror of
https://github.com/openbullet/openbullet.git
synced 2023-10-21 07:33:42 -05:00
Bugfix on proxy parsing from previous commit and added defaults for proxy username and password.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:OpenBullet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="350" d:DesignWidth="270"
|
||||
d:DesignHeight="450" d:DesignWidth="270"
|
||||
Title="Add Proxies">
|
||||
|
||||
<Grid Width="270">
|
||||
@@ -75,6 +75,9 @@
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock x:Name="advancedWarning" Grid.Row="0" Grid.ColumnSpan="2" FontFamily="Consolas" Margin="5">
|
||||
@@ -88,9 +91,19 @@
|
||||
<LineBreak/>
|
||||
<Span Foreground="{DynamicResource ForegroundCustom}">Auth and Chain won't work with Selenium</Span>
|
||||
</TextBlock>
|
||||
<Label Grid.Column="0" Grid.Row="1" Content="Type:" VerticalAlignment="Center"/>
|
||||
<ComboBox x:Name="proxyTypeCombobox" Grid.Column="1" Grid.Row="1" Margin="5"/>
|
||||
<Button x:Name="acceptButton" Grid.ColumnSpan="2" Grid.Row="2" Content="ACCEPT" Click="acceptButton_Click" Margin="5" />
|
||||
|
||||
<Label Grid.Row="1" Grid.ColumnSpan="2" Content="Defaults (when not specified):" />
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="2" Content="Type:" VerticalAlignment="Center"/>
|
||||
<ComboBox x:Name="proxyTypeCombobox" Grid.Column="1" Grid.Row="2" Margin="5"/>
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="3" Content="Username:" />
|
||||
<TextBox x:Name="usernameTextbox" Grid.Column="1" Grid.Row="3" Margin="5"/>
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="4" Content="Password:" />
|
||||
<TextBox x:Name="passwordTextbox" Grid.Column="1" Grid.Row="4" Margin="5"/>
|
||||
|
||||
<Button x:Name="acceptButton" Grid.ColumnSpan="2" Grid.Row="5" Content="ACCEPT" Click="acceptButton_Click" Margin="5" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace OpenBullet
|
||||
|
||||
if(Caller.GetType() == typeof(ProxyManager))
|
||||
{
|
||||
((ProxyManager)Caller).AddProxies((ProxyType)Enum.Parse(typeof(ProxyType), proxyTypeCombobox.Text), lines);
|
||||
((ProxyManager)Caller).AddProxies(lines, (ProxyType)Enum.Parse(typeof(ProxyType), proxyTypeCombobox.Text), usernameTextbox.Text, passwordTextbox.Text);
|
||||
}
|
||||
((MainDialog)Parent).Close();
|
||||
}
|
||||
|
||||
@@ -225,33 +225,33 @@ namespace OpenBullet
|
||||
|
||||
if ((file.ToLower()).Contains("http"))
|
||||
{
|
||||
AddProxies(ProxyType.Http, lines);
|
||||
AddProxies(lines, ProxyType.Http);
|
||||
}
|
||||
else if ((file.ToLower()).Contains("socks4a"))
|
||||
{
|
||||
AddProxies(ProxyType.Socks4a, lines);
|
||||
AddProxies(lines, ProxyType.Socks4a);
|
||||
}
|
||||
else if ((file.ToLower()).Contains("socks4"))
|
||||
{
|
||||
AddProxies(ProxyType.Socks4, lines);
|
||||
AddProxies(lines, ProxyType.Socks4);
|
||||
}
|
||||
else if ((file.ToLower()).Contains("socks5"))
|
||||
{
|
||||
AddProxies(ProxyType.Socks5, lines);
|
||||
AddProxies(lines, ProxyType.Socks5);
|
||||
}
|
||||
else
|
||||
{
|
||||
Globals.LogError(Components.ProxyManager, "Failed to parse proxies type from file name, defaulting to HTTP");
|
||||
AddProxies(ProxyType.Http, lines);
|
||||
AddProxies(lines);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
public void AddProxies(ProxyType type, List<string> lines)
|
||||
public void AddProxies(List<string> lines, ProxyType defaultType = ProxyType.Http, string defaultUsername = "", string defaultPassword = "")
|
||||
{
|
||||
Globals.LogInfo(Components.ProxyManager, $"Adding {lines.Count} {type} proxies to the database");
|
||||
Globals.LogInfo(Components.ProxyManager, $"Adding {lines.Count} {defaultType} proxies to the database");
|
||||
|
||||
// Check if they're valid
|
||||
var proxies = new List<CProxy>();
|
||||
@@ -260,7 +260,7 @@ namespace OpenBullet
|
||||
{
|
||||
try
|
||||
{
|
||||
CProxy proxy = new CProxy(p, type);
|
||||
CProxy proxy = new CProxy().Parse(p, defaultType, defaultUsername, defaultPassword);
|
||||
if (!proxy.IsNumeric || proxy.IsValidNumeric)
|
||||
{
|
||||
vm.ProxyList.Add(proxy);
|
||||
|
||||
@@ -120,8 +120,10 @@ namespace RuriLib.Models
|
||||
/// </summary>
|
||||
/// <param name="proxy">The string to parse the proxy from</param>
|
||||
/// <param name="defaultType">The default type to use when not specified</param>
|
||||
/// <param name="defaultUsername">The default username to use when not specified</param>
|
||||
/// <param name="defaultPassword">The default password to use when not specified</param>
|
||||
/// <returns>The parsed CProxy object</returns>
|
||||
public CProxy Parse(string proxy, ProxyType defaultType = ProxyType.Http)
|
||||
public CProxy Parse(string proxy, ProxyType defaultType = ProxyType.Http, string defaultUsername = "", string defaultPassword = "")
|
||||
{
|
||||
// Take the first proxy of the chain
|
||||
var chain = proxy.Split(new string[] { "->" }, 2, StringSplitOptions.None);
|
||||
@@ -150,11 +152,16 @@ namespace RuriLib.Models
|
||||
Username = fields[2];
|
||||
Password = fields[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
Username = defaultUsername;
|
||||
Password = defaultPassword;
|
||||
}
|
||||
|
||||
// If the chain is not finished, set the next proxy by parsing recursively
|
||||
if (chain.Count() > 1)
|
||||
{
|
||||
Next = (new CProxy()).Parse(chain[1], defaultType);
|
||||
Next = (new CProxy()).Parse(chain[1], defaultType, defaultUsername, defaultPassword);
|
||||
}
|
||||
|
||||
// Finally return this proxy
|
||||
|
||||
Reference in New Issue
Block a user