]>
Commit | Line | Data |
---|---|---|
ff8ec5ef MT |
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 red_db_path() { | |
23 | local zone=${1} | |
24 | ||
25 | echo "${RED_DB_DIR}/${zone}" | |
26 | } | |
27 | ||
28 | function red_db_exists() { | |
29 | local zone=${1} | |
30 | ||
31 | [ -d "$(red_db_path ${zone})" ] | |
32 | } | |
33 | ||
34 | function red_db_create() { | |
35 | local zone=${1} | |
36 | ||
37 | red_db_exists ${zone} && return ${EXIT_OK} | |
38 | ||
39 | mkdir -p $(red_db_path ${zone}) | |
40 | } | |
41 | ||
42 | function red_db_remove() { | |
43 | local zone=${1} | |
44 | ||
45 | [ -z "${zone}" ] && return ${EXIT_ERROR} | |
46 | ||
47 | rm -rf ${RED_DB_DIR} | |
48 | } | |
49 | ||
50 | function red_db_set() { | |
51 | local zone=${1} | |
52 | local parameter=${2} | |
53 | shift 2 | |
54 | ||
55 | local value="$@" | |
56 | ||
57 | red_db_create ${zone} | |
58 | ||
59 | echo "${value}" > $(red_db_path ${zone})/${parameter} | |
60 | } | |
61 | ||
62 | function red_db_get() { | |
63 | local zone=${1} | |
64 | local parameter=${2} | |
65 | shift 2 | |
66 | ||
67 | cat $(red_db_path ${zone})/${parameter} 2>/dev/null | |
68 | } | |
69 | ||
70 | function red_db_from_ppp() { | |
71 | local zone=${1} | |
72 | ||
73 | # Save ppp configuration | |
74 | red_db_set ${zone} type "ppp" | |
75 | red_db_set ${zone} local-ip-address ${PPP_IPLOCAL} | |
76 | red_db_set ${zone} remote-ip-address ${PPP_IPREMOTE} | |
77 | ||
78 | red_db_set ${zone} dns ${PPP_DNS1} ${PPP_DNS2} | |
79 | ||
80 | red_db_set ${zone} remote-address ${PPP_MACREMOTE,,} | |
81 | } | |
82 | ||
83 | function red_routing_update() { | |
84 | local zone=${1} | |
85 | ||
86 | local table=${zone} | |
87 | ||
88 | # Create routing table if not exists | |
89 | routing_table_create ${table} | |
90 | ||
91 | local remote_ip_address=$(red_db_get ${zone} remote-ip-address) | |
92 | local local_ip_address=$(red_db_get ${zone} local-ip-address) | |
93 | ||
94 | ip route replace table ${table} default nexthop via ${remote_ip_address} | |
95 | ||
96 | ip rule add from ${local_ip_address} lookup ${table} | |
97 | } |