#!/bin/sh
#(c) Copyright Barry Kauler September 2010
#License: GPL2 /usr/share/doc/legal
#want to see if a network connection, if so offer to start firewall.
#also, offer to make pupdial the default when click 'connect' icon.
#101017 checkbox to not run this dialog again.
#101026 improve ppp0 active test.
#101206 now called from pupdial after wvdial run.
#120202 BK: internationalized.
#120210 rodin.s: fix typo line 36.

export TEXTDOMAIN=pupdial_wizard_helper
export OUTPUT_CHARSET=UTF-8

DEFAULTCONNECT="`cat /usr/local/bin/defaultconnect | tail -n 1 | tr -s " " | cut -f 2 -d " "`"
[ "$DEFAULTCONNECT" == "pupdial" ] && exit

[ -f /var/local/sns/pupdial_default_noask ] && exit #101017

#101206 test for ppp0 up...
sleep 60 #yep, needs a very big sleep.
[ "`ifconfig | grep '^ppp'`" = "" ] && exit

#dlg to ask (code copied from /usr/local/simple_network_setup/sns)...
MSGFIREWALL=""
CHKFIREWALL=""
if [ ! -f /etc/rc.d/rc.firewall ];then
 MSGFIREWALL="<text><label>$(gettext "However, there is one item of recommended housekeeping: you really should be running a firewall. Puppy is inherently secure, however a firewall will give you that extra protection while online. Recommend that you tick the 'Start firewall' checkbox (the firewall will install and will automatically run at all future boots)...")</label></text>"
 CHKFIREWALL="<checkbox><label>$(gettext 'Start firewall')</label><default>true</default><variable>CHK_FIREWALL</variable></checkbox>"
fi
export WIN3_DLG="<window title=\"$(gettext 'Wizard: PupDial post-connect')\" icon-name=\"gtk-network\">
        <vbox>
         <pixmap><input file>/usr/local/lib/X11/pixmaps/ok.xpm</input></pixmap>
         <text><label>$(gettext 'It seems that you have successfully dialed the Internet!')</label></text>
         ${MSGFIREWALL}
         ${CHKFIREWALL}
         <text><label>$(gettext "Recommend leave this checkbox ticked, so that Puppy will use PupDial to automatically connect to the Internet at bootup. Also clicking the 'connect' icon on the desktop will immediately launch PupDial...")</label></text>
         <checkbox><label>$(gettext 'Set PupDial as default network setup tool')</label><default>true</default><variable>CHK_SNSDEF</variable></checkbox>
         <text><label>$(gettext "If you sometimes connect with PupDial, sometimes by other means such as via a LAN or router, and you don't want to set PupDial as the default connection method and you don't want this dialog box to pop up everytime you run PupDial, then leave the above checkbox unticked and tick this box...")</label></text>
         <checkbox><label>$(gettext 'Do not display this dialog box again')</label><default>false</default><variable>CHK_NOASK</variable></checkbox>
         <hbox>
          <button ok></button>
         </hbox>
        </vbox>
        </window>"
RETSTR3="`gtkdialog3 --program=WIN3_DLG --center`"
if [ "`echo "$RETSTR3" | grep '^CHK_SNSDEF' | grep 'true'`" != "" ];then
 echo -e '#!/bin/sh\nexec pupdial' > /usr/local/bin/defaultconnect
else
 echo -e '#!/bin/sh\nexec connectwizard' > /usr/local/bin/defaultconnect
 if [ "`echo "$RETSTR3" | grep '^CHK_NOASK' | grep 'true'`" != "" ];then #101017
  echo "true" > /var/local/sns/pupdial_default_noask
 fi
fi
if [ "`echo "$RETSTR3" | grep '^CHK_FIREWALL' | grep 'true'`" != "" ];then
 rxvt -e firewallinstallshell
fi

###END###
