steptail.com

Does expecting the unexpected make the unexpected the expected?

User Tools

Site Tools


guides:virtual_modem:script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
guides:virtual_modem:script [2019-02-20 02:11]
omolini
guides:virtual_modem:script [2020-03-05 06:05] (current)
omolini [vmodem.sh]
Line 17: Line 17:
 # VMODEM - Virtual Modem bootstrap # VMODEM - Virtual Modem bootstrap
 # -------------------------------- # --------------------------------
-# Oliver Molini ​2019+# Oliver Molini ​2020 
 +
 +# Billy Stoughton II for bug fixes and contributions
 # #
 # Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License # Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
 # https://​creativecommons.org/​licenses/​by-nc-sa/​4.0/​ # https://​creativecommons.org/​licenses/​by-nc-sa/​4.0/​
-# + 
-# Tested working out of box with the following ​host configurations:​+# Tested working out of box with the following ​client ​configurations:​
 # #
 # o Standard VT100 terminal # o Standard VT100 terminal
Line 32: Line 34:
 # o Microsoft Windows 3.1 # o Microsoft Windows 3.1
 #   - Trumpet Winsock #   - Trumpet Winsock
 +#
 +# o Microsoft Windows 95 OSR 2.5 + DUN 1.4
 +#   - Generic
 +#     - Standard 28800 bps Modem
 # #
 # o Microsoft Windows 98 # o Microsoft Windows 98
Line 43: Line 49:
  
 # Script version # Script version
-vmodver=1.4+vmodver=1.4.3
  
-# CONFIGURATION ​VARIABLES+# CONFIGURATION
 # ----------------------- # -----------------------
- 
 # Variable: serport # Variable: serport
 # serport specifies which local serial device to use. # serport specifies which local serial device to use.
-# For example, ​using "ttyAMA0" will tell the script +# For example, "ttyUSB0" will tell the script ​to use 
-# to use /dev/ttyAMA0 ​for communication. +# to use /dev/ttyUSB0 ​for communication. 
-# +Common valuesttyUSB0 or ttyAMA0
-# Default: +
-# serport=ttyAMA0+
 # #
-serport=ttyAMA0+serport=ttyUSB0
  
 # Variable: baud # Variable: baud
Line 68: Line 71:
 # baud=57600 # baud=57600
 # #
-#baud 9600+#baud=9600
 #baud=38400 #baud=38400
 baud=57600 baud=57600
Line 79: Line 82:
  
 # Variable: resultverbose # Variable: resultverbose
-# Controls default ​behaviour ​when printing result +# Controls default ​behavior ​when printing ​Hayes result 
-# codes. When 0, will print result codes in numerical +# codes. ​ 
-form. When 1, will print result codes in english.+When 0, prints ​result codes in numerical form. (eg. 0) 
 +When 1, prints ​result codes in english. ​(eg. CONNECT)
 # Default is 1. # Default is 1.
 resultverbose=1 resultverbose=1
 +
 +# Variable: TERM
 +# Tells the script and environment which type of terminal to emulate.
 +# It is only useful to change this, if you're using a serial ​
 +# terminal to connect to this script. If you're connecting form a ANSI 
 +# cabable machine such as DOS, you may want to use TERM="​ansi"​
 +#
 +TERM="​vt100"​
  
 # EXPORT SHELL VARS # EXPORT SHELL VARS
Line 89: Line 101:
 export serport export serport
 export baud export baud
 +export TERM
  
 # FUNCTIONS # FUNCTIONS
Line 144: Line 157:
  
     #     #
-    # --- MODEM EMULATION ---+    # --- HAYES EMULATION ---
     #     #
     if [[ $cmd == AT* ]]; then     if [[ $cmd == AT* ]]; then
Line 213: Line 226:
         number=`echo $seq |tr -dc '​0-9'​`         number=`echo $seq |tr -dc '​0-9'​`
         if [ ! -z "​$number"​ ]; then         if [ ! -z "​$number"​ ]; then
