#!/bin/sh
#Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
#Barry Kauler www.puppylinux.com
#Modified by Laurent Cas, April 2007
#to display current IP status
#

DEFAULTCONNECT="`cat /usr/local/bin/defaultconnect | tail -n 1 | tr -s " " | cut -f 2 -d " "`"
[ "$DEFAULTCONNECT" = "gkdial" ] && DEFAULTCONNECT="pupdial" #for older pups.
#radiobuttons...
DEFGNOMEPPP="no"
DEFPUPDIAL="no"
DEFPPPOE="no"
DEFICW="no"
case $DEFAULTCONNECT in
 gnome-ppp)
  DEFGNOMEPPP="yes"
  ;;
 pupdial)
  DEFPUPDIAL="yes"
  ;;
 tkpppoe)
  DEFPPPOE="yes"
  ;;
 *)
  DEFICW="yes"
  ;;
esac

#v2.17 removed. this can o/p multiple lines, which crashes gtkdialog...
##Added by LC
#SHOWIPSTATE="`ifconfig | grep inet | grep Bcast`"
#if [ "$SHOWIPSTATE" == "" ] ; then
#   SHOWIPSTATE="`ifconfig | grep inet`"
#fi

MSGMODEM="モデムは検出されませんでした。"
if [ -e /dev/modem ];then
 DEVMODEM="`readlink /dev/modem`"
 MSGMODEM="ダイアルアップモデムが $DEVMODEM に検出されました。"
fi

FLAGGNOMEPPP=""
if [ ! "`which gnome-ppp`" = "" ];then
 FLAGGNOMEPPP="<radiobutton><label>GnomePPP (modem dialup)</label><variable>RADIOGNOMEPPP</variable><default>$DEFGNOMEPPP</default></radiobutton>"
fi

#v2.12 removed...
#  <hbox>
#   <text>
#    <label>Connect to Internet by wireless interface...</label>
#   </text>
#   <button>
#    <input file>/usr/local/lib/X11/mini-icons/wizard16.xpm</input>
#    <action>/usr/sbin/wirelesswizard &</action>
#    <action>exit</action>
#   </button>
#  </hbox>

#   <button>
#    <input file>/usr/local/lib/X11/mini-icons/wizard16.xpm</input>
#    <action>/usr/sbin/modem-wizard</action>
#    <action>/usr/local/bin/gkdial &</action>
#    <action>exit</action>
#   </button>

#    <text>
#     <label>$SHOWIPSTATE</label>
#    </text>

WizardWizard="
 <wtitle>インターネット接続ウィザード</wtitle>
 <vbox>
 <frame 現在の設定と状態>
    <text>
     <label>$MSGMODEM</label>
    </text>
 </frame>
 <frame 接続>
  <hbox>
   <text>
    <label>ダイヤルアップ・アナログモデムでインターネットに接続...</label>
   </text>
   <button>
    <input file>/usr/local/lib/X11/mini-icons/phone16.xpm</input>
    <action>/usr/sbin/pupdial &</action>
    <action>exit</action>
   </button>
  </hbox>
  <hbox>
   <text>
    <label>ネットワーク・インターフェースでインターネットに接続...</label>
   </text>
   <button>
    <input file>/usr/local/lib/X11/mini-icons/pc-2x.xpm</input>
    <action>/usr/sbin/net-setup.sh &</action>
    <action>exit</action>
   </button>
  </hbox>
 </frame>
 <frame ツール>
  <hbox>
   <text>
    <label>ファイアウォールの設定...</label>
   </text>
   <button>
    <input file>/usr/local/lib/X11/mini-icons/mini-firewall.xpm</input>
    <action>rxvt -e /usr/sbin/firewallinstallshell &</action>
    <action>exit</action>
   </button>
  </hbox>
 </frame>
 <frame デスクトップ「接続」アイコン>
  <vbox>
  <text><label>ここで選択すると、次回デスクトップの「接続」アイコンをクリックしてすぐにスタートできます：</label></text>
   $FLAGGNOMEPPP
   <radiobutton><label>PupDial (モデム・ダイアルアップ)</label><variable>RADIOPUPDIAL</variable><default>$DEFPUPDIAL</default></radiobutton>
   <radiobutton><label>Roaring Penguin (PPPoE)</label><variable>RADIOPPPOE</variable><default>$DEFPPPOE</default></radiobutton>
   <radiobutton><label>インターネット接続ウィザード</label><variable>RADIOICW</variable><default>$DEFICW</default></radiobutton>
  </vbox>
 </frame>
  <hbox>
   <button ok></button>
  </hbox>
 </vbox>
"

RETSTR="`echo "$WizardWizard" | gtkdialog2 --stdin`"
#gtkdialog --program=WizardWizard

RADIOBUT="`echo "$RETSTR" | grep '^RADIO' | grep '"true"' | cut -f 1 -d '='`"
[ "$RADIOBUT" = "RADIOGNOMEPPP" ] && echo -e '#!/bin/sh\nexec gnomepppshell' > /usr/local/bin/defaultconnect
[ "$RADIOBUT" = "RADIOPUPDIAL" ] && echo -e '#!/bin/sh\nexec pupdial' > /usr/local/bin/defaultconnect
[ "$RADIOBUT" = "RADIOPPPOE" ] && echo -e '#!/bin/sh\nexec tkpppoe' > /usr/local/bin/defaultconnect
[ "$RADIOBUT" = "RADIOICW" ] && echo -e '#!/bin/sh\nexec connectwizard' > /usr/local/bin/defaultconnect

###end###
