Merge pull request #115 from MaxXor/pr/114

Added NoIP.org Integration
This commit is contained in:
MaxXor 2015-05-10 18:14:36 +02:00
commit f727452426
7 changed files with 213 additions and 12 deletions

View File

@ -582,9 +582,6 @@ namespace xClient.Core.Commands
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
{
using (Stream dataStream = response.GetResponseStream())
{
}
}
}
catch

View File

@ -0,0 +1,56 @@
using System;
using System.Net;
using System.Text;
using System.Threading;
using xServer.Settings;
namespace xServer.Core.Misc
{
public static class NoIpUpdater
{
private static bool _running;
public static void Start()
{
if (_running) return;
Thread updateThread = new Thread(BackgroundUpdater) {IsBackground = true};
updateThread.Start();
}
private static void BackgroundUpdater()
{
_running = true;
while (XMLSettings.IntegrateNoIP)
{
try
{
string wanIp = string.Empty;
using (WebClient wc = new WebClient())
{
wanIp = wc.DownloadString("http://icanhazip.com/");
}
if (!string.IsNullOrEmpty(wanIp))
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://dynupdate.no-ip.com/nic/update?hostname={0}&myip={1}", XMLSettings.NoIPHost, wanIp));
request.UserAgent = string.Format("X IP Automation Tool/3 {0}", XMLSettings.NoIPUsername);
request.Timeout = 20000;
request.Headers.Add(HttpRequestHeader.Authorization, string.Format("Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", XMLSettings.NoIPUsername, XMLSettings.NoIPPassword)))));
request.Method = "GET";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
}
}
}
catch
{
}
Thread.Sleep(TimeSpan.FromMinutes(10));
}
_running = false;
}
}
}

View File

@ -29,10 +29,13 @@ namespace xServer.Forms
XMLSettings.AutoListen = bool.Parse(XMLSettings.ReadValue("AutoListen"));
XMLSettings.ShowPopup = bool.Parse(XMLSettings.ReadValue("ShowPopup"));
XMLSettings.UseUPnP = bool.Parse(XMLSettings.ReadValue("UseUPnP"));
XMLSettings.ShowToolTip =
bool.Parse(!string.IsNullOrEmpty(XMLSettings.ReadValue("ShowToolTip"))
? XMLSettings.ReadValue("ShowToolTip")
: "False"); //fallback
XMLSettings.ShowToolTip = bool.Parse(XMLSettings.ReadValueSafe("ShowToolTip", "False"));
XMLSettings.IntegrateNoIP = bool.Parse(XMLSettings.ReadValueSafe("EnableNoIPUpdater", "False"));
XMLSettings.NoIPHost = XMLSettings.ReadValueSafe("NoIPHost");
XMLSettings.NoIPUsername = XMLSettings.ReadValueSafe("NoIPUsername");
XMLSettings.NoIPPassword = XMLSettings.ReadValueSafe("NoIPPassword");
XMLSettings.Password = XMLSettings.ReadValue("Password");
}
@ -158,6 +161,11 @@ namespace xServer.Forms
UPnP.ForwardPort(ushort.Parse(XMLSettings.ListenPort.ToString()));
ListenServer.Listen(XMLSettings.ListenPort);
}
if (XMLSettings.IntegrateNoIP)
{
NoIpUpdater.Start();
}
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)

View File

