]> git.ipfire.org Git - people/arne_f/network.git/blob - functions.ppp
network: Magnificent changes on code.
[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 function ppp_common_ip_pre_up() {
27 local zone=${1}
28 shift
29
30 if ! zone_exists ${zone}; then
31 error "Zone '${zone}' does not exist."
32 return ${EXIT_ERROR}
33 fi
34
35 red_db_from_ppp ${zone}
36
37 # Request firewall reload
38 event_firewall_reload
39
40 return ${EXIT_OK}
41 }
42
43 function ppp_common_ip_up() {
44 local zone=${1}
45 shift
46
47 if ! zone_exists ${zone}; then
48 error "Zone '${zone}' does not exist."
49 return ${EXIT_ERROR}
50 fi
51
52 red_db_set ${zone} active 1
53 red_routing_update ${zone}
54
55 # Emit interface-up event
56 event_interface_up ${zone}
57
58 return ${EXIT_OK}
59 }
60
61 function ppp_common_ip_down() {
62 local zone=${1}
63 shift
64
65 if ! zone_exists ${zone}; then
66 error "Zone '${zone}' does not exist."
67 return ${EXIT_ERROR}
68 fi
69
70 # Save accounting information
71 ppp_accounting ${zone}
72
73 # Emit interface-up event
74 event_interface_down ${zone}
75
76 return ${EXIT_OK}
77 }
78
79 function ppp_secret() {
80 local USER=${1}
81 local SECRET=${2}
82 local a
83 local secret
84 local user
85
86 # Updateing secret file
87 > ${PPP_SECRETS}.tmp
88 while read user a secret; do
89 if [ "'${USER}'" != "${user}" ]; then
90 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
91 fi
92 done < ${PPP_SECRETS}
93 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
94 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
95 rm -f ${PPP_SECRETS}.tmp
96 }
97
98 function ppp_accounting() {
99 local zone=${1}
100 shift
101
102 db_ppp_update ${zone} --duration="${CONNECT_TIME}" \
103 --rcvd="${BYTES_RCVD}" --sent="${BYTES_SENT}"
104 }
105
106 function pppd_exec() {
107 ppp_init
108
109 log DEBUG "Running pppd with parameters '$@'."
110
111 pppd $@ > /dev/null
112 }