1 |
Douglas Thrift |
77 |
// Host Update Sharp |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
using System; |
8 |
|
|
using System.IO; |
9 |
|
|
using System.Net; |
10 |
Douglas Thrift |
82 |
using System.Text; |
11 |
Douglas Thrift |
98 |
#if !_FreeBSD_ |
12 |
|
|
using System.Windows.Forms; |
13 |
|
|
#endif |
14 |
Douglas Thrift |
77 |
|
15 |
Douglas Thrift |
78 |
public class HostUpdateSharp |
16 |
Douglas Thrift |
77 |
{ |
17 |
Douglas Thrift |
78 |
public static void Main(string[] args) |
18 |
Douglas Thrift |
77 |
{ |
19 |
Douglas Thrift |
98 |
foreach (string arg in args) |
20 |
|
|
{ |
21 |
|
|
switch (arg) |
22 |
|
|
{ |
23 |
|
|
case "-D": |
24 |
|
|
debug = true; |
25 |
|
|
break; |
26 |
Douglas Thrift |
100 |
default: |
27 |
|
|
uname = arg; |
28 |
|
|
break; |
29 |
Douglas Thrift |
98 |
} |
30 |
|
|
} |
31 |
|
|
|
32 |
Douglas Thrift |
90 |
try |
33 |
|
|
{ |
34 |
|
|
new HostUpdateSharp(); |
35 |
|
|
} |
36 |
|
|
catch (Exception exception) { Console.Error.WriteLine(exception); } |
37 |
|
|
} |
38 |
|
|
public HostUpdateSharp() |
39 |
|
|
{ |
40 |
Douglas Thrift |
83 |
StringBuilder host = new StringBuilder("host=" + Dns.GetHostName()); |
41 |
Douglas Thrift |
78 |
string url = "http://topsecret.douglasthrift.net/auth/hostupdate.cgi"; |
42 |
|
|
|
43 |
Douglas Thrift |
88 |
if ((host + "").IndexOf('.') < 0) |
44 |
Douglas Thrift |
82 |
{ |
45 |
|
|
host.Append(".local.douglasthrift.net"); |
46 |
|
|
} |
47 |
|
|
|
48 |
Douglas Thrift |
96 |
WebHeaderCollection headers = new WebHeaderCollection(); |
49 |
Douglas Thrift |
93 |
|
50 |
Douglas Thrift |
96 |
headers.Add("Authorization", "Basic " + Convert.ToBase64String((new |
51 |
|
|
ASCIIEncoding()).GetBytes("HostUpdate:frell2003"))); |
52 |
Douglas Thrift |
93 |
|
53 |
Douglas Thrift |
82 |
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); |
54 |
|
|
|
55 |
|
|
request.Accept = "text/plain"; |
56 |
Douglas Thrift |
83 |
request.ContentLength = host.Length; |
57 |
Douglas Thrift |
82 |
request.ContentType = "application/x-www-form-urlencoded"; |
58 |
Douglas Thrift |
96 |
request.Headers = headers; |
59 |
Douglas Thrift |
83 |
request.KeepAlive = false; |
60 |
Douglas Thrift |
82 |
request.Method = "POST"; |
61 |
Douglas Thrift |
88 |
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 |
Douglas Thrift |
98 |
#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 |
Douglas Thrift |
90 |
content.Close(); |
82 |
Douglas Thrift |
77 |
} |
83 |
Douglas Thrift |
98 |
private static bool debug = false; |
84 |
Douglas Thrift |
100 |
private static string uname = ""; |
85 |
Douglas Thrift |
88 |
#if _FreeBSD_ |
86 |
Douglas Thrift |
100 |
private static string platform() |
87 |
|
|
{ |
88 |
|
|
if (uname == "") |
89 |
|
|
{ |
90 |
|
|
"Unknown 0.0 x86"; |
91 |
|
|
} |
92 |
|
|
} |
93 |
Douglas Thrift |
88 |
#else |
94 |
Douglas Thrift |
100 |
private static string platform() |
95 |
Douglas Thrift |
88 |
{ |
96 |
Douglas Thrift |
100 |
if (uname == "") |
97 |
Douglas Thrift |
88 |
{ |
98 |
Douglas Thrift |
100 |
OperatingSystem os = Environment.OSVersion; |
99 |
|
|
string system = "Unknown"; |
100 |
Douglas Thrift |
88 |
|
101 |
Douglas Thrift |
100 |
switch (os.Platform) |
102 |
Douglas Thrift |
88 |
{ |
103 |
Douglas Thrift |
100 |
case PlatformID.Win32NT: |
104 |
|
|
system = "Windows NT"; |
105 |
Douglas Thrift |
88 |
break; |
106 |
Douglas Thrift |
100 |
case PlatformID.Win32Windows: |
107 |
|
|
system = "Windows"; |
108 |
|
|
break; |
109 |
Douglas Thrift |
88 |
} |
110 |
Douglas Thrift |
100 |
|
111 |
|
|
uname = system + ' ' + os.Version.Major + '.' + os.Version.Minor + |
112 |
|
|
" x86"; |
113 |
Douglas Thrift |
88 |
} |
114 |
|
|
|
115 |
Douglas Thrift |
100 |
return uname; |
116 |
Douglas Thrift |
88 |
} |
117 |
|
|
#endif |
118 |
Douglas Thrift |
77 |
} |