slitaz-tools view tinyutils/netbox @ rev 34

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