125 lines
3.9 KiB
C#
125 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace DynUpdater
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private async void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
|
|
{
|
|
var x = new Properties.Settings();
|
|
|
|
HttpClient client = new HttpClient();
|
|
var byteArray = Encoding.ASCII.GetBytes(x.DynUsername+":"+x.DynPassword);
|
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
|
|
|
|
try
|
|
{
|
|
BTNsave.Invoke((MethodInvoker)delegate () {
|
|
ProgressBarStatus.Visible = true;
|
|
});
|
|
HttpResponseMessage response = await client.GetAsync("https://www.ovh.com/nic/update?system=dyndns&hostname="+x.DynHostname);
|
|
HttpContent content = response.Content;
|
|
var result = content.ReadAsStringAsync();
|
|
|
|
Console.WriteLine(StripHtml(result.Result));
|
|
BTNsave.Invoke((MethodInvoker)delegate () {
|
|
TXTstatus.Text = StripHtml(result.Result);
|
|
LBLstatus.Text = response.StatusCode.ToString();
|
|
});
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
{
|
|
BTNsave.Invoke((MethodInvoker)delegate () {
|
|
TXTstatus.Text = ex.Message;
|
|
});
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
BTNsave.Invoke((MethodInvoker)delegate () {
|
|
ProgressBarStatus.Visible = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
private string StripHtml(string source)
|
|
{
|
|
string output;
|
|
output = Regex.Replace(source, "<[^>]*>", string.Empty);
|
|
output = Regex.Replace(output, @"^\s*$\n", string.Empty, RegexOptions.Multiline);
|
|
return output;
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
LBLstatus.Text = "";
|
|
var x = new Properties.Settings();
|
|
TXTusername.Text = x.DynUsername;
|
|
TXTpassword.Text = x.DynPassword;
|
|
TXThostname.Text = x.DynHostname;
|
|
timer1.Start();
|
|
RunTask();
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
RunTask();
|
|
}
|
|
|
|
private void RunTask()
|
|
{
|
|
if(!backgroundWorker1.IsBusy) backgroundWorker1.RunWorkerAsync();
|
|
}
|
|
|
|
private void BTNexit_Click(object sender, EventArgs e)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
|
|
private void BTNopen_Click(object sender, EventArgs e)
|
|
{
|
|
this.WindowState = FormWindowState.Normal;
|
|
}
|
|
|
|
private void BTNsave_Click(object sender, EventArgs e)
|
|
{
|
|
var x = new Properties.Settings();
|
|
x.DynUsername = TXTusername.Text;
|
|
x.DynPassword = TXTpassword.Text;
|
|
x.DynHostname = TXThostname.Text;
|
|
x.Save();
|
|
RunTask();
|
|
}
|
|
|
|
private void configurazioneToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
|
|
Process.Start("notepad.exe", path);
|
|
}
|
|
|
|
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
this.WindowState = FormWindowState.Normal;
|
|
}
|
|
}
|
|
}
|