home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / alphapage < prev    next >
Text File  |  2020-01-01  |  12KB  |  323 lines

  1. #!/usr/local/bin/kermit +
  2. ;
  3. ; ALPHAPAGE 6.0 for C-Kermit 8.0.201, 206, or 209 (but not 208)
  4. ; F. da Cruz, The Kermit Project, Columbia University
  5. ;
  6. ; TAP/IXO alphanumeric paging script for C-Kermit.
  7. ; For a detailed explanation, consult "Using C-Kermit", 2nd Ed., pp.454-456.
  8. ;
  9. if LLT \v(version) 800201 stop 1 C-Kermit 8.0.201 or later required.
  10. if EQU \v(version) 800208 stop 1 -
  11. "Sorry - This script doesn't work in 8.0.208; please use 201, 206, or 209.
  12.  
  13. ; Set defaults here.
  14.  
  15. define d_LINE /dev/ttyb           ; Device modem is attached to
  16.  
  17. ; The following are critical - the script won't work unless
  18. ; all of them are set appropriately for the specific paging service,
  19. ; Verizon PCS in this example.
  20.  
  21. define d_APAGEPHONE 18668230501   ; Paging service phone number (VERIZON PCS)
  22. define d_MODEM usrobotics         ; Actual specific modem type
  23. define d_SPEED 1200               ; Serial port speed
  24. define d_PARITY EVEN              ; Parity (usually EVEN or NONE)
  25. define d_FLOW NONE                ; Flow control
  26. define d_PACING 0                 ; Output character pacing (milliseconds)
  27.  
  28. ; Other defaults
  29.  
  30. define d_REDIALS 20               ; Allow 20 redials (IF LEGAL!)
  31. define d_TESTING 0                ; Set to 1 or 2 for debugging
  32.  
  33. ; You can override defaults with Kermit variables or environment variables:
  34.  
  35. if not def APAGEPHONE assign APAGEPHONE \$(APAGEPHONE)
  36. if not def APAGEPHONE asg APAGEPHONE \m(d_APAGEPHONE)
  37. if not def LINE assign LINE \$(LINE)
  38. if not def LINE asg LINE \m(d_LINE)
  39. if not def SPEED asg SPEED \$(SPEED)
  40. if not def SPEED asg SPEED \m(d_SPEED)
  41. if not def MODEM assign MODEM \$(MODEM)
  42. if not def MODEM asg MODEM \m(d_MODEM)
  43. if not def PARITY assign PARITY \$(PARITY)
  44. if not def PARITY asg PARITY \m(d_PARITY)
  45. if not def FLOW assign FLOW \$(FLOW)
  46. if not def FLOW asg FLOW \m(d_FLOW)
  47. if not def PACING assign PACING \$(PACING)
  48. if not def PACING asg PACING \m(d_PACING)
  49. ;
  50. ; WARNING: Automatic redialing is restricted or illegal in some
  51. ; countries.  Modify the lines marked "IF LEGAL!" above if this applies
  52. ; in your location.
  53. ;
  54. assign REDIALS \$(REDIALS)
  55. if not def REDIALS asg REDIALS \m(d_REDIALS)
  56. if not def TESTING {
  57.     assign TESTING \$(TESTING)
  58.     if not def TESTING asg TESTING \m(d_TESTING)
  59.     if not def TESTING asg TESTING 0
  60.     if not numeric \m(TESTING) asg TESTING 1
  61. }
  62.  
  63. ; TAPMSG, defined below, is an alphanumeric pager dialing script that
  64. ; implements the Telocator Alphanumeric Protocol (TAP), also known as IXO,
  65. ; for sending one-line alphanumeric pages.  TAPMSG assumes the connection
  66. ; to the paging service is already made.
  67. ;
  68. ; The APAGE macro makes a connection to the paging service using the
  69. ; device, modem, and phone number definitions at the top of this file,
  70. ; and then invokes TAPMSG to send the page.
  71. ;
  72. ; INSTRUCTIONS
  73. ;
  74. ; Edit the defaults at the top of this file as needed.
  75. ;
  76. ; Change the top line to indicate the full pathname of the C-Kermit 8.0
  77. ; executable if necessary, then store this file in your PATH with a name like
  78. ; "verizon", give it execute permission, and then you can run it by name from
  79. ; the shell prompt:
  80. ;
  81. ;   verizon pagerid message
  82. ;
  83. ; Command-line args containing spaces must be quoted.  Example:
  84. ;
  85. ;   verizon 9876543 "This is a message"
  86. ; You can also pass the pagerid and message as environment variables instead
  87. ; of command-line arguments:
  88. ;
  89. ;   export PIN=19177654321
  90. ;   export MESSAGE="Everything is broken - come and fix!"
  91. ;   verizon
  92. ;
  93. ; To use different paging services, make copies of this file with the
  94. ; appropriate names and configuration changes, e.g. skytel with skytel's
  95. ; phone number, pagenet, whatever.
  96. ;
  97. ; EDIT HISTORY
  98. ;
  99. ; Version 1.0: Sept 1996, for C-Kermit 6.0.
  100. ; Version 2.0: July 1997:
  101. ;  1. To make TAPMSG fit into 1K for small C-Kermit versions.
  102. ;  2. Change END to STOP within SWITCH to work around C-Kermit bug.
  103. ; Version 3.0: September 1997, for C-Kermit 7.0 Beta.
  104. ;  1. Change STOP back to END because bug is fixed.
  105. ;  2. Added robustness.
  106. ; Version 4.0: August 1998:
  107. ;  1. Additional robustness - requires 2K command buffer.
  108. ;  2. Diagnostics.
  109. ; Version 5.0: May 2000, for C-Kermit 7.0:
  110. ;  1. Improved portability, parameterization, and error checking.
  111. ; Version 6.0: Mar 2003, for C-Kermit 8.0:
  112. ;  1. More debugging.
  113. ;  2. Accept environment variables as well as command-line args.
  114. ;  3. Parameterize output pacing -- it can make all the difference.
  115. ;
  116. if \m(TESTING) {         ; Set up debugging messages and logs
  117.     set quiet off
  118.     echo TESTING=\m(TESTING)
  119.     echo COMMAND FILE: \fpathname(\v(cmdfile))
  120.     echo EXEDIR: \v(exedir) ; where Kermit is running from
  121.     set dial display on          ; Watch computer/modem dialog
  122.     set command byte 7           ; Filter out the 8th bit when debugging
  123.     if > \m(TESTING) 1 {         ; serious debugging
  124.         log session              ; Creates session.log in current directory
  125.         log debug                ; Creates debug.log in current directory
  126.         set input echo on        ; Watch input (can mess up your screen)
  127.     }
  128. }
  129.  
  130. ; APSETUP - Set up dialing device and modem.
  131.  
  132. define APSETUP {                 ; Set up the calling parameters.
  133.     set exit warning off         ; No warnings on exit.
  134.     if eq \v(system) WIN32 {     ; In Windows use the default TAPI device.
  135.         set port tapi          
  136.         if fail end 1
  137.     } else {                     ; Elsewhere...
  138.         set modem type \m(MODEM) ; Specify the modem type.
  139.         if fail end 1 Bad modem type: "\m(MODEM)"
  140.         if eq "\v(modem)" "multitech" {
  141.             set modem command init ATQ0E1X4&E8&Q0&S0$BA0$MB\m(speed)\13
  142.             set modem command error-correction off AT&E0\13
  143.         }
  144.         set line \m(LINE)        ; Specify dialout port.
  145.     if fail end 1 Can't SET LINE to "\m(LINE)"
  146.     }
  147.     if \m(TESTING) {
  148.         echo "PHONE:   \m(APAGEPHONE)"
  149.         echo "PORT:    \m(LINE)"
  150.         echo "MODEM:   \m(MODEM)"
  151.         echo "SPEED:   \m(SPEED)"
  152.         echo "PARITY:  \m(PARITY)"
  153.         echo "FLOW:    \m(FLOW)"
  154.         echo "PACING:  \m(PACING)"
  155.     }
  156.     set term byte 7              ; Ignore the 8th bit - TAP is ASCII only
  157.     set input echo off           ; (this can confuse the terminal)
  158.     set speed \m(SPEED)          ; Speed required by paging service
  159.     if fail stop 1 Bad SPEED - "\m(SPEED)"
  160.     set parity \m(PARITY)        ; Parity required by paging service
  161.     if fail stop 1 Bad PARITY - "\m(PARITY)"
  162.     set flow \m(FLOW)            ; Flow control (usually NONE)
  163.     if fail stop 1 Bad FLOW-CONTROL - "\m(FLOW)"
  164.     set dial interval 1          ; 1 sec between redial attempts
  165.     set dial retries \m(REDIALS)
  166.     if fail stop 1 Bad DIAL RETRIES - "\m(REDIALS)"
  167.     if \m(TESTING) show comm     ; Let's see the modem signals
  168. }
  169.  
  170. ; APAGE - Make the call and send the page.
  171. ;   \%1 = Pager ID (PIN)
  172. ;   \%2 = Message (single line)
  173. ;
  174. define APAGE {                   ; Call the paging service and send a page.
  175.     local rc t                   ; rc = Return code for this macro
  176.     if < \v(argc) 2 end 1 Pager ID required
  177.     if \m(TESTING) {
  178.         asg t \v(ntime)
  179.         echo
  180.         echo "PIN:     \%1"
  181.         echo "MESSAGE: \%2"
  182.     }
  183.     do apsetup                   ; Make the call.
  184.     if fail end 1                ; Quit if the call failed.
  185.     set modem error-correction off  ; Turn OFF error correction
  186.     set modem data-compression off  ; and data compression
  187.     set modem speed-matching on     ; and speed-buffering.
  188.     if def PACING {                 ; Intercharacter pacing for OUTPUT.
  189.         if numeric \m(PACING) set output pacing \m(PACING)
  190.     }
  191.     dial \m(APAGEPHONE)          ; Call the pager service
  192.     asg rc \v(status)             ; Save DIAL status
  193.     if = \m(rc) 0 {              ; If the call is answered
  194.         tapmsg \%1 {\%2}         ; Send the page
  195.         asg rc \v(status)        ; Save the result
  196.     }
  197.     set dial display off         ; Don't display garbage burst on hangup
  198.     if k-95 set line             ; Release the port
  199.     ;; if c-kermit set line
  200.  
  201. ; In UNIX or VMS: Uncomment previous command if running this script in a 
  202. ; loop to send multiple pages AND job has a controlling terminal (if there
  203. ; is no controlling terminal, e.g. under Cron or Sendmail, the "set line"
  204. ; command can fail.
  205.  
  206.     if \m(TESTING) echo PORT RELEASED
  207.     if not quiet {
  208.     if = \m(rc) 0 {
  209.         echo PAGE OK
  210.     } else {
  211.         echo PAGE FAILED
  212.     }
  213.     }
  214.     if \m(TESTING) {
  215.         echo TIME \feval(\v(ntime) - \m(t))
  216.         echo
  217.     }
  218.     ;
  219.     ; For shared in-out ports you might need to reset the port's original
  220.     ; speed here and maybe also send it some kind of reset command like ATZ.
  221.     ;
  222.     set modem type \v(modem)     ; Restore default modem settings
  223.     end \m(rc)                   ; Return
  224. }
  225.  
  226. dcl \&m[] = "ACK" "NAK" "ID=" "FORCED DISCONNECT"
  227. def \&m[0] "TIMEOUT"
  228.  
  229. ; TAPMSG Telocator Alphanumeric Protocol execution.  Call with:
  230. ;   \%1 = Pager ID (PIN)
  231. ;   \%2 = Message (single line)
  232. ;  Assumes connection is made.  Uses TAP to send PIN and 1-line message.
  233. ;
  234. def TAPMSG {
  235.     local \%i \%m \%s blk        ; Local variables
  236.     set case on                         ; INPUT is case sensitive
  237.     asg \%m \2\%1\13\%2\13\3        ; <STX>ID<CR>msg<CR><ETX>
  238.     asg \%s \fchecksum(\%m)        ; Get checksum and make block
  239.     asg blk \%m\fchar(\fmod(\%s/256,16)+48)-
  240. \fchar(\fmod(\%s/16,16)+48)-
  241. \fchar(\fmod(\%s,16)+48)\13        ; Checksummed TAP block
  242.     if \m(TESTING) { echo, echo WAITING FOR ID= PROMPT... }
  243.     msleep 500                          ; Wait half a sec...
  244.     for \%i 1 6 1 {            ; Try six times to get prompt
  245.     out \13                ; Send <CR>
  246.         if fail end 1 OUTPUT I/O ERROR
  247.         if \m(TESTING) echo SENT <CR>(\%i)
  248.     input 2 {ID=}                   ; Look for "ID=" prompt
  249.     if success break
  250.         if not open connection end 1 FATAL - Connection Lost
  251.         if > \v(instatus) 2 end 1 FATAL INPUT ERROR
  252.     }
  253.     if > \%i 6 end 1 {FAILED: NO "ID=" PROMPT (TRIES=\feval(\%i-1))}
  254.     if \m(TESTING) echo {RCVD "ID="}
  255.  
  256.     for \%i 1 8 1 {            ; Send <ESC>PG1, get <ACK>
  257.     msleep 500                      ; First wait half a second
  258.     output \27PG1\13
  259.         if \m(TESTING) echo SENT <ESC>PG1(\%i)
  260.     minput 3 {\6\13} {\21\13} {ID=} {\27\4\13}
  261.         if \m(TESTING) echo RCVD \&m[\v(minput)]
  262.     switch \v(minput) {
  263.       :0, continue            ; Timeout
  264.       :1, break            ; <ACK>
  265.       :2, continue            ; <NAK>
  266.       :3, continue                  ; ID= again
  267.       :4, end 1 FORCED DISCONNECT    ; Forced disconnect - fatal
  268.     }
  269.     break
  270.     }
  271.     if > \%i 8 end 1
  272.     def \&m[3] "FORCED DISCONNECT"
  273.     def \&m[4] "ERROR INDICATION"
  274.     in 10 \27[p\13            ; Wait for go-ahead
  275.     if fail end 1 NO GO-AHEAD        ; Didn't get it
  276.     for \%i 1 8 1 {            ; Try eight times
  277.     msleep 500
  278.     output \m(blk)            ; Send block
  279.         if \m(TESTING) echo SENT MESSAGE (\%i)
  280.     minput 8 {\6\13} {\21\13} {\13\27\4\13} {\30\13}
  281.         if \m(TESTING) echo RCVD \&m[\v(minput)]
  282.     switch \v(minput) {             ; Get response
  283.       :0, continue                  ; Timeout
  284.       :1, break                     ; <ACK> - success
  285.       :2, continue                  ; <NAK> - transmission error
  286.       :3, end 1 FORCED DISCONNECT
  287.       :4, echo "ERROR - RETRYING", continue
  288.     }
  289.     out \4\13                       ; Sign off with <EOT>
  290.         if \m(TESTING) echo SENT EOT
  291.     in 8 \27\4\13                   ; Get <ESC><EOT> back
  292.         if \m(TESTING) {
  293.             if fail {
  294.                 echo "TIMEOUT (IGNORED)"
  295.             } else {
  296.                 echo "RCVD ACK"
  297.             }
  298.         }
  299.     break
  300.     }
  301.     if > \%i 8 end 1 Too many retries
  302. }
  303.  
  304. ; If invoked as a "kerbang" script execute it now.
  305. ; Otherwise TAKE'ing this file simply defines the macros so you can
  306. ; use them interactively, e.g. 'apage 7654321 "this is a message"'.
  307. ;
  308. if kerbang {
  309.     if not def \%1 asg \%1 \$(PIN)
  310.     if not def \%2 asg \%1 \$(MESSAGE)
  311.     if ( not def \%1 || not def \%2 ) exit 1 {usage: \%0 <pagerid> <message>}
  312.     apage {\%1} {\%2}
  313.     exit \v(status)
  314. } else if > \v(argc) 1 {
  315.     apage {\%1} {\%2}
  316.     exit \v(status)
  317. } else {
  318.     echo APAGE <pin> "<message>" (defined)
  319. }
  320.  
  321. ; (End)
  322.