-          if [[ $resultverbose == 1 ]]; then sendtty "​RINGING";​ fi+          if [[ $resultverbose == 1 ]]; then sendtty "​RINGING"​; sleep 1; fi
           if [ -f "​$number.sh"​ ]; then           if [ -f "​$number.sh"​ ]; then
             if [[ $resultverbose == 1 ]]; then sendtty "​CONNECT $baud";​ else sendtty "​1";​ fi             if [[ $resultverbose == 1 ]]; then sendtty "​CONNECT $baud";​ else sendtty "​1";​ fi
-            # Close serial port 
-            exec 99>&​- 
             # Execute dialed script             # Execute dialed script
-            /sbin/getty -8 -L $serport $baud vt100 -n -l "​./​$number.sh"​+            /sbin/getty -8 -L $serport $baud $TERM -n -l "​./​$number.sh"​
             # Reset serial settings             # Reset serial settings
             ttyinit             ttyinit
-            # Reopen serial port 
-            exec 99<>/​dev/​$serport 
             result=3             result=3
           else           else
Line 274: Line 283:
     if [[ $cmd == LOGIN ]]; then     if [[ $cmd == LOGIN ]]; then
       exec 99>&​-       exec 99>&​-
-      /sbin/getty -8 -L ttyAMA0 ​$baud vt100+      /sbin/getty -8 -L $serport ​$baud $TERM
       ttyinit       ttyinit
       exec 99<>/​dev/​$serport       exec 99<>/​dev/​$serport
Line 300: Line 309:
  
 ===== ppp.sh ===== ===== ppp.sh =====
-This script will initiate a PPP session but will not wait around for user input. ​This is in place only to make Trumpet Winsock 3.0 think that it's logging on, and make it proceed when it receives the expected printouts. The built-in dial-up connection in Windows 95 and later operating systems ​by default do not expect a login prompt unless specifically told to do so.+This script will initiate a PPP session ​and will present a fake login shell, ​but will not wait around for user input. ​The fake login shell is in place for compatibility with Trumpet Winsock 3.0, as it by default expects one, so we're fooling it to make it think that it's logging on. It will then proceed when it receives the expected printouts. The built-in dial-up connection in Windows 95/​98/​Me ​by default do not expect a login prompt unless specifically told to do so.
  
-Specifically when Trumpet Winsock is in PPP mode, by default it will expect the following output after dialing the ISP's number and establishing a connection:  +When Trumpet Winsock is in PPP mode, by default it will expect the following output after dialing the ISP's number and establishing a connection:  
-  * A username prompt, matched by the text "​sername:"​ +  * A username prompt, matched by Trumpet with the text "​sername:"​ 
-  * A password prompt, matched by the text "​ssword:"​ +  * A password prompt, matched by Trumpet with the text "​ssword:"​ 
-  * A command prompt, matched by the text ">"​+  * A command prompt, matched by Trumpet with the character ​">"​
  
 This script has been tested with the default installation of Trumpet Winsock 3.0 revision D with PPP mode switched on. This script has also been tested with the default dial-up utility of Windows 95 and Windows 98 with PPP enabled. ​ This script has been tested with the default installation of Trumpet Winsock 3.0 revision D with PPP mode switched on. This script has also been tested with the default dial-up utility of Windows 95 and Windows 98 with PPP enabled. ​
  
