home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / tbsource.lha / TBSource / Logger / Lv1.05.S < prev    next >
Text File  |  1993-12-21  |  26KB  |  1,458 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1992        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    Don´t try to understand the code    *
  8. *                        *
  9. * Version 0.01    ??/??/1992            *
  10. *     -0.99ö                    *
  11. *                        *
  12. * BUGS:                        *
  13. *                        *
  14. * Version 1.00    01/08/1992            *
  15. *                        *
  16. * BUGS:    Logging problems, grr...        *
  17. *                        *
  18. * Version 1.01    08/08/1992            *
  19. *                        *
  20. * BUGS:                        *
  21. *                        *
  22. * Version 1.02    09/08/1992            *
  23. *                        *
  24. * Added speeds.                    *
  25. *                        *
  26. * Version 1.03    14/08/1992            *
  27. *                        *
  28. * Added log!                    *
  29. *                        *
  30. * BUGS:    Didn't give correct device in arguments    *
  31. *                        *
  32. * Version 1.04    15/08/1992            *
  33. *                        *
  34. * Version 1.05    22/08/1992            *
  35. *                        *
  36. * Changed log to be opened/closed before/after    *
  37. * writes.                    *
  38. *                        *
  39. *************************************************
  40.  
  41.     INCLUDE    "JMPLibs.i"
  42.     INCLUDE    "exec/types.i"
  43.     INCLUDE    "exec/nodes.i"
  44.     INCLUDE    "exec/lists.i"
  45.     INCLUDE    "exec/ports.i"
  46.     INCLUDE    "exec/memory.i"
  47.     INCLUDE    "exec/devices.i"
  48.     INCLUDE    "exec/io.i"
  49.     INCLUDE    "exec/tasks.i"
  50.     INCLUDE    "libraries/dosextens.i"
  51.     INCLUDE    "libraries/dos.i"
  52.     INCLUDE    "devices/serial.i"
  53.     INCLUDE    "dos/dostags.i"
  54.     INCLUDE    "dos/datetime.i"
  55.  
  56.     INCLUDE    "XREF:2.0.xref"
  57.     INCLUDE    "XREF:exec.xref"
  58.     INCLUDE    "XREF:dos.xref"
  59.  
  60.     XREF    _LVOCurrentTime
  61.     XREF    _LVOSystemTagList
  62.  
  63. TRUE:        EQU    1
  64.  
  65.         section    Logger,CODE
  66.  
  67.         push    d2-d7/a2-a6
  68.         push    d0/a0
  69.  
  70.         sub.l    a1,a1            ;Find our task
  71.         lib    Exec,FindTask
  72.         move.l    d0,OurTask
  73.  
  74.         openlib    Dos,NoDos        ;Keep at beginning
  75.  
  76. CLIStart:    lib    Dos,Output
  77.         move.l    d0,_stdout
  78.  
  79.         openlib    Utility,NoUtility
  80.  
  81.         pull    d0/a0
  82.         clr.b    -1(a0,d0.l)
  83.         cmp.b    #'?',(a0)
  84.         beq    Usage
  85.         cmp.w    #'-?',(a0)
  86.         beq    Usage
  87.         cmp.w    #'-h',(a0)
  88.         beq    Usage
  89.         cmp.b    #'h',(a0)
  90.         beq    Usage
  91.         cmp.w    #'-1',(a0)
  92.         bne    CLIStart1
  93.         move.w    #1,LogLevel
  94.         add.l    #3,a0
  95. CLIStart1:    cmp.w    #'-2',(a0)
  96.         bne    CLIStart2
  97.         move.w    #2,LogLevel
  98.         add.l    #3,a0
  99. CLIStart2:    cmp.w    #'-3',(a0)
  100.         bne    CLIStart3
  101.         move.w    #3,LogLevel
  102.         add.l    #3,a0
  103. CLIStart3:    cmp.w    #'-d',(a0)
  104.         bne    CLIStart9
  105.         move.w    #1,Dumb
  106.         add.l    #3,a0
  107. CLIStart9:    cmp.w    #'-s',(a0)
  108.         bne    CLIStart10
  109.         add.l    #2,a0
  110.         bsr    ConvASCII
  111.         tst.l    d0
  112.         beq    CLIStart2
  113.         move.l    d0,Speed
  114.  
  115. CLIStart10:    cmp.b    #' ',(a0)
  116.         bne    CLIStart11
  117.         add.l    #1,a0
  118.         bra    CLIStart10
  119. CLIStart11:
  120.  
  121. Cont0.2:    bsr    ConvASCII
  122.         tst.l    d0
  123.         beq    Cont1
  124.         move.l    d0,SerUnit
  125. Cont1:        cmp.b    #' ',(a0)
  126.         bne    Cont1.1
  127.         add.l    #1,a0
  128. Cont1.1:    tst.b    (a0)
  129.         beq    Cont1.2
  130.         move.l    a0,SerName
  131. Cont1.2:
  132.  
  133. MainStart:    openlib    Intuition,NoInt
  134.  
  135.  
  136. ;Create read reply port for serial.device (or modem0.device etc.)
  137.  
  138.         lib    Exec,CreateMsgPort
  139.         move.l    d0,SRRPort
  140.         beq    NoMsgPort
  141.  
  142. ;Create read IOReq for serial.device (or for other device, but size is EXTSER)
  143.  
  144.         move.l    #IOEXTSER_SIZE,d0
  145.         move.l    SRRPort,a0
  146.         lib    Exec,CreateIORequest
  147.         move.l    d0,IORRequest
  148.         beq    NoIOReq
  149.  
  150. ;Create write reply port for serial.device (or modem0.device etc.)
  151.  
  152.         lib    Exec,CreateMsgPort
  153.         move.l    d0,SWRPort
  154.         beq    NoMsgPort
  155.  
  156. ;Create write IOReq for serial.device (or for other device, but size is EXTSER)
  157.  
  158.         move.l    #IOEXTSER_SIZE,d0
  159.         move.l    SWRPort,a0
  160.         lib    Exec,CreateIORequest
  161.         move.l    d0,IOWRequest
  162.         beq    NoIOReq
  163.  
  164. ;open serial.device
  165.  
  166.         move.l    SerName,a0
  167.         move.l    SerUnit,d0
  168.         move.l    IORRequest,a1
  169.         move.l    Speed,IO_BAUD(a1)
  170.         move.b    #SERF_SHARED,IO_SERFLAGS(a1)
  171.         clr.l    d1                ;no flags
  172.         lib    Exec,OpenDevice
  173.         tst.l    d0
  174.         bne    NoSerial
  175.         move.w    #$1,SerOpen        ;just to tell if open
  176.  
  177. ;Copy info from one req to the other
  178.  
  179.         move.l    IORRequest,a0
  180.         move.l    IOWRequest,a1
  181.         move.l    IO_DEVICE(a0),IO_DEVICE(a1)
  182.         move.l    IO_UNIT(a0),IO_UNIT(a1)
  183.         add.l    #48,a0            ;get start of ioser
  184.         add.l    #48,a1
  185.         move.l    #34,d0
  186.         lib    Exec,CopyMem
  187.  
  188. ;set preferences with IOWReq
  189.  
  190.         tst.l    Speed
  191.         beq    SkipSpeed
  192.         move.l    IOWRequest,a1
  193.         clr.l    IO_LENGTH(a1)
  194.         clr.l    IO_DATA(a1)
  195.         move.w    #SDCMD_SETPARAMS,IO_COMMAND(a1)
  196.         move.l    Speed,IO_BAUD(a1)
  197.         lib    Exec,DoIO
  198.         tst.l    d0
  199.         bne    NoSetSer
  200. SkipSpeed:
  201.  
  202. ;
  203. ;Main loop here
  204. ;
  205. ;1.  Reset modem
  206. ;2.  Setup read
  207. ;3.  Wait for RING (*)
  208. ;4.  Answer with ATA (*)
  209. ;5.  Wait for CONNECT (*)
  210. ;6.  Delay of 1 SEC
  211. ;7.  Display Getty-Header
  212. ;8.  Ask login
  213. ;9.  Ask for password
  214. ;10. Test password with login
  215. ;11. Loop if incorrect or null
  216. ;12. Execute Login-Start of $username
  217.  
  218. ;(*) only if -d(umb) option is not set
  219.  
  220.         bsr    Reader
  221.  
  222. StartLoop:    clr.l    d1
  223.         bset.l    #SIGBREAKB_CTRL_C,d1    ;check for CTRL_C
  224.         lib    Dos,CheckSignal
  225.         btst.l    #SIGBREAKB_CTRL_C,d0
  226.         bne    ShutDown
  227.  
  228.         tst.w    Dumb
  229.         bne    StartLoop1
  230.         bsr    Reset
  231.  
  232. StartLoop1:    tst.w    Dumb
  233.         bne    Logging
  234.  
  235. StartLoop2:    clr.w    BufCount
  236.         bsr    WaitForRing
  237.         tst.l    d0
  238.         beq    ShutDown
  239.  
  240.         bsr    Answer
  241.         clr.w    BufCount
  242.         bsr    WaitForConnect
  243.         tst.l    d0
  244.         beq    ShutDown
  245.         cmp.l    #1111111,d0
  246.         beq    StartLoop2
  247.  
  248.         clr.l    d0
  249.         bsr    WaitUntilLF    ;clears connect speed + CR
  250.         clr.l    d0
  251.         bsr    WaitUntilLF    ;should clear LF
  252.  
  253. ;Login part starts here
  254.  
  255. Logging:    lea.l    LoginSeconds,a0
  256.         lea.l    MicrosTemp,a1
  257.         lib    Intuition,CurrentTime
  258.  
  259.         clr.w    LogFailCount
  260.         tst.w    Dumb
  261.         bne    Logging0.11111
  262.         bsr    Delay11SECS
  263.  
  264. Logging0.11111:    bsr    Welcome
  265. Logging1:    bsr    AskLogin
  266.         tst.l    d0
  267.         beq    ShutDown
  268.         tst.b    Buffer3
  269.         beq    Logging1
  270.         bsr    AskPassword
  271.         tst.l    d0
  272.         beq    ShutDown
  273.  
  274.         lea.l    PassWdFileN,a0
  275.         move.l    a0,d1
  276.         move.l    #MODE_OLDFILE,d2
  277.         lib    Dos,Open
  278.         move.l    d0,PassWdFile
  279.         bne    Logging1.1
  280.  
  281.         lea.l    PassWdFileN,a3
  282.         bsr    FileError1
  283.         bra    Logging2.9
  284.  
  285. Logging1.1:    bsr    ReadUser
  286.         tst.l    d0
  287.         bne    Logging2.9
  288.         lea.l    TempBuf1,a0
  289.         lea.l    UserName,a1
  290.         bsr    CmpStrings
  291.         tst.l    d0
  292.         beq    Logging1.1
  293.  
  294. Logging2:    lea.l    PassWord,a0
  295.         lea.l    Buffer4,a1
  296.         bsr    Decrypt
  297.         lea.l    Buffer4,a0
  298.         lea.l    Buffer3,a1
  299.         bsr    CmpStrings
  300.         tst.l    d0
  301.         bne    LoggedOn
  302. Logging2.9:    add.w    #1,LogFailCount
  303.         bsr    IncorrectLogin
  304.         cmp.w    #5,LogFailCount
  305.         beq    LoginFailure
  306.         bra    Logging1
  307.  
  308. LoggedOn:    move.l    PassWdFile,d1
  309.         beq    LoggedOn1
  310.         lib    Dos,Close
  311.         clr.l    PassWdFile
  312.  
  313. LoggedOn1:    lea.l    LoginSeconds,a0
  314.         lea.l    MicrosTemp,a1
  315.         lib    Intuition,CurrentTime
  316.  
  317.         lea.l    CRLFText1,a0
  318.         bsr    GetLength
  319.         bsr    Writer
  320.  
  321. ;Do log stuff
  322.  
  323.         cmp.w    #2,LogLevel
  324.         beq    LoggedOn2
  325.         cmp.w    #3,LogLevel
  326.         bne    LoggedOn3
  327. LoggedOn2:    lea.l    CorrectText1,a0
  328.         bsr    GetLength
  329.         bsr    Writer2
  330.         lea.l    TempBuf1,a0
  331.         bsr    GetLength
  332.         bsr    Writer2
  333.         lea.l    LogFailIncText1,a0
  334.         bsr    GetLength
  335.         bsr    Writer2
  336.         bsr    PutDate
  337.         lea.l    CRLFText1,a0
  338.         bsr    GetLength
  339.         bsr    Writer2
  340.  
  341. LoggedOn3:    bsr    OpenNIL
  342.         tst.l    NILFile
  343.         beq    ShutDown
  344.  
  345.         bsr    ClearSer
  346.  
  347.         bsr    MakeCmdString
  348.  
  349.         lea.l    CmdString1,a0
  350.         move.l    a0,d1
  351.         clr.l    d2
  352.         move.l    NILFile,d3
  353.         lib    Dos,Execute
  354.  
  355.         bsr    CloseNIL
  356.  
  357. LogOut:        lea.l    CRLFText1,a0
  358.         bsr    GetLength
  359.         bsr    Writer
  360.         bsr    OnTime
  361.  
  362.         tst.w    Dumb
  363.         bne    LogOut1
  364.         bsr    HangUp
  365. LogOut1:    cmp.w    #5,LogFailCount        ;don't wait for character
  366.         beq    LogOut2
  367.         bsr    CheckEvent
  368.         tst.l    d0
  369.         beq    ShutDown
  370.         bsr    Reader
  371. LogOut2:    bra    StartLoop
  372.  
  373. OnTime:        lea.l    LogoutSeconds,a0
  374.         lea.l    MicrosTemp,a1
  375.         lib    Intuition,CurrentTime
  376.  
  377.         move.l    LoginSeconds,d0
  378.         move.l    LogoutSeconds,d1
  379.         sub.l    d0,d1
  380.         divu.w    #60,d1            ;Minutes
  381.         clr.l    d0
  382.         move.w    d1,d0            ;test moving it straight to mins...
  383.         move.w    d0,OnTimeMins
  384.  
  385.         lea.l    fstrl,a0        ;HEX->ASCII
  386.         lea.l    OnTimeMins,a1        ;Number2Print
  387.         lea.l    PutChProc,a2
  388.         lea.l    OnTimeText2,a3        ;Destination
  389.         lib    Exec,RawDoFmt
  390.  
  391.         lea.l    OnTimeText1,a0
  392.         bsr    GetLength
  393.         bsr    Writer
  394.  
  395.         cmp.w    #2,LogLevel
  396.         beq    OnTime2
  397.         cmp.w    #3,LogLevel
  398.         bne    OnTime3
  399. OnTime2:    lea.l    LogOutText1,a0
  400.         bsr    GetLength
  401.         bsr    Writer2
  402.         bsr    PutDate
  403.         lea.l    CRLFText2,a0
  404.         bsr    GetLength
  405.         bsr    Writer2
  406.         lea.l    OnTimeText1,a0
  407.         bsr    GetLength
  408.         bsr    Writer2
  409.  
  410. OnTime3:    lea.l    ConnectionText1,a0
  411.         bsr    GetLength
  412.         bsr    Writer
  413.         rts
  414.  
  415. ;Waits for RING
  416. ;
  417. ;INPUT
  418. ;
  419. ;OUTPUT
  420. ;
  421. ;D0 = -1 if OK
  422. ;D0 =  0 if Break
  423. ;
  424. ;ACTION
  425. ;
  426. ;1. Wait for input, serial or CTRL_C
  427. ;2. If CTRL_C then break
  428. ;3. If serial test for ring
  429. ;4. If D0 = -1 then RING -> OUT
  430. ;5. If not then loop
  431.  
  432. WaitForRing:    bsr    CheckEvent
  433.         tst.l    d0
  434.         beq    WaitForRing_OUT
  435.  
  436.         bsr    TestRing
  437.         tst.l    d0
  438.         beq    WaitForRing        ;No RING so get more chars
  439. WaitForRing_OUT: rts
  440.  
  441. TestRing:    tst.w    BufCount
  442.         bne    TestRing2
  443.         cmp.b    #'R',Buffer1
  444.         bne    TestRing4
  445. TestRing2:    lea.l    Buffer2,a0
  446.         add.w    BufCount,a0
  447.         move.b    Buffer1,(a0)
  448.         add.w    #1,BufCount
  449.         cmp.w    #4,BufCount
  450.         bne    TestRing4
  451.         clr.w    BufCount
  452.         cmp.l    #'RING',Buffer2
  453.         bne    TestRing4
  454. TestRing3:    bsr    ClearSer
  455.         bsr    Reader
  456.         move.l    #-1,d0            ;indicate ring
  457.         rts
  458. TestRing4:    bsr    ClearSer        ;Abort possible prev. read
  459.         bsr    Reader            ;Set up new read
  460.         clr.l    d0
  461.         rt