mirror of
https://github.com/openbullet/openbullet.git
synced 2023-10-21 07:33:42 -05:00
Proxy import dialog improvements.
This commit is contained in:
@@ -5,37 +5,93 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:OpenBullet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="320" d:DesignWidth="270"
|
||||
d:DesignHeight="350" d:DesignWidth="270"
|
||||
Title="Add Proxies">
|
||||
|
||||
<StackPanel Margin="5">
|
||||
<Grid>
|
||||
<Grid Width="270">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="0">
|
||||
<Label Content="Import from:" />
|
||||
<Label x:Name="fileMode" Content="File" FontWeight="Bold" Foreground="{DynamicResource ForegroundMenuSelected}" MouseDown="FileMode_MouseDown" />
|
||||
<Label x:Name="pasteMode" Content="Paste" FontWeight="Bold" MouseDown="PasteMode_MouseDown" />
|
||||
<Label x:Name="apiMode" Content="API" FontWeight="Bold" MouseDown="ApiMode_MouseDown" />
|
||||
</StackPanel>
|
||||
|
||||
<TabControl x:Name="modeTabControl" Background="Transparent" Grid.Row="1" Margin="5" BorderThickness="0">
|
||||
<TabControl.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type TabItem}">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</Style>
|
||||
</TabControl.ItemContainerStyle>
|
||||
<TabItem x:Name="fileTab">
|
||||
<StackPanel>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Column="0" Content="Location:" VerticalAlignment="Center"/>
|
||||
<TextBox x:Name="locationTextbox" Grid.Column="1" VerticalContentAlignment="Center" Margin="5" IsReadOnly="True"/>
|
||||
<Image x:Name="loadProxiesButton" Grid.Column="2" Source="/Images/Icons/folder.png" Width="20" MouseDown="loadProxiesButton_MouseDown"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem x:Name="pasteTab">
|
||||
<StackPanel>
|
||||
<Label Content="Paste your proxies in the box below" />
|
||||
<TextBox x:Name="proxiesBox" AcceptsReturn="True" TextWrapping="Wrap" Height="100" VerticalScrollBarVisibility="Auto" Margin="0 5" FontFamily="Consolas"/>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem x:Name="apiTab">
|
||||
<StackPanel>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Column="0" Content="URL:" VerticalAlignment="Center"/>
|
||||
<TextBox x:Name="urlTextbox" Grid.Column="1" VerticalContentAlignment="Center" Margin="5"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Label Grid.Column="0" Content="Location:" VerticalAlignment="Center"/>
|
||||
<TextBox x:Name="locationTextbox" Grid.Column="1" VerticalContentAlignment="Center" Margin="5" IsReadOnly="True"/>
|
||||
<Image x:Name="loadProxiesButton" Grid.Column="2" Source="/Images/Icons/folder.png" Width="20" MouseDown="loadProxiesButton_MouseDown"/>
|
||||
|
||||
<TextBlock x:Name="advancedWarning" Grid.Row="0" Grid.ColumnSpan="2" FontFamily="Consolas" Margin="5">
|
||||
<Span Foreground="{DynamicResource ForegroundMain}" FontWeight="Bold">Advanced Syntax:</Span>
|
||||
<LineBreak/>
|
||||
<Span Foreground="{DynamicResource ForegroundMain}">Type: (http)1.1.1.1:80</Span>
|
||||
<LineBreak/>
|
||||
<Span Foreground="{DynamicResource ForegroundMain}">Auth: 1.1.1.1:80:username:password</Span>
|
||||
<LineBreak/>
|
||||
<Span Foreground="{DynamicResource ForegroundMain}">Chain: 1.1.1.1:80 -> 2.2.2.2:80</Span>
|
||||
<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" />
|
||||
</Grid>
|
||||
<Label Content="ADVANCED MODE (auth, chain)" HorizontalContentAlignment="Center" FontWeight="Bold"/>
|
||||
<Label Content="Hover on the box below to see the syntax" HorizontalContentAlignment="Center"/>
|
||||
<TextBox x:Name="proxiesBox" AcceptsReturn="True" TextWrapping="Wrap" Height="100" VerticalScrollBarVisibility="Auto" Margin="0 5" FontFamily="Consolas">
|
||||
<TextBox.ToolTip>
|
||||
<TextBlock>Start the line with the proxy type between round brackets.<LineBreak/>Auth:<LineBreak/>(http)127.0.0.1:8888:username:password<LineBreak/>Chain:<LineBreak/>(socks4)127.0.0.1:8000->(http)127.0.0.1:8888</TextBlock>
|
||||
</TextBox.ToolTip>
|
||||
</TextBox>
|
||||
|
||||
<Label Content="Auth and Chain won't work with Selenium" Foreground="{DynamicResource ForegroundCustom}" HorizontalContentAlignment="Center"/>
|
||||
<Button x:Name="acceptButton" Content="ACCEPT" Click="acceptButton_Click" Margin="0 5" />
|
||||
</Grid>
|
||||
|
||||
</StackPanel>
|
||||
</Page>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Extreme.Net;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -37,13 +39,89 @@ namespace OpenBullet
|
||||
|
||||
private void acceptButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var fileName = locationTextbox.Text;
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
switch (modeTabControl.SelectedIndex)
|
||||
{
|
||||
// File
|
||||
case 0:
|
||||
if (fileName != "")
|
||||
{
|
||||
Globals.LogInfo(Components.ProxyManager, $"Trying to load from file {fileName}");
|
||||
lines.AddRange(File.ReadAllLines(fileName).ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
Globals.LogError(Components.ProxyManager, "No file specified!", true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (proxiesBox.Text != "")
|
||||
{
|
||||
lines.AddRange(proxiesBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None));
|
||||
}
|
||||
else
|
||||
{
|
||||
Globals.LogError(Components.ProxyManager, "The box is empty!", true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (urlTextbox.Text != "")
|
||||
{
|
||||
HttpRequest request = new HttpRequest();
|
||||
var response = request.Get(urlTextbox.Text).ToString();
|
||||
lines.AddRange(response.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None));
|
||||
}
|
||||
else
|
||||
{
|
||||
Globals.LogError(Components.ProxyManager, "No URL specified!", true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.LogError(Components.ProxyManager, $"There was an error: {ex.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
if(Caller.GetType() == typeof(ProxyManager))
|
||||
{
|
||||
((ProxyManager)Caller).AddProxies(locationTextbox.Text,
|
||||
(ProxyType)Enum.Parse(typeof(ProxyType), proxyTypeCombobox.Text),
|
||||
proxiesBox.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
|
||||
((ProxyManager)Caller).AddProxies((ProxyType)Enum.Parse(typeof(ProxyType), proxyTypeCombobox.Text), lines);
|
||||
}
|
||||
((MainDialog)Parent).Close();
|
||||
}
|
||||
|
||||
private void FileMode_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
fileMode.Foreground = Globals.GetBrush("ForegroundMenuSelected");
|
||||
pasteMode.Foreground = Globals.GetBrush("ForegroundMain");
|
||||
apiMode.Foreground = Globals.GetBrush("ForegroundMain");
|
||||
modeTabControl.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
private void PasteMode_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
fileMode.Foreground = Globals.GetBrush("ForegroundMain");
|
||||
pasteMode.Foreground = Globals.GetBrush("ForegroundMenuSelected");
|
||||
apiMode.Foreground = Globals.GetBrush("ForegroundMain");
|
||||
modeTabControl.SelectedIndex = 1;
|
||||
}
|
||||
|
||||
private void ApiMode_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
fileMode.Foreground = Globals.GetBrush("ForegroundMain");
|
||||
pasteMode.Foreground = Globals.GetBrush("ForegroundMain");
|
||||
apiMode.Foreground = Globals.GetBrush("ForegroundMenuSelected");
|
||||
modeTabControl.SelectedIndex = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,44 +221,42 @@ namespace OpenBullet
|
||||
{
|
||||
try
|
||||
{
|
||||
var lines = File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList();
|
||||
|
||||
if ((file.ToLower()).Contains("http"))
|
||||
AddProxies(file, ProxyType.Http, File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
|
||||
else if ((file.ToLower()).Contains("socks4"))
|
||||
AddProxies(file, ProxyType.Socks4, File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
|
||||
{
|
||||
AddProxies(ProxyType.Http, lines);
|
||||
}
|
||||
else if ((file.ToLower()).Contains("socks4a"))
|
||||
AddProxies(file, ProxyType.Socks4a, File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
|
||||
{
|
||||
AddProxies(ProxyType.Socks4a, lines);
|
||||
}
|
||||
else if ((file.ToLower()).Contains("socks4"))
|
||||
{
|
||||
AddProxies(ProxyType.Socks4, lines);
|
||||
}
|
||||
else if ((file.ToLower()).Contains("socks5"))
|
||||
AddProxies(file, ProxyType.Socks5, File.ReadAllText(file).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).ToList());
|
||||
{
|
||||
AddProxies(ProxyType.Socks5, lines);
|
||||
}
|
||||
else
|
||||
Globals.LogError(Components.ProxyManager, "Failed to parse proxies type from file name");
|
||||
{
|
||||
Globals.LogError(Components.ProxyManager, "Failed to parse proxies type from file name, defaulting to HTTP");
|
||||
AddProxies(ProxyType.Http, lines);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
public void AddProxies(string fileName, ProxyType type, List<string> lines)
|
||||
public void AddProxies(ProxyType type, List<string> lines)
|
||||
{
|
||||
List<string> fromFile = new List<string>();
|
||||
List<string> fromBox = new List<string>();
|
||||
|
||||
// Load proxies from file
|
||||
if (fileName != "")
|
||||
{
|
||||
Globals.LogInfo(Components.ProxyManager, $"Trying to load from file {fileName}");
|
||||
fromFile.AddRange(File.ReadAllLines(fileName).ToList());
|
||||
}
|
||||
else { Globals.LogInfo(Components.ProxyManager, "No file specified, skipping the import from file"); }
|
||||
|
||||
// Load proxies from textbox lines
|
||||
fromBox.AddRange(lines);
|
||||
|
||||
Globals.LogInfo(Components.ProxyManager, $"Adding {fromFile.Count + fromBox.Count} proxies to the database");
|
||||
Globals.LogInfo(Components.ProxyManager, $"Adding {lines.Count} {type} proxies to the database");
|
||||
|
||||
// Check if they're valid
|
||||
var proxies = new List<CProxy>();
|
||||
|
||||
foreach (var p in fromFile.Where(p => !string.IsNullOrEmpty(p)).Distinct().ToList())
|
||||
foreach (var p in lines.Where(p => !string.IsNullOrEmpty(p)).Distinct().ToList())
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -272,21 +270,6 @@ namespace OpenBullet
|
||||
catch { }
|
||||
}
|
||||
|
||||
foreach (var p in fromBox.Where(p => !string.IsNullOrEmpty(p)).Distinct().ToList())
|
||||
{
|
||||
try
|
||||
{
|
||||
CProxy proxy = new CProxy();
|
||||
proxy.Parse(p, type);
|
||||
if (!proxy.IsNumeric || proxy.IsValidNumeric)
|
||||
{
|
||||
vm.ProxyList.Add(proxy);
|
||||
proxies.Add(proxy);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
using (var db = new LiteDatabase(Globals.dataBaseFile))
|
||||
{
|
||||
db.GetCollection<CProxy>("proxies").InsertBulk(proxies);
|
||||
|
||||
Reference in New Issue
Block a user