ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/winhost/nettest.frm
Revision: 1.27
Committed: Wed Feb 28 09:18:26 2001 UTC (23 years, 9 months ago) by pjm2
Branch: MAIN
Changes since 1.26: +7 -7 lines
Log Message:
Tidied the appearance of the form.

File Contents

# User Rev Content
1 pjm2 1.1 VERSION 5.00
2     Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
3 pjm2 1.11 Object = "{33155A3D-0CE0-11D1-A6B4-444553540000}#1.0#0"; "SysTray.ocx"
4 pjm2 1.1 Begin VB.Form Form1
5 pjm2 1.17 BorderStyle = 3 'Fixed Dialog
6 pjm2 1.10 Caption = "i-scream Winhost"
7 pjm2 1.27 ClientHeight = 1185
8 pjm2 1.1 ClientLeft = 45
9 pjm2 1.17 ClientTop = 330
10 pjm2 1.12 ClientWidth = 4710
11 pjm2 1.20 Icon = "nettest.frx":0000
12 pjm2 1.1 LinkTopic = "Form1"
13     MaxButton = 0 'False
14 pjm2 1.17 MinButton = 0 'False
15 pjm2 1.27 ScaleHeight = 1185
16 pjm2 1.12 ScaleWidth = 4710
17 pjm2 1.1 ShowInTaskbar = 0 'False
18 pjm2 1.24 StartUpPosition = 2 'CenterScreen
19     Visible = 0 'False
20 pjm2 1.26 Begin VB.CommandButton Command1
21     Caption = "more"
22     Height = 255
23     Left = 3960
24     TabIndex = 8
25     Top = 840
26     Width = 615
27     End
28     Begin VB.TextBox Text1
29     Height = 2055
30     Left = 120
31     Locked = -1 'True
32     MultiLine = -1 'True
33     ScrollBars = 2 'Vertical
34     TabIndex = 7
35     Top = 1200
36     Width = 4455
37     End
38 pjm2 1.11 Begin VB.CommandButton Hide
39 pjm2 1.27 Caption = "hide"
40     Height = 255
41     Left = 3960
42 pjm2 1.24 TabIndex = 6
43 pjm2 1.27 Top = 480
44     Width = 615
45 pjm2 1.11 End
46     Begin SysTray.SystemTray SystemTray
47 pjm2 1.26 Left = 2520
48     Top = 4200
49 pjm2 1.11 _ExtentX = 847
50     _ExtentY = 847
51     SysTrayText = "i-scream Winhost"
52     IconFile = 0
53     End
54 pjm2 1.8 Begin VB.Timer Timer1
55 pjm2 1.26 Left = 3120
56     Top = 4200
57 pjm2 1.1 End
58 pjm2 1.10 Begin VB.CommandButton Reconfigure
59     Caption = "Reconfigure with FilterManager"
60 pjm2 1.12 Height = 375
61 pjm2 1.26 Left = 840
62 pjm2 1.10 TabIndex = 0
63 pjm2 1.26 Top = 3480
64 pjm2 1.10 Width = 2895
65 pjm2 1.1 End
66 pjm2 1.5 Begin MSWinsockLib.Winsock TCPSock
67 pjm2 1.26 Left = 4080
68     Top = 4200
69 pjm2 1.1 _ExtentX = 741
70     _ExtentY = 741
71     _Version = 393216
72     End
73 pjm2 1.5 Begin MSWinsockLib.Winsock UDPSock
74 pjm2 1.26 Left = 3600
75     Top = 4200
76 pjm2 1.1 _ExtentX = 741
77     _ExtentY = 741
78     _Version = 393216
79     Protocol = 1
80     End
81 pjm2 1.9 Begin VB.Label Label2
82     Alignment = 1 'Right Justify
83     Caption = "Next heartbeat:"
84 pjm2 1.8 Height = 255
85 pjm2 1.26 Left = 120
86 pjm2 1.24 TabIndex = 5
87 pjm2 1.26 Top = 480
88 pjm2 1.9 Width = 1455
89 pjm2 1.8 End
90 pjm2 1.9 Begin VB.Label Label1
91     Alignment = 1 'Right Justify
92     Caption = "Next UDP packet:"
93 pjm2 1.8 Height = 255
94 pjm2 1.24 Left = 120
95     TabIndex = 4
96 pjm2 1.9 Top = 120
97     Width = 1455
98 pjm2 1.8 End
99 pjm2 1.9 Begin VB.Label Label4
100 pjm2 1.10 BorderStyle = 1 'Fixed Single
101 pjm2 1.9 Caption = "0"
102 pjm2 1.7 Height = 255
103 pjm2 1.26 Left = 1680
104 pjm2 1.24 TabIndex = 3
105 pjm2 1.26 Top = 480
106 pjm2 1.9 Width = 615
107 pjm2 1.7 End
108 pjm2 1.9 Begin VB.Label Label3
109 pjm2 1.10 BorderStyle = 1 'Fixed Single
110 pjm2 1.9 Caption = "0"
111 pjm2 1.7 Height = 255
112 pjm2 1.24 Left = 1680
113     TabIndex = 2
114 pjm2 1.9 Top = 120
115     Width = 615
116 pjm2 1.7 End
117 pjm2 1.6 Begin VB.Label Status
118 pjm2 1.12 Alignment = 2 'Center
119 pjm2 1.6 Caption = "Status:"
120 pjm2 1.1 Height = 255
121 pjm2 1.18 Left = 0
122 pjm2 1.24 TabIndex = 1
123 pjm2 1.26 Top = 840
124     Width = 3855
125 pjm2 1.1 End
126     End
127     Attribute VB_Name = "Form1"
128     Attribute VB_GlobalNameSpace = False
129     Attribute VB_Creatable = False
130     Attribute VB_PredeclaredId = True
131     Attribute VB_Exposed = False
132 pjm2 1.15 ' For the system tray bits
133 pjm2 1.4 Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
134     Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
135    
136     Dim filterManagerHostname As String
137 pjm2 1.18 Dim filterManagerTCPPort As Long
138 pjm2 1.4
139 pjm2 1.13 Dim seqNo As Long
140     Dim machineName As String
141    
142 pjm2 1.2 Dim filterHostname As String
143 pjm2 1.3 Dim filterTCPPort As Integer
144     Dim filterUDPPort As Integer
145     Dim fileList As String
146     Dim lastModified As String
147 pjm2 1.2
148 pjm2 1.7 Dim UDPUpdateTime As Integer
149     Dim TCPUpdateTime As Integer
150    
151 pjm2 1.2 Dim protocolVersion As String
152     Dim connected As Boolean
153 pjm2 1.16
154 pjm2 1.21 Dim CUpTime As New CUpTime
155 pjm2 1.25 Dim wksta As New CNetWksta
156 pjm2 1.16
157 pjm2 1.26 Dim windowBig As Boolean
158    
159 pjm2 1.1 Dim responseNumber As Integer
160    
161 pjm2 1.26 Private Sub Command1_Click()
162    
163     ' Toggle visibility of the debug output.
164    
165     If windowBig Then
166     Form1.Height = 1500
167     windowBig = False
168     Else
169     Form1.Height = 4350
170     windowBig = True
171     End If
172    
173     End Sub
174    
175 pjm2 1.2 Private Sub Form_Load()
176 pjm2 1.13
177 pjm2 1.22 If App.PrevInstance Then
178     x = MsgBox("There is already an i-scream Winhost running on this machine.", 48, "i-scream host already running")
179 pjm2 1.25 End
180 pjm2 1.22 End If
181    
182 pjm2 1.2 protocolVersion = "1.1"
183 pjm2 1.13
184 pjm2 1.10 Status.Caption = "Loading"
185 pjm2 1.21 Form1.Caption = "i-scream Winhost " & protocolVersion
186    
187     CUpTime.Init
188    
189     If CUpTime.isWin9x Then
190 pjm2 1.25 x = MsgBox("Sorry, the i-scream host can only be used to monitor servers (i.e. not Win9x)", 48, "Not a server")
191 pjm2 1.21 End
192     End If
193 pjm2 1.6
194 pjm2 1.26 windowBig = False
195    
196 pjm2 1.4 ''''TEMP
197 pjm2 1.18 'filterManagerHostname = "killigrew.ukc.ac.uk"
198     'filterManagerTCPPort = 4567
199 pjm2 1.13 ''''' END TEMP
200 pjm2 1.4
201 pjm2 1.18 'GoTo skip
202 pjm2 1.4 On Error GoTo iniError
203     Dim buf As String * 256
204     Dim length As Long
205 pjm2 1.18 length = GetPrivateProfileString("i-scream Winhost", "FilterManager", "<no value>", buf, Len(buf), App.Path & "/winhost.ini")
206 pjm2 1.4 filterManagerHostname = Left$(buf, length)
207 pjm2 1.18 length = GetPrivateProfileInt("i-scream Winhost", "FilterManagerPort", 0, App.Path & "/winhost.ini")
208     filterManagerTCPPort = length
209 pjm2 1.25 If filterManagerHostname = "" Then
210     GoTo iniError
211     End If
212 pjm2 1.20 On Error GoTo 0
213 pjm2 1.13 skip:
214    
215 pjm2 1.18 Status.Caption = "Connecting to Filter Manager " & filterManagerHostname & ":" & filterManagerTCPPort
216 pjm2 1.13 Reconfigure_Click
217 pjm2 1.6
218 pjm2 1.20 SystemTray.Icon = Val(Form1.Icon)
219 pjm2 1.15 SystemTray.Action = 0
220    
221    
222 pjm2 1.4 Exit Sub
223    
224     iniError:
225 pjm2 1.18 x = MsgBox("The i-scream Winhost could not read the correct settings from the winhost.ini file. Please correct these and try again. " & Err.Description, 48, "Configuration not found")
226 pjm2 1.4 End
227    
228     End Sub
229    
230 pjm2 1.10 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
231 pjm2 1.11 x = MsgBox("Are you sure you want to shut down the Winhost? This will stop your computer sending information to the i-scream Central Monitoring System.", vbYesNo, "i-scream Winhost")
232 pjm2 1.10 If x = 7 Then
233     Cancel = True
234 pjm2 1.15 Else
235     SystemTray.Action = 2
236 pjm2 1.10 End If
237    
238     End Sub
239    
240 pjm2 1.11 Private Sub Hide_Click()
241     Form1.Visible = False
242     SystemTray.Icon = Val(Form1.Icon)
243     End Sub
244    
245 pjm2 1.10 Private Sub Reconfigure_Click()
246     ' establish a TCP connection to a filtermanager
247     connected = False
248     TCPSock.Close
249     TCPSock.Connect filterManagerHostname, filterManagerTCPPort
250 pjm2 1.11 End Sub
251    
252    
253    
254     Private Sub SystemTray_MouseDblClk(ByVal Button As Integer)
255    
256     Form1.Visible = True
257     Form1.SetFocus
258    
259 pjm2 1.10 End Sub
260    
261 pjm2 1.5 Private Sub TCPSock_Connect()
262 pjm2 1.6
263     responseNumber = 0
264 pjm2 1.1
265 pjm2 1.3 ' Send something as soon as we connect to the server.
266     If connected = False Then
267     ' contact the FilterManager
268 pjm2 1.5 TCPSock.SendData "STARTCONFIG" & vbCrLf
269 pjm2 1.3 Else
270     ' Contact the Filter
271 pjm2 1.5 TCPSock.SendData "HEARTBEAT" & vbCrLf
272 pjm2 1.3 End If
273 pjm2 1.1
274     End Sub
275    
276 pjm2 1.5 Private Sub TCPSock_DataArrival(ByVal bytesTotal As Long)
277 pjm2 1.1
278     responseNumber = responseNumber + 1
279    
280     ' Get the line from the server.
281 pjm2 1.5 TCPSock.GetData response, vbString, bytesTotal
282 pjm2 1.1
283     ' Remove linefeeds and returns from the line.
284     response = Replace(response, Chr(13), "")
285     response = Replace(response, Chr(10), "")
286 pjm2 1.24 'Text4.Text = Text4.Text & vbCrLf & response
287 pjm2 1.1
288 pjm2 1.2 If connected = False Then
289     ' Perform TCP configuration (1.1)
290     On Error GoTo configError
291     Select Case responseNumber
292     Case 1:
293     If Not response = "OK" Then GoTo configError
294 pjm2 1.5 TCPSock.SendData "LASTMODIFIED" & vbCrLf
295 pjm2 1.26 Text1.Text = "Requesting configuration from FilterManager:- " & vbCrLf
296     Text1.Text = Text1.Text & response & vbCrLf
297 pjm2 1.2 Case 2:
298     If response = "ERROR" Then GoTo configError
299 pjm2 1.3 lastModified = response
300 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
301 pjm2 1.5 TCPSock.SendData "FILELIST" & vbCrLf
302 pjm2 1.26 ''' Uncomment this for new protocol release.
303     'Case 2a:
304     'If response = "ERROR" Then GoTo configError
305     'fileList = response
306     'Text1.Text = Text1.Text & response & vbCrLf
307     'TCPSock.SendData "FQDN" & vbCrLf
308 pjm2 1.2 Case 3:
309     If response = "ERROR" Then GoTo configError
310 pjm2 1.3 fileList = response
311 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
312     ' REMOVE above line, uncomment next
313     'machineName = response
314 pjm2 1.5 TCPSock.SendData "UDPUpdateTime" & vbCrLf
315 pjm2 1.2 Case 4:
316     If response = "ERROR" Then GoTo configError
317 pjm2 1.7 UDPUpdateTime = response
318 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
319 pjm2 1.5 TCPSock.SendData "TCPUpdateTime" & vbCrLf
320 pjm2 1.2 Case 5:
321     If response = "ERROR" Then GoTo configError
322 pjm2 1.7 TCPUpdateTime = response
323 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
324 pjm2 1.5 TCPSock.SendData "ENDCONFIG" & vbCrLf
325 pjm2 1.2 Case 6:
326     If Not response = "OK" Then GoTo configError
327 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
328 pjm2 1.5 TCPSock.SendData "FILTER" & vbCrLf
329 pjm2 1.2 Case 7:
330 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
331 pjm2 1.2 'we got a filter list here.
332     readTo = 0
333     ' get hostname
334     readTo = InStr(1, response, ";", vbBinaryCompare)
335     filterHostname = Mid(response, 1, readTo - 1)
336     response = Mid(response, readTo + 1, Len(response))
337     ' get UDP Port number
338     readTo = InStr(1, response, ";")
339     filterUDPPort = Mid(response, 1, readTo - 1)
340     response = Mid(response, readTo + 1, Len(response))
341     ' get TCP Port number
342     filterTCPPort = response
343 pjm2 1.5 TCPSock.SendData "END" & vbCrLf
344 pjm2 1.2 Case 8:
345     If Not response = "OK" Then GoTo configError
346     connected = True
347     responseNumber = 0
348 pjm2 1.5 TCPSock.Close
349 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
350 pjm2 1.24 'Text4.Text = Text4.Text & vbCrLf & " <closed>"
351 pjm2 1.10 Status.Caption = "Configuration successful"
352 pjm2 1.8 Label3.Caption = UDPUpdateTime
353     Label4.Caption = TCPUpdateTime
354     Timer1.Interval = 1000
355 pjm2 1.2 End Select
356     Else
357     ' Perform a heartbeat (1.1)
358     On Error GoTo heartbeatError
359     Select Case responseNumber
360     Case 1:
361 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
362 pjm2 1.26 Text1.Text = "Performing heartbeat: -" & vbCrLf
363     Text1.Text = Text1.Text & response & vbCrLf
364 pjm2 1.5 TCPSock.SendData "CONFIG" & vbCrLf
365 pjm2 1.2 Case 2:
366 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
367 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
368 pjm2 1.5 TCPSock.SendData fileList & vbCrLf
369 pjm2 1.2 Case 3:
370 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
371 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
372 pjm2 1.5 TCPSock.SendData lastModified & vbCrLf
373 pjm2 1.2 Case 4:
374 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
375 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
376 pjm2 1.5 TCPSock.SendData "ENDHEARTBEAT" & vbCrLf
377 pjm2 1.2 Case 5:
378 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
379 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
380 pjm2 1.5 TCPSock.Close
381 pjm2 1.10 Status.Caption = "Heartbeat sent successfully."
382 pjm2 1.2 End Select
383    
384     End If
385    
386    
387     Exit Sub
388    
389     configError:
390 pjm2 1.10 Status.Caption = "FAILED to get configuration"
391 pjm2 1.8 Exit Sub
392 pjm2 1.2 heartbeatError:
393 pjm2 1.10 Status.Caption = "Heatbeat FAILED"
394 pjm2 1.8 Exit Sub
395 pjm2 1.1 End Sub
396 pjm2 1.5
397 pjm2 1.8 Private Sub Timer1_Timer()
398    
399     Label3.Caption = Label3.Caption - 1
400     Label4.Caption = Label4.Caption - 1
401    
402 pjm2 1.10 Status.Caption = ""
403 pjm2 1.8
404     If Label3.Caption < 1 Then
405 pjm2 1.15
406     ' prepare the contents of the XML packet.
407     seqNo = seqNo + 1
408 pjm2 1.26
409     ' Comment this line in the next protocol
410 pjm2 1.15 machineName = TCPSock.LocalHostName
411 pjm2 1.26
412 pjm2 1.16 LocalIP = TCPSock.LocalIP
413 pjm2 1.14 packetDate = Date2Num()
414 pjm2 1.15
415    
416     Dim verinfo As OSVERSIONINFO
417     verinfo.dwOSVersionInfoSize = Len(verinfo)
418     ret% = GetVersionEx(verinfo)
419     If ret% = 0 Then
420     MsgBox "Error getting Windows version Information"
421     End
422     End If
423    
424 pjm2 1.21 osName = GetVersion()
425 pjm2 1.15 osVersionMajor = verinfo.dwMajorVersion
426     osVersionMinor = verinfo.dwMinorVersion
427     osBuild = verinfo.dwBuildNumber
428    
429     Dim sysinfo As SYSTEM_INFO
430     GetSystemInfo sysinfo
431     Select Case sysinfo.dwProcessorType
432     Case PROCESSOR_INTEL_386
433     processorType = "Intel 386"
434     Case PROCESSOR_INTEL_486
435     processorType = "Intel 486"
436     Case PROCESSOR_INTEL_PENTIUM
437     processorType = "Intel Pentium variant"
438     Case PROCESSOR_MIPS_R4000
439     processorType = "MIPS R4000"
440     Case PROCESSOR_ALPHA_21064
441     processorType = "DEC Alpha 21064"
442     Case Else
443     processorType = "(unknown)"
444     End Select
445    
446     Dim memsts As MEMORYSTATUS
447     Dim memory&
448     GlobalMemoryStatus memsts
449     memory& = memsts.dwTotalPhys
450     memTotal = memory& \ 1024
451     memory& = memsts.dwAvailPhys
452     memFree = memory& \ 1024
453     memory& = memsts.dwTotalVirtual
454     swapTotal = memory& \ 1024
455     memory& = memsts.dwAvailVirtual
456     swapFree = memory& \ 1024
457    
458 pjm2 1.25 uptime = CUpTime.MilliSecs \ 1000
459 pjm2 1.19
460 pjm2 1.23 CUpTime.Capture
461     cpu_time = CUpTime.CPUTime
462     percent_idle = CUpTime.PercentIdle
463    
464 pjm2 1.15 ' build the contents of the XML packet
465 pjm2 1.16 xml = "<packet seq_no=""" & seqNo & """ machine_name=""" & machineName & """ date=""" & packetDate & """ type=""data"" ip=""" & LocalIP & """>" & _
466 pjm2 1.15 "<os>" & _
467     "<name>" & osName & "</name>" & _
468     "<version>" & osVersionMajor & "</version>" & _
469     "<release>" & osBuild & "</release>" & _
470     "<platform>" & osName & "</platform>" & _
471     "<minor_version>" & osVersionMinor & "</minor_version>" & _
472     "<processor>" & processorType & "</processor>" & _
473 pjm2 1.19 "<uptime>" & uptime & "</uptime>" & _
474 pjm2 1.15 "</os>" & _
475 pjm2 1.23 "<cpu><idle>" & percent_idle & "</idle><user>" & cpu_time & "</user></cpu>" & _
476 pjm2 1.15 "<memory><total>" & memTotal & "</total><free>" & memFree & "</free></memory>" & _
477     "<swap><total>" & swapTotal & "</total><free>" & swapFree & "</free></swap>" & _
478 pjm2 1.17 "</packet>"
479 pjm2 1.26 Text1.Text = "Last packet contained: -" & vbCrLf & xml
480 pjm2 1.8
481     ' Use the first winsock control to send a UDP packet.
482     UDPSock.RemoteHost = filterHostname
483     UDPSock.RemotePort = filterUDPPort
484     UDPSock.SendData xml
485 pjm2 1.10 Status.Caption = "UDP packet sent"
486 pjm2 1.8 Label3.Caption = UDPUpdateTime
487     End If
488    
489     If Label4.Caption < 1 Then
490     ' establish a TCP connection to a filter
491     TCPSock.Close
492     TCPSock.Connect filterHostname, filterTCPPort
493     Label4.Caption = TCPUpdateTime
494     End If
495    
496     End Sub
497 pjm2 1.13
498     Function Date2Num() As Long
499 pjm2 1.14 Dim x As Long
500     x = DateDiff("s", "1-1-1970", Now)
501     Date2Num = x
502 pjm2 1.13 End Function