1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2025-03-27 02:23:59 +03:00

添加NaiveProxy一键安装02

This commit is contained in:
ProxySU 2020-04-26 23:59:27 +08:00
parent eec8b46ea6
commit 409f717db7
6 changed files with 741 additions and 9 deletions

View File

@ -162,14 +162,11 @@
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Header="参数设置" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="2">
<Grid>
@ -184,6 +181,7 @@
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="模式NaiveProxy+TLS+Caddy" Grid.Column="1" Grid.Row="0"></TextBlock>
<TextBlock Text="服务器地址(域名)" Grid.Column="0" Grid.Row="1"></TextBlock>
@ -195,6 +193,9 @@
<TextBlock Text="密码:" Grid.Column="0" Grid.Row="3"></TextBlock>
<TextBox x:Name="TextBoxNaivePassword" Grid.Column="1" Grid.Row="3" Margin="3"></TextBox>
<Button x:Name="ButtonNaivePassword" Content="更新" Grid.Column="2" Grid.Row="3" Margin="2" Click="ButtonNaivePassword_Click"></Button>
<TextBlock Text="伪装网站:" Grid.Column="0" Grid.Row="4"></TextBlock>
<TextBox x:Name="TextBoxNaiveSites" Style="{StaticResource TitleText}" Tag="可以增加代理的隐蔽(可为空)" Grid.Column="1" Grid.Row="4" Margin="3"></TextBox>
</Grid>
</GroupBox>
<!--<Button x:Name="ButtonNaiveTemplate" Content="Naive设置" Grid.Column="1" Grid.Row="0" Margin="5" Click="ButtonTrojanTemplate_Click"/>

View File

