summaryrefslogtreecommitdiffstats
path: root/conf/default.in
blob: 07c237cca5f197cb15d8436e8cc847c590aaf1e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash

# $Id$

# This file is part of waproamd.
#
# waproamd is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# waproamd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with waproamd; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

KEYDIR="@sysconfdir@/waproamd/keys"

if [ -z "$AP" -o -z "$IFACE" ] ; then
   echo "Corrupt environment" > /dev/stderr
   exit 1
fi

AP_UC="$(echo $AP | tr [a-f] [A-F])"
METHOD=open
for M in aes wep ; do
    for F in "$AP" "$AP_UC" "essid:$ESSID_ESCAPED" ; do
        if test -r "$KEYDIR/$F.$M" ; then 
            METHOD="$M"
            FILE="$F"
            break
         fi
    done
    [ "x$METHOD" != "xopen" ] && break
done

[ "x$1" = "xstart" ] && echo "Setting policy '$METHOD'"

case "$1.$METHOD" in
    start.aes)
        aeswepd -i "$IFACE" -w -F "$KEYDIR/$FILE.aes"
        iwconfig "$IFACE" key on 2> /dev/null
        ;;

    stop.aes)
        aeswepd -i "$IFACE" -kW
        iwconfig "$IFACE" key off 2> /dev/null
        ;;
    
    start.wep)
        KEY="$(cat $KEYDIR/$FILE.wep)"
        iwconfig "$IFACE" key "$KEY"
        iwconfig "$IFACE" key [1] 2> /dev/null
        iwconfig "$IFACE" key restricted 2> /dev/null
        iwconfig "$IFACE" key on 2> /dev/null
        ;;

    *.open|stop.wep)
        iwconfig "$IFACE" key off 2> /dev/null
        ;;
    *)
        echo "Unknown command\n" > /dev/stderr
	exit 1
        ;;
esac

[ "$1" = "start" ] && exec /sbin/ifup "$IFACE"
[ "$1" = "stop" ] && exec /sbin/ifdown "$IFACE"

exit 0