]>
Commit | Line | Data |
---|---|---|
5b20e43a MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
1848564d | 5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # |
5b20e43a MT |
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 | ||
5b20e43a | 22 | function ppp_pre_up() { |
0dbe3f01 | 23 | : |
1848564d | 24 | #connection --starting --zone=${zone} |
5b20e43a MT |
25 | } |
26 | ||
27 | function ppp_post_up() { | |
1848564d MT |
28 | : |
29 | #connection --up --zone=${zone} | |
5b20e43a MT |
30 | } |
31 | ||
32 | function ppp_pre_down() { | |
1848564d MT |
33 | : |
34 | # connection --stopping --zone=${zone} | |
5b20e43a MT |
35 | } |
36 | ||
37 | function ppp_post_down() { | |
1848564d MT |
38 | : |
39 | #connection --down --zone=${zone} | |
5b20e43a MT |
40 | } |
41 | ||
c7ad7801 MT |
42 | function ppp_common_ip_pre_up() { |
43 | local zone=${1} | |
44 | shift | |
45 | ||
46 | if ! zone_exists ${zone}; then | |
47 | error "Zone '${zone}' does not exist." | |
48 | return ${EXIT_ERROR} | |
49 | fi | |
50 | ||
51 | # Request firewall reload | |
52 | event_firewall_reload | |
53 | ||
54 | return ${EXIT_OK} | |
55 | } | |
56 | ||
57 | function ppp_common_ip_up() { | |
58 | local zone=${1} | |
59 | shift | |
60 | ||
61 | if ! zone_exists ${zone}; then | |
62 | error "Zone '${zone}' does not exist." | |
63 | return ${EXIT_ERROR} | |
64 | fi | |
65 | ||
66 | # Emit interface-up event | |
67 | event_interface_up ${zone} | |
68 | ||
69 | return ${EXIT_OK} | |
70 | } | |
71 | ||
72 | function ppp_common_ip_down() { | |
73 | local zone=${1} | |
74 | shift | |
75 | ||
76 | if ! zone_exists ${zone}; then | |
77 | error "Zone '${zone}' does not exist." | |
78 | return ${EXIT_ERROR} | |
79 | fi | |
80 | ||
81 | # Emit interface-up event | |
82 | event_interface_down ${zone} | |
83 | ||
84 | return ${EXIT_OK} | |
85 | } | |
86 | ||
5b20e43a MT |
87 | function ppp_secret() { |
88 | local USER=${1} | |
89 | local SECRET=${2} | |
90 | local a | |
91 | local secret | |
92 | local user | |
93 | ||
94 | # Updateing secret file | |
95 | > ${PPP_SECRETS}.tmp | |
96 | while read user a secret; do | |
97 | if [ "'${USER}'" != "${user}" ]; then | |
98 | echo "${user} ${a} ${secret}" >> ${PPP_SECRETS}.tmp | |
99 | fi | |
100 | done < ${PPP_SECRETS} | |
101 | echo "'${USER}' * '${SECRET}'" >> ${PPP_SECRETS}.tmp | |
102 | cat ${PPP_SECRETS}.tmp > ${PPP_SECRETS} | |
103 | rm -f ${PPP_SECRETS}.tmp | |
104 | } | |
105 | ||
106 | function ppp_stat() { | |
107 | local name=${1} | |
108 | local time=${2} | |
109 | local rcvd=${3} | |
110 | local sent=${4} | |
111 | ||
112 | local file="${LOG_DIR}/ppp_${name}.db" | |
113 | if ! [ -e "${file}" ]; then | |
114 | sqlite3 -batch ${file} <<EOF | |
115 | CREATE TABLE connections(date, duration, rcvd, sent); | |
116 | EOF | |
117 | fi | |
118 | ppp_stat_init ${file} | |
119 | ||
120 | sqlite3 -batch ${file} <<EOF | |
121 | INSERT INTO connections(date, duration, rcvd, sent) VALUES('$(date -u '+%s')', '${time}', '${rcvd}', '${sent}'); | |
122 | EOF | |
123 | } | |
124 | ||
125 | function ppp_linkname_get() { | |
126 | local config=${1} | |
127 | ( | |
128 | . ${config} | |
1848564d | 129 | echo "${NAME}" |
5b20e43a MT |
130 | ) |
131 | } | |
132 | ||
133 | function red_defaultroute_update() { | |
134 | local command="ip route replace default" | |
135 | ||
1848564d | 136 | local uplink |
5b20e43a MT |
137 | for uplink in ${RED_RUN}/*; do |
138 | [ -d "${uplink}" ] || continue | |
139 | ||
140 | # Skip if no gateway given | |
141 | [ -e "${uplink}/gateway" ] || continue | |
142 | ||
143 | command="${command} nexthop via $(<${uplink}/gateway)" | |
144 | if [ -e "${uplink}/weight" ]; then | |
145 | command="${command} weight $(<${uplink}/weight)" | |
146 | fi | |
147 | done | |
148 | $command | |
1848564d | 149 | #ip route flush cache |
5b20e43a MT |
150 | } |
151 | ||
152 | function red_dns_update() { | |
153 | : # XXX todo | |
154 | } |