@ -38,7 +38,7 @@ namespace ProxySU
//ReceiveConfigurationParameters[0]----模板类型
//ReceiveConfigurationParameters[1]----服务端口
//ReceiveConfigurationParameters[2]----uuid
//ReceiveConfigurationParameters[3]----path
//ReceiveConfigurationParameters[3]----path/naive'user
//ReceiveConfigurationParameters[4]----domain
//ReceiveConfigurationParameters[5]----伪装类型
//ReceiveConfigurationParameters[6]----QUIC密钥
@ -1842,8 +1842,7 @@ namespace ProxySU
Guid uuid = Guid.NewGuid();
TextBoxNaivePassword.Text = uuid.ToString();
}
//生成随机UUID
private string RandomUUID()
{
@ -1872,8 +1871,580 @@ namespace ProxySU
//NaiveProxy一键安装开始
private void ButtonNavieSetUp_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(TextBoxNaiveHostDomain.Text) == true)
{
MessageBox.Show("域名不能为空!");
return;
}
ReceiveConfigurationParameters[4] = TextBoxNaiveHostDomain.Text;
ConnectionInfo connectionInfo = GenerateConnectionInfo();
if (connectionInfo == null)
{
MessageBox.Show("远程主机连接信息有误,请检查");
return;
}
string serverConfig = "TemplateConfg\\Naiveproxy_server_config.json"; //服务端配置文件
string clientConfig = "TemplateConfg\\Naiveproxy_client_config.json"; //生成的客户端配置文件
string upLoadPath = "/etc/caddy/Caddyfile"; //Caddy服务端文件位置
//传递参数
ReceiveConfigurationParameters[4] = TextBoxNaiveHostDomain.Text;//传递域名
ReceiveConfigurationParameters[3] = TextBoxNaiveUser.Text;//传递用户名
ReceiveConfigurationParameters[2] = TextBoxNaivePassword.Text;//传递密码
ReceiveConfigurationParameters[7] = TextBoxNaiveSites.Text;//传递伪装网站
if (TextBoxNaiveSites.Text.ToString().Length >= 7)
{
string testDomain = TextBoxNaiveSites.Text.Substring(0, 7);
if (String.Equals(testDomain, "https:/") || String.Equals(testDomain, "http://"))
{
//MessageBox.Show(testDomain);
MainWindow.ReceiveConfigurationParameters[7] = TextBoxNaiveSites.Text.Replace("/", "\\/");
}
else
{
MainWindow.ReceiveConfigurationParameters[7] = "http:\\/\\/" + TextBoxNaiveSites.Text;
}
}
Thread thread = new Thread(() => StartSetUpNaive(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing, serverConfig, clientConfig, upLoadPath));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
//登录远程主机布署NaiveProxy程序
private void StartSetUpNaive(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar, string serverConfig, string clientConfig, string upLoadPath)
{
string currentStatus = "正在登录远程主机......";
Action<TextBlock, ProgressBar, string> updateAction = new Action<TextBlock, ProgressBar, string>(UpdateTextBlock);
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
try
{
#region
//byte[] expectedFingerPrint = new byte[] {
// 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31,
// 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b
// };
#endregion
using (var client = new SshClient(connectionInfo))
{
#region ssh登录验证主机指纹代码块
// client.HostKeyReceived += (sender, e) =>
// {
// if (expectedFingerPrint.Length == e.FingerPrint.Length)
// {
// for (var i = 0; i < expectedFingerPrint.Length; i++)
// {
// if (expectedFingerPrint[i] != e.FingerPrint[i])
// {
// e.CanTrust = false;
// break;
// }
// }
// }
// else
// {
// e.CanTrust = false;
// }
// };
#endregion
client.Connect();
if (client.IsConnected == true)
{
currentStatus = "主机登录成功";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
}
//检测是否安装有Trojan
currentStatus = "检测系统是否已经安装NaiveProxy......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//string cmdTestTrojanInstalled = @"find / -name trojan";
string resultCmdTestTrojanInstalled = client.RunCommand(@"find / -name naive").Result;
if (resultCmdTestTrojanInstalled.Contains("/usr/local/bin/naive") == true)
{
MessageBoxResult messageBoxResult = MessageBox.Show("远程主机已安装Trojan,是否强制重新安装?", "", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.No)
{
currentStatus = "安装取消,退出";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
return;
}
}
//检测远程主机系统环境是否符合要求
currentStatus = "检测系统是否符合安装要求......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
string resultCmd = client.RunCommand("uname -m").Result;
//var result = client.RunCommand("cat /root/test.ver");
//string[] linuxKernelVerStr = resultCmd.Split('-');
//bool detectResult = DetectKernelVersion(linuxKernelVerStr[0]);
if (resultCmd.Contains("x86_64") == false)
{
MessageBox.Show($"请在x86_64系统中安装NaiveProxy");
currentStatus = "系统不符合要求,安装失败!!";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
}
//检测系统是否支持yum 或 apt-get或zypper且支持Systemd
//如果不存在组件则命令结果为空string.IsNullOrEmpty值为真
bool getApt = String.IsNullOrEmpty(client.RunCommand("command -v apt-get").Result);
bool getYum = String.IsNullOrEmpty(client.RunCommand("command -v yum").Result);
bool getZypper = String.IsNullOrEmpty(client.RunCommand("command -v zypper").Result);
bool getSystemd = String.IsNullOrEmpty(client.RunCommand("command -v systemctl").Result);
bool getGetenforce = String.IsNullOrEmpty(client.RunCommand("command -v getenforce").Result);
//安装所需软件
if (getApt == false)
{
client.RunCommand("apt-get -qq update");
client.RunCommand("apt-get -y -qq install curl libnss3 xz-utils lsof");
}
if (getYum == false)
{
client.RunCommand("yum -q makecache");
client.RunCommand("yum -y -q install curl libnss3 xz-utils lsof");
}
if (getZypper == false)
{
client.RunCommand("zypper ref");
client.RunCommand("zypper -y install curl libnss3 xz-utils lsof");
}
//没有安装apt-get也没有安装yum也没有安装zypper,或者没有安装systemd的不满足安装条件
//也就是apt-get yum, zypper必须安装其中之一且必须安装Systemd的系统才能安装。
if ((getApt && getYum && getZypper) || getSystemd)
{
MessageBox.Show($"系统缺乏必要的安装组件如:apt-get||yum||zypper||Syetemd主机系统推荐使用CentOS 7/8,Debian 8/9/10,Ubuntu 16.04及以上版本");
currentStatus = "系统环境不满足要求,安装失败!!";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
return;
}
//判断是否启用了SELinux,如果启用了并且工作在Enforcing模式下则改为Permissive模式
if (getGetenforce == false)
{
string testSELinux = client.RunCommand("getenforce").Result;
//MessageBox.Show(testSELinux);
if (testSELinux.Contains("Enforcing") == true)
{
//MessageBox.Show("Enforcing");
client.RunCommand("setenforce 0");//不重启改为Permissive模式
client.RunCommand("sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config");//重启也工作在Permissive模式下
}
}
//如果使用如果是WebSocket + TLS + Web/http2/Http2Web/tcp_TLS/WebSocket_TLS模式需要检测域名解析是否正确
//if (serverConfig.Contains("Naiveproxy") == true)
//{
currentStatus = "正在检测域名是否解析到当前VPS的IP上......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//在相应系统内安装curl(如果没有安装curl)
//if (string.IsNullOrEmpty(client.RunCommand("command -v curl").Result) == true)
//{
// //为假则表示系统有相应的组件。
// if (getApt == false)
// {
// client.RunCommand("apt-get -qq update");
// client.RunCommand("apt-get -y -qq install curl");
// }
// if (getYum == false)
// {
// client.RunCommand("yum -q makecache");
// client.RunCommand("yum -y -q install curl");
// }
// if (getZypper == false)
// {
// client.RunCommand("zypper ref");
// client.RunCommand("zypper -y install curl");
// }
//}
string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString();
//MessageBox.Show(nativeIp);
string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\"";
//MessageBox.Show(testDomainCmd);
string resultTestDomainCmd = client.RunCommand(testDomainCmd).Result.ToString();
//MessageBox.Show(resultTestDomainCmd);
if (String.Equals(nativeIp, resultTestDomainCmd) == true)
{
currentStatus = "解析正确!";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
}
else
{
currentStatus = "域名未能正确解析到当前VPS的IP上!安装失败!";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
MessageBox.Show("域名未能正确解析到当前VPS的IP上请检查若解析设置正确请等待生效后再重试安装。如果域名使用了CDN请先关闭");
return;
}
//}
//if (serverConfig.Contains("Naiveproxy") == true)
//{
//检测是否安装lsof
//if (string.IsNullOrEmpty(client.RunCommand("command -v lsof").Result) == true)
//{
// //为假则表示系统有相应的组件。
// if (getApt == false)
// {
// client.RunCommand("apt-get -qq update");
// client.RunCommand("apt-get -y -qq install lsof");
// }
// if (getYum == false)
// {
// client.RunCommand("yum -q makecache");
// client.RunCommand("yum -y -q install lsof");
// }
// if (getZypper == false)
// {
// client.RunCommand("zypper ref");
// client.RunCommand("zypper -y install lsof");
// }
//}
currentStatus = "正在检测端口占用情况......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//MessageBox.Show(@"lsof -n -P -i :80 | grep LISTEN");
//MessageBox.Show(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result);
if (String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result) == false || String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :443 | grep LISTEN").Result) == false)
{
MessageBoxResult dialogResult = MessageBox.Show("80/443端口之一或全部被占用将强制停止占用80/443端口的程序?", "Stop application", MessageBoxButton.YesNo);
if (dialogResult == MessageBoxResult.No)
{
currentStatus = "端口被占用,安装失败......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
return;
}
currentStatus = "正在释放80/443端口......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN";
string cmdResult = client.RunCommand(cmdTestPort).Result;
//MessageBox.Show(cmdTestPort);
if (String.IsNullOrEmpty(cmdResult) == false)
{
//MessageBox.Show(cmdResult);
string[] cmdResultArry443 = cmdResult.Split(' ');
//MessageBox.Show(cmdResultArry443[3]);
client.RunCommand($"systemctl stop {cmdResultArry443[0]}");
client.RunCommand($"systemctl disable {cmdResultArry443[0]}");
client.RunCommand($"kill -9 {cmdResultArry443[3]}");
}
cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN";
cmdResult = client.RunCommand(cmdTestPort).Result;
if (String.IsNullOrEmpty(cmdResult) == false)
{
string[] cmdResultArry80 = cmdResult.Split(' ');
client.RunCommand($"systemctl stop {cmdResultArry80[0]}");
client.RunCommand($"systemctl disable {cmdResultArry80[0]}");
client.RunCommand($"kill -9 {cmdResultArry80[3]}");
}
currentStatus = "80/443端口释放完毕";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
}
//}
currentStatus = "符合安装要求,布署中......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//在相应系统内安装curl(如果没有安装curl)
//if (string.IsNullOrEmpty(client.RunCommand("command -v curl").Result) == true)
//{
// //为假则表示系统有相应的组件。
// if (getApt == false)
// {
// client.RunCommand("apt-get -qq update");
// client.RunCommand("apt-get -y -qq install curl");
// }
// if (getYum == false)
// {
// client.RunCommand("yum -q makecache");
// client.RunCommand("yum -y -q install curl");
// }
// if (getZypper == false)
// {
// client.RunCommand("zypper ref");
// client.RunCommand("zypper -y install curl");
// }
//}
//下载安装脚本安装
client.RunCommand("curl -o /tmp/naive-quickstart.sh https://raw.githubusercontent.com/proxysu/shellscript/master/naive-quickstart.sh");
client.RunCommand("yes | bash /tmp/naive-quickstart.sh");
string installResult = client.RunCommand("find / -name naive").Result.ToString();
if (!installResult.Contains("/usr/local/bin/naive"))
{
MessageBox.Show("安装NaiveProxy失败(脚本运行出错!");
client.Disconnect();
currentStatus = "安装NaiveProxy失败(脚本运行出错!";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
return;
}
//client.RunCommand("mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.1");
//上传配置文件
currentStatus = "NaiveProxy程序安装完毕......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//生成服务端配置
//using (StreamReader reader = File.OpenText(serverConfig))
//{
// JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader));
// //设置密码
// serverJson["password"][0] = ReceiveConfigurationParameters[2];
// //设置监听端口
// //serverJson["inbounds"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]);
// using (StreamWriter sw = new StreamWriter(@"config.json"))
// {
// sw.Write(serverJson.ToString());
// }
//}
//UploadConfig(connectionInfo, @"config.json", upLoadPath);
//File.Delete(@"config.json");
//打开防火墙端口
string openFireWallPort = ReceiveConfigurationParameters[1];
if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false)
{
if (String.Equals(openFireWallPort, "443"))
{
client.RunCommand("firewall-cmd --zone=public --add-port=80/tcp --permanent");
client.RunCommand("firewall-cmd --zone=public --add-port=443/tcp --permanent");
client.RunCommand("firewall-cmd --reload");
}
else
{
client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/tcp --permanent");
client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/udp --permanent");
client.RunCommand("firewall-cmd --reload");
}
}
if (String.IsNullOrEmpty(client.RunCommand("command -v ufw").Result) == false)
{
if (String.Equals(openFireWallPort, "443"))
{
client.RunCommand("ufw allow 80");
client.RunCommand("ufw allow 443");
client.RunCommand("ufw reset");
}
else
{
client.RunCommand($"ufw allow {openFireWallPort}/tcp");
client.RunCommand($"ufw allow {openFireWallPort}/udp");
client.RunCommand("ufw reset");
}
}
//if (serverConfig.Contains("Naiveproxy") == true)
//{
// currentStatus = "使用Trojan+TLS+Web模式正在安装acme.sh......";
// textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
// Thread.Sleep(1000);
// if (getApt == false)
// {
// //client.RunCommand("apt-get -qq update");
// client.RunCommand("apt-get -y -qq install socat");
// }
// if (getYum == false)
// {
// //client.RunCommand("yum -q makecache");
// client.RunCommand("yum -y -q install socat");
// }
// if (getZypper == false)
// {
// // client.RunCommand("zypper ref");
// client.RunCommand("zypper -y install socat");
// }
// client.RunCommand("curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh");
// client.RunCommand("cd ~/.acme.sh/");
// client.RunCommand("alias acme.sh=~/.acme.sh/acme.sh");
// currentStatus = "申请域名证书......";
// textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
// Thread.Sleep(1000);
// //client.RunCommand("mkdir -p /etc/v2ray/ssl");
// client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}");
// currentStatus = "安装证书到Trojan......";
// textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
// Thread.Sleep(1000);
// client.RunCommand($"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan/trojan_ssl.crt --keypath /usr/local/etc/trojan/trojan_ssl.key --capath /usr/local/etc/trojan/trojan_ssl.crt --reloadcmd \"systemctl restart trojan\"");
//}
currentStatus = "正在启动NaiveProxy......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//启动V2ray服务
client.RunCommand("systemctl restart naive");
currentStatus = "NaivePrxoy启动成功";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//安装Caddy
//if (serverConfig.Contains("Naiveproxy") == true)
//{
currentStatus = "正在安装Caddy";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
client.RunCommand("curl https://getcaddy.com -o getcaddy");
client.RunCommand("bash getcaddy personal hook.service http.forwardproxy");
client.RunCommand("mkdir -p /etc/caddy");
client.RunCommand("mkdir -p /var/www");
currentStatus = "上传Caddy配置文件......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//if (serverConfig.Contains("Naiveproxy") == true)
//{
string caddyConfig = "TemplateConfg\\Naiveproxy_server_config.caddyfile";
//}
upLoadPath = "/etc/caddy/Caddyfile";
UploadConfig(connectionInfo, caddyConfig, upLoadPath);
//设置Caddyfile文件中的tls 邮箱
string email = $"user@{ReceiveConfigurationParameters[4]}";
string sshCmd;
//设置域名
sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}";
//MessageBox.Show(sshCmd);
client.RunCommand(sshCmd);
//设置用户名密码
sshCmd = $"sed -i 's/##basicauth##/basicauth {ReceiveConfigurationParameters[3]} {ReceiveConfigurationParameters[2]}/' {upLoadPath}";
//设置伪装网站
if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false)
{
sshCmd = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}";
//MessageBox.Show(sshCmd);
client.RunCommand(sshCmd);
}
Thread.Sleep(2000);
//安装Caddy服务
sshCmd = $"caddy -service install -agree -conf /etc/caddy/Caddyfile -email {email}";
//MessageBox.Show(sshCmd);
client.RunCommand(sshCmd);
//启动Caddy服务
client.RunCommand("caddy -service restart");
//}
//生成客户端配置
currentStatus = "生成客户端配置......";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
if (!Directory.Exists("naive_config"))//如果不存在就创建file文件夹     
{
Directory.CreateDirectory("naive_config");//创建该文件夹  
}
//string clientConfig = "TemplateConfg\\tcp_client_config.json";
using (StreamReader reader = File.OpenText(clientConfig))
{
JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader));
clientJson["proxy"] = $"https://{ReceiveConfigurationParameters[3]}:{ReceiveConfigurationParameters[2]}@{ReceiveConfigurationParameters[4]}";
//clientJson["remote_port"] = int.Parse(ReceiveConfigurationParameters[1]);
//clientJson["password"][0] = ReceiveConfigurationParameters[2];
using (StreamWriter sw = new StreamWriter(@"naive_config\config.json"))
{
sw.Write(clientJson.ToString());
}
}
client.Disconnect();
currentStatus = "安装成功";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
Thread.Sleep(1000);
//显示服务端连接参数
//MessageBox.Show("用于Trojan官方客户端的配置文件已保存在config文件夹中");
NaiveProxyResultInfoWindow resultClientInformation = new NaiveProxyResultInfoWindow();
resultClientInformation.ShowDialog();
return;
}
}
catch (Exception ex1)//例外处理
#region
{
//MessageBox.Show(ex1.Message);
if (ex1.Message.Contains("连接尝试失败") == true)
{
MessageBox.Show($"{ex1.Message}\n请检查主机地址及端口是否正确如果通过代理请检查代理是否正常工作");
}
else if (ex1.Message.Contains("denied (password)") == true)
{
MessageBox.Show($"{ex1.Message}\n密码错误或用户名错误");
}
else if (ex1.Message.Contains("Invalid private key file") == true)
{
MessageBox.Show($"{ex1.Message}\n所选密钥文件错误或者格式不对");
}
else if (ex1.Message.Contains("denied (publickey)") == true)
{
MessageBox.Show($"{ex1.Message}\n使用密钥登录密钥文件错误或用户名错误");
}
else if (ex1.Message.Contains("目标计算机积极拒绝") == true)
{
MessageBox.Show($"{ex1.Message}\n主机地址错误如果使用了代理也可能是连接代理的端口错误");
}
else
{
MessageBox.Show("发生错误");
MessageBox.Show(ex1.Message);
}
currentStatus = "主机登录失败";
textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);
}
#endregion
}
//private void ButtonTestTrojanClientInfoWin_Click(object sender, RoutedEventArgs e)
//{

