slitaz-tools annotate tinyutils/netbox @ rev 33

Add : 'netbox' a GTK+ interface for network wired configuration
author Christophe Lincoln <pankso@slitaz.org>
date Sun Jan 13 18:06:32 2008 +0100 (2008-01-13)
parents
children 6766819798c7
rev   line source
pankso@33 1 #!/bin/sh
pankso@33 2 #
pankso@33 3 # Gtkdialog box to manage network connexion.
pankso@33 4 # - SliTaz GNU/Linux 2008.
pankso@33 5 #
pankso@33 6 VERSION=20080113
pankso@33 7
pankso@33 8 # Check if user is root.
pankso@33 9 check_root()
pankso@33 10 {
pankso@33 11 if test $(id -u) != 0 ; then
pankso@33 12 echo -e "
pankso@33 13 You must be root to run `basename $0`. Please type 'su' and
pankso@33 14 root password to become super-user.\n"
pankso@33 15 exit 0
pankso@33 16 fi
pankso@33 17 }
pankso@33 18
pankso@33 19 # Interafce status with ifconfig without arguments to show all
pankso@33 20 # active connections.
pankso@33 21 #
pankso@33 22 export IFCONFIG='
pankso@33 23 <vbox>
pankso@33 24 <text use-markup="true">
pankso@33 25 <label>"
pankso@33 26 <b>Active network interfaces</b>"
pankso@33 27 </label>
pankso@33 28 </text>
pankso@33 29 <text wrap="false">
pankso@33 30 <input>date</input>
pankso@33 31 </text>
pankso@33 32 <frame Ifconfig>
pankso@33 33 <text wrap="false" width-chars="58">
pankso@33 34 <input>ifconfig</input>
pankso@33 35 </text>
pankso@33 36 </frame>
pankso@33 37 <hbox>
pankso@33 38 <button>
pankso@33 39 <input file icon="exit"></input>
pankso@33 40 <action type="closewindow">IFCONFIG</action>
pankso@33 41 </button>
pankso@33 42 </hbox>
pankso@33 43 </vbox>
pankso@33 44 '
pankso@33 45
pankso@33 46 # The main dialog with notebook and all options.
pankso@33 47 #
pankso@33 48 export NET_BOX='
pankso@33 49 <vbox>
pankso@33 50 <text use-markup="true">
pankso@33 51 <label>"
pankso@33 52 <b>SliTaz - Netbox</b>"
pankso@33 53 </label>
pankso@33 54 </text>
pankso@33 55 <text wrap="true" width-chars="44">
pankso@33 56 <label>
pankso@33 57 "
pankso@33 58 Manage network connections getting dynamic IP by
pankso@33 59 DHCP or static IP. Netbox can start or stop networking,
pankso@33 60 configure network interfaces or directly edit files.
pankso@33 61 "
pankso@33 62 </label>
pankso@33 63 </text>
pankso@33 64
pankso@33 65 <frame General>
pankso@33 66 <hbox>
pankso@33 67 <text use-markup="true">
pankso@33 68 <label>"<b>Interface : </b>"</label>
pankso@33 69 </text>
pankso@33 70 <entry>
pankso@33 71 <input>. /etc/network.conf; echo $INTERFACE</input>
pankso@33 72 <variable>INTERFACE</variable>
pankso@33 73 </entry>
pankso@33 74 </hbox>
pankso@33 75 </frame>
pankso@33 76
pankso@33 77 <notebook labels="DHCP|Static IP|System wide">
pankso@33 78
pankso@33 79 <frame Udhcpc>
pankso@33 80 <hbox>
pankso@33 81 <text wrap="true">
pankso@33 82 <label>
pankso@33 83 "The -b options make DHCP client run in background
pankso@33 84 if lease cannot be immediatly negociated."
pankso@33 85 </label>
pankso@33 86 </text>
pankso@33 87 </hbox>
pankso@33 88 <hbox>
pankso@33 89 <text use-markup="true">
pankso@33 90 <label>"<b>Options : </b>"</label>
pankso@33 91 </text>
pankso@33 92 <entry>
pankso@33 93 <default>-b</default>
pankso@33 94 <variable>UDHCPC_OPTS</variable>
pankso@33 95 </entry>
pankso@33 96 </hbox>
pankso@33 97 <hbox>
pankso@33 98 <button>
pankso@33 99 <label>Start</label>
pankso@33 100 <input file icon="forward"></input>
pankso@33 101 <action>sed -i s/`cat /etc/network.conf | grep ^INTERFACE=`/INTERFACE=\"$INTERFACE\"/ /etc/network.conf</action>
pankso@33 102 <action>sed -i s/DHCP=\"no\"/DHCP=\"yes\"/ /etc/network.conf</action>
pankso@33 103 <action>sed -i s/STATIC=\"yes\"/STATIC=\"no\"/ /etc/network.conf</action>
pankso@33 104 <action>udhcpc $UDHCPC_OPTS -i $INTERFACE -p /var/run/udhcpc.$INTERFACE.pid</action>
pankso@33 105 </button>
pankso@33 106 <button>
pankso@33 107 <label>Stop</label>
pankso@33 108 <input file icon="stop"></input>
pankso@33 109 <action>echo -n "Stopping interface : $INTERFACE... "</action>
pankso@33 110 <action>ifconfig $INTERFACE down</action>
pankso@33 111 <action>killall -q udhcpc; echo "done"</action>
pankso@33 112 </button>
pankso@33 113 </hbox>
pankso@33 114 </frame>
pankso@33 115
pankso@33 116 <frame Configuration>
pankso@33 117 <hbox>
pankso@33 118 <text use-markup="true">
pankso@33 119 <label>"<b>IP : </b>"</label>
pankso@33 120 </text>
pankso@33 121 <entry>
pankso@33 122 <input>. /etc/network.conf; echo "$IP"</input>
pankso@33 123 <variable>IP</variable>
pankso@33 124 </entry>
pankso@33 125 </hbox>
pankso@33 126 <hbox>
pankso@33 127 <text use-markup="true">
pankso@33 128 <label>"<b>Netmask : </b>"</label>
pankso@33 129 </text>
pankso@33 130 <entry>
pankso@33 131 <input>. /etc/network.conf; echo "$NETMASK"</input>
pankso@33 132 <variable>NETMASK</variable>
pankso@33 133 </entry>
pankso@33 134 </hbox>
pankso@33 135 <hbox>
pankso@33 136 <text use-markup="true">
pankso@33 137 <label>"<b>Gateway : </b>"</label>
pankso@33 138 </text>
pankso@33 139 <entry>
pankso@33 140 <input>. /etc/network.conf; echo "$GATEWAY"</input>
pankso@33 141 <variable>GATEWAY</variable>
pankso@33 142 </entry>
pankso@33 143 </hbox>
pankso@33 144 <hbox>
pankso@33 145 <text use-markup="true">
pankso@33 146 <label>"<b>DNS server : </b>"</label>
pankso@33 147 </text>
pankso@33 148 <entry>
pankso@33 149 <input>. /etc/network.conf; echo "$DNS_SERVER"</input>
pankso@33 150 <variable>DNS_SERVER</variable>
pankso@33 151 </entry>
pankso@33 152 </hbox>
pankso@33 153 <hbox>
pankso@33 154 <button>
pankso@33 155 <label>Start</label>
pankso@33 156 <input file icon="forward"></input>
pankso@33 157 <action>ifconfig lo down</action>
pankso@33 158 <action>ifconfig $INTERFACE down</action>
pankso@33 159 <action>sed -i s/`cat /etc/network.conf | grep ^INTERFACE=`/INTERFACE=\"$INTERFACE\"/ /etc/network.conf</action>
pankso@33 160 <action>sed -i s/DHCP=\"yes\"/DHCP=\"no\"/ /etc/network.conf</action>
pankso@33 161 <action>sed -i s/STATIC=\"no\"/STATIC=\"yes\"/ /etc/network.conf</action>
pankso@33 162 <action>sed -i s/`cat /etc/network.conf | grep ^IP=`/IP=\"$IP\"/ /etc/network.conf</action>
pankso@33 163 <action>sed -i s/`cat /etc/network.conf | grep ^NETMASK=`/NETMASK=\"$NETMASK\"/ /etc/network.conf</action>
pankso@33 164 <action>sed -i s/`cat /etc/network.conf | grep ^GATEWAY=`/GATEWAY=\"$GATEWAY\"/ /etc/network.conf</action>
pankso@33 165 <action>sed -i s/`cat /etc/network.conf | grep ^DNS_SERVER=`/DNS_SERVER=\"$DNS_SERVER\"/ /etc/network.conf</action>
pankso@33 166 <action>/etc/init.d/network.sh</action>
pankso@33 167 </button>
pankso@33 168 <button>
pankso@33 169 <label>Stop</label>
pankso@33 170 <input file icon="stop"></input>
pankso@33 171 <action>echo -n "Stopping interface : $INTERFACE... "</action>
pankso@33 172 <action>ifconfig $INTERFACE down; echo "done"</action>
pankso@33 173 </button>
pankso@33 174 </hbox>
pankso@33 175 </frame>
pankso@33 176
pankso@33 177 <frame Configuration files>
pankso@33 178 <hbox>
pankso@33 179 <text use-markup="true">
pankso@33 180 <label>"<b>Hosts : </b>"</label>
pankso@33 181 </text>
pankso@33 182 <entry editable="false">
pankso@33 183 <default>/etc/hosts</default>
pankso@33 184 <variable>HOSTS</variable>
pankso@33 185 </entry>
pankso@33 186 <button>
pankso@33 187 <input file icon="accessories-text-editor"></input>
pankso@33 188 <action type="lauch">leafpad $HOSTS</action>
pankso@33 189 </button>
pankso@33 190 </hbox>
pankso@33 191 <hbox>
pankso@33 192 <text use-markup="true">
pankso@33 193 <label>"<b>Host name : </b>"</label>
pankso@33 194 </text>
pankso@33 195 <entry editable="false">
pankso@33 196 <default>/etc/hostname</default>
pankso@33 197 <variable>HOSTNAME</variable>
pankso@33 198 </entry>
pankso@33 199 <button>
pankso@33 200 <input file icon="accessories-text-editor"></input>
pankso@33 201 <action type="lauch">leafpad $HOSTNAME</action>
pankso@33 202 </button>
pankso@33 203 </hbox>
pankso@33 204 <hbox>
pankso@33 205 <text use-markup="true">
pankso@33 206 <label>"<b>Network : </b>"</label>
pankso@33 207 </text>
pankso@33 208 <entry editable="false">
pankso@33 209 <default>/etc/network.conf</default>
pankso@33 210 <variable>CONFIG_FILE</variable>
pankso@33 211 </entry>
pankso@33 212 <button>
pankso@33 213 <input file icon="accessories-text-editor"></input>
pankso@33 214 <action type="lauch">leafpad $CONFIG_FILE</action>
pankso@33 215 </button>
pankso@33 216 </hbox>
pankso@33 217 <hbox>
pankso@33 218 <button>
pankso@33 219 <label>Restart</label>
pankso@33 220 <input file icon="reload"></input>
pankso@33 221 <action>echo -n "Stopping interface : $INTERFACE... "</action>
pankso@33 222 <action>ifconfig lo down</action>
pankso@33 223 <action>ifconfig $INTERFACE down</action>
pankso@33 224 <action>killall -q udhcpc; echo "done"</action>
pankso@33 225 <action>/etc/init.d/network.sh</action>
pankso@33 226 </button>
pankso@33 227 </hbox>
pankso@33 228 </frame>
pankso@33 229
pankso@33 230 </notebook>
pankso@33 231
pankso@33 232 <hbox>
pankso@33 233 <button>
pankso@33 234 <label>Status</label>
pankso@33 235 <input file icon="network-wired"></input>
pankso@33 236 <action type="launch">IFCONFIG</action>
pankso@33 237 </button>
pankso@33 238 <button>
pankso@33 239 <input file icon="exit"></input>
pankso@33 240 <action type="exit">Exit</action>
pankso@33 241 </button>
pankso@33 242 </hbox>
pankso@33 243
pankso@33 244 </vbox>
pankso@33 245 '
pankso@33 246
pankso@33 247 # Only root can configure network.
pankso@33 248 check_root
pankso@33 249 gtkdialog --program=NET_BOX
pankso@33 250
pankso@33 251 exit 0