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 930 by douglas, 2007-06-19T14:07:50-07: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)
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 + "").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.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";
35                request.PreAuthenticate = true;
66                  request.UserAgent = "Host Update Sharp/1.0 (" + platform() + ')';
67  
68                  StreamWriter post = new StreamWriter(request.GetRequestStream(),
# Line 46 | Line 76 | public class HostUpdateSharp
76                  StreamReader content = new StreamReader(response.GetResponseStream(),
77                          Encoding.ASCII);
78  
49                Console.Write(content.ReadToEnd());
50        }
79   #if _FreeBSD_
80 <        private static string platform() { return "FreeBSD 4.9-STABLE i386"; }
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 <                OperatingSystem os = Environment.OSVersion;
57 <                string system = "Unknown";
58 <
59 <                switch (os.Platform)
93 >                if (uname == "")
94                  {
95 <                case PlatformID.Win32NT:
62 <                        system = "Windows NT";
63 <                        break;
64 <                case PlatformID.Win32Windows:
65 <                        system = "Windows";
66 <                        break;
95 >                        uname = "Unknown";
96                  }
97  
98 <                int major = os.Version.Major, minor = os.Version.Minor;
99 <                string version = os + "";
100 <
101 <                switch (system)
98 >                return uname;
99 >        }
100 > #else
101 >        private static string platform()
102 >        {
103 >                if (uname == "")
104                  {
105 <                case "Windows NT":
106 <                        switch (major)
105 >                        OperatingSystem os = Environment.OSVersion;
106 >                        string system = "Unknown";
107 >
108 >                        switch (os.Platform)
109                          {
110 <                        case 5:
111 <                                switch (minor)
112 <                                {
113 <                                case 0:
114 <                                        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 <                                }
110 >                        case PlatformID.Win32NT:
111 >                                system = "Windows NT";
112 >                                break;
113 >                        case PlatformID.Win32Windows:
114 >                                system = "Windows";
115                                  break;
116                          }
117 <                        break;
118 <                case "Windows":
119 <                        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;
117 >
118 >                        uname = system + ' ' + os.Version.Major + '.' + os.Version.Minor +
119 >                                " x86";
120                  }
121  
122 <                return system + ' ' + major + '.' + minor + " [" + version + "] ix86";
122 >                return uname;
123          }
124   #endif
125   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines