ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdateSharp/HostUpdateSharp.cs
(Generate patch)

Comparing HostUpdateSharp/HostUpdateSharp.cs (file contents):
Revision 82 by Douglas Thrift, 2004-03-01T16:28:58-08:00 vs.
Revision 930 by douglas, 2007-06-19T14:07:50-07:00

# Line 8 | Line 8 | using System;
8   using System.IO;
9   using System.Net;
10   using System.Text;
11 + #if !_FreeBSD_
12 + using System.Windows.Forms;
13 + #endif
14  
15   public class HostUpdateSharp
16   {
17          public static void Main(string[] args)
18          {
19 <                StringBuilder host = new StringBuilder(Dns.GetHostName());
19 >                foreach (string arg in args)
20 >                {
21 >                        switch (arg)
22 >                        {
23 >                        case "-D":
24 >                                debug = true;
25 >                                break;
26 >                        default:
27 >                                uname = arg;
28 >                                break;
29 >                        }
30 >                }
31 >
32 >                try
33 >                {
34 >                        new HostUpdateSharp();
35 >                }
36 >                catch (Exception exception)
37 >                {
38 >                        Console.Error.WriteLine(exception);
39 >                        Environment.Exit(1);
40 >                }
41 >        }
42 >        public HostUpdateSharp()
43 >        {
44 >                StringBuilder host = new StringBuilder("host=" +
45 >                        Dns.GetHostName().ToLower());
46                  string url = "http://topsecret.douglasthrift.net/auth/hostupdate.cgi";
47  
48 <                if (host.ToString().IndexOf('.') < 0)
48 >                if ((host + "").IndexOf('.') < 0)
49                  {
50 <                        host.Append(".local.douglasthrift.net");
50 >                        host.Append(".douglasthrift.net");
51                  }
52  
53 +                WebHeaderCollection headers = new WebHeaderCollection();
54 +
55 +                headers.Add("Authorization", "Basic " + Convert.ToBase64String((new
56 +                        ASCIIEncoding()).GetBytes("HostUpdate:frell2003")));
57 +
58                  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
59  
60                  request.Accept = "text/plain";
61 <                request.AllowAutoRedirect = false;
61 >                request.ContentLength = host.Length;
62                  request.ContentType = "application/x-www-form-urlencoded";
63 <                request.Credentials = new NetworkCredential("HostUpdate", "frell2003");
63 >                request.Headers = headers;
64 >                request.KeepAlive = false;
65                  request.Method = "POST";
66 +                request.UserAgent = "Host Update Sharp/1.0 (" + platform() + ')';
67 +
68 +                StreamWriter post = new StreamWriter(request.GetRequestStream(),
69 +                        Encoding.ASCII);
70 +
71 +                post.Write(host);
72 +                post.Close();
73 +
74 +                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
75 +
76 +                StreamReader content = new StreamReader(response.GetResponseStream(),
77 +                        Encoding.ASCII);
78 +
79 + #if _FreeBSD_
80 +                if (debug) Console.Write(content.ReadToEnd());
81 + #else
82 +                if (debug) MessageBox.Show(content.ReadToEnd(), "Host Update Sharp",
83 +                        MessageBoxButtons.OK, MessageBoxIcon.Information);
84 + #endif
85 +
86 +                content.Close();
87 +        }
88 +        private static bool debug = false;
89 +        private static string uname = "";
90 + #if _FreeBSD_
91 +        private static string platform()
92 +        {
93 +                if (uname == "")
94 +                {
95 +                        uname = "Unknown";
96 +                }
97 +
98 +                return uname;
99 +        }
100 + #else
101 +        private static string platform()
102 +        {
103 +                if (uname == "")
104 +                {
105 +                        OperatingSystem os = Environment.OSVersion;
106 +                        string system = "Unknown";
107 +
108 +                        switch (os.Platform)
109 +                        {
110 +                        case PlatformID.Win32NT:
111 +                                system = "Windows NT";
112 +                                break;
113 +                        case PlatformID.Win32Windows:
114 +                                system = "Windows";
115 +                                break;
116 +                        }
117 +
118 +                        uname = system + ' ' + os.Version.Major + '.' + os.Version.Minor +
119 +                                " x86";
120 +                }
121 +
122 +                return uname;
123          }
124 + #endif
125   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines