]>
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 | ||
2c973348 | 37 | routing_db_from_ppp ${zone} ipv4 |
ff8ec5ef | 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 | ||
2c973348 MT |
54 | routing_db_set ${zone} ipv4 active 1 |
55 | routing_update ${zone} ipv4 | |
ff8ec5ef | 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 | ||
201b7dff MT |
72 | # Remove the information about this zone from the routing database |
73 | # and update the routing table. | |
74 | routing_db_remove ${zone} ipv4 | |
75 | routing_update ${zone} ipv4 | |
76 | ||
77 | # Save accounting information | |
78 | ppp_accounting ${zone} | |
79 | ||
80 | # Emit interface-up event | |
81 | event_interface_down ${zone} | |
82 | ||
83 | return ${EXIT_OK} | |
84 | } | |
85 | ||
86 | function ppp_common_ipv6_up() { | |
87 | local zone=${1} | |
88 | shift | |
89 | ||
90 | if ! zone_exists ${zone}; then | |
91 | error "Zone '${zone}' does not exist." | |
92 | return ${EXIT_ERROR} | |
93 | fi | |
94 | ||
95 | # Add information about this zone to the routing database. | |
96 | routing_db_from_ppp ${zone} ipv6 | |
97 | ||
98 | routing_db_set ${zone} ipv6 active 1 | |
99 | routing_update ${zone} ipv6 | |
100 | ||
101 | # Emit interface-up event | |
102 | event_interface_up ${zone} | |
103 | ||
104 | return ${EXIT_OK} | |
105 | } | |
106 | ||
107 | function ppp_common_ipv6_down() { | |
108 | local zone=${1} | |
109 | shift | |
110 | ||
111 | if ! zone_exists ${zone}; then | |
112 | error "Zone '${zone}' does not exist." | |
113 | return ${EXIT_ERROR} | |
114 | fi | |
115 | ||
116 | # Remove the information about this zone from the routing database | |
117 | # and update the routing table. | |
118 | routing_db_remove ${zone} ipv6 | |
119 | routing_update ${zone} ipv6 | |
120 | ||
059469a8 MT |
121 | # Save accounting information |
122 | ppp_accounting ${zone} | |
123 | ||
c7ad7801 MT |
124 | # Emit interface-up event |
125 | event_interface_down ${zone} | |
126 | ||
127 | return ${EXIT_OK} | |
128 | } | |
129 | ||
5b20e43a MT |
130 | function ppp_secret() { |
131 | local USER=${1} | |
132 | local SECRET=${2} | |
133 | local a | |
134 | local secret | |
135 | local user | |
136 | ||
137 | # Updateing secret file | |
138 | > ${PPP_SECRETS}.tmp | |
139 | while read user a secret; do | |
140 | if [ "'${USER}'" != "${user}" ]; then | |
141 | echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp | |
142 | fi | |
143 | done < ${PPP_SECRETS} | |
144 | echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp | |
145 | cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS} | |
146 | rm -f ${PPP_SECRETS}.tmp | |
147 | } | |
148 | ||
059469a8 MT |
149 | function ppp_accounting() { |
150 | local zone=${1} | |
151 | shift | |
5b20e43a | 152 | |
059469a8 MT |
153 | db_ppp_update ${zone} --duration="${CONNECT_TIME}" \ |
154 | --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}" | |
5b20e43a | 155 | } |
711ffac1 MT |
156 | |
157 | function pppd_exec() { | |
711ffac1 MT |
158 | log DEBUG "Running pppd with parameters '$@'." |
159 | ||
160 | pppd $@ > /dev/null | |
161 | } |