AliDDNS/net.nutcore.aliddns/net.nutcore.aliddns/Form_ngrok.cs
2020-02-14 17:25:13 +08:00

96 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Windows.Forms;
namespace net.nutcore.aliddns
{
public partial class Form_ngrok : Form
{
//初始化ngrok操作类
private NgrokHelper ngrok = new NgrokHelper();
public Form_ngrok()
{
InitializeComponent();
this.MinimizeBox = false; //取消窗口最小化按钮
this.MaximizeBox = false; //取消窗口最大化按钮
}
private void button_cancel_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
}
private void button_save_Click(object sender, EventArgs e)
{
var token = textBox_AuthToken.Text.ToString();
var server_addr = textBox_serverAddr.Text.ToString();
var lanhttp = 80;
int.TryParse(textBox_lanHttp.Text, out lanhttp);
textBox_lanHttp.Text = lanhttp.ToString();
var lanhttps = 443;
int.TryParse(textBox_lanHttps.Text, out lanhttps);
textBox_lanHttps.Text = lanhttp.ToString();
var subdomain = textBox_subDomain.Text.ToString();
var remoteport1 = 2221;
int.TryParse(textBox_remotePort1.Text, out remoteport1);
textBox_remotePort1.Text = remoteport1.ToString();
var lanport1 = 21;
int.TryParse(textBox_lanPort1.Text, out lanport1);
textBox_lanPort1.Text = lanport1.ToString();
var remoteport2 = 2222;
int.TryParse(textBox_remotePort2.Text, out remoteport2);
textBox_remotePort2.Text = remoteport2.ToString();
var lanport2 = 22;
int.TryParse(textBox_lanPort2.Text, out lanport2);
textBox_lanPort2.Text = lanport2.ToString();
var remoteport3 = 33890;
int.TryParse(textBox_remotePort3.Text, out remoteport3);
textBox_remotePort3.Text = remoteport3.ToString();
var lanport3 = 3389;
int.TryParse(textBox_lanPort3.Text, out lanport3);
textBox_lanPort3.Text = lanport3.ToString();
ngrok.Save(token, server_addr, subdomain, lanhttp, lanhttps, remoteport1, lanport1, remoteport2, lanport2, remoteport3, lanport3, true, true);
this.Close();
this.Dispose();
}
private void Form_ngrok_Shown(object sender, EventArgs e)
{
//检测ngrok.exe是否存在
if (!ngrok.IsExists())
{
MessageBox.Show("设置在当前目录没有发现ngrok.exe请往官网下载自行编译。\nNgrok官网https://ngrok.com/download");
}
//读取配置文件
try
{
var config = ngrok.Load();
textBox_AuthToken.Text = config.authtoken;
textBox_serverAddr.Text = config.server_addr;
textBox_subDomain.Text = config.tunnels.website_http.subdomain.ToString();
textBox_lanHttp.Text = config.tunnels.website_http.proto.http.ToString();
textBox_lanHttps.Text = config.tunnels.website_https.proto.https.ToString();
textBox_remotePort1.Text = config.tunnels.tcp1.remote_port.ToString();
textBox_lanPort1.Text = config.tunnels.tcp1.proto.tcp.ToString();
textBox_remotePort2.Text = config.tunnels.tcp2.remote_port.ToString();
textBox_lanPort2.Text = config.tunnels.tcp2.proto.tcp.ToString();
textBox_remotePort3.Text = config.tunnels.tcp3.remote_port.ToString();
textBox_lanPort3.Text = config.tunnels.tcp3.proto.tcp.ToString();
}
catch (Exception error)
{
MessageBox.Show("设置文件ngrok.cfg读取出错错误信息\n" + error);
this.Dispose();
}
}
}
}