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 88 by Douglas Thrift, 2004-03-01T19:03:40-08:00 vs.
Revision 106 by Douglas Thrift, 2004-03-02T14:08:44-08:00

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines