]>
Commit | Line | Data |
---|---|---|
999d659b 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 | . /usr/lib/network/header-config | |
23 | ||
70c971ce | 24 | HOOK_CONFIG_SETTINGS="HOOK DNS_SERVERS MTU SERVICE_NAME SUBNET MAX_SESSIONS" |
999d659b MT |
25 | |
26 | # Maximum Transmission Unit. | |
27 | MTU=1492 | |
28 | ||
29 | # Service Name. | |
30 | SERVICE_NAME= | |
31 | ||
32 | # A subnet. Addresses from this subnet will be given to the remote hosts. | |
33 | # The net address will be the gateway address for the PPPoE server. | |
34 | SUBNET= | |
35 | ||
f94b87ab MT |
36 | # Defines the max. number of sessions per MAC address. |
37 | # 0 = unlimited. | |
38 | MAX_SESSIONS=0 | |
39 | ||
b6d9bf2b | 40 | hook_check_config_settings() { |
999d659b MT |
41 | assert isset MTU |
42 | assert isset SUBNET | |
f94b87ab | 43 | assert isset MAX_SESSIONS |
70c971ce SS |
44 | |
45 | local server | |
46 | for server in ${DNS_SERVERS}; do | |
47 | assert ipv4_is_valid "${server}" | |
48 | done | |
999d659b MT |
49 | } |
50 | ||
b6d9bf2b | 51 | hook_new() { |
999d659b MT |
52 | local zone=${1} |
53 | shift | |
54 | ||
55 | while [ $# -gt 0 ]; do | |
56 | case "${1}" in | |
70c971ce SS |
57 | --dns-server=*) |
58 | local dns_servers="$(cli_get_val "${1}")" | |
59 | ||
60 | local dns_server | |
61 | for dns_server in ${dns_servers}; do | |
62 | if ! ipv4_is_valid "${dns_server}"; then | |
63 | warning "Invalid IPv4 address: ${dns_server}. Skipped." | |
64 | continue | |
65 | fi | |
66 | ||
67 | list_append DNS_SERVERS "${dns_server}" | |
68 | done | |
69 | ;; | |
f94b87ab MT |
70 | --max-sessions=*) |
71 | MAX_SESSIONS=$(cli_get_val ${1}) | |
72 | ;; | |
999d659b MT |
73 | --mtu=*) |
74 | MTU=$(cli_get_val ${1}) | |
75 | ;; | |
76 | --service-name=*) | |
77 | SERVICE_NAME=$(cli_get_val ${1}) | |
78 | ;; | |
79 | --subnet=*) | |
80 | SUBNET=$(cli_get_val ${1}) | |
81 | ;; | |
82 | esac | |
83 | shift | |
84 | done | |
85 | ||
b6d9bf2b | 86 | zone_config_settings_write "${zone}" "${HOOK}" |
999d659b MT |
87 | |
88 | exit ${EXIT_OK} | |
89 | } | |
90 | ||
1c6a4e30 | 91 | hook_up() { |
999d659b MT |
92 | local zone=${1} |
93 | local config=${2} | |
94 | shift 2 | |
95 | ||
96 | # Start the PPPoE server. | |
97 | pppoe_server_start ${zone} | |
98 | ||
99 | exit ${EXIT_OK} | |
100 | } | |
101 | ||
1c6a4e30 | 102 | hook_down() { |
999d659b MT |
103 | local zone=${1} |
104 | local config=${2} | |
105 | shift 2 | |
106 | ||
107 | if ! device_exists ${zone}; then | |
108 | error "Zone '${zone}' doesn't exist." | |
109 | exit ${EXIT_ERROR} | |
110 | fi | |
111 | ||
112 | # Stop the PPPoE server. | |
113 | pppoe_server_stop ${zone} | |
114 | ||
115 | exit ${EXIT_OK} | |
116 | } | |
117 | ||
1c6a4e30 | 118 | hook_status() { |
999d659b MT |
119 | local zone=${1} |
120 | local config=${2} | |
121 | shift 2 | |
122 | ||
123 | if ! device_exists ${zone}; then | |
124 | error "Zone '${zone}' doesn't exist." | |
125 | exit ${EXIT_ERROR} | |
126 | fi | |
e9df08ad | 127 | |
b6d9bf2b | 128 | zone_config_settings_read "${zone}" "${config}" |
999d659b MT |
129 | |
130 | local status | |
131 | if pppoe_server_status ${zone}; then | |
132 | status="${MSG_HOOK_UP}" | |
133 | else | |
134 | status="${MSG_HOOK_DOWN}" | |
135 | fi | |
136 | cli_statusline 3 "PPPoE server" "${status}" | |
137 | ||
9689be27 MT |
138 | local gateway=$(ipv4_get_network ${SUBNET}) |
139 | cli_print_fmt1 3 "Gateway" "${gateway}" | |
140 | ||
141 | local start_address=$(ipv4_encode ${gateway}) | |
142 | start_address=$(( ${start_address} + 1 )) | |
143 | start_address=$(ipv4_decode ${start_address}) | |
144 | local end_address=$(ipv4_get_broadcast ${SUBNET}) | |
145 | ||
146 | cli_print_fmt1 3 "Client range" \ | |
147 | "${start_address}-${end_address}" | |
148 | cli_space | |
149 | ||
f94b87ab MT |
150 | local max_sessions=${MAX_SESSIONS} |
151 | if [ "${max_sessions}" = "0" ]; then | |
152 | max_sessions="unlimited" | |
153 | fi | |
154 | cli_print_fmt1 3 "${max_sessions} session(s) per MAC" | |
155 | cli_space | |
156 | ||
999d659b MT |
157 | exit ${EXIT_OK} |
158 | } |