]> git.ipfire.org Git - people/stevee/network.git/blob - functions.ppp
network: Update codebase.
[people/stevee/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_pre_up() {
23 # Load the ppp_generic module if not already done
24 if ! grep -q ^ppp_generic /proc/modules; then
25 modprobe -q ppp_generic
26 fi
27
28 #connection --starting --zone=${zone}
29 }
30
31 function ppp_post_up() {
32 :
33 #connection --up --zone=${zone}
34 }
35
36 function ppp_pre_down() {
37 :
38 # connection --stopping --zone=${zone}
39 }
40
41 function ppp_post_down() {
42 :
43 #connection --down --zone=${zone}
44 }
45
46 function ppp_secret() {
47 local USER=${1}
48 local SECRET=${2}
49 local a
50 local secret
51 local user
52
53 # Updateing secret file
54 > ${PPP_SECRETS}.tmp
55 while read user a secret; do
56 if [ "'${USER}'" != "${user}" ]; then
57 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
58 fi
59 done < ${PPP_SECRETS}
60 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
61 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
62 rm -f ${PPP_SECRETS}.tmp
63 }
64
65 function ppp_stat() {
66 local name=${1}
67 local time=${2}
68 local rcvd=${3}
69 local sent=${4}
70
71 local file="${LOG_DIR}/ppp_${name}.db"
72 if ! [ -e "${file}" ]; then
73 sqlite3 -batch ${file} <<EOF
74 CREATE TABLE connections(date, duration, rcvd, sent);
75 EOF
76 fi
77 ppp_stat_init ${file}
78
79 sqlite3 -batch ${file} <<EOF
80 INSERT INTO connections(date, duration, rcvd, sent) VALUES('$(date -u '+%s')', '${time}', '${rcvd}', '${sent}');
81 EOF
82 }
83
84 function ppp_linkname_get() {
85 local config=${1}
86 (
87 . ${config}
88 echo "${NAME}"
89 )
90 }
91
92 function red_defaultroute_update() {
93 local command="ip route replace default"
94
95 local uplink
96 for uplink in ${RED_RUN}/*; do
97 [ -d "${uplink}" ] || continue
98
99 # Skip if no gateway given
100 [ -e "${uplink}/gateway" ] || continue
101
102 command="${command} nexthop via $(<${uplink}/gateway)"
103 if [ -e "${uplink}/weight" ]; then
104 command="${command} weight $(<${uplink}/weight)"
105 fi
106 done
107 $command
108 #ip route flush cache
109 }
110
111 function red_dns_update() {
112 : # XXX todo
113 }