]> git.ipfire.org Git - people/arne_f/network.git/blob - functions.ppp
network: Initial support for IPv6 tunnels with aiccu.
[people/arne_f/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 red_db_from_ppp ${zone}
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 red_db_set ${zone} active 1
55 red_routing_update ${zone}
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 # Save accounting information
73 ppp_accounting ${zone}
74
75 # Emit interface-up event
76 event_interface_down ${zone}
77
78 return ${EXIT_OK}
79 }
80
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
100 function ppp_accounting() {
101 local zone=${1}
102 shift
103
104 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
105 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
106 }
107
108 function pppd_exec() {
109 log DEBUG "Running pppd with parameters '$@'."
110
111 pppd $@ > /dev/null
112 }