tazpanel rev 485

network.cgi : edit arp table
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue May 12 13:10:58 2015 +0200 (2015-05-12)
parents 925a593037d3
children 9309ccae1a59
files network.cgi
line diff
     1.1 --- a/network.cgi	Tue May 12 09:36:14 2015 +0200
     1.2 +++ b/network.cgi	Tue May 12 13:10:58 2015 +0200
     1.3 @@ -111,6 +111,13 @@
     1.4  	done
     1.5  }
     1.6  
     1.7 +select_if() {
     1.8 +	echo '<select name="interface">'
     1.9 +	for i in $(ls /sys/class/net); do
    1.10 +		echo "<option>$i"
    1.11 +	done
    1.12 +	echo '</select>'
    1.13 +}
    1.14  
    1.15  # Actions commands before page is displayed
    1.16  
    1.17 @@ -143,6 +150,12 @@
    1.18  		get_hostname="$(GET host)"
    1.19  		echo $(_ 'Changed hostname: %s' $get_hostname) | log
    1.20  		echo "$get_hostname" > /etc/hostname ;;
    1.21 +	*\ rmarp\ *)
    1.22 +		arp -d $(urldecode "$(GET entry)") ;;
    1.23 +	*\ addarp\ *)
    1.24 +		arp -i $(GET interface) -s $(GET ip) $(GET mac) ;;
    1.25 +	*\ proxyarp\ *)
    1.26 +		arp -i $(GET interface) -Ds $(GET ip) $(GET interface) ;;
    1.27  esac
    1.28  
    1.29  case " $(POST) " in
    1.30 @@ -644,18 +657,20 @@
    1.31  
    1.32  
    1.33  <section>
    1.34 -	<header id="hosts">$(_ 'Hosts')</header>
    1.35 -	<pre>$(cat /etc/hosts)</pre>
    1.36 +	<header id="hosts">
    1.37 +		$(_ 'Hosts')
    1.38  EOT
    1.39  		[ -w /etc/hosts ] && cat <<EOT
    1.40 -	<footer>
    1.41  		<form action="index.cgi">
    1.42  			<input type="hidden" name="file" value="/etc/hosts"/>
    1.43  			<button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
    1.44  		</form>
    1.45 -	</footer>
    1.46  EOT
    1.47  		cat <<EOT
    1.48 +	</header>
    1.49 +	<footer>
    1.50 +		<pre>$(cat /etc/hosts)</pre>
    1.51 +	</footer>
    1.52  </section>
    1.53  
    1.54  
    1.55 @@ -681,32 +696,72 @@
    1.56  
    1.57  <section>
    1.58  	<header id="ifconfig">$(_ 'Output of ifconfig')</header>
    1.59 -	<pre>$(ifconfig)</pre>
    1.60 +	<footer><pre>$(ifconfig)</pre></footer>
    1.61  </section>
    1.62  
    1.63  
    1.64  <section>
    1.65  	<header id="routing">$(_ 'Routing table')</header>
    1.66 -	<pre>$(route -n)</pre>
    1.67 +	<footer><pre>$(route -n)</pre></footer>
    1.68  </section>
    1.69  
    1.70  
    1.71  <section>
    1.72 -	<header id="dns">$(_ 'Domain name resolution')</header>
    1.73 -	<pre>$(cat /etc/resolv.conf)</pre>
    1.74 +	<header id="dns">
    1.75 +		$(_ 'Domain name resolution')
    1.76 +EOT
    1.77 +		[ -w /etc/resolv.conf ] && cat <<EOT
    1.78 +		<form action="index.cgi">
    1.79 +			<input type="hidden" name="file" value="/etc/resolv.conf"/>
    1.80 +			<button name="action" value="edit" data-icon="edit">$(_ 'Edit')</button>
    1.81 +		</form>
    1.82 +EOT
    1.83 +		cat <<EOT
    1.84 +	</header>
    1.85 +	<footer><pre>$(cat /etc/resolv.conf)</pre></footer>
    1.86  </section>
    1.87  
    1.88  
    1.89  <section>
    1.90  	<header id="arp">$(_ 'ARP table')</header>
    1.91 -	<pre>$(arp)</pre>
    1.92 +	<footer>
    1.93 +EOT
    1.94 +		if [ "$REMOTE_USER" == "root" ]; then
    1.95 +			echo "<table>"
    1.96 +			arp -n | while read line ; do
    1.97 +				cat <<EOT
    1.98 +<form>
    1.99 +	<tr><td>
   1.100 +	<input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
   1.101 +		sed 's/) .* on/ -i/;s/.*(//')")">
   1.102 +	<button type="submit" data-icon="remove" name="rmarp"></button>
   1.103 +	</td><td><pre>$line</pre></td></tr>
   1.104 +</form>
   1.105 +EOT
   1.106 +			done
   1.107 +			cat <<EOT
   1.108 +			</table>
   1.109 +		<form>
   1.110 +			IP <input type="text" name="ip" value="10.20.30.40" size="12" /> on $(select_if)<!--
   1.111 +			--><button type="submit" data-icon="upgrade" name="proxyarp">$(_ 'Proxy')</button>
   1.112 +			or <button type="submit" data-icon="add" name="addarp">$(_ 'Add')</button>
   1.113 +			 MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
   1.114 +		</form>
   1.115 +EOT
   1.116 +		else
   1.117 +			echo "<pre>$(arp -n)</pre>"
   1.118 +		fi
   1.119 +		cat <<EOT
   1.120 +	</footer>
   1.121  </section>
   1.122  
   1.123  
   1.124  <section>
   1.125  	<header id="connections">$(_ 'IP Connections')</header>
   1.126 +	<footer>
   1.127  	<pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
   1.128  -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
   1.129 +	</footer>
   1.130  </section>
   1.131  EOT
   1.132  		;;