View File

@ -0,0 +1,37 @@
<Window x:Class="ProxySU.NaiveProxyResultInfoWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ProxySU"
mc:Ignorable="d"
Title="NaiveProxyResultInfoWindow" Height="200" Width="400">
<Grid>
<GroupBox Header="服务器连接参数">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.6*"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="0.4*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="服务器地址:" Grid.Column="0" Grid.Row="1"></TextBlock>
<TextBox x:Name="TextBoxNaiveServerHost" Grid.Column="1" Grid.Row="1" Margin="4"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="1"></TextBlock>
<TextBlock Text="用户名:" Grid.Column="0" Grid.Row="2"></TextBlock>
<TextBox x:Name="TextBoxNaiveUser" Grid.Column="1" Grid.Row="2" Margin="4"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="2"></TextBlock>
<TextBlock Text="密码:" Grid.Column="0" Grid.Row="3"></TextBlock>
<TextBox x:Name="TextBoxNaivePassword" Grid.Column="1" Grid.Row="3" Margin="4"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="3"></TextBlock>
<Button x:Name="ButtonOpenDir" Content="确定" Grid.Column="1" Grid.Row="4" Margin="40,3,40,3" Click="ButtonOpenDir_Click"></Button>
</Grid>
</GroupBox>
</Grid>
</Window>

