ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/winhost/nettest.frm
Revision: 1.32
Committed: Thu Mar 1 09:30:55 2001 UTC (23 years, 8 months ago) by pjm2
Branch: MAIN
Changes since 1.31: +16 -2 lines
Log Message:
Fixed uptime > 47 problem by sending uptime as the number of seconds the
program has been running rather than milliseconds_running / 1000.  This is
not ideal, but it should be okay if the host is started automatically as
each machine starts.

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.32 Dim secondsRunning As Long
143    
144 pjm2 1.2 Dim filterHostname As String
145 pjm2 1.3 Dim filterTCPPort As Integer
146     Dim filterUDPPort As Integer
147     Dim fileList As String
148     Dim lastModified As String
149 pjm2 1.2
150 pjm2 1.32 Dim fourtySevenDays As Integer
151    
152 pjm2 1.7 Dim UDPUpdateTime As Integer
153     Dim TCPUpdateTime As Integer
154    
155 pjm2 1.2 Dim protocolVersion As String
156     Dim connected As Boolean
157 pjm2 1.16
158 pjm2 1.21 Dim CUpTime As New CUpTime
159 pjm2 1.25 Dim wksta As New CNetWksta
160 pjm2 1.16
161 pjm2 1.26 Dim windowBig As Boolean
162    
163 pjm2 1.1 Dim responseNumber As Integer
164    
165 pjm2 1.26 Private Sub Command1_Click()
166    
167     ' Toggle visibility of the debug output.
168    
169     If windowBig Then
170     Form1.Height = 1500
171     windowBig = False
172     Else
173     Form1.Height = 4350
174     windowBig = True
175     End If
176    
177     End Sub
178    
179 pjm2 1.2 Private Sub Form_Load()
180 pjm2 1.13
181 pjm2 1.22 If App.PrevInstance Then
182     x = MsgBox("There is already an i-scream Winhost running on this machine.", 48, "i-scream host already running")
183 pjm2 1.25 End
184 pjm2 1.22 End If
185    
186 pjm2 1.32 ' Assume the host is run within the first 47 days of the machine starting.
187     fourtySevenDays = 0
188    
189 pjm2 1.2 protocolVersion = "1.1"
190 pjm2 1.13
191 pjm2 1.10 Status.Caption = "Loading"
192 pjm2 1.21 Form1.Caption = "i-scream Winhost " & protocolVersion
193    
194     CUpTime.Init
195    
196     If CUpTime.isWin9x Then
197 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")
198 pjm2 1.21 End
199     End If
200 pjm2 1.6
201 pjm2 1.26 windowBig = False
202    
203 pjm2 1.4 ''''TEMP
204 pjm2 1.18 'filterManagerHostname = "killigrew.ukc.ac.uk"
205     'filterManagerTCPPort = 4567
206 pjm2 1.13 ''''' END TEMP
207 pjm2 1.4
208 pjm2 1.18 'GoTo skip
209 pjm2 1.4 On Error GoTo iniError
210     Dim buf As String * 256
211     Dim length As Long
212 pjm2 1.18 length = GetPrivateProfileString("i-scream Winhost", "FilterManager", "<no value>", buf, Len(buf), App.Path & "/winhost.ini")
213 pjm2 1.4 filterManagerHostname = Left$(buf, length)
214 pjm2 1.18 length = GetPrivateProfileInt("i-scream Winhost", "FilterManagerPort", 0, App.Path & "/winhost.ini")
215     filterManagerTCPPort = length
216 pjm2 1.25 If filterManagerHostname = "" Then
217     GoTo iniError
218     End If
219 pjm2 1.20 On Error GoTo 0
220 pjm2 1.13 skip:
221    
222 pjm2 1.18 Status.Caption = "Connecting to Filter Manager " & filterManagerHostname & ":" & filterManagerTCPPort
223 pjm2 1.13 Reconfigure_Click
224 pjm2 1.6
225 pjm2 1.20 SystemTray.Icon = Val(Form1.Icon)
226 pjm2 1.15 SystemTray.Action = 0
227    
228    
229 pjm2 1.4 Exit Sub
230    
231     iniError:
232 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")
233 pjm2 1.4 End
234    
235     End Sub
236    
237 pjm2 1.10 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
238 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")
239 pjm2 1.10 If x = 7 Then
240     Cancel = True
241 pjm2 1.15 Else
242     SystemTray.Action = 2
243 pjm2 1.10 End If
244    
245     End Sub
246    
247 pjm2 1.11 Private Sub Hide_Click()
248     Form1.Visible = False
249     SystemTray.Icon = Val(Form1.Icon)
250     End Sub
251    
252 pjm2 1.30 Private Sub Image1_Click()
253    
254     End Sub
255    
256 pjm2 1.10 Private Sub Reconfigure_Click()
257     ' establish a TCP connection to a filtermanager
258     connected = False
259     TCPSock.Close
260     TCPSock.Connect filterManagerHostname, filterManagerTCPPort
261 pjm2 1.11 End Sub
262    
263    
264    
265     Private Sub SystemTray_MouseDblClk(ByVal Button As Integer)
266    
267     Form1.Visible = True
268     Form1.SetFocus
269    
270 pjm2 1.10 End Sub
271    
272 pjm2 1.5 Private Sub TCPSock_Connect()
273 pjm2 1.6
274     responseNumber = 0
275 pjm2 1.1
276 pjm2 1.3 ' Send something as soon as we connect to the server.
277     If connected = False Then
278     ' contact the FilterManager
279 pjm2 1.5 TCPSock.SendData "STARTCONFIG" & vbCrLf
280 pjm2 1.3 Else
281     ' Contact the Filter
282 pjm2 1.5 TCPSock.SendData "HEARTBEAT" & vbCrLf
283 pjm2 1.3 End If
284 pjm2 1.1
285     End Sub
286    
287 pjm2 1.5 Private Sub TCPSock_DataArrival(ByVal bytesTotal As Long)
288 pjm2 1.1
289     responseNumber = responseNumber + 1
290    
291     ' Get the line from the server.
292 pjm2 1.5 TCPSock.GetData response, vbString, bytesTotal
293 pjm2 1.1
294     ' Remove linefeeds and returns from the line.
295     response = Replace(response, Chr(13), "")
296     response = Replace(response, Chr(10), "")
297    
298 pjm2 1.2 If connected = False Then
299     ' Perform TCP configuration (1.1)
300     On Error GoTo configError
301     Select Case responseNumber
302     Case 1:
303     If Not response = "OK" Then GoTo configError
304 pjm2 1.5 TCPSock.SendData "LASTMODIFIED" & vbCrLf
305 pjm2 1.26 Text1.Text = "Requesting configuration from FilterManager:- " & vbCrLf
306     Text1.Text = Text1.Text & response & vbCrLf
307 pjm2 1.2 Case 2:
308     If response = "ERROR" Then GoTo configError
309 pjm2 1.3 lastModified = response
310 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
311 pjm2 1.5 TCPSock.SendData "FILELIST" & vbCrLf
312 pjm2 1.29 ' New addition to the protocol.
313 pjm2 1.2 Case 3:
314     If response = "ERROR" Then GoTo configError
315 pjm2 1.3 fileList = response
316 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
317 pjm2 1.29 TCPSock.SendData "FQDN" & vbCrLf
318     Case 4:
319     If response = "ERROR" Then GoTo configError
320     Text1.Text = Text1.Text & response & vbCrLf
321     machineName = response
322 pjm2 1.5 TCPSock.SendData "UDPUpdateTime" & vbCrLf
323 pjm2 1.29 Case 5:
324 pjm2 1.2 If response = "ERROR" Then GoTo configError
325 pjm2 1.7 UDPUpdateTime = response
326 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
327 pjm2 1.5 TCPSock.SendData "TCPUpdateTime" & vbCrLf
328 pjm2 1.29 Case 6:
329 pjm2 1.2 If response = "ERROR" Then GoTo configError
330 pjm2 1.7 TCPUpdateTime = response
331 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
332 pjm2 1.5 TCPSock.SendData "ENDCONFIG" & vbCrLf
333 pjm2 1.29 Case 7:
334 pjm2 1.2 If Not response = "OK" Then GoTo configError
335 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
336 pjm2 1.5 TCPSock.SendData "FILTER" & vbCrLf
337 pjm2 1.29 Case 8:
338 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
339 pjm2 1.2 'we got a filter list here.
340     readTo = 0
341     ' get hostname
342     readTo = InStr(1, response, ";", vbBinaryCompare)
343     filterHostname = Mid(response, 1, readTo - 1)
344     response = Mid(response, readTo + 1, Len(response))
345     ' get UDP Port number
346     readTo = InStr(1, response, ";")
347     filterUDPPort = Mid(response, 1, readTo - 1)
348     response = Mid(response, readTo + 1, Len(response))
349     ' get TCP Port number
350     filterTCPPort = response
351 pjm2 1.5 TCPSock.SendData "END" & vbCrLf
352 pjm2 1.29 Case 9:
353 pjm2 1.2 If Not response = "OK" Then GoTo configError
354     connected = True
355     responseNumber = 0
356 pjm2 1.5 TCPSock.Close
357 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
358 pjm2 1.24 'Text4.Text = Text4.Text & vbCrLf & " <closed>"
359 pjm2 1.10 Status.Caption = "Configuration successful"
360 pjm2 1.8 Label3.Caption = UDPUpdateTime
361     Label4.Caption = TCPUpdateTime
362     Timer1.Interval = 1000
363 pjm2 1.2 End Select
364     Else
365     ' Perform a heartbeat (1.1)
366     On Error GoTo heartbeatError
367     Select Case responseNumber
368     Case 1:
369 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
370 pjm2 1.26 Text1.Text = "Performing heartbeat: -" & vbCrLf
371     Text1.Text = Text1.Text & response & vbCrLf
372 pjm2 1.5 TCPSock.SendData "CONFIG" & vbCrLf
373 pjm2 1.2 Case 2:
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 fileList & vbCrLf
377 pjm2 1.2 Case 3:
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.SendData lastModified & vbCrLf
381 pjm2 1.2 Case 4:
382 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
383 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
384 pjm2 1.5 TCPSock.SendData "ENDHEARTBEAT" & vbCrLf
385 pjm2 1.2 Case 5:
386 pjm2 1.3 If Not response = "OK" Then GoTo heartbeatError
387 pjm2 1.26 Text1.Text = Text1.Text & response & vbCrLf
388 pjm2 1.5 TCPSock.Close
389 pjm2 1.10 Status.Caption = "Heartbeat sent successfully."
390 pjm2 1.2 End Select
391    
392     End If
393    
394    
395     Exit Sub
396    
397     configError:
398 pjm2 1.10 Status.Caption = "FAILED to get configuration"
399 pjm2 1.8 Exit Sub
400 pjm2 1.2 heartbeatError:
401 pjm2 1.10 Status.Caption = "Heatbeat FAILED"
402 pjm2 1.8 Exit Sub
403 pjm2 1.1 End Sub
404 pjm2 1.5
405 pjm2 1.8 Private Sub Timer1_Timer()
406    
407     Label3.Caption = Label3.Caption - 1
408     Label4.Caption = Label4.Caption - 1
409    
410 pjm2 1.10 Status.Caption = ""
411 pjm2 1.8
412     If Label3.Caption < 1 Then
413 pjm2 1.15
414     ' prepare the contents of the XML packet.
415     seqNo = seqNo + 1
416 pjm2 1.26
417 pjm2 1.31 netbiosName = TCPSock.LocalHostName
418 pjm2 1.26
419 pjm2 1.16 LocalIP = TCPSock.LocalIP
420 pjm2 1.14 packetDate = Date2Num()
421 pjm2 1.15
422    
423     Dim verinfo As OSVERSIONINFO
424     verinfo.dwOSVersionInfoSize = Len(verinfo)
425     ret% = GetVersionEx(verinfo)
426     If ret% = 0 Then
427     MsgBox "Error getting Windows version Information"
428     End
429     End If
430    
431 pjm2 1.21 osName = GetVersion()
432 pjm2 1.15 osVersionMajor = verinfo.dwMajorVersion
433     osVersionMinor = verinfo.dwMinorVersion
434     osBuild = verinfo.dwBuildNumber
435    
436     Dim sysinfo As SYSTEM_INFO
437     GetSystemInfo sysinfo
438     Select Case sysinfo.dwProcessorType
439     Case PROCESSOR_INTEL_386
440     processorType = "Intel 386"
441     Case PROCESSOR_INTEL_486
442     processorType = "Intel 486"
443     Case PROCESSOR_INTEL_PENTIUM
444     processorType = "Intel Pentium variant"
445     Case PROCESSOR_MIPS_R4000
446     processorType = "MIPS R4000"
447     Case PROCESSOR_ALPHA_21064
448     processorType = "DEC Alpha 21064"
449     Case Else
450     processorType = "(unknown)"
451     End Select
452    
453     Dim memsts As MEMORYSTATUS
454     Dim memory&
455     GlobalMemoryStatus memsts
456     memory& = memsts.dwTotalPhys
457 pjm2 1.29 memTotal = memory& \ 1048576
458 pjm2 1.15 memory& = memsts.dwAvailPhys
459 pjm2 1.29 memFree = memory& \ 1048576
460 pjm2 1.15 memory& = memsts.dwTotalVirtual
461 pjm2 1.29 swapTotal = memory& \ 1048576
462 pjm2 1.15 memory& = memsts.dwAvailVirtual
463 pjm2 1.29 swapFree = memory& \ 1048576
464 pjm2 1.15
465 pjm2 1.23 CUpTime.Capture
466     cpu_time = CUpTime.CPUTime
467     percent_idle = CUpTime.PercentIdle
468 pjm2 1.32
469     '' Causes numbers to be too big :-/
470     'uptime = CUpTime.MilliSecs \ 1000
471    
472     '' Doesn't work after 47 days :-/
473     'uptime = GetTickCount \ 1000
474    
475     secondsRunning = secondsRunning + UDPUpdateTime
476     uptime = secondsRunning
477 pjm2 1.23
478 pjm2 1.28 userCount = wksta.LoggedOnUsers
479    
480 pjm2 1.15 ' build the contents of the XML packet
481 pjm2 1.16 xml = "<packet seq_no=""" & seqNo & """ machine_name=""" & machineName & """ date=""" & packetDate & """ type=""data"" ip=""" & LocalIP & """>" & _
482 pjm2 1.15 "<os>" & _
483 pjm2 1.31 "<netbios_name>" & netbiosName & "</netbios_name>" & _
484 pjm2 1.15 "<name>" & osName & "</name>" & _
485     "<version>" & osVersionMajor & "</version>" & _
486     "<release>" & osBuild & "</release>" & _
487     "<platform>" & osName & "</platform>" & _
488     "<minor_version>" & osVersionMinor & "</minor_version>" & _
489     "<processor>" & processorType & "</processor>" & _
490 pjm2 1.19 "<uptime>" & uptime & "</uptime>" & _
491 pjm2 1.15 "</os>" & _
492 pjm2 1.28 "<users><count>" & userCount & "</count></users>" & _
493 pjm2 1.23 "<cpu><idle>" & percent_idle & "</idle><user>" & cpu_time & "</user></cpu>" & _
494 pjm2 1.15 "<memory><total>" & memTotal & "</total><free>" & memFree & "</free></memory>" & _
495     "<swap><total>" & swapTotal & "</total><free>" & swapFree & "</free></swap>" & _
496 pjm2 1.17 "</packet>"
497 pjm2 1.26 Text1.Text = "Last packet contained: -" & vbCrLf & xml
498 pjm2 1.8
499     ' Use the first winsock control to send a UDP packet.
500     UDPSock.RemoteHost = filterHostname
501     UDPSock.RemotePort = filterUDPPort
502     UDPSock.SendData xml
503 pjm2 1.10 Status.Caption = "UDP packet sent"
504 pjm2 1.8 Label3.Caption = UDPUpdateTime
505     End If
506    
507     If Label4.Caption < 1 Then
508     ' establish a TCP connection to a filter
509     TCPSock.Close
510     TCPSock.Connect filterHostname, filterTCPPort
511     Label4.Caption = TCPUpdateTime
512     End If
513    
514     End Sub
515 pjm2 1.13
516     Function Date2Num() As Long
517 pjm2 1.14 Dim x As Long
518     x = DateDiff("s", "1-1-1970", Now)
519     Date2Num = x
520 pjm2 1.13 End Function