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