/[AnywhereTS-MSSQL]/trunk/TSAdminTool/DHCP.cs
ViewVC logotype

Contents of /trunk/TSAdminTool/DHCP.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations) (download)
Wed Jul 11 14:19:13 2012 UTC (7 years, 7 months ago) by william
File size: 10606 byte(s)
imported from https://anywherets.svn.sourceforge.net/svnroot/anywherets/trunk/
Revision: 1
Author: beartown
Date: 3:10:40 AM, Monday, June 21, 2010
Message:
First upload. Still todo in order to get a fully working product: Replace Thinstation images with vanilla Thinstation, modify ImageDesigntimeConfig.cs, ImageRuntimeConfig.cs in order to support the Thinstation image
1 using System;
2 using System.ServiceProcess;
3 using System.Collections.Generic;
4 using System.Text;
5 using System.Reflection; // For path (assembly)
6 using System.IO; // For Path
7 using System.Security; // Security Exception
8 using System.Windows.Forms; // Message Box
9 using System.Text.RegularExpressions; // For validate MAC address
10
11 namespace AnywhereTS
12 {
13 public static class AtsDhcp // DHCP Support
14 {
15 static public string TFTPD_SERVICE_NAME="TS TFTP";
16 static public string strTftpd32IP; // The IP of the nic used by AnywhereTS TFTPD32
17 static public int intPoolSize; // The IP pool Size used by AnywhereTS TFTPD32
18 static public int intDHCP_IP; // The IP of the nic used by AnywhereTS TFTPD32
19 static public int intNetMask; // The netmask AnywhereTS TFTPD32
20 static public int intGateway; // The Gateway AnywhereTS TFTPD32
21 static public int intDNS; // The DNS AnywhereTS TFTPD32
22 static public int intIP_Pool; // The first ip used by AnywhereTS TFTPD32 DHCP
23 static public int intDHCPon; // The mode of TFTPD 32 5= dhcp + tftp 1=TFTP
24
25 // Constructor
26 static AtsDhcp()
27 {
28 }
29
30 public static void OpenTFTP32regKey()
31 {
32 intIP_Pool = Int32.Parse(ATSGlobals.GetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", @"IP_Pool"));
33 intPoolSize = Int32.Parse(ATSGlobals.GetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", @"PoolSize"));
34 intNetMask = Int32.Parse(ATSGlobals.GetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "Mask"));
35 intGateway = Int32.Parse(ATSGlobals.GetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "Gateway"));
36 intDNS = Int32.Parse(ATSGlobals.GetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "DNS"));
37 strTftpd32IP = ATSGlobals.GetRegValue(ATSGlobals.strTFTPD32RegRoot, "LocalIP");
38 intDHCPon = Int32.Parse(ATSGlobals.GetRegValue(ATSGlobals.strTFTPD32RegRoot, "Services"));
39 //error
40 //AtsDhcp.intIP_Pool = &H1400DF0A
41 //AtsDhcp.intDNS = &H100DF0A
42 //AtsDhcp.intNetMask = &HFFFF
43 //AtsDhcp.intPoolSize = &HC8
44 //AtsDhcp.intGateway = &H100DF0A
45 //AtsDhcp.strTftpd32IP = "10.223.0.1"
46 //AtsDhcp.intDHCPon = 1
47 //On Error GoTo 0
48 //return
49 }
50 //Configure TFTPD32. bolDHCP = true -> DHCP enabled
51 public static void ConfTFTPD32(bool bolDHCP)
52 {
53 StopTFTPD32();
54 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "LastWindowPos", "60 49 860 642 ");
55 //objRegkey.SetValue("BaseDirectory", Globals.strTFTPdir)
56 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "TftpPort", 69);
57 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Hide", 0);
58 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "WinSize", 0);
59 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Negociate", 1);
60 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "PXECompatibility", 0);
61 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "DirText", 0);
62 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "ShowProgressBar", 0);
63 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Timeout", 3);
64 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "MaxRetransmit", 6);
65 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "SecurityLevel", 1);
66 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "UnixStrings", 1);
67 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Beep", 0);
68 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "VirtualRoot", 1);
69 //If Globals.intNoOfValidAdapters = 1 Then
70 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "LocalIP", strTftpd32IP);//fix mee
71 if (bolDHCP)
72 {
73 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Services", 5);//DHCP + TFTP
74 }
75 else
76 {
77 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Services", 1);//TFTP only
78 }
79 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "TftpLogFile", "");
80 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "SaveSyslogFile", "");
81 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "IP_Pool", intIP_Pool);
82 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "PoolSize", intPoolSize);
83 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "Mask", intNetMask);
84 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "Gateway", intGateway);
85 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "DNS", intDNS);
86 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "BootFile", "client.zpxe");
87 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "DomainName", "");
88 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "AddOptionNumber1", "");
89 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "AddOptionValue1", 0);
90 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "AddOptionNumber2", "");
91 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "AddOptionValue2", 0);
92 StartTFTPD32();
93 //Return
94 }
95 public static void StartTFTPD32()
96 {
97 System.ServiceProcess.ServiceController srvController = new System.ServiceProcess.ServiceController(TFTPD_SERVICE_NAME);
98 try
99 {
100 srvController.Start();
101 srvController.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(50));
102 }
103 catch
104 {
105 MessageBox.Show(@"Could not start the TFTPD service.");
106 }
107 }
108 public static void StopTFTPD32()
109 {
110 ServiceController srvController = new ServiceController(TFTPD_SERVICE_NAME);
111 if (srvController.CanStop)
112 {
113 try
114 {
115 srvController.Stop();
116 srvController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(30));
117 }
118 catch
119 {
120 MessageBox.Show(@"Could not stop the TFTPD service.");
121 }
122 }
123 }
124 public static bool UDPPortInUse(int intPort)
125 {
126 System.Net.IPAddress localAddress;
127 localAddress=System.Net.Dns.GetHostEntry("localhost").AddressList[0];
128 System.Net.Sockets.Socket udpSocket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
129 System.Net.IPEndPoint localEndpoint = new System.Net.IPEndPoint(localAddress, intPort);
130 bool retVal = false;
131 try
132 {
133 udpSocket.Bind(localEndpoint);
134 }
135 catch
136 {
137 retVal = true;
138 }
139 udpSocket.Close();
140 return retVal;
141 }
142 public static bool CheckForLocalTFTPD()
143 {
144 return UDPPortInUse(69);
145 }
146 public static bool CheckForLocalDHCP()
147 {
148 return UDPPortInUse(67);
149 }
150 public static bool IsTFTPD32Running()
151 {
152 ServiceController srvController = new ServiceController(TFTPD_SERVICE_NAME);
153 return srvController.Status == ServiceControllerStatus.Running;
154 }
155 //Check if the TFTPD32 service is installed on this computer
156 public static bool HasTFTPD32()
157 {
158 ServiceController[] arrController;
159 int i;
160 arrController = ServiceController.GetServices();
161 for (i = 0; i <= arrController.Length - 1; i ++)
162 {
163 if (arrController[i].DisplayName == TFTPD_SERVICE_NAME)
164 return true;
165 }
166 return false;
167 }
168
169 //Configures TFTPD mode
170 public static void ConfigureTFTPD32service(bool bolTFTP, bool bolDHCP)
171 {
172 string strTFTPD32root;
173 StopTFTPD32();
174 strTFTPD32root = ATSGlobals.GetATSRegValueString("TFTP_root");
175 if (bolDHCP == false)
176 if (bolTFTP == false)
177 {
178 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Services", 2); //TFTP client "no service"
179 }
180 else
181 {
182 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Services", 1); //TFTP Server no DHCP Server
183 }
184 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "BaseDirectory", strTFTPD32root);
185 if (bolDHCP == true)
186 {
187 if (bolTFTP == false)
188 {
189 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Services", 4);//DHCP Server no TFTP Server
190 }
191 else
192 {
193 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "Services", 5);//DHCP Server and TFTP Server
194 }
195 }
196 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot, "BaseDirectory", strTFTPD32root);
197 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "IP_Pool", intIP_Pool);
198 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "PoolSize", intPoolSize);
199 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "DNS", intDNS);
200 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "Mask", intNetMask);
201 ATSGlobals.SetRegValue(ATSGlobals.strTFTPD32RegRoot + @"\DHCP", "Gateway", intGateway);
202 if (bolTFTP || bolDHCP )
203 {
204 StartTFTPD32();
205 }
206 }
207
208
209 // Create all needed registry values for TFTPD32
210 public static void CreateRegistryValues()
211 {
212 }
213
214 }
215 }

  ViewVC Help
Powered by ViewVC 1.1.22