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