-I've added a parameter to send an LCP echo to the client to test if the connection is still up. If the connection has abruptly been closed, pppd will know this by not receiving an echo reply, and will exit and relinquish control back to the vmodem.sh script. The only reason the timeout is in there, is because it seems like Trumpet Winsock 3.0 doesn'​t know how to tell pppd to terminate a PPP session from within a PPP session, and it will just attempt to hang up the call. As a result, pppd daemon will be left running indefinitely. This is obviously not preferred, so LCP echo is added to let pppd know when the link has been cut. If you can think of better ways to accomplish this check, feel free to send tips on how to improve the script.+I've added a parameter to send an LCP echo to the client to test if the connection is still up. If the connection has abruptly been closed, pppd will know this by not receiving an echo reply, and will exit and relinquish control back to the vmodem.sh script. The only reason the timeout is in there, is because it seems like Trumpet Winsock 3.0 doesn'​t know how to tell pppd to terminate a PPP session from within a PPP session, and it will just hang up the call. As a result, pppd daemon will be left running indefinitely ​and won't ever give control back to vmodem. This is obviously not preferred, so LCP echo is added to let pppd know when the link has been cut. If you can think of better ways to accomplish this check, feel free to send tips on how to improve the script.
  
 <code bash ppp.sh> <code bash ppp.sh>
 #!/bin/bash #!/bin/bash
 # RUN PPPD DAEMON # RUN PPPD DAEMON
 +#
 +# Oliver Molini 2019
 +
 +# Billy Stoughton II for bug fixes and contributions
 +#
 +# Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
 +# https://​creativecommons.org/​licenses/​by-nc-sa/​4.0/​
 # #
 # Note on PPPD settings: # Note on PPPD settings:
Line 319: Line 335:
 # - Make sure DNS servers are defined (add ms-dns 1.2.3.4 twice) # - Make sure DNS servers are defined (add ms-dns 1.2.3.4 twice)
 # #
 +
 +# Variable: etherp
 +# Specify the ethernet device to use to connect to your network.
 +
 +# Default: ​   etherp=eth0
 +etherp=eth0
 +
 # Variable: lcpidle # Variable: lcpidle
 # Specifies the idle timeout period in seconds for lcp-echo-interval. # Specifies the idle timeout period in seconds for lcp-echo-interval.
Line 325: Line 348:
 # #
 # Default: ​   lcpidle=5 # Default: ​   lcpidle=5
-# 
 lcpidle=5 lcpidle=5
  
Line 346: Line 368:
  
 # Share eth0 over ppp0 # Share eth0 over ppp0
-iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE +iptables -t nat -A POSTROUTING -o $etherp ​-j MASQUERADE 
-iptables -t filter -A FORWARD -i ppp0 -o eth0 -m state --state RELATED,​ESTABLISHED -j ACCEPT +iptables -t filter -A FORWARD -i ppp0 -o $etherp ​-m state --state RELATED,​ESTABLISHED -j ACCEPT 
-iptables -t filter -A FORWARD -i eth0 -o ppp0 -j ACCEPT+iptables -t filter -A FORWARD -i $etherp ​-o ppp0 -j ACCEPT
  
 # Run PPP daemon and establish a link. # Run PPP daemon and establish a link.
Line 370: Line 392:
 echo "​---------------------"​ echo "​---------------------"​
 echo echo
-echo "You have just successfully ​dialled ​this virtual box!"+echo "You have just successfully ​dialed ​this virtual box!"
 echo echo
 echo "​Please enter your name: " echo "​Please enter your name: "
 read username read username
 echo echo
-echo "Welcome ​$username!"​+echo "Hello, ​$username!"​ 
 +echo
 echo "Thank you for visiting! Bye!" echo "Thank you for visiting! Bye!"
 sleep 2 sleep 2
 +</​code>​
 +
 +===== 3.sh =====
 +This example script allows VT100 compatible terminal access to the web by way of running lynx as soon as the number "​3"​ is dialed with "​ATD3"​. It demonstrates how to add a Linux based web browser for simple terminals.
 +
 +<code bash 3.sh>
 +#!/bin/bash
 +#
 +echo "​Terminal type set to $TERM. Running Lynx ..."
 +lynx
 </​code>​ </​code>​
  
guides/virtual_modem/script.1550628697.txt.gz · Last modified: 2019-02-20 02:11 by omolini