~vcs-imports/ipfire/ipfire-2.x

« back to all changes in this revision

Viewing changes to src/initscripts/system/connectd

  • Committer: Daniel Glanzmann
  • Date: 2008-09-26 17:05:28 UTC
  • mto: (1394.1.12)
  • mto: This revision was merged to the branch mainline in revision 1401.
  • Revision ID: git-v1:19ac4d1b6e234e1391b3d406381e3b74e92c40dd
added new useragent thunderbird

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
###############################################################################
3
 
#                                                                             #
4
 
# IPFire.org - A linux based firewall                                         #
5
 
# Copyright (C) 2007-2022  IPFire Team  <info@ipfire.org>                     #
6
 
#                                                                             #
7
 
# This program is free software: you can redistribute it and/or modify        #
8
 
# it under the terms of the GNU General Public License as published by        #
9
 
# the Free Software Foundation, either version 3 of the License, or           #
10
 
# (at your option) any later version.                                         #
11
 
#                                                                             #
12
 
# This program is distributed in the hope that it will be useful,             #
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
15
 
# GNU General Public License for more details.                                #
16
 
#                                                                             #
17
 
# You should have received a copy of the GNU General Public License           #
18
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
19
 
#                                                                             #
20
 
###############################################################################
21
 
 
22
 
. /etc/sysconfig/rc
23
 
. ${rc_functions}
24
 
 
25
 
# Stop if nothing is configured
26
 
if [ ! -s "/var/ipfire/ppp/settings" ];then
27
 
 exit 0
28
 
fi
29
 
 
30
 
eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
31
 
 
32
 
MAX=160
33
 
ATTEMPTS=0
34
 
COUNT=0
35
 
if [ ! $HOLDOFF ]; then
36
 
        HOLDOFF=30
37
 
fi
38
 
 
39
 
if [ "$RECONNECTION" = "dialondemand" ]; then
40
 
        exit 0
41
 
fi
42
 
 
43
 
msg_log () {
44
 
        logger -t $(basename $0)[$$] $*
45
 
}
46
 
 
47
 
msg_log "Connectd ($1) started with PID $$"
48
 
 
49
 
 
50
 
if [ -s "/var/ipfire/red/keepconnected" ]; then
51
 
        ATTEMPTS=$(cat /var/ipfire/red/keepconnected)
52
 
else
53
 
        echo "0" > /var/ipfire/red/keepconnected
54
 
fi
55
 
 
56
 
case "$1" in
57
 
  start)
58
 
        boot_mesg "Starting connection daemon..."
59
 
        echo_ok
60
 
 
61
 
                while [ "$COUNT" -lt "$MAX" ]; do
62
 
                        if [ ! -e "/var/ipfire/red/keepconnected" ]; then
63
 
                                # User pressed disconnect in gui
64
 
                                msg_log "Stopping by user request. Exiting."
65
 
                                /etc/rc.d/init.d/network stop red
66
 
                                exit 0
67
 
                        fi
68
 
                        if [ -e "/var/ipfire/red/active" ]; then
69
 
                                # Successfully connected in time
70
 
                                echo "0" > /var/ipfire/red/keepconnected
71
 
                                msg_log "System is online. Exiting."; exit 0
72
 
                        fi
73
 
                        if ( ! ps ax | grep -q [p]ppd ); then
74
 
                                msg_log "No pppd is running. Trying reconnect."
75
 
                                break # because pppd died
76
 
                        fi
77
 
                        sleep 5
78
 
                        (( COUNT+=1 ))
79
 
                done
80
 
 
81
 
                /etc/rc.d/init.d/network stop red
82
 
 
83
 
                (( ATTEMPTS+=1 ))
84
 
                msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}"
85
 
                if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then
86
 
                        echo "0" > /var/ipfire/red/keepconnected
87
 
                        if [ "$BACKUPPROFILE" != '' ]; then
88
 
                                rm -f /var/ipfire/ppp/settings
89
 
                                cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings
90
 
                                msg_log "Switched to backup profile ${BACKUPPROFILE}"
91
 
                                # to be shure the right secrets are used
92
 
        eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings-${BACKUPPROFILE})
93
 
        echo "'$USERNAME' * '$PASSWORD'" > /var/ipfire/ppp/secrets
94
 
                        else
95
 
                                msg_log "No backup profile given. Exiting."
96
 
                                exit 0
97
 
                        fi
98
 
                else
99
 
                        echo $ATTEMPTS > /var/ipfire/red/keepconnected
100
 
                        sleep ${HOLDOFF}
101
 
                fi
102
 
                /etc/rc.d/init.d/network start red >/dev/tty12 2>&1 </dev/tty12 &
103
 
                ;;
104
 
 
105
 
  reconnect)
106
 
                while ( ps ax | grep -q [p]ppd ); do
107
 
                        msg_log "There is a pppd still running. Waiting 2 seconds for exit."
108
 
                        sleep 2
109
 
                done
110
 
 
111
 
                /etc/rc.d/init.d/network restart red
112
 
                ;;
113
 
 
114
 
  *)
115
 
                echo "Usage: $0 {start|reconnect}"
116
 
                exit 1
117
 
        ;;
118
 
esac
119
 
 
120
 
msg_log "Exiting gracefully connectd with PID $$."