@ -40,15 +40,22 @@
this.txtPassword = new System.Windows.Forms.TextBox();
this.chkUseUpnp = new System.Windows.Forms.CheckBox();
this.chkShowTooltip = new System.Windows.Forms.CheckBox();
this.chkNoIPIntegration = new System.Windows.Forms.CheckBox();
this.lblHost = new System.Windows.Forms.Label();
this.lblPass = new System.Windows.Forms.Label();
this.lblUser = new System.Windows.Forms.Label();
this.txtNoIPPass = new System.Windows.Forms.TextBox();
this.txtNoIPUser = new System.Windows.Forms.TextBox();
this.txtNoIPHost = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.ncPort)).BeginInit();
this.SuspendLayout();
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(227, 210);
this.btnSave.Location = new System.Drawing.Point(227, 253);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(75, 23);
this.btnSave.TabIndex = 10;
this.btnSave.TabIndex = 17;
this.btnSave.Text = "&Save";
this.btnSave.UseVisualStyleBackColor = true;
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
@ -116,10 +123,10 @@
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(146, 210);
this.btnCancel.Location = new System.Drawing.Point(146, 253);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 9;
this.btnCancel.TabIndex = 16;
this.btnCancel.Text = "&Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
@ -160,11 +167,83 @@
this.chkShowTooltip.Text = "Show tooltip on client with system information";
this.chkShowTooltip.UseVisualStyleBackColor = true;
//
// chkNoIPIntegration
//
this.chkNoIPIntegration.AutoSize = true;
this.chkNoIPIntegration.Location = new System.Drawing.Point(15, 155);
this.chkNoIPIntegration.Name = "chkNoIPIntegration";
this.chkNoIPIntegration.Size = new System.Drawing.Size(184, 17);
this.chkNoIPIntegration.TabIndex = 9;
this.chkNoIPIntegration.Text = "Activate NoIP.org DNS Updater";
this.chkNoIPIntegration.UseVisualStyleBackColor = true;
this.chkNoIPIntegration.CheckedChanged += new System.EventHandler(this.chkNoIPIntegration_CheckedChanged);
//
// lblHost
//
this.lblHost.AutoSize = true;
this.lblHost.Enabled = false;
this.lblHost.Location = new System.Drawing.Point(33, 181);
this.lblHost.Name = "lblHost";
this.lblHost.Size = new System.Drawing.Size(34, 13);
this.lblHost.TabIndex = 10;
this.lblHost.Text = "Host:";
//
// lblPass
//
this.lblPass.AutoSize = true;
this.lblPass.Enabled = false;
this.lblPass.Location = new System.Drawing.Point(170, 209);
this.lblPass.Name = "lblPass";
this.lblPass.Size = new System.Drawing.Size(32, 13);
this.lblPass.TabIndex = 14;
this.lblPass.Text = "Pass:";
//
// lblUser
//
this.lblUser.AutoSize = true;
this.lblUser.Enabled = false;
this.lblUser.Location = new System.Drawing.Point(33, 209);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(33, 13);
this.lblUser.TabIndex = 12;
this.lblUser.Text = "User:";
//
// txtNoIPPass
//
this.txtNoIPPass.Enabled = false;
this.txtNoIPPass.Location = new System.Drawing.Point(202, 206);
this.txtNoIPPass.Name = "txtNoIPPass";
this.txtNoIPPass.Size = new System.Drawing.Size(100, 22);
this.txtNoIPPass.TabIndex = 15;
//
// txtNoIPUser
//
this.txtNoIPUser.Enabled = false;
this.txtNoIPUser.Location = new System.Drawing.Point(73, 206);
this.txtNoIPUser.Name = "txtNoIPUser";
this.txtNoIPUser.Size = new System.Drawing.Size(91, 22);
this.txtNoIPUser.TabIndex = 13;
//
// txtNoIPHost
//
this.txtNoIPHost.Enabled = false;
this.txtNoIPHost.Location = new System.Drawing.Point(73, 178);
this.txtNoIPHost.Name = "txtNoIPHost";
this.txtNoIPHost.Size = new System.Drawing.Size(229, 22);
this.txtNoIPHost.TabIndex = 11;
//
// FrmSettings
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(314, 245);
this.ClientSize = new System.Drawing.Size(314, 288);
this.Controls.Add(this.txtNoIPHost);
this.Controls.Add(this.txtNoIPUser);
this.Controls.Add(this.txtNoIPPass);
this.Controls.Add(this.lblUser);
this.Controls.Add(this.lblPass);
this.Controls.Add(this.lblHost);
this.Controls.Add(this.chkNoIPIntegration);
this.Controls.Add(this.chkShowTooltip);
this.Controls.Add(this.chkUseUpnp);
this.Controls.Add(this.txtPassword);
@ -204,5 +283,12 @@
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.CheckBox chkUseUpnp;
private System.Windows.Forms.CheckBox chkShowTooltip;
private System.Windows.Forms.CheckBox chkNoIPIntegration;
private System.Windows.Forms.Label lblHost;
private System.Windows.Forms.Label lblPass;
private System.Windows.Forms.Label lblUser;
private System.Windows.Forms.TextBox txtNoIPPass;
private System.Windows.Forms.TextBox txtNoIPUser;
private System.Windows.Forms.TextBox txtNoIPHost;
}
}

View File

