]>
Commit | Line | Data |
---|---|---|
58cbe2e4 AF |
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 | . /lib/network/header-zone | |
23 | ||
6c74a64c MT |
24 | # Modems support all authentication methods, that pppd does support. |
25 | MODEM_ALLOWED_AUTH_METHODS="${PPP_ALLOWED_AUTH_METHODS}" | |
58cbe2e4 | 26 | |
d389e96b MT |
27 | HOOK_SETTINGS=( |
28 | "APN" | |
29 | "AUTH" | |
30 | "BAUDRATE" | |
31 | "DEVICE" | |
32 | "MONITOR_DEVICE" | |
33 | "MTU" | |
34 | "USERNAME" | |
35 | "PASSWORD" | |
36 | "PIN" | |
37 | "PHONE_NUMBER" | |
38 | "IMSI" | |
39 | ) | |
6c74a64c | 40 | |
53e764a7 | 41 | DEFAULT_BAUDRATE=921600 |
87102ab4 | 42 | |
1c6a4e30 | 43 | hook_check_settings() { |
58cbe2e4 | 44 | assert isset DEVICE |
6c74a64c MT |
45 | assert isset PHONE_NUMBER |
46 | ||
47 | # Make sure the PIN code is an integer, when set. | |
48 | if isset PIN; then | |
49 | assert isinteger PIN | |
50 | assert [ ${#PIN} -ge 4 ] | |
51 | assert [ ${#PIN} -le 8 ] | |
52 | fi | |
58cbe2e4 | 53 | |
6c74a64c | 54 | assert isoneof BAUDRATE ${SERIAL_BAUDRATES} |
58cbe2e4 | 55 | |
90906214 MT |
56 | if isset AUTH; then |
57 | assert isoneof AUTH ${MODEM_ALLOWED_AUTH_METHODS} | |
58 | fi | |
58cbe2e4 AF |
59 | } |
60 | ||
1c6a4e30 | 61 | hook_parse_cmdline() { |
58cbe2e4 AF |
62 | local value |
63 | ||
64 | while [ $# -gt 0 ]; do | |
6c74a64c MT |
65 | case "${1}" in |
66 | --apn=*) | |
2212045f | 67 | APN=$(cli_get_val "${1}") |
58cbe2e4 | 68 | ;; |
6c74a64c | 69 | --auth=*) |
2212045f | 70 | AUTH=$(cli_get_val "${1}") |
58cbe2e4 | 71 | ;; |
6c74a64c | 72 | --baudrate=*) |
2212045f | 73 | BAUDRATE=$(cli_get_val "${1}") |
6c74a64c MT |
74 | assert isoneif "${BAUDRATE}" ${SERIAL_BAUDRATES} |
75 | ;; | |
76 | --device=*) | |
2212045f | 77 | DEVICE=$(cli_get_val "${1}") |
6c74a64c | 78 | ;; |
87102ab4 MT |
79 | --imsi=*) |
80 | IMSI="$(cli_get_val "${1}")" | |
81 | ;; | |
6c74a64c | 82 | --monitor-device=*) |
2212045f | 83 | MONITOR_DEVICE=$(cli_get_val "${1}") |
58cbe2e4 AF |
84 | ;; |
85 | --mtu=*) | |
2212045f | 86 | MTU=$(cli_get_val "${1}") |
6c74a64c | 87 | assert isinteger ${MTU} |
58cbe2e4 | 88 | ;; |
6c74a64c | 89 | --password=*) |
2212045f | 90 | PASSWORD=$(cli_get_val "${1}") |
58cbe2e4 | 91 | ;; |
6c74a64c | 92 | --phone-number=*) |
2212045f | 93 | PHONE_NUMBER=$(cli_get_val "${1}") |
58cbe2e4 | 94 | ;; |
6c74a64c | 95 | --pin=*) |
2212045f | 96 | PIN=$(cli_get_val "${1}") |
58cbe2e4 | 97 | ;; |
6c74a64c | 98 | --username=*) |
2212045f | 99 | USERNAME=$(cli_get_val "${1}") |
58cbe2e4 AF |
100 | ;; |
101 | *) | |
6c74a64c | 102 | echo "Unknown argument: ${1}" >&2 |
58cbe2e4 AF |
103 | exit ${EXIT_ERROR} |
104 | ;; | |
105 | esac | |
106 | shift | |
107 | done | |
108 | } | |
109 | ||
1c6a4e30 | 110 | hook_up() { |
58cbe2e4 | 111 | local zone=${1} |
58cbe2e4 AF |
112 | assert isset zone |
113 | ||
6c74a64c | 114 | # Load configuration file. |
1e6f187e | 115 | zone_settings_read "${zone}" |
58cbe2e4 | 116 | |
6c74a64c MT |
117 | # If we have got a PIN, we try to unlock the device first. |
118 | if isset PIN; then | |
87102ab4 MT |
119 | if ! modem_sim_auto_unlock "${DEVICE}" "${PIN}"; then |
120 | # Reset the PIN setting. | |
121 | PIN="" | |
1e6f187e | 122 | zone_settings_write "${zone}" |
87102ab4 MT |
123 | error "Could not unlock the SIM card. Removing PIN from settings." |
124 | fi | |
58cbe2e4 | 125 | |
6c74a64c MT |
126 | # For mobile devices, check if a PIN is required although none is set. |
127 | elif modem_is_mobile ${DEVICE} && modem_sim_locked ${DEVICE}; then | |
128 | error "The SIM card is locked. Please configure the PIN code." | |
129 | exit ${EXIT_ERROR} | |
130 | fi | |
58cbe2e4 | 131 | |
6c74a64c MT |
132 | # Start the PPP daemon. |
133 | pppd_start ${zone} | |
58cbe2e4 | 134 | |
6c74a64c | 135 | exit ${EXIT_OK} |
58cbe2e4 AF |
136 | } |
137 | ||
1c6a4e30 | 138 | hook_down() { |
58cbe2e4 | 139 | local zone=${1} |
6c74a64c | 140 | assert isset zone |
58cbe2e4 | 141 | |
6c74a64c | 142 | # Stop the PPP daemon. |
6d91bb88 | 143 | pppd_stop ${zone} |
58cbe2e4 AF |
144 | |
145 | exit ${EXIT_OK} | |
146 | } | |
147 | ||
1c6a4e30 | 148 | hook_status() { |
58cbe2e4 | 149 | local zone=${1} |
58cbe2e4 AF |
150 | assert isset zone |
151 | ||
3cb2fc42 | 152 | cli_device_headline ${zone} |
58cbe2e4 | 153 | |
1e6f187e | 154 | zone_settings_read "${zone}" |
58cbe2e4 | 155 | |
6c74a64c MT |
156 | cli_headline 2 "Configuration" |
157 | cli_print_fmt1 2 "Username" "${USERNAME}" | |
158 | cli_print_fmt1 2 "Password" "<hidden>" | |
159 | cli_space | |
160 | ||
161 | cli_headline 2 "Device settings" | |
162 | cli_print_fmt1 2 "Device" "${DEVICE}" | |
163 | if isset MONITOR_DEVICE; then | |
164 | cli_print_fmt1 2 "Monitor device" "${MONITOR_DEVICE}" | |
58cbe2e4 | 165 | fi |
6c74a64c MT |
166 | cli_print_fmt1 2 "Baudrate" "${BAUDRATE}" |
167 | cli_print_fmt1 2 "MTU/MRU" "${MTU}" | |
168 | cli_space | |
58cbe2e4 | 169 | |
6c74a64c MT |
170 | # If the device and the monitor device are both locked, |
171 | # we cannot show any carrier information. | |
172 | local device dev | |
173 | for dev in ${DEVICE} ${MONITOR_DEVICE}; do | |
174 | if ! serial_exists ${dev}; then | |
175 | continue | |
176 | fi | |
5ebde108 | 177 | |
6c74a64c MT |
178 | if serial_is_locked ${dev}; then |
179 | continue | |
180 | fi | |
181 | ||
182 | device=${dev} | |
183 | done | |
184 | ||
d3096443 | 185 | if isset device && modem_is_mobile "${device}"; then |
36aeb387 | 186 | modem_mobile_network_status "${device}" 2 |
6c74a64c MT |
187 | else |
188 | cli_print 2 "Device is locked." | |
189 | fi | |
190 | cli_space | |
191 | ||
a59ef968 MT |
192 | # Exit if zone is down |
193 | if ! zone_is_up ${zone}; then | |
194 | echo # Empty line | |
195 | exit ${EXIT_ERROR} | |
196 | fi | |
197 | ||
58cbe2e4 AF |
198 | # XXX display time since connection started |
199 | ||
6c74a64c MT |
200 | cli_headline 2 "Point-to-Point-over-Ethernet protocol" |
201 | local proto | |
202 | for proto in ${IP_SUPPORTED_PROTOCOLS}; do | |
c041b631 | 203 | db_exists "${zone}/${proto}" || continue |
6c74a64c MT |
204 | |
205 | local headline | |
206 | case "${proto}" in | |
207 | ipv6) | |
208 | headline="Internet Protocol Version 6" | |
209 | ;; | |
210 | ipv4) | |
211 | headline="Internet Protocol Version 4" | |
212 | ;; | |
213 | *) | |
214 | headline="Unkown protocol" | |
215 | ;; | |
216 | esac | |
217 | cli_headline 3 "${headline}" | |
218 | ||
c041b631 MT |
219 | cli_print_fmt1 3 "IP address" "$(db_get "${zone}/${proto}/local-ip-address")" |
220 | cli_print_fmt1 3 "Gateway" "$(db_get "${zone}/${proto}/remote-ip-address")" | |
221 | cli_print_fmt1 3 "DNS servers" "$(db_get "${zone}/${proto}/domain-name-servers")" | |
6c74a64c MT |
222 | cli_space |
223 | done | |
224 | ||
225 | exit ${EXIT_OK} | |
226 | } | |
227 | ||
1c6a4e30 | 228 | hook_ppp_write_config() { |
6c74a64c MT |
229 | local zone=${1} |
230 | assert isset zone | |
231 | ||
232 | local file=${2} | |
233 | assert isset file | |
234 | ||
235 | # Read in the configuration files. | |
1e6f187e | 236 | zone_settings_read "${zone}" |
6c74a64c MT |
237 | |
238 | pppd_write_config ${file} \ | |
239 | --interface="${zone}" \ | |
240 | --username="${USERNAME}" \ | |
241 | --password="${PASSWORD}" \ | |
242 | --mtu="${MTU}" \ | |
243 | --auth="${AUTH}" \ | |
244 | \ | |
245 | --serial="true" \ | |
246 | --serial-device="${DEVICE}" \ | |
247 | --baudrate="${BAUDRATE}" \ | |
248 | --connect-command="/usr/lib/network/dialer ${zone}" | |
249 | ||
58cbe2e4 AF |
250 | exit ${EXIT_OK} |
251 | } |