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 77 by Douglas Thrift, 2004-02-28T00:37:46-08:00 vs.
Revision 98 by Douglas Thrift, 2004-03-02T01:17:58-08:00

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines