summaryrefslogtreecommitdiffstats
path: root/obsolete-buildroot/sources/openwrt/patches/ppp/011_scripts_redialer.diff
blob: 657f566c9d5b0ed85032986df130ca87f775201a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
--- ppp-2.4.0b4.orig/scripts/redialer
+++ ppp-2.4.0b4/scripts/redialer
@@ -1,96 +1,69 @@
 #!/bin/sh
-###################################################################
 #
-# These parameters control the attack dialing sequence.
+# A chatscript that will attempt to dial multiple numbers in sequence, until
+# you get connected.
 #
-# Maximum number of attempts to reach the telephone number(s)
-MAX_ATTEMPTS=10
-
-# Delay between each of the attempts. This is a parameter to sleep
-# so use "15s" for 15 seconds, "1m" for 1 minute, etc.
-SLEEP_DELAY=15s
-
-###################################################################
+# To use: edit /etc/peers/provider, and change the connect line to read:
+# connect "/usr/local/bin/redialer"
 #
-# This is a list of telephone numbers. Add new numbers if you wish
-# and see the function 'callall' below for the dial process.
-PHONE1=555-1212
-PHONE2=411
+# See below for configuration.
 
-###################################################################
+# This is a list of chatscripts to use to get connected, and (optional)
+# telephone numbers to call for each of those chatscripts.
 #
-# If you use the ppp-on script, then these are passed to this routine
-# automatically. There is no need to define them here. If not, then
-# you will need to set the values.
-#
-ACCOUNT=my_account_name
-PASSWORD=my_password
+# Note that in the chatscripts, you may use #NUMBER#, this will be replaced
+# with the number it is calling. You might want to use this to only have one
+# chatscript that is used for all numbers, or you might need multiple
+# chatscripts.
 
-###################################################################
-#
-# Function to initialize the modem and ensure that it is in command
-# state. This may not be needed, but it doesn't hurt.
-#
-function initialize
-{
-    chat -v TIMEOUT 3 '' AT 'OK-+++\c-OK'
-    return
-}
+PHONE1=123456789
+CHAT1=/etc/chatscripts/provider
 
-###################################################################
-#
-# Script to dial a telephone
-#
-function callnumber
-{
-chat -v							\
-	ABORT		'\nBUSY\r'			\
-	ABORT		'\nNO ANSWER\r'			\
-	ABORT		'\nRINGING\r\n\r\nRINGING\r'	\
-	''		ATDT$1				\
-	CONNECT		''				\
-	ogin:--ogin:	$ACCOUNT			\
-	assword:	$PASSWORD
-#
-# If the connection was successful then end the whole script with a
-# success.
-#
-    if [ "$?" = "0" ]; then
-       exit 0
-    fi
+PHONE2=912345678
+CHAT2=/etc/chatscripts/provider
 
-    return
-}
+PHONE3=891234567
+CHAT3=/etc/chatscripts/provider
 
-###################################################################
-#
-# Script to dial any telephone number
-#
-function callall
-{
-#   echo "dialing attempt number: $1" >/dev/console
-    callnumber $PHONE1
-#    callnumber $PHONE2
-}
+PHONE4=789123456
+CHAT4=/etc/chatscripts/provider
 
-###################################################################
-#
-# Initialize the modem to ensure that it is in the command state
-#
-initialize
-if [ ! "$?" = "0" ]; then
-   exit 1
-fi
+PHONE5=001234567
+CHAT5=/etc/chatscripts/provider
 
+# How long to sleep between retries:
 #
-# Dial telephone numbers until one answers
-#
+# Note that this is a parameter to sleep so use "15s" for 15 seconds,
+# "1m" for 1 minute, etc
+SLEEP_DELAY=1s
+
+# The code below does the dialing.
+
 attempt=0
 while : ; do
-    attempt=`expr $attempt + 1`
-    callall $attempt
-    if [ "$attempt" = "$MAX_ATTEMPTS" ]; then
-	exit 1
-    fi	
-    sleep "$SLEEP_DELAY"
+        attempt=`expr $attempt + 1`
+        NUMBER=`eval echo '$PHONE'$attempt`
+        CHAT=`eval echo '$CHAT'$attempt`
+        if [ ! "$CHAT" ]; then
+                attempt=0
+        else
+                logger "Dialing attempt number: $attempt"
+                sed s/#NUMBER#/$NUMBER/ $CHAT >/etc/chatscripts/tmpchat
+                /usr/sbin/chat -v -f /etc/chatscripts/tmpchat
+                rm -f /etc/chatscripts/tmpchat
+                case $? in
+                        0) logger Connection established ; exit 0;;
+                        1) logger chat: exit 1, see manpage for details. ; exit 1;;
+                        2) logger chat: exit 2, see manpage for details. ; exit 2;;
+                        3) logger chat: exit 3, see manpage for details. ;;
+                        4) logger Line busy. ;;
+                        5) logger No Carrier. ;;
+                        6) logger A call is coming. Exiting! ; exit 1;;
+                        7) logger No dialtone. ;;
+                        8) logger An error occured. Exiting! ; exit 1;;
+                        *) logger chat: exit $?, see manpage for details. ;;
+                esac
+                logger "Waiting $SLEEP_DELAY seconds before next try."
+                sleep $SLEEP_DELAY
+        fi
 done