3 CONFIGFILE
=/etc
/aiccu.conf
4 TMPCONF
=/etc
/aiccu.conf.$$.dpkg-tmp
5 TMPFILE
=/etc
/aiccu.temp.$$.dpkg-tmp
8 # Note: the two temp files are placed in /etc thus should be symlink-attack safe
10 if [ ! -x $BINARY ]; then
11 # Can't configure yet as we don't have our binary yet
15 # Make sure that files we create are not readable by anyone but us (root)
18 .
/usr
/share
/debconf
/confmodule
20 if [ -e $CONFIGFILE ]; then
21 USERNAME
=$
(grep ^username
$CONFIGFILE |
awk '{print $2}')
22 PASSWORD
=$
(grep ^password
$CONFIGFILE |
awk '{print $2}')
23 PROTO
=$
(grep ^protocol
$CONFIGFILE |
awk '{print $2}')
24 SERVER
=$
(grep ^server
$CONFIGFILE |
awk '{print $2}')
25 TUNNEL
=$
(grep ^tunnel_id
$CONFIGFILE |
awk '{print $2}')
27 if [ "$USERNAME" != "" ]; then
28 db_set aiccu
/username
"$USERNAME"
31 if [ "$PASSWORD" != "" ]; then
32 db_set aiccu
/password
"$PASSWORD"
35 if [ "$PROTO" != "" -a "$SERVER" != "" ]; then
36 db_set aiccu
/brokername
"$PROTO://$SERVER"
39 if [ "$TUNNEL" != "" ]; then
40 db_set aiccu
/tunnelname
"$TUNNEL"
45 db_reset aiccu
/badauth
49 # 1 Get Tunnel Brokername
55 while [ $STATE -ge 1 -a $STATE -le 3 ]; do
59 # Fetch the list of tunnel brokers
60 BROKERS
=$
($BINARY brokers |
sort >$TMPFILE)
62 if [ "$?" != "0" ]; then
63 # No TunnelBrokers found
64 db_input high aiccu
/nobrokers || true
67 # Found Tunnel brokers, present them to the user
68 BROKERS
=$
(cat $TMPFILE | cut
-f1 -d'|' |
awk '{print $0","}')
69 BROKERS
=$
(echo -n $BROKERS |
sed 'N;s/\n//g' |
sed 's/,$//g')
70 db_subst aiccu
/brokername brokers
"$BROKERS"
71 db_fset aiccu
/brokername seen false
72 db_input high aiccu
/brokername || true
76 # Remove temporary file
82 db_input high aiccu
/username || true
83 db_input high aiccu
/password || true
88 # Reset our temp config file
89 echo "# Temporary AICCU config written by debconf" > $TMPCONF
90 #echo "verbose true" >> $TMPCONF
92 # Take the Protocol and server from the Brokername
93 db_get aiccu
/brokername
94 URL
=$
($BINARY brokers |
grep "$RET")
95 PROTO
=$
(echo $URL | cut
-f2 -d'|' | cut
-f1 -d:)
96 SERVER
=$
(echo $URL | cut
-f2 -d'|' | cut
-f3 -d/)
98 echo "protocol $PROTO" >> $TMPCONF
99 echo "server $SERVER" >> $TMPCONF
101 db_get aiccu
/username
104 db_get aiccu
/password
107 # Try to get the tunnels using the provided user/pass
108 if [ "$USERNAME" != "" -a "$PASSWORD" != "" ]; then
109 echo "username $USERNAME" >> $TMPCONF
110 echo "password $PASSWORD" >> $TMPCONF
112 TUNNELS
=$
($BINARY tunnels
$TMPCONF >$TMPFILE)
114 if [ "$?" != "0" ]; then
115 db_input high aiccu
/badauth || true
117 db_set aiccu
/badauth
"false"
119 TUNNELS
=$
(cat $TMPFILE | cut
-f1 -d' ' |
awk '{print $0","}')
120 TUNNELS
=$
(echo -n $TUNNELS |
sed 'N;s/\n//g' |
sed 's/,$//g')
122 if [ "$TUNNELS" = "" ]; then
123 db_input high aiccu
/notunnels || true
125 db_subst aiccu
/tunnelname tunnels
"$TUNNELS"
126 db_input high aiccu
/tunnelname || true
131 # Remove temporary file
134 db_set aiccu
/badauth
"false"
137 # Remove the temporary as we don't need it anymore
154 # When badly authenticated do it all over
155 if [ "$RET" = "true" ]; then
157 db_reset aiccu
/brokername
158 db_reset aiccu
/username
159 db_reset aiccu
/password
160 db_reset aiccu
/tunnelname
164 db_reset aiccu
/badauth