]>
Commit | Line | Data |
---|---|---|
5b20e43a MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
1848564d | 5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # |
5b20e43a MT |
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 | ||
711ffac1 MT |
22 | function ppp_init() { |
23 | mkdir -p /var/run/ppp 2>/dev/null | |
24 | } | |
25 | ||
b8357295 | 26 | init_register ppp_init |
a63c45b9 | 27 | |
c7ad7801 MT |
28 | function ppp_common_ip_pre_up() { |
29 | local zone=${1} | |
30 | shift | |
31 | ||
32 | if ! zone_exists ${zone}; then | |
33 | error "Zone '${zone}' does not exist." | |
34 | return ${EXIT_ERROR} | |
35 | fi | |
36 | ||
ff8ec5ef MT |
37 | red_db_from_ppp ${zone} |
38 | ||
c7ad7801 MT |
39 | # Request firewall reload |
40 | event_firewall_reload | |
41 | ||
42 | return ${EXIT_OK} | |
43 | } | |
44 | ||
45 | function ppp_common_ip_up() { | |
46 | local zone=${1} | |
47 | shift | |
48 | ||
49 | if ! zone_exists ${zone}; then | |
50 | error "Zone '${zone}' does not exist." | |
51 | return ${EXIT_ERROR} | |
52 | fi | |
53 | ||
ff8ec5ef MT |
54 | red_db_set ${zone} active 1 |
55 | red_routing_update ${zone} | |
56 | ||
c7ad7801 MT |
57 | # Emit interface-up event |
58 | event_interface_up ${zone} | |
59 | ||
60 | return ${EXIT_OK} | |
61 | } | |
62 | ||
63 | function ppp_common_ip_down() { | |
64 | local zone=${1} | |
65 | shift | |
66 | ||
67 | if ! zone_exists ${zone}; then | |
68 | error "Zone '${zone}' does not exist." | |
69 | return ${EXIT_ERROR} | |
70 | fi | |
71 | ||
059469a8 MT |
72 | # Save accounting information |
73 | ppp_accounting ${zone} | |
74 | ||
c7ad7801 MT |
75 | # Emit interface-up event |
76 | event_interface_down ${zone} | |
77 | ||
78 | return ${EXIT_OK} | |
79 | } | |
80 | ||
5b20e43a MT |
81 | function ppp_secret() { |
82 | local USER=${1} | |
83 | local SECRET=${2} | |
84 | local a | |
85 | local secret | |
86 | local user | |
87 | ||
88 | # Updateing secret file | |
89 | > ${PPP_SECRETS}.tmp | |
90 | while read user a secret; do | |
91 | if [ "'${USER}'" != "${user}" ]; then | |
92 | echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp | |
93 | fi | |
94 | done < ${PPP_SECRETS} | |
95 | echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp | |
96 | cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS} | |
97 | rm -f ${PPP_SECRETS}.tmp | |
98 | } | |
99 | ||
059469a8 MT |
100 | function ppp_accounting() { |
101 | local zone=${1} | |
102 | shift | |
5b20e43a | 103 | |
059469a8 MT |
104 | db_ppp_update ${zone} --duration="${CONNECT_TIME}" \ |
105 | --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}" | |
5b20e43a | 106 | } |
711ffac1 MT |
107 | |
108 | function pppd_exec() { | |
711ffac1 MT |
109 | log DEBUG "Running pppd with parameters '$@'." |
110 | ||
111 | pppd $@ > /dev/null | |
112 | } |