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