@ -2,6 +2,7 @@
using System.Globalization;
using System.Windows.Forms;
using xServer.Core;
using xServer.Core.Misc;
using xServer.Settings;
namespace xServer.Forms
@ -32,6 +33,10 @@ namespace xServer.Forms
txtPassword.Text = XMLSettings.Password;
chkUseUpnp.Checked = XMLSettings.UseUPnP;
chkShowTooltip.Checked = XMLSettings.ShowToolTip;
chkNoIPIntegration.Checked = XMLSettings.IntegrateNoIP;
txtNoIPHost.Text = XMLSettings.NoIPHost;
txtNoIPUser.Text = XMLSettings.NoIPUsername;
txtNoIPPass.Text = XMLSettings.NoIPPassword;
}
private void btnListen_Click(object sender, EventArgs e)
@ -42,6 +47,8 @@ namespace xServer.Forms
{
if (chkUseUpnp.Checked)
Core.Helper.UPnP.ForwardPort(ushort.Parse(ncPort.Value.ToString(CultureInfo.InvariantCulture)));
if(chkNoIPIntegration.Checked)
NoIpUpdater.Start();
_listenServer.Listen(ushort.Parse(ncPort.Value.ToString(CultureInfo.InvariantCulture)));
}
finally
@ -86,6 +93,21 @@ namespace xServer.Forms
XMLSettings.WriteValue("ShowToolTip", chkShowTooltip.Checked.ToString());
XMLSettings.ShowToolTip = chkShowTooltip.Checked;
XMLSettings.WriteValue("EnableNoIPUpdater", chkNoIPIntegration.Checked.ToString());
XMLSettings.IntegrateNoIP = chkNoIPIntegration.Checked;
if (chkNoIPIntegration.Checked)
{
XMLSettings.WriteValue("NoIPHost", txtNoIPHost.Text);
XMLSettings.NoIPHost = txtNoIPHost.Text;
XMLSettings.WriteValue("NoIPUsername", txtNoIPUser.Text);
XMLSettings.NoIPUsername = txtNoIPUser.Text;
XMLSettings.WriteValue("NoIPPassword", txtNoIPPass.Text);
XMLSettings.NoIPPassword = txtNoIPPass.Text;
}
this.Close();
}
@ -95,5 +117,20 @@ namespace xServer.Forms
DialogResult.Yes)
this.Close();
}
private void chkNoIPIntegration_CheckedChanged(object sender, EventArgs e)
{
NoIPControlHandler(chkNoIPIntegration.Checked);
}
private void NoIPControlHandler(bool enable)
{
lblHost.Enabled = enable;
lblUser.Enabled = enable;
lblPass.Enabled = enable;
txtNoIPHost.Enabled = enable;
txtNoIPUser.Enabled = enable;
txtNoIPPass.Enabled = enable;
}
}
}

View File

@ -74,6 +74,7 @@
<Compile Include="Core\Compression\JpgCompression.cs" />
<Compile Include="Core\Misc\ListViewColumnSorter.cs" />
<Compile Include="Core\Extensions\ListViewExtensions.cs" />
<Compile Include="Core\Misc\NoIpUpdater.cs" />
<Compile Include="Core\Misc\SavedVariables.cs" />
<Compile Include="Core\Packets\ClientPackets\DesktopResponse.cs" />
<Compile Include="Core\Packets\ClientPackets\DirectoryResponse.cs" />

View File

@ -15,6 +15,11 @@ namespace xServer.Settings
public static bool UseUPnP { get; set; }
public static bool ShowToolTip { get; set; }
public static string Password { get; set; }
public static bool IntegrateNoIP { get; set; }
public static string NoIPHost { get; set; }
public static string NoIPUsername { get; set; }
public static string NoIPPassword { get; set; }
private static string _settingsFilePath = Path.Combine(Application.StartupPath, "settings.xml");
@ -36,6 +41,11 @@ namespace xServer.Settings
root.AppendChild(doc.CreateElement("UseUPnP")).InnerText = "False";
root.AppendChild(doc.CreateElement("ShowToolTip")).InnerText = "False";
root.AppendChild(doc.CreateElement("EnableNoIPUpdater")).InnerText = "False";
root.AppendChild(doc.CreateElement("NoIPHost")).InnerText = "";
root.AppendChild(doc.CreateElement("NoIPUsername")).InnerText = "";
root.AppendChild(doc.CreateElement("NoIPPassword")).InnerText = "";
doc.Save(_settingsFilePath);
}
return true;
@ -67,6 +77,12 @@ namespace xServer.Settings
}
}
public static string ReadValueSafe(string pstrValueToRead, string defaultValue = "")
{
string value = ReadValue(pstrValueToRead);
return (!string.IsNullOrEmpty(value)) ? value: defaultValue;
}
public static bool WriteValue(string pstrValueToRead, string pstrValueToWrite)
{
try