]> git.ipfire.org Git - people/ms/network.git/blob - functions.ppp
Update paths to match a modern filesystem layout.
[people/ms/network.git] / functions.ppp
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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 function ppp_init() {
23 mkdir -p /var/run/ppp 2>/dev/null
24 }
25
26 init_register ppp_init
27
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
37 routing_db_from_ppp ${zone} ipv4
38
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
54 routing_db_set ${zone} ipv4 active 1
55 routing_update ${zone} ipv4
56
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
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
121 # Save accounting information
122 ppp_accounting ${zone}
123
124 # Emit interface-up event
125 event_interface_down ${zone}
126
127 return ${EXIT_OK}
128 }
129
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
149 function ppp_accounting() {
150 local zone=${1}
151 shift
152
153 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
154 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
155 }
156
157 function pppd_exec() {
158 log DEBUG "Running pppd with parameters '$@'."
159
160 pppd $@ > /dev/null
161 }