]> git.ipfire.org Git - people/ms/network.git/blob - functions.ppp
network: Remove some unused functions.
[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_common_ip_pre_up() {
23 local zone=${1}
24 shift
25
26 if ! zone_exists ${zone}; then
27 error "Zone '${zone}' does not exist."
28 return ${EXIT_ERROR}
29 fi
30
31 # Request firewall reload
32 event_firewall_reload
33
34 return ${EXIT_OK}
35 }
36
37 function ppp_common_ip_up() {
38 local zone=${1}
39 shift
40
41 if ! zone_exists ${zone}; then
42 error "Zone '${zone}' does not exist."
43 return ${EXIT_ERROR}
44 fi
45
46 # Emit interface-up event
47 event_interface_up ${zone}
48
49 return ${EXIT_OK}
50 }
51
52 function ppp_common_ip_down() {
53 local zone=${1}
54 shift
55
56 if ! zone_exists ${zone}; then
57 error "Zone '${zone}' does not exist."
58 return ${EXIT_ERROR}
59 fi
60
61 # Emit interface-up event
62 event_interface_down ${zone}
63
64 return ${EXIT_OK}
65 }
66
67 function ppp_secret() {
68 local USER=${1}
69 local SECRET=${2}
70 local a
71 local secret
72 local user
73
74 # Updateing secret file
75 > ${PPP_SECRETS}.tmp
76 while read user a secret; do
77 if [ "'${USER}'" != "${user}" ]; then
78 echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp
79 fi
80 done < ${PPP_SECRETS}
81 echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp
82 cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS}
83 rm -f ${PPP_SECRETS}.tmp
84 }
85
86 function ppp_stat() {
87 local name=${1}
88 local time=${2}
89 local rcvd=${3}
90 local sent=${4}
91
92 local file="${LOG_DIR}/ppp_${name}.db"
93 if ! [ -e "${file}" ]; then
94 sqlite3 -batch ${file} <<EOF
95 CREATE TABLE connections(date, duration, rcvd, sent);
96 EOF
97 fi
98 ppp_stat_init ${file}
99
100 sqlite3 -batch ${file} <<EOF
101 INSERT INTO connections(date, duration, rcvd, sent) VALUES('$(date -u '+%s')', '${time}', '${rcvd}', '${sent}');
102 EOF
103 }
104
105 function ppp_linkname_get() {
106 local config=${1}
107 (
108 . ${config}
109 echo "${NAME}"
110 )
111 }
112
113 function red_defaultroute_update() {
114 local command="ip route replace default"
115
116 local uplink
117 for uplink in ${RED_RUN}/*; do
118 [ -d "${uplink}" ] || continue
119
120 # Skip if no gateway given
121 [ -e "${uplink}/gateway" ] || continue
122
123 command="${command} nexthop via $(<${uplink}/gateway)"
124 if [ -e "${uplink}/weight" ]; then
125 command="${command} weight $(<${uplink}/weight)"
126 fi
127 done
128 $command
129 #ip route flush cache
130 }
131
132 function red_dns_update() {
133 : # XXX todo
134 }