View File

@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using Renci.SshNet;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System.Drawing;
using QRCoder;
namespace ProxySU
{
/// <summary>
/// NaiveProxyResultInfoWindow.xaml 的交互逻辑
/// </summary>
public partial class NaiveProxyResultInfoWindow : Window
{
private string saveFileFolder = "";
public NaiveProxyResultInfoWindow()
{
InitializeComponent();
TextBoxNaiveServerHost.Text = MainWindow.ReceiveConfigurationParameters[4];
TextBoxNaiveUser.Text = MainWindow.ReceiveConfigurationParameters[3];
TextBoxNaivePassword.Text= MainWindow.ReceiveConfigurationParameters[2];
}
private void GenerateV2rayShareQRcodeAndBase64Url()
{
string saveFileFolderFirst = TextBoxNaiveServerHost.Text;
int num = 1;
saveFileFolder = saveFileFolderFirst;
CheckDir("naive_config");
while (Directory.Exists(@"naive_config\" + saveFileFolder))
{
saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString();
num++;
}
CheckDir(@"naive_config\" + saveFileFolder);
//string trojanUrl = $"trojan://{TextBoxTrojanServerPassword.Text}@{TextBoxTrojanServerHost.Text}:{TextBoxTrojanServerPort.Text}#{TextBoxTrojanServerHost.Text}";
//MessageBox.Show(v2rayNjsonObject.ToString());
//string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString());
//TextBoxTrojanUrl.Text = trojanUrl;
//using (StreamWriter sw = new StreamWriter($"trojan_config\\{saveFileFolder}\\url.txt"))
//{
// sw.WriteLine(trojanUrl);
//}
//CreateQRCode(trojanUrl);
//移动Trojan官方程序配置文件到相应目录
if (File.Exists(@"naive_config\config.json"))
{
File.Move(@"naive_config\config.json", @"naive_config\" + saveFileFolder + @"\config.json");
//File.Delete(@"config\config.json");//删除该文件
}
using (StreamWriter sw = new StreamWriter($"naive_config\\{saveFileFolder}\\说明.txt"))
{
sw.WriteLine("config.json");
sw.WriteLine("此文件为NaiveProxy官方程序所使用的客户端配置文件配置为全局模式socks5地址127.0.0.1:1080");
sw.WriteLine("NaiveProxy官方网站https://github.com/klzgrad/naiveproxy");
sw.WriteLine("Trojan官方程序下载地址https://github.com/klzgrad/naiveproxy/releases");
sw.WriteLine("下载相应版本Windows选择naiveproxy-x.xx-win.zip,解压后提取naive.exe。与config.json放在同一目录运行naive.exe即可。");
sw.WriteLine("-----------------------------------------\n");
sw.WriteLine("其他平台的客户端,暂未发布");
//sw.WriteLine("QR.bmp");
//sw.WriteLine("此文件为Trojan-QT5 (windows)、igniterAndroid、Shadowrocket(ios)扫码导入节点");
//sw.WriteLine("Trojan-QT5 (windows)下载网址https://github.com/TheWanderingCoel/Trojan-Qt5/releases");
//sw.WriteLine("igniterAndroid下载网址https://github.com/trojan-gfw/igniter/releases");
//sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。");
//sw.WriteLine("-----------------------------------------\n");
//sw.WriteLine("url.txt");
//sw.WriteLine("此文件为Trojan-QT5 (windows)、igniterAndroid、Shadowrocket(ios)复制粘贴导入节点的网址");
//sw.WriteLine("-----------------------------------------\n");
sw.WriteLine("服务器通用连接配置参数");
sw.WriteLine($"地址(address){TextBoxNaiveServerHost.Text}");
sw.WriteLine($"用户名:{TextBoxNaiveUser.Text}");
sw.WriteLine($"密钥:{TextBoxNaivePassword.Text}");
}
}
//判断目录是否存在,不存在则创建
private static bool CheckDir(string folder)
{
try
{
if (!Directory.Exists(folder))//如果不存在就创建file文件夹
Directory.CreateDirectory(folder);//创建该文件夹  
return true;
}
catch (Exception)
{
return false;
}
}
private void ButtonOpenDir_Click(object sender, RoutedEventArgs e)
{
string openFolderPath = @"naive_config\" + saveFileFolder;
System.Diagnostics.Process.Start("explorer.exe", openFolderPath);
this.Close();
}
}
}

View File

@ -81,6 +81,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="NaiveProxyResultInfoWindow.xaml.cs">
<DependentUpon>NaiveProxyResultInfoWindow.xaml</DependentUpon>
</Compile>
<Compile Include="ProofreadTimeWindow.xaml.cs">
<DependentUpon>ProofreadTimeWindow.xaml</DependentUpon>
</Compile>
@ -108,6 +111,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="NaiveProxyResultInfoWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ProofreadTimeWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -30,13 +30,13 @@
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="服务器地址" Grid.Column="0" Grid.Row="1"></TextBlock>
<TextBlock Text="服务器地址" Grid.Column="0" Grid.Row="1"></TextBlock>
<TextBox x:Name="TextBoxTrojanServerHost" Grid.Column="1" Grid.Row="1" Margin="4"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="1"></TextBlock>
<TextBlock Text="端口" Grid.Column="0" Grid.Row="2"></TextBlock>
<TextBlock Text="端口" Grid.Column="0" Grid.Row="2"></TextBlock>
<TextBox x:Name="TextBoxTrojanServerPort" Grid.Column="1" Grid.Row="2" Margin="4"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="2"></TextBlock>
<TextBlock Text="密钥" Grid.Column="0" Grid.Row="3"></TextBlock>
<TextBlock Text="密钥" Grid.Column="0" Grid.Row="3"></TextBlock>
<TextBox x:Name="TextBoxTrojanServerPassword" Grid.Column="1" Grid.Row="3" Margin="4"></TextBox>
<TextBlock Grid.Column="2" Grid.Row="3"></TextBlock>
</Grid>