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 101 by Douglas Thrift, 2004-03-02T01:40:20-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 >                        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=" + Dns.GetHostName());
41 +                string url = "http://topsecret.douglasthrift.net/auth/hostupdate.cgi";
42 +
43 +                if ((host + "").IndexOf('.') < 0)
44 +                {
45 +                        host.Append(".local.douglasthrift.net");
46 +                }
47 +
48 +                WebHeaderCollection headers = new WebHeaderCollection();
49 +
50 +                headers.Add("Authorization", "Basic " + Convert.ToBase64String((new
51 +                        ASCIIEncoding()).GetBytes("HostUpdate:frell2003")));
52 +
53 +                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
54 +
55 +                request.Accept = "text/plain";
56 +                request.ContentLength = host.Length;
57 +                request.ContentType = "application/x-www-form-urlencoded";
58 +                request.Headers = headers;
59 +                request.KeepAlive = false;
60 +                request.Method = "POST";
61 +                request.UserAgent = "Host Update Sharp/1.0 (" + platform() + ')';
62 +
63 +                StreamWriter post = new StreamWriter(request.GetRequestStream(),
64 +                        Encoding.ASCII);
65 +
66 +                post.Write(host);
67 +                post.Close();
68 +
69 +                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
70 +
71 +                StreamReader content = new StreamReader(response.GetResponseStream(),
72 +                        Encoding.ASCII);
73 +
74 + #if _FreeBSD_
75 +                if (debug) Console.Write(content.ReadToEnd());
76 + #else
77 +                if (debug) MessageBox.Show(content.ReadToEnd(), "Host Update Sharp",
78 +                        MessageBoxButtons.OK, MessageBoxIcon.Information);
79 + #endif
80 +
81 +                content.Close();
82 +        }
83 +        private static bool debug = false;
84 +        private static string uname = "";
85 + #if _FreeBSD_
86 +        private static string platform()
87 +        {
88 +                if (uname == "")
89 +                {
90 +                        uname = "Unknown 0.0 x86";
91 +                }
92 +
93 +                return uname;
94 +        }
95 + #else
96 +        private static string platform()
97 +        {
98 +                if (uname == "")
99 +                {
100 +                        OperatingSystem os = Environment.OSVersion;
101 +                        string system = "Unknown";
102 +
103 +                        switch (os.Platform)
104 +                        {
105 +                        case PlatformID.Win32NT:
106 +                                system = "Windows NT";
107 +                                break;
108 +                        case PlatformID.Win32Windows:
109 +                                system = "Windows";
110 +                                break;
111 +                        }
112 +
113 +                        uname = system + ' ' + os.Version.Major + '.' + os.Version.Minor +
114 +                                " x86";
115 +                }
116 +
117 +                return uname;
118          }
119 + #endif
120   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines