]> git.ipfire.org Git - people/stevee/network.git/blame - src/hooks/zones/isdn
Remove executable permissions from source files.
[people/stevee/network.git] / src / hooks / zones / isdn
CommitLineData
b6402343
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
f41fa3d7 22. /usr/lib/network/header-zone
b6402343
MT
23
24HOOK_SETTINGS="HOOK AUTH LINKNAME USER SECRET PEERDNS DEFAULTROUTE MSN MTU"
25HOOK_SETTINGS="${HOOK_SETTINGS} L2PROTO L3PROTO ENCAP PHONE"
26
27AUTH=
28CHANNELS="auto"
29DEFAULTROUTE=1
30ENCAP="syncppp"
31L2PROTO="hdlc"
32L3PROTO="trans"
33LINKNAME="$(uuid)"
34MSN=
35MTU=1500
36PEERDNS=1
37TIMEOUT=10
38SECRET=
39USER=
40PHONE=
41
42MODE="persistent"
43
44ISDN_ALLOWED_AUTHS="chap pap"
45
2181765d 46function hook_check() {
b6402343
MT
47 assert isset USER
48 assert isset SECRET
49 assert isset LINKNAME
50 assert isset DEFAULTROUTE
51 assert isset PEERDNS
52 assert isset TIMEOUT
53 assert isset PHONE
54
55 assert isbool DEFAULTROUTE
56 assert isbool PEERDNS
57 assert isinteger MSN
58 assert isinteger TIMEOUT
59
60 isset AUTH && assert isoneof AUTH ${ISDN_ALLOWED_AUTHS}
61}
62
2181765d 63function hook_parse_cmdline() {
b6402343
MT
64 local value
65
66 while [ $# -gt 0 ]; do
67 case "$1" in
68 --user=*)
69 USER=${1#--user=}
70 ;;
71 --secret=*)
72 SECRET=${1#--secret=}
73 ;;
74 --linkname=*)
75 LINKNAME=${1#--name=}
76 ;;
77 --mtu=*)
78 MTU=${1#--mtu=}
79 ;;
80 --defaultroute=*)
81 value=${1#--defaultroute=}
82 if enabled value; then
83 DEFAULTROUTE=1
84 else
85 DEFAULTROUTE=0
86 fi
87 ;;
88 --dns=*)
89 value=${1#--dns=}
90 if enabled value; then
91 PEERDNS=1
92 else
93 PEERDNS=0
94 fi
95 ;;
96 --auth=*)
97 AUTH=${1#--auth=}
98 ;;
99 --device=*)
100 DEVICE=${1#--device=}
101 ;;
102 --msn=*)
103 MSN=${1#--msn=}
104 ;;
105 --timeout=*)
106 TIMEOUT=${1#--timeout=}
107 ;;
108 --phone=*)
109 PHONE="${PHONE} ${1#--phone=}"
110 ;;
111 *)
112 echo "Unknown option: $1" >&2
113 exit ${EXIT_ERROR}
114 ;;
115 esac
116 shift
117 done
118}
119
2181765d 120function hook_up() {
b6402343
MT
121 local zone=${1}
122 shift
123
124 assert isset zone
125
126 zone_config_read ${zone}
127
128 assert [ -e "/dev/${DEVICE}" ]
129
130 # Creating necessary files
131 # XXX must be PPP_RUN
132 [ -d "${RED_RUN}/${LINKNAME}" ] || mkdir -p ${RED_RUN}/${LINKNAME}
133
134 # Create device node.
135 isdn_create_device ${zone}
136
137 # Apply configuration to the ISDN stack.
138 isdn_set_l2proto ${zone} ${L2PROTO}
139 isdn_set_l3proto ${zone} ${L3PROTO}
140 isdn_set_encap ${zone} ${ENCAP}
141
142 isdn_set_eaz ${zone} ${MSN}
143 isdn_set_huptimeout ${zone} $(( ${TIMEOUT} * 60 ))
144 isdn_addphone ${zone} out ${PHONE}
145
146 # Updating PPP credentials.
147 ppp_secret "${USER}" "${SECRET}"
148
149 # Bring up connection.
150 isdn_dial ${zone} \
151 --mode=${MODE} \
152 --channels=${CHANNELS} \
153 --user=${USER} \
154 --mtu=${MTU}
155
156 exit ${EXIT_OK}
157}
158
2181765d 159function hook_down() {
b6402343
MT
160 local zone=${1}
161 shift
162
163 # Bring down ISDN interface.
164 isdn_hangup ${zone}
165
166 # Remove ISDN device.
167 isdn_remove_device ${zone}
168
169 exit ${EXIT_OK}
170}
171
2181765d 172function hook_status() {
b6402343 173 local zone=${1}
b6402343
MT
174 assert isset zone
175
3cb2fc42 176 cli_device_headline ${zone}
b6402343
MT
177
178 zone_config_read ${zone}
179
3cb2fc42
MT
180 cli_headline 2 "Configuration:"
181 cli_print_fmt1 2 "User" "${USER}"
182 cli_print_fmt1 2 "Secret" "<hidden>"
183 cli_space
b6402343
MT
184
185 if device_exists ${zone}; then
3cb2fc42
MT
186 cli_headline 3 "ISDN information:"
187 cli_print_fmt1 3 "L2 protocol" "$(isdn_get_l2proto ${zone})"
188 cli_print_fmt1 3 "L3 protocol" "$(isdn_get_l3proto ${zone})"
189 cli_print_fmt1 3 "Encapsulation" "$(isdn_get_encap ${zone})"
190 cli_space
b6402343
MT
191 fi
192
193 # Exit if zone is down
3cb2fc42 194 zone_is_up ${zone} || exit ${EXIT_ERROR}
b6402343
MT
195
196 # XXX display time since connection started
197
3cb2fc42
MT
198 cli_headline 2 "Point-to-Point protocol"
199 cli_print_fmt1 2 "IP address" "$(routing_db_get ${zone} local-ip-address)"
200 cli_print_fmt1 2 "Gateway" "$(routing_db_get ${zone} remote-ip-address)"
201 cli_print_fmt1 2 "DNS servers" "$(routing_db_get ${zone} dns)"
202 cli_space
203
b6402343
MT
204 exit ${EXIT_OK}
205}