Comment ========================================================== This program is used to call the Navy atomic clock and set all your file servers to the correct time. You need to set the ComPort to your modem port and the TimeOffset to match your time zone. 5 - New York 6 - Chicago 7 - Denver 8 - San Francisco You might have to change the phone number if you to deal with getting an outside line. This program will set the time on all servers you are attached to and have Console Operator status. It will then try to log into all other servers and set the time. To log into the other servers and set the time,you will need to create a dummy user called TIMESYNC and a password of SETTIME. Give this user no rights but make him a console operator. You can even restrict the login time to late at night when this program is run. MarxMenu will attempt to log into all not attached servers under this name and set the time. MarxMenu will detach as soon as the time is set. ========================================================= EndComment var NumberToDial TimeOffset StartTime Tries StandardIO ;----- Set com port, number, and time offset to match your system. if ParamStr(2) = '1' ComPort = Com1 elseif ParamStr(2) = '2' ComPort = Com2 else ComPort = Com2 endif NumberToDial = '9,1-202-653-0351' TimeOffSet = 6 ;Offset for Central Standard Time ;===================[ Start of main program ]====================== Writeln Writeln 'MarxMenu NavyTime' Writeln 'Copyright 1992-93 by Marc Perkel * All right reserved.' Writeln ExitCode = 1 ;errorlevel 1=fail 0=success ComInitPort(1200,8,'N',1) ;1200 baud access only if ComResult <> 0 Writeln 'Comport failed to open!' ExitMenu endif ComWriteRecChar ComSendKbdChar KeyEvent(AltX) = loc HangupAndExit KeyEvent(Esc) = loc HangupAndExit repeat StartTime = Now Writeln '==> Reseting Modem' ComWrite 'ATZ' CR WaitFor 'OK' Writeln { Writeln '==> Sending Modem Init String' ComWrite 'AT&Q0' CR ;&Q0 puts modem in dumb mode allowing it to WaitFor 'OK' ;connect faster to atomic clock and save $$$ Writeln } Writeln '==> Calling Naval Atomic Clock' ComWriteln 'ATDT ' NumberToDial CallClock Tries = Tries + 1 if Tries >= 100 then HangupAndExit DrainModem forever ;========================[ Procedures ]============================= Procedure SetAllClocks ComWatchCD SetTime(GetTimeString) SetAllServers ExitCode = 0 ;success HangupAndExit EndProc Procedure SetTime (UtcTime) var T DayOfYear DateSt TimeSt ;- First we pick out the date. DayOfYear = Value(Mid(UtcTime,7,3)) DateSt = DateString(TimeOf('01-01-' + Str(Year)) + (DayOfYear - 1 * SecondsInDay)) ;- Then we pick out the time. TimeSt = Mid(UtcTime,11,6) Insert(':',TimeSt,3) Insert(':',TimeSt,6) T = TimeOf(DateSt + ' ' + TimeSt) T = T - (TimeOffset - DaylightSavingsTime * 3600) + 1 Writeln Writeln Writeln 'Setting WorkStation Clock ... ' DateString(T) ' ' TimeString(T) Now = T NovServerTime = T SetServerTime(NovDefaultServer) EndProc Procedure SetAllServers var AttachedServers AllServers ThisServer ;- We set the clock on all servers are are attached to. ThisServer = NovDefaultServer NovAttachedServers(AttachedServers) SortArray(AttachedServers) Loop AttachedServers if LoopVal <> ThisServer SetServerTime(LoopVal) endif EndLoop NovServers(AllServers) SortArray(AllServers) ;- We set the clock on all servers are are not attached to. Loop AllServers if PosInSortedList(LoopVal,AttachedServers) = 0 ;not attached NovLogin(LoopVal + '/TIMESYNC','SETTIME') if (NovResult = 0) or (NovResult = 223) SetServerTime(LoopVal) NovDetach(LoopVal) else Writeln 'Login on Server ' LoopVal ' failed! * Error = ' NovResult endif endif EndLoop EndProc Procedure SetServerTime (Server) Write 'Setting Server ' Server ' Clock ... ' NovSetPreferredServer Server NovServerTime = Now if NovResult = 0 Writeln DateString ' ' TimeString else Writeln 'Failed!' endif NovSetPreferredServer '' EndProc Procedure GetTimeString while True CharLoop if (length(ComLastLine) = 20) and (Right(ComLastLine,3) = 'UTC') ;- Hangup Modem ComDTR Off Return ComLastLine endif endwhile EndProc Procedure TestAbort ;- ConCDAbort is set to True if Carrier drops. if ComCDAbort Writeln '[Carrier Dropped]' HangupAndExit endif ;- 2 Minutes or I'm out of here if Now - StartTime > 120 Writeln Writeln '==> Timeout Disconnect' HangupAndExit endif EndProc Procedure CharLoop TestAbort ComCheckActivity EndProc Procedure WaitFor (St) ComLastLine = '' while ComLastLine <> St CharLoop endwhile Wait 20 EndProc Procedure DrainModem StartTime = Now while Now - StartTime < 2 CharLoop endwhile Writeln EndProc Procedure HangupAndExit ComDTR Off ComWatchCD Off ComWriteln 'ATZ' Wait 40 ExitMenu EndProc Procedure CallClock repeat CharLoop ; if pos('CONNECT',ComLastLine) > 0 ; Return if ComCD DrainModem SetAllClocks elseif ComLastLine = 'BUSY' Return elseif ComLastLine = 'NO DIALTONE' HangupAndExit elseif ComLastLine = 'NO CARRIER' Return endif forever EndProc Procedure DaylightSavingsTime var B E ;- First Sunday in April B = TimeOf('04-01-' + Str(Year)) while DayOfWeekOf(B) <> 0 B = B + SecondsInDay endwhile ;- Last Sunday in October E = TimeOf('10-31-' + Str(Year)) while DayOfWeekOf(E) <> 0 E = E - SecondsInDay endwhile if Now Within(B,E) Return 1 else Return 0 endif EndProc