home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Aktiv 1 / CDA1_96.ISO / novell / marxmenu.exe / NAVYTIME.MNU < prev    next >
Text File  |  1995-04-17  |  6KB  |  301 lines

  1. Comment
  2. ==========================================================
  3.  
  4. This program is used to call the Navy atomic clock and set all
  5. your file servers to the correct time.
  6.  
  7. You need to set the ComPort to your modem port and the TimeOffset
  8. to match your time zone.
  9.  
  10.  5 - New York
  11.  6 - Chicago
  12.  7 - Denver
  13.  8 - San Francisco
  14.  
  15. You might have to change the phone number if you to deal with getting an
  16. outside line.
  17.  
  18. This program will set the time on all servers you are attached to and
  19. have Console Operator status. It will then try to log into all other
  20. servers and set the time.
  21.  
  22. To log into the other servers and set the time,you will need to create a
  23. dummy user called TIMESYNC and a password of SETTIME. Give this user no
  24. rights but make him a console operator. You can even restrict the login
  25. time to late at night when this program is run. MarxMenu will attempt to
  26. log into all not attached servers under this name and set the time.
  27. MarxMenu will detach as soon as the time is set.
  28.  
  29. =========================================================
  30. EndComment
  31.  
  32. var
  33.   NumberToDial
  34.   TimeOffset
  35.   StartTime
  36.   Tries
  37.  
  38.  
  39. StandardIO
  40.  
  41. ;----- Set com port, number, and time offset to match your system.
  42.  
  43. if ParamStr(2) = '1'
  44.    ComPort = Com1
  45.  
  46. elseif ParamStr(2) = '2'
  47.    ComPort = Com2
  48.  
  49. else
  50.    ComPort = Com2
  51.  
  52. endif
  53.  
  54. NumberToDial = '9,1-202-653-0351'
  55. TimeOffSet = 6                     ;Offset for Central Standard Time
  56.  
  57. ;===================[ Start of main program ]======================
  58.  
  59. Writeln
  60. Writeln 'MarxMenu NavyTime'
  61. Writeln 'Copyright 1992-93 by Marc Perkel * All right reserved.'
  62. Writeln
  63. ExitCode = 1                     ;errorlevel 1=fail 0=success
  64.  
  65. ComInitPort(1200,8,'N',1)        ;1200 baud access only
  66. if ComResult <> 0
  67.    Writeln 'Comport failed to open!'
  68.    ExitMenu
  69. endif
  70.  
  71. ComWriteRecChar
  72. ComSendKbdChar
  73. KeyEvent(AltX)  = loc HangupAndExit
  74. KeyEvent(Esc)  = loc HangupAndExit
  75.  
  76. repeat
  77.    StartTime = Now
  78.    Writeln '==> Reseting Modem'
  79.  
  80.    ComWrite 'ATZ' CR
  81.    WaitFor 'OK'
  82.    Writeln
  83.  
  84.    Writeln '==> Sending Modem Init String'
  85.  
  86.    ComWrite 'AT&Q0' CR       ;&Q0 puts modem in dumb mode allowing it to
  87.    WaitFor 'OK'              ;connect faster to atomic clock and save $$$
  88.    Writeln
  89.  
  90.    Writeln '==> Calling Naval Atomic Clock'
  91.  
  92.    ComWriteln 'ATD ' NumberToDial
  93.  
  94.    CallClock
  95.    Tries = Tries + 1
  96.    if Tries >= 100 then HangupAndExit
  97.    DrainModem
  98. forever
  99.  
  100. ;========================[ Procedures ]=============================
  101.  
  102. Procedure SetAllClocks
  103.    ComWatchCD
  104.    SetTime(GetTimeString)
  105.    SetAllServers
  106.    ExitCode = 0           ;success
  107.    HangupAndExit
  108. EndProc
  109.  
  110.  
  111. Procedure SetTime (UtcTime)
  112. var T DayOfYear DateSt TimeSt
  113.  
  114.    ;- First we pick out the date.
  115.  
  116.    DayOfYear = Value(Mid(UtcTime,7,3))
  117.    DateSt = DateString(TimeOf('01-01-' + Str(Year)) + (DayOfYear - 1 * SecondsInDay))
  118.  
  119.    ;- Then we pick out the time.
  120.  
  121.    TimeSt = Mid(UtcTime,11,6)
  122.    Insert(':',TimeSt,3)
  123.    Insert(':',TimeSt,6)
  124.  
  125.    T = TimeOf(DateSt + ' ' + TimeSt)
  126.    T = T - (TimeOffset - DaylightSavingsTime * 3600) + 1
  127.  
  128.    Writeln
  129.    Writeln
  130.    Writeln 'Setting WorkStation Clock ... ' DateString(T) ' ' TimeString(T)
  131.    Now = T
  132.    NovServerTime = T
  133.    SetServerTime(NovDefaultServer)
  134. EndProc
  135.  
  136.  
  137. Procedure SetAllServers
  138. var AttachedServers AllServers ThisServer
  139.  
  140.    ;- We set the clock on all servers are are attached to.
  141.  
  142.    ThisServer = NovDefaultServer
  143.    NovAttachedServers(AttachedServers)
  144.    SortArray(AttachedServers)
  145.  
  146.    Loop AttachedServers
  147.       if LoopVal <> ThisServer
  148.          SetServerTime(LoopVal)
  149.       endif
  150.    EndLoop
  151.  
  152.    NovServers(AllServers)
  153.    SortArray(AllServers)
  154.  
  155.    ;- We set the clock on all servers are are not attached to.
  156.  
  157.    Loop AllServers
  158.       if PosInSortedList(LoopVal,AttachedServers) = 0    ;not attached
  159.          NovLogin(LoopVal + '/TIMESYNC','SETTIME')
  160.          if (NovResult = 0) or (NovResult = 223)
  161.             SetServerTime(LoopVal)
  162.             NovDetach(LoopVal)
  163.          else
  164.             Writeln 'Login on Server ' LoopVal ' failed! * Error = ' NovResult
  165.          endif
  166.       endif
  167.    EndLoop
  168. EndProc
  169.  
  170.  
  171. Procedure SetServerTime (Server)
  172.    Write 'Setting Server ' Server ' Clock ... '
  173.    NovSetPreferredServer Server
  174.  
  175.    NovServerTime = Now
  176.    if NovResult = 0
  177.       Writeln DateString ' ' TimeString
  178.    else
  179.       Writeln 'Failed!'
  180.    endif
  181.  
  182.    NovSetPreferredServer ''
  183. EndProc
  184.  
  185.  
  186. Procedure GetTimeString
  187.    while True
  188.       CharLoop
  189.       if (length(ComLastLine) = 20) and (Right(ComLastLine,3) = 'UTC')
  190.  
  191.          ;- Hangup Modem
  192.  
  193.          ComDTR Off
  194.          Return ComLastLine
  195.       endif
  196.    endwhile
  197. EndProc
  198.  
  199.  
  200. Procedure TestAbort
  201.  
  202.    ;- ConCDAbort is set to True if Carrier drops.
  203.  
  204.    if ComCDAbort
  205.       Writeln '[Carrier Dropped]'
  206.       HangupAndExit
  207.    endif
  208.  
  209.    ;- 2 Minutes or I'm out of here
  210.  
  211.    if Now - StartTime > 120
  212.       Writeln
  213.       Writeln '==> Timeout Disconnect'
  214.       HangupAndExit
  215.    endif
  216.  
  217. EndProc
  218.  
  219.  
  220. Procedure CharLoop
  221.    TestAbort
  222.    ComCheckActivity
  223. EndProc
  224.  
  225.  
  226. Procedure WaitFor (St)
  227.    ComLastLine = ''
  228.    while ComLastLine <> St
  229.       CharLoop
  230.    endwhile
  231.    Wait 20
  232. EndProc
  233.  
  234.  
  235. Procedure DrainModem
  236.    StartTime = Now
  237.    while Now - StartTime < 2
  238.       CharLoop
  239.    endwhile
  240.    Writeln
  241. EndProc
  242.  
  243.  
  244. Procedure HangupAndExit
  245.    ComDTR Off
  246.    ComWatchCD Off
  247.    ComWriteln 'ATZ'
  248.    Wait 40
  249.    ExitMenu
  250. EndProc
  251.  
  252.  
  253. Procedure CallClock
  254.    repeat
  255.       CharLoop
  256.  
  257. ;      if pos('CONNECT',ComLastLine) > 0
  258. ;         Return
  259.  
  260.       if ComCD
  261.          DrainModem
  262.          SetAllClocks
  263.  
  264.       elseif ComLastLine = 'BUSY'
  265.          Return
  266.  
  267.       elseif ComLastLine = 'NO DIALTONE'
  268.          HangupAndExit
  269.  
  270.       elseif ComLastLine = 'NO CARRIER'
  271.          Return
  272.  
  273.       endif
  274.    forever
  275. EndProc
  276.  
  277.  
  278. Procedure DaylightSavingsTime
  279. var B E
  280.  
  281.    ;- First Sunday in April
  282.  
  283.    B = TimeOf('04-01-' + Str(Year))
  284.    while DayOfWeekOf(B) <> 0
  285.       B = B + SecondsInDay
  286.    endwhile
  287.  
  288.    ;- Last Sunday in October
  289.  
  290.    E = TimeOf('10-31-' + Str(Year))
  291.    while DayOfWeekOf(E) <> 0
  292.       E = E - SecondsInDay
  293.    endwhile
  294.  
  295.    if Now Within(B,E)
  296.       Return 1
  297.    else
  298.       Return 0
  299.    endif
  300. EndProc
  301.