// Host Update Sharp // // Douglas Thrift // // $Id$ using System; using System.IO; using System.Net; using System.Text; #if !_FreeBSD_ using System.Windows.Forms; #endif public class HostUpdateSharp { public static void Main(string[] args) { foreach (string arg in args) { switch (arg) { case "-D": debug = true; break; default: uname = arg; break; } } try { new HostUpdateSharp(); } catch (Exception exception) { Console.Error.WriteLine(exception); Environment.Exit(1); } } public HostUpdateSharp() { StringBuilder host = new StringBuilder("host=" + Dns.GetHostName().ToLower()); string url = "http://topsecret.douglasthrift.net/auth/hostupdate.cgi"; if ((host + "").IndexOf('.') < 0) { host.Append(".douglasthrift.net"); } WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Authorization", "Basic " + Convert.ToBase64String((new ASCIIEncoding()).GetBytes("HostUpdate:frell2003"))); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Accept = "text/plain"; request.ContentLength = host.Length; request.ContentType = "application/x-www-form-urlencoded"; request.Headers = headers; request.KeepAlive = false; request.Method = "POST"; request.UserAgent = "Host Update Sharp/1.0 (" + platform() + ')'; StreamWriter post = new StreamWriter(request.GetRequestStream(), Encoding.ASCII); post.Write(host); post.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader content = new StreamReader(response.GetResponseStream(), Encoding.ASCII); #if _FreeBSD_ if (debug) Console.Write(content.ReadToEnd()); #else if (debug) MessageBox.Show(content.ReadToEnd(), "Host Update Sharp", MessageBoxButtons.OK, MessageBoxIcon.Information); #endif content.Close(); } private static bool debug = false; private static string uname = ""; #if _FreeBSD_ private static string platform() { if (uname == "") { uname = "Unknown"; } return uname; } #else private static string platform() { if (uname == "") { OperatingSystem os = Environment.OSVersion; string system = "Unknown"; switch (os.Platform) { case PlatformID.Win32NT: system = "Windows NT"; break; case PlatformID.Win32Windows: system = "Windows"; break; } uname = system + ' ' + os.Version.Major + '.' + os.Version.Minor + " x86"; } return uname; } #endif }