s243a

network.cgi - /var/www/tazpanel

Mar 15th, 2019
228
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. #
  3. # Network configuration CGI interface
  4. #
  5. # Copyright (C) 2012-2015 SliTaz GNU/Linux - BSD License
  6. #
  7. # Modified by mistfire for TazPuppy
  8.  
  9. . ./lib/libtazpanel
  10. get_config
  11. header
  12. TITLE=$(_ 'Network')
  13. ip_forward=/proc/sys/net/ipv4/ip_forward
  14.  
  15. if [ ! -d /etc/network-config ]; then
  16.  mkdir /etc/network-config
  17. fi
  18.  
  19. ALL_INTF=`ls -1 /sys/class/net | grep -v '^lo$' | tr '\n' ' '`
  20. xETH=""
  21. xWLAN=""
  22.  
  23. for IF1 in $ALL_INTF
  24. do
  25.  
  26. xIF_DRIVER="`readlink /sys/class/net/$IF1/device/driver | rev | cut -f1 -d'/' | rev`" #ex: ath5k
  27. [ "$xIF_DRIVER" = "ath5k_pci" ] && [ "`lsmod | grep '^ath5k '`" != "" ] && xIF_DRIVER='ath5k'
  28.  
  29. ePATTERN="${IF1}:"
  30. if [ "`grep "$ePATTERN" /proc/net/wireless`" != "" ] || [ "$xIF_DRIVER" = "prism2_usb" ] || [ -d /sys/class/net/${IF1}/wireless ]; then
  31.  if [ "$xWLAN" == "" ]; then
  32.   xWLAN="$IF1"
  33.  else
  34.   xWLAN="$xWLAN $IF1"
  35.  fi
  36. else
  37.  if [ "$xETH" == "" ]; then
  38.   xETH="$IF1"
  39.  else
  40.   xETH="$xETH $IF1"
  41.  fi
  42. fi
  43.  
  44. done
  45.  
  46. start_wifi() {
  47. sed -i -e 's|^WIFI=.*|WIFI="yes"|' /etc/network.conf
  48. . /etc/network.conf
  49. . /etc/network-config/$WIFI_INTERFACE.conf
  50. ifconfig $WIFI_INTERFACE up
  51. iwconfig $WIFI_INTERFACE txpower auto
  52. /etc/init.d/network.sh restart "" $WIFI_INTERFACE | log
  53.  
  54. for i in $(seq 5); do
  55. [ -n "$(iwconfig 2>/dev/null | fgrep Link)" ] && break
  56. sleep 1
  57. done
  58. }
  59.  
  60. stop_wifi() {
  61. . /etc/network.conf
  62. /etc/init.d/network.sh stop "" $WIFI_INTERFACE | log
  63. sleep 1
  64. }
  65.  
  66. set_wlan_interface(){
  67. INTF="$1"
  68. sed -i -e 's|^WIFI_INTERFACE=.*|WIFI_INTERFACE="'$INTF'"|' /etc/network.conf
  69. . /etc/network.conf
  70. }
  71.  
  72. start_eth() {
  73.  
  74. for eth10 in $xETH
  75. do
  76. /etc/init.d/network.sh start "" $eth10 | log
  77. sleep 1
  78. done
  79.  
  80. }
  81.  
  82. stop_eth() {
  83.  
  84. for eth10 in $xETH
  85. do
  86.  /etc/init.d/network.sh stop "" $eth10 | log
  87. done
  88.  
  89. }
  90.  
  91.  
  92. parse_wpa_conf() {
  93. awk '
  94. BEGIN { print "networks = ["; begin_list = 1; network = 0; }
  95. {
  96. if ($0 == "network={") {
  97. if (begin_list == 0) print ",";
  98. begin_list = 0;
  99. printf "{"; begin_obj = 1;
  100. network = 1; next;
  101. }
  102. if (network == 1) {
  103. if ($0 ~ "=") {
  104. if (begin_obj == 0) printf ", ";
  105. begin_obj = 0;
  106. split($0, a, "="); variable = a[1];
  107. value = gensub(variable "=", "", "");
  108. value = gensub("\\\\", "\\\\",    "g", value);
  109. value = gensub("&",    "\\&", "g", value);
  110. value = gensub("<",    "\\&lt;",  "g", value);
  111. value = gensub(">",    "\\&gt;",  "g", value);
  112. value = gensub("\"",   "\\\"",    "g", value);
  113. if (substr(value, 1, 2) == "\\\"")
  114. value = substr(value, 3, length(value) - 4);
  115. printf "%s:\"%s\"", variable, value;
  116. }
  117. }
  118. if (network == 1 && $0 ~ "}") { printf "}"; network = 0; next; }
  119. }
  120. END {print "\n];"}
  121. ' /etc/wpa/wpa.conf | sed 's|\t||g;'
  122. }
  123.  
  124. wait_up() {
  125. for i in $(seq 5); do
  126. if [ -z "$(cat /sys/class/net/*/operstate 2>/dev/null | fgrep up)"] || [ -z "$(cat /sys/class/net/*/operstate 2>/dev/null | fgrep unknown)" ]; then #s243a: fixed missing space before right bracket in second test case
  127.  sleep 1
  128. fi
  129. done
  130. }
  131.  
  132. wait_down() {
  133. for i in $(seq 5); do
  134. if [ -z "$(cat /sys/class/net/*/operstate 2>/dev/null | fgrep down)" ]; then  #s243a: fixed missing space before right bracket in test case
  135.  sleep 1
  136. fi
  137. done
  138. }
  139.  
  140. select_if() {
  141. echo '<select name="interface">'
  142. for i in $(ls /sys/class/net); do
  143. grep -qs 1 /sys/class/net/$i/carrier &&
  144. echo "<option>$i"
  145. done
  146. echo '</select>'
  147. }
  148.  
  149. case " $(GET) " in
  150. *\ start\ *)
  151. /etc/init.d/network.sh start | log
  152. wait_up
  153. ;;
  154. *\ stop\ *)
  155. /etc/init.d/network.sh stop | log
  156. #wait_down
  157. ;;
  158. *\ restart\ *)
  159. /etc/init.d/network.sh restart | log
  160. wait_up;;
  161. *\ apply_wlan\ *)
  162.  
  163.     case "$(GET staticip)" in
  164.      on) STATIC='yes';;
  165.      *)  STATIC='no';;
  166.     esac
  167.  
  168.     ITF="$(GET iface)"
  169.    
  170.     sed -i -e "s|^WIFI_INTERFACE=.*|WIFI_INTERFACE=\"$ITF\"|" /etc/network.conf
  171.     . /etc/network.conf
  172.  
  173.     sed -i \
  174.     -e "s|^STATIC=.*|STATIC=\"$STATIC\"|" \
  175.     -e "s|^IP=.*|IP=\"$(GET ip)\"|" \
  176.     -e "s|^NETMASK=.*|NETMASK=\"$(GET netmask)\"|" \
  177.     -e "s|^GATEWAY=.*|GATEWAY=\"$(GET gateway)\"|" \
  178.     -e "s|^DNS_SERVER=.*|DNS_SERVER=\"$(GET dns)\"|" \
  179.     -e "s|^METRICS=.*|METRICS=\"$(GET metrics)\"|" \
  180.     /etc/network-config/$ITF.conf
  181.    
  182.     . /etc/network-config/$ITF.conf
  183.  
  184.     start_wifi;;
  185.  
  186.  
  187. *\ apply_eth\ *)
  188.  
  189.     case "$(GET staticip)" in
  190.      on) STATIC='yes';;
  191.      *)  STATIC='no';;
  192.     esac
  193.  
  194.     ITF="$(GET iface)"
  195.     sed -i \
  196.     -e "s|^INTERFACE=.*|INTERFACE=\"$ITF\"|" \
  197.     /etc/network.conf
  198.     . /etc/network.conf
  199.  
  200.     sed -i \
  201.     -e "s|^STATIC=.*|STATIC=\"$STATIC\"|" \
  202.     -e "s|^IP=.*|IP=\"$(GET ip)\"|" \
  203.     -e "s|^NETMASK=.*|NETMASK=\"$(GET netmask)\"|" \
  204.     -e "s|^GATEWAY=.*|GATEWAY=\"$(GET gateway)\"|" \
  205.     -e "s|^DNS_SERVER=.*|DNS_SERVER=\"$(GET dns)\"|" \
  206.     -e "s|^METRICS=.*|METRICS=\"$(GET metrics)\"|" \
  207.     /etc/network-config/${ITF}.conf
  208.     . /etc/network-config/${ITF}.conf
  209.  
  210.     /etc/init.d/network.sh stop "" $ITF | log
  211.     sleep 2
  212.     /etc/init.d/network.sh start "" $ITF | log
  213.  
  214. wait_up;;
  215.  
  216. *\ start_wifi\ *)
  217. start_wifi;;
  218. *\ start_eth\ *)
  219. start_eth;;
  220. *\ stop_eth\ *)
  221. stop_eth;;
  222. *\ dowakeup\ *)
  223. mac="$(GET macwakup)"
  224. unset pass
  225. [ "$(GET macpass)" ] && pass="-p $(GET macpass)"
  226. if [ "$mac" ]; then
  227. ether-wake $(GET iface) $mac $pass
  228. else
  229. ether-wake -b $(GET iface) $pass
  230. fi
  231. ;;
  232. *\ hostname\ *)
  233. hostname="$(GET hostname)"
  234. echo $(_ 'Changed hostname: %s' "$hostname") | log
  235. echo "$hostname"> /etc/hostname;;
  236. *\ rmarp\ *)
  237. arp -d $(urldecode "$(GET entry)");;
  238. *\ addarp\ *)
  239. arp -i $(GET interface) -s $(GET ip) $(GET mac);;
  240. *\ proxyarp\ *)
  241. arp -i $(GET interface) -Ds $(GET ip) $(GET interface) pub;;
  242. *\ toggleipforward\ *)
  243. echo $((1 - $(cat $ip_forward))) > $ip_forward;;
  244. *\ delvlan\ *)
  245. vconfig rem $(GET vlan);;
  246. *\ addvlan\ *)
  247. grep -q '^8021q ' /proc/modules || modprobe 8021q
  248. vlan=$(GET if).$(GET id)
  249. prio=$(GET priority)
  250. [ -e /proc/net/vlan/$vlan ] || vconfig add ${vlan/./ }
  251. for i in $(seq 0 7); do
  252. vconfig set_ingress_map $vlan $i ${prio:-$i}
  253. vconfig set_egress_map $vlan $i ${prio:-$i}
  254. done;;
  255. esac
  256.  
  257. case " $(POST) " in
  258. *\ connect_wifi\ *)
  259.  
  260. . /etc/network.conf
  261.  
  262. /etc/init.d/network.sh stop | log
  263. password="$(POST password)"
  264. password="$(echo -n "$password" | sed 's|\\|\\\\|g; s|&|\\\&|g' | sed "s|'|'\"'\"'|g")"
  265. sed -i \
  266. -e "s|^WIFI_ESSID=.*|WIFI_ESSID=\"$(POST essid)\"|" \
  267. -e "s|^WIFI_BSSID=.*|WIFI_BSSID=\"$(POST bssid)\"|" \
  268. -e "s|^WIFI_KEY_TYPE=.*|WIFI_KEY_TYPE=\"$(POST keyType)\"|" \
  269. -e "s|^WIFI_KEY=.*|WIFI_KEY='$password'|" \
  270. -e "s|^WIFI_EAP_METHOD=.*|WIFI_EAP_METHOD=\"$(POST eap)\"|" \
  271. -e "s|^WIFI_CA_CERT=.*|WIFI_CA_CERT=\"$(POST caCert)\"|" \
  272. -e "s|^WIFI_CLIENT_CERT=.*|WIFI_CLIENT_CERT=\"$(POST clientCert)\"|" \
  273. -e "s|^WIFI_IDENTITY=.*|WIFI_IDENTITY=\"$(POST identity)\"|" \
  274. -e "s|^WIFI_ANONYMOUS_IDENTITY=.*|WIFI_ANONYMOUS_IDENTITY=\"$(POST anonymousIdentity)\"|" \
  275. -e "s|^WIFI_PHASE2=.*|WIFI_PHASE2=\"$(POST phase2)\"|" \
  276. /etc/network-config/$WIFI_INTERFACE.conf
  277. . /etc/network.conf
  278. . /etc/network-config/$WIFI_INTERFACE.conf
  279. start_wifi
  280. ;;
  281. *\ apply_proxy\ *)
  282. sed -i \
  283. -e "s|^HTTP_ENABLE=.*|HTTP_ENABLE=\"$(POST http_enabled)\"|" \
  284. -e "s|^HTTP_PROXY_ADDRESS=.*|HTTP_PROXY_ADDRESS=\"$(POST http_proxy)\"|" \
  285. -e "s|^HTTP_PROXY_PORT=.*|HTTP_PROXY_PORT=\"$(POST http_port)\"|" \
  286. -e "s|^HTTP_USERNAME=.*|HTTP_USERNAME=\"$(POST http_user)\"|" \
  287. -e "s|^HTTP_PASSWORD=.*|HTTP_PASSWORD=\"$(POST http_pass)\"|" \
  288. -e "s|^HTTPS_ENABLE=.*|HTTPS_ENABLE=\"$(POST https_enabled)\"|" \
  289. -e "s|^HTTPS_PROXY_ADDRESS=.*|HTTPS_PROXY_ADDRESS=\"$(POST https_proxy)\"|" \
  290. -e "s|^HTTPS_PROXY_PORT=.*|HTTPS_PROXY_PORT=\"$(POST https_port)\"|" \
  291. -e "s|^HTTPS_USERNAME=.*|HTTPS_USERNAME=\"$(POST https_user)\"|" \
  292. -e "s|^HTTPS_PASSWORD=.*|HTTPS_PASSWORD=\"$(POST https_pass)\"|" \
  293. -e "s|^FTP_ENABLE=.*|FTP_ENABLE=\"$(POST ftp_enabled)\"|" \
  294. -e "s|^FTP_PROXY_ADDRESS=.*|FTP_PROXY_ADDRESS=\"$(POST ftp_proxy)\"|" \
  295. -e "s|^FTP_PROXY_PORT=.*|FTP_PROXY_PORT=\"$(POST ftp_port)\"|" \
  296. -e "s|^FTP_USERNAME=.*|FTP_USERNAME=\"$(POST ftp_user)\"|" \
  297. -e "s|^FTP_PASSWORD=.*|FTP_PASSWORD=\"$(POST ftp_pass)\"|" \
  298. /etc/proxy.conf
  299.  
  300. ;;
  301. esac
  302.  
  303. . /etc/network.conf
  304.  
  305. case " $(GET) " in
  306. *\ scan\ *)
  307. scan=$(GET scan); back=$(GET back)
  308. xhtml_header
  309. loading_msg "$(_ 'Scanning open ports...')"
  310. cat <<EOT
  311. <section>
  312. <header>
  313. $(_ 'Port scanning for %s' $scan)
  314. $(back_button "$back" "$(_ 'Network')" "")
  315. </header>
  316. <pre>$(pscan -b $scan)</pre>
  317. </section>
  318. EOT
  319.  
  320. ;;
  321. *\ proxy\ *)
  322.  
  323. xhtml_header "$(_ 'Proxy Servers')"
  324.  
  325. . /etc/proxy.conf
  326.  
  327. case "$HTTP_ENABLE" in
  328. on) http_use='checked';;
  329. *)   http_use='';;
  330. esac
  331.  
  332. case "$HTTPS_ENABLE" in
  333. on) https_use='checked';;
  334. *)   https_use='';;
  335. esac
  336.  
  337. case "$FTP_ENABLE" in
  338. on) ftp_use='checked';;
  339. *)   ftp_use='';;
  340. esac
  341.  
  342. cat <<EOT
  343. <form action="network.cgi?proxy" method="post">
  344.     <section>
  345.         <header>
  346.             <span>$(_ 'HTTP Proxy')</span>
  347.         </header>
  348.         <input type="checkbox" name="http_enabled" id="http_enabled" $http_use/>Enabled
  349.         <table>
  350.             <tr>
  351.             <td>$(_ 'Proxy Address')</td>
  352.             <td><input type="text" name="http_proxy" size="40" value="$HTTP_PROXY_ADDRESS"/></td>
  353.         </tr>
  354.         <tr>
  355.             <td>$(_ 'Port Number')</td>
  356.             <td><input type="number" name="http_port" size="40" value="$HTTP_PROXY_PORT"/></td>
  357.         </tr>
  358.         <tr>
  359.             <td>$(_ 'Username')</td>
  360.             <td><input type="text" name="http_user" size="40" value="$HTTP_USERNAME" /></td>
  361.         </tr>
  362.         <tr>
  363.             <td>$(_ 'Password')</td>
  364.             <td><input type="password" name="http_pass" size="40" value="$HTTP_PASSWORD" /></td>
  365.         </tr>
  366.         </table>
  367.     </section>
  368.    
  369.     <section>
  370.         <header>
  371.             <span>$(_ 'HTTPS Proxy')</span>
  372.         </header>
  373.         <input type="checkbox" name="https_enabled" id="https_enabled" $https_use/>Enabled
  374.         <table>
  375.             <tr>
  376.             <td>$(_ 'Proxy Address')</td>
  377.             <td><input type="text" name="https_proxy" size="40" value="$HTTPS_PROXY_ADDRESS"/></td>
  378.         </tr>
  379.         <tr>
  380.             <td>$(_ 'Port Number')</td>
  381.             <td><input type="number" name="https_port" size="40" value="$HTTPS_PROXY_PORT" /></td>
  382.         </tr>
  383.         <tr>
  384.             <td>$(_ 'Username')</td>
  385.             <td><input type="text" name="https_user" size="40" value="$HTTPS_USERNAME" /></td>
  386.         </tr>
  387.         <tr>
  388.             <td>$(_ 'Password')</td>
  389.             <td><input type="password" name="https_pass" size="40" value="$HTTPS_PASSWORD" /></td>
  390.         </tr>
  391.         </table>
  392.     </section>
  393.  
  394.     <section>
  395.         <header>
  396.             <span>$(_ 'FTP Proxy')</span>
  397.         </header>
  398.         <input type="checkbox" name="ftp_enabled" id="ftp_enabled" $ftp_use/>Enabled
  399.         <table>
  400.             <tr>
  401.             <td>$(_ 'Proxy Address')</td>
  402.             <td><input type="text" name="ftp_proxy" size="40" value="$FTP_PROXY_ADDRESS"/></td>
  403.         </tr>
  404.         <tr>
  405.             <td>$(_ 'Port Number')</td>
  406.             <td><input type="number" name="ftp_port" size="40" value="$FTP_PROXY_PORT" /></td>
  407.         </tr>
  408.         <tr>
  409.             <td>$(_ 'Username')</td>
  410.             <td><input type="text" name="ftp_user" size="40" value="$FTP_USERNAME" /></td>
  411.         </tr>
  412.         <tr>
  413.             <td>$(_ 'Password')</td>
  414.             <td><input type="password" name="ftp_pass" size="40" value="$FTP_PASSWORD" /></td>
  415.         </tr>
  416.         </table>
  417.     </section>
  418.     <br>
  419.     <footer>
  420.          <button type="submit" name="apply_proxy" data-icon="start" >$(_ 'Apply')</button>
  421.     </footer>
  422. </form>
  423. EOT
  424.  
  425. ;;
  426. *\ eth\ *)
  427.  
  428. xhtml_header "$(_ 'Ethernet connection')"
  429. PAR1="size=\"20\" required"; PAR="$PAR1 pattern=\"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\""
  430.  
  431. stop_disabled=''; start_disabled=''
  432.  
  433. act1=0
  434.  
  435. if [ "$xETH" == "" ]; then
  436.  
  437. echo "<br><br><center>No network adapters found</center><br><br>"
  438.  
  439. else
  440.  
  441. for lan2 in $xETH
  442. do
  443. if [ "$(cat /sys/class/net/$lan2/operstate 2>/dev/null | grep "down")" != "" ]; then
  444.   echo "" > /dev/null
  445. else
  446.   act1=`expr $act1 + 1`  
  447. fi
  448. done
  449.  
  450. echo $at1
  451.  
  452.   if [ $act1 -ne 0 ]; then
  453.    start_disabled='disabled'
  454.   else
  455.    stop_disabled='disabled'
  456.   fi
  457.  
  458. if [ ! -w /etc/network.conf ]; then
  459.  stop_disabled='disabled'; start_disabled='disabled'
  460. fi
  461.  
  462. [ -s /etc/ethers ] || echo "#01:02:03:04:05:06 mystation"> /etc/ethers
  463.  
  464. if [ ! -e /sys/class/net/$INTERFACE ] || [ "$INTERFACE" == "" ]; then
  465.  
  466. TGL=""
  467.  
  468. for lan2 in $xETH
  469. do
  470.  if [ "$lan2" != "" ] && [ "$TGL" == "" ]; then
  471.  TGL="$lan2"
  472.   sed -i  -e "s|^INTERFACE=.*|INTERFACE=\"$lan2\"|"  /etc/network.conf
  473.   break
  474.  fi
  475. done
  476.  
  477. . /etc/network.conf
  478.  
  479. fi
  480.  
  481. if [ ! -e /etc/network-config/$INTERFACE.conf ]; then
  482.  cp -f /etc/wired-template.conf /etc/network-config/$INTERFACE.conf
  483. fi
  484.  
  485. . /etc/network-config/$INTERFACE.conf
  486.  
  487. case "$STATIC" in
  488. yes) use_static='checked';;
  489. *)   use_static='';;
  490. esac
  491.  
  492. if [ -w /etc/network.conf ]; then
  493.  
  494. cat <<EOT
  495.  
  496. <p>$(_ "Here you can configure a wired connection using DHCP to \
  497. automatically get a random IP or configure a static/fixed IP")</p>
  498. <br>
  499. Wired Networking
  500. <button form="conf" type="submit" name="start_eth" data-icon="" $start_disabled>$(_ 'Start')</button>
  501. <button form="conf" type="submit" name="stop_eth"      data-icon=""  $stop_disabled >$(_ 'Stop')</button>
  502. <br>
  503.  
  504. <section>
  505. <header>$(_ 'Configuration')</header>
  506. <form action="index.cgi" id="indexform"></form>
  507. <form id="conf">
  508. <input type="hidden" name="eth"/>
  509. <div>
  510. <table>
  511. <tr><td>$(_ 'Default interface')</td>
  512. <td><select name="iface" value="$INTERFACE" type="submit" style="width:100%">
  513. $(cd /sys/class/net; ls -1 | grep -v 'lo' | awk -viface="$INTERFACE" '{
  514. sel = ($0 == iface) ? " selected":""
  515. printf "<option value=\"%s\"%s>%s", $0, sel, $0
  516. }')
  517. </select></td>
  518. </tr>
  519. <tr><td>$(_ 'Static IP')</td>
  520. <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
  521. $(_ 'Use static IP')</td>
  522. </tr>
  523. <tr id="st1"><td>$(_ 'IP address')</td>
  524. <td><input type="text" name="ip"      value="$IP"         $PAR/></td>
  525. </tr>
  526. <tr id="st2"><td>$(_ 'Netmask')</td>
  527. <td><input type="text" name="netmask" value="$NETMASK"    $PAR/></td>
  528. </tr>
  529. <tr id="st3"><td>$(_ 'Gateway')</td>
  530. <td><input type="text" name="gateway" value="$GATEWAY"    $PAR/></td>
  531. </tr>
  532. <tr id="st4"><td>$(_ 'DNS server')</td>
  533. <td><input type="text" name="dns"     value="$DNS_SERVER" $PAR/></td>
  534. </tr>
  535. <tr id="st5"><td>$(_ 'Metrics')</td>
  536. <td><input type="number" name="metrics"  value="$METRICS" $PAR/></td>
  537. </tr>
  538. <tr><td>$(_ 'Wake up')</td>
  539. <td><label><input type="checkbox" name="wakeup" id="wakeup" />
  540. $(_ 'Wake up machines by network')</td>
  541. </tr>
  542. <tr id="wk1"><td>$(_ 'MAC address to wake up')</td>
  543. <td><input type="text" name="macwakup" title="$(_ 'Leave empty for a general wakeup')" $PAR/><!--
  544. --><button form="indexform" name="file" value="/etc/ethers" data-icon="">$(_ 'List')</button>
  545. </td>
  546. </tr>
  547. <tr id="wk2"><td>$(_ 'MAC/IP address password')</td>
  548. <td><input type="text" name="macpass" title="$(_ 'Optional')" $PAR/><!--
  549. --><button form="indexform" name="exec" value="ether-wake --help" data-icon="">$(_ 'Help')</button>
  550. </td>
  551. </tr>
  552. </table>
  553. <button form="conf" type="submit" name="apply_eth" data-icon="">Apply</button>
  554. <button id="wk3" form="conf" type="submit" name="dowakeup"  data-icon="" $stop_disabled >$(_ 'Wake up')</button>
  555. </div>
  556. </form>
  557. <footer>
  558. <!--
  559. --></footer>
  560. </section>
  561. <script type="text/javascript">
  562. function check_change() {
  563. enabled = document.getElementById('staticip').checked;
  564. for (i = 1; i < 5; i++) {
  565. document.getElementById('st' + i).style.display = enabled ? '' : 'none';
  566. }
  567. enabled = document.getElementById('wakeup').checked;
  568. for (i = 1; i < 4; i++) {
  569. document.getElementById('wk' + i).style.display = enabled ? '' : 'none';
  570. }
  571. }
  572. document.getElementById('staticip').onchange = check_change;
  573. document.getElementById('wakeup').onchange = check_change;
  574. check_change();
  575. </script>
  576. EOT
  577.  
  578. fi
  579.  
  580. for lan1 in $xETH
  581. do
  582.  cat <<EOT
  583. <section>
  584. <header>
  585. $(_ 'Configuration file %s' $lan1 ; edit_button /etc/network-config/$lan1.conf)
  586. </header>
  587. EOT
  588.  
  589. cat <<EOT
  590. <div>$(_ "These values are the ethernet settings in the main /etc/network-config/$lan1.conf configuration file")</div>
  591. <pre>$(awk '{if($1 !~ "WIFI" && $1 !~ "#" && $1 != ""){print $0}}' /etc/network-config/$lan1.conf | syntax_highlighter conf)</pre>
  592. </section>
  593. EOT
  594.  
  595. done
  596.  
  597. fi
  598.  
  599. ;;
  600. *\ wifi_list\ *)
  601. HIDDEN="$(_ '(hidden)')"
  602.  
  603. SCANNED_WIFI=""
  604.  
  605. if [ -d /sys/class/net/$WIFI_INTERFACE/wireless ]; then
  606. ifconfig $WIFI_INTERFACE up
  607. for i in $(iwlist $WIFI_INTERFACE scan | sed '/Cell /!d;s/.*Cell \([^ ]*\).*/Cell.\1/')
  608. do
  609. SCAN=$(iwlist $WIFI_INTERFACE scan last | sed "/$i/,/Cell/!d" | sed '$d')
  610. BSSID=$(echo "$SCAN" | sed -n 's|.*Address: \([^ ]*\).*|\1|p')
  611. CHANNEL=$(echo "$SCAN" | sed -n 's|.*Channel[:=]\([^ ]*\).*|\1|p')
  612. QUALITY=$(echo "$SCAN" | sed -n 's|.*Quality[:=]\([^ ]*\).*|\1|p')
  613. QUALITY_ICON="lvl$(( 5*${QUALITY:-0} ))"        # lvl0 .. lvl4, lvl5
  614. case $QUALITY_ICON in
  615. lvl0) QUALITY_ICON='';;
  616. lvl1) QUALITY_ICON='';;
  617. lvl2) QUALITY_ICON='';;
  618. lvl3) QUALITY_ICON='';;
  619. lvl4|lvl5) QUALITY_ICON='';;
  620. esac
  621. LEVEL=$(echo "$SCAN" | sed -n 's|.*Signal level[:=]\([^ ]*\).*|\1|p; s|-|−|')
  622. ENCRYPTION=$(echo "$SCAN" | sed -n 's|.*Encryption key[:=]\([^ ]*\).*|\1|p')        # on/off
  623. ESSID=$(echo "$SCAN" | sed -n 's|.*ESSID:"\([^"]*\).*|\1|p')
  624. AUTH="$(echo "$SCAN" | sed -n 's|.*Authentication Suites[^:]*: *\(.*\)|\1|p')"
  625. if [ -n "$(echo -n $AUTH | fgrep PSK)" ]; then
  626. WIFI_KEY_TYPE='WPA'
  627. elif [ -n "$(echo -n $AUTH | fgrep 802.1x)" ]; then
  628. WIFI_KEY_TYPE='EAP'
  629. else
  630. WIFI_KEY_TYPE='NONE'
  631. fi
  632. if [ "$ENCRYPTION" == 'on' ]; then
  633. ENC_SIMPLE=$(echo "$SCAN" | sed -n '/.*WPA.*/ s|.*\(WPA[^ ]*\).*|\1|p')
  634. ENC_SIMPLE=$(echo $ENC_SIMPLE | sed 's| |/|')
  635. ENC_ICON='' # high
  636. if [ -z "$ENC_SIMPLE" ]; then
  637. WIFI_KEY_TYPE='WEP'
  638. ENC_SIMPLE='WEP'; ENC_ICON='' # middle
  639. fi
  640. else
  641. WIFI_KEY_TYPE='NONE'
  642. ENC_SIMPLE="$(_ 'None')"; ENC_ICON='' # low
  643. fi
  644. if  ifconfig $WIFI_INTERFACE | fgrep -q inet && \
  645. iwconfig $WIFI_INTERFACE | fgrep -q "ESSID:\"$ESSID\""; then
  646. status="$(_ 'Connected')"
  647. else
  648. status='---'
  649. fi
  650.  
  651. CFG1="loadcfg('$ESSID', '$BSSID', '$WIFI_KEY_TYPE')"
  652.  
  653. SCANNED_WIFI=$SCANNED_WIFI'
  654. <tr>
  655. <td><a data-icon="" onclick="'$CFG1'">'${ESSID:-$HIDDEN}'</a></td>
  656. <td><span data-icon="'$QUALITY_ICON'" title="Quality: '$QUALITY'">'$LEVEL' dBm</span></td>
  657. <td>'$CHANNEL'</td>
  658. <td><span data-icon="'$ENC_ICON'">'$ENC_SIMPLE'</span></td>
  659. <td>'$status'</td>
  660. </tr>
  661. '
  662.  
  663. done
  664. fi
  665.  
  666. if [ "$SCANNED_WIFI" != "" ]; then
  667.  
  668. cat <<EOT
  669. <table class="wide center zebra">
  670. <thead>
  671. <tr>
  672. <td>$(_ 'Name')</td>
  673. <td>$(_ 'Signal level')</td>
  674. <td>$(_ 'Channel')</td>
  675. <td>$(_ 'Encryption')</td>
  676. <td>$(_ 'Status')</td>
  677. </tr>
  678. </thead>
  679. <tbody>
  680. $SCANNED_WIFI
  681. </tbody>
  682. </table>
  683. EOT
  684.  
  685. else
  686.  
  687.  echo '<div style="text-align: center;">No wifi networks found</span></div>'
  688.  
  689. fi
  690.  
  691. exit 0
  692. ;;
  693. *\ netconfig\ *)
  694. cat <<EOT
  695. <section>
  696. <header>
  697. $(_ 'Configuration file'; edit_button /etc/network.conf)
  698. </header>
  699. <div>$(_ "These values are the ethernet settings in the main /etc/network.conf configuration file")</div>
  700. <pre>$(cat /etc/network.conf | syntax_highlighter conf)</pre>
  701. </section>
  702. EOT
  703. ;;
  704. *\ wifi\ *)
  705. xhtml_header "$(_ 'Wireless connection')"
  706.  
  707. . /etc/network.conf
  708.  
  709. if [ "$xWLAN" != "" ]; then
  710.  
  711. start_disabled=''; stop_disabled=''
  712.  
  713. if iwconfig 2>/dev/null | grep -q 'Tx-Power=off'; then
  714.  stop_disabled='disabled'
  715. else
  716.  start_disabled='disabled'
  717. fi
  718.  
  719. if [ -w /etc/network.conf ]; then
  720. cat <<EOT
  721.  
  722. <form method="GET">
  723. <input type="hidden" name="wifi"/>
  724. Wireless Networking
  725. <button name="start_wifi" data-icon=""   $start_disabled>$(_ 'Start')</button>
  726. <button name="stop_wifi"       data-icon=""    $stop_disabled >$(_ 'Stop')</button>
  727. </form>
  728. <button name="scan_wifi" onclick="scan_wifi_async();" data-icon="" $stop_disabled >$(_ 'Scan')</button>
  729.  
  730. EOT
  731. fi
  732.  
  733.  
  734. fi
  735.  
  736.  
  737.  
  738. if [ "$xWLAN" != "" ]; then
  739.  
  740. if [ -w /etc/network.conf ]; then
  741.  
  742. if [ ! -e /sys/class/net/$WIFI_INTERFACE ] || [ "$WIFI_INTERFACE" == "" ]; then
  743.  
  744. TGL=""
  745.  
  746. for wlan2 in $xWLAN
  747. do
  748.  if [ "$wlan2" != "" ] && [ "$TGL" == "" ]; then
  749.  TGL="$wlan2"
  750.   sed -i  -e "s|^WIFI_INTERFACE=.*|WIFI_INTERFACE=\"$wlan2\"|"  /etc/network.conf
  751.   break
  752.  fi
  753. done
  754.  
  755. . /etc/network.conf
  756.  
  757. fi
  758.  
  759. if [ ! -e /etc/network-config/$WIFI_INTERFACE.conf ]; then
  760.  cp -f /etc/wireless-template.conf /etc/network-config/$WIFI_INTERFACE.conf
  761. fi
  762.  
  763.  
  764. if [ -n "$start_disabled" ]; then
  765. cat <<EOT
  766. <section>
  767. <header>Available WiFi Networks</header>
  768. <section id="wifiList">
  769. <div style="text-align: center;"><span data-icon="">$(_ 'Scanning wireless interface...')</span></div>
  770. </section>
  771. </section>
  772.  
  773. <script type="text/javascript">
  774. function scan_wifi_async(){
  775. document.getElementById("wifiList").innerHTML="<div style=\"text-align: center;\"><span data-icon=\"\">$(_ 'Scanning wireless interface...')<\/span><\/div>";
  776. ajax('network.cgi?wifi_list', '1', 'wifiList');
  777. $(parse_wpa_conf)
  778. }
  779. </script>
  780.  
  781. <script type="text/javascript">
  782. ajax('network.cgi?wifi_list', '1', 'wifiList');
  783. $(parse_wpa_conf)
  784. </script>
  785. EOT
  786.  
  787. WIFI_KEY_ESCAPED="$(echo -n "$WIFI_KEY" | sed 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g')"
  788. cat <<EOT
  789. <section>
  790. <header>$(_ 'Connection')</header>
  791. <div>
  792. <form method="POST" action="?wifi" id="connection">
  793. <input type="hidden" name="connect_wifi"/>
  794. <input type="hidden" name="bssid" id="bssid"/>
  795. <table>
  796. <tr><td>$(_ 'Network SSID')</td>
  797. <td><input type="text" name="essid" value="$WIFI_ESSID" id="essid"/></td>
  798. </tr>
  799. <tr><td>$(_ 'Security')</td>
  800. <td><select name="keyType" id="keyType">
  801. <option value="NONE">$(_ 'None')</option>
  802. <option value="WEP">WEP</option>
  803. <option value="WPA">WPA/WPA2 PSK</option>
  804. <option value="EAP">802.1x EAP</option>
  805. </select>
  806. </td>
  807. </tr>
  808. <tr class="eap">
  809. <td><div>$(_ 'EAP method')</div></td>
  810. <td><div><select name="eap" id="eap">
  811. <option value="PEAP">PEAP</option>
  812. <option value="TLS">TLS</option>
  813. <option value="TTLS">TTLS</option>
  814. <option value="PWD">PWD</option>
  815. </select>
  816. </div></td>
  817. </tr>
  818. <tr class="eap1">
  819. <td><div>$(_ 'Phase 2 authentication')</div></td>
  820. <td><div><select name="phase2" id="phase2">
  821. <option value="none">$(_ 'None')</option>
  822. <option value="pap">PAP</option>
  823. <option value="mschap">MSCHAP</option>
  824. <option value="mschapv2">MSCHAPV2</option>
  825. <option value="gtc">GTC</option>
  826. </select>
  827. </div></td>
  828. </tr>
  829. <tr class="eap1">
  830. <td><div>$(_ 'CA certificate')</div></td>
  831. <td><div><input type="text" name="caCert" id="caCert"></div></td>
  832. </tr>
  833. <tr class="eap1">
  834. <td><div>$(_ 'User certificate')</div></td>
  835. <td><div><input type="text" name="clientCert" id="clientCert"></div></td>
  836. </tr>
  837. <tr class="eap">
  838. <td><div>$(_ 'Identity')</div></td>
  839. <td><div><input type="text" name="identity" id="identity"></div></td>
  840. </tr>
  841. <tr class="eap1">
  842. <td><div>$(_ 'Anonymous identity')</div></td>
  843. <td><div><input type="text" name="anonymousIdentity" id="anonymousIdentity"></div></td>
  844. </tr>
  845. <tr class="wep wpa eap">
  846. <td><div>$(_ 'Password')</div></td>
  847. <td><div>
  848. <input type="password" name="password" value="$WIFI_KEY_ESCAPED" id="password"/>
  849. <span data-img="" title="$(_ 'Show password')"
  850. onmousedown="document.getElementById('password').type='text'; return false"
  851. onmouseup="document.getElementById('password').type='password'"
  852. onmouseout="document.getElementById('password').type='password'"
  853. ></span>
  854. </div></td>
  855. </tr>
  856. </table>
  857. </form>
  858. </div>
  859. <footer>
  860. <button form="connection" type="submit" name="wifi" data-icon="">$(_ 'Configure')</button>
  861. <button data-icon="" onclick="shareWiFi(); popup('popup_qr', 'show');">$(_ 'Share')</button>
  862. </footer>
  863. </section>
  864. <script type="text/javascript">
  865. function wifiSettingsChange() {
  866. document.getElementById('connection').className =
  867. document.getElementById('keyType').value.toLowerCase() + ' ' +
  868. document.getElementById('eap').value.toLowerCase();
  869. }
  870. document.getElementById('keyType').onchange = wifiSettingsChange;
  871. document.getElementById('eap').onchange = wifiSettingsChange;
  872. document.getElementById('keyType').value = "$WIFI_KEY_TYPE"; wifiSettingsChange();
  873. function shareWiFi() {
  874. // S=<SSID>; T={WPA|WEP|nopass}; P=<password>; H=<hidden?>
  875. // Escape ":" and ";" -> "\:" and "\;"
  876. // No harm for regular networks marked as hidden
  877. var text = "WIFI:" +
  878. "S:" + document.getElementById('essid').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
  879. "T:" + document.getElementById('keyType').value.replace("NONE", "nopass") + ";" +
  880. "P:" + document.getElementById('password').value.replace(/:/g, "\\\\:").replace(/;/g, "\\\\;") + ";" +
  881. "H:true;" +
  882. ";";
  883. document.getElementById('qrimg').title = text;
  884. qr.image({
  885. image: document.getElementById('qrimg'),
  886. value: text,
  887. size: 10
  888. });
  889. }
  890. </script>
  891. <div id="shader" class="hidden" onclick="popup('popup_qr', 'close');"></div>
  892. <table id="popup_qr" class="hidden" onclick="popup('popup_qr', 'close')">
  893. <tr>
  894. <td style="text-align: center;">
  895. <div id="popup_qr_inner">
  896. <img id="qrimg"/><br/>
  897. $(_ 'Share Wi-Fi network with your friends')
  898. </div>
  899. </td>
  900. </tr>
  901. </table>
  902. EOT
  903. fi
  904.  
  905. . /etc/network-config/$WIFI_INTERFACE.conf
  906.  
  907. case "$STATIC" in
  908. yes) use_static='checked';;
  909. *)   use_static='';;
  910. esac
  911.  
  912. cat <<EOT
  913. <section>
  914. <header>$(_ 'Configuration')</header>
  915. <form id="conf" method="GET">
  916. <input type="hidden" name="wifi"/>
  917. <div>
  918. <p>$(_ "Here you can configure a wireless connection using DHCP to \
  919. automatically get a random IP or configure a static/fixed IP")</p>
  920. <table>
  921. <tr><td>$(_ 'Default wifi interface')</td>
  922. <td><select name="iface" value="$WIFI_INTERFACE" type="submit" style="width:100%">
  923. $(echo "$xWLAN" | tr ' ' '\n' | awk -viface="$WIFI_INTERFACE" '{
  924. sel = ($0 == iface) ? " selected":""
  925. printf "<option value=\"%s\"%s>%s", $0, sel, $0
  926. }')
  927. </select></td>
  928. </tr>
  929. <tr><td>$(_ 'Static IP')</td>
  930. <td><label><input type="checkbox" name="staticip" id="staticip" $use_static/>
  931. $(_ 'Use static IP')</td>
  932. </tr>
  933. <tr id="st1"><td>$(_ 'IP address')</td>
  934. <td><input type="text" name="ip"      value="$IP"         $PAR/></td>
  935. </tr>
  936. <tr id="st2"><td>$(_ 'Netmask')</td>
  937. <td><input type="text" name="netmask" value="$NETMASK"    $PAR/></td>
  938. </tr>
  939. <tr id="st3"><td>$(_ 'Gateway')</td>
  940. <td><input type="text" name="gateway" value="$GATEWAY"    $PAR/></td>
  941. </tr>
  942. <tr id="st4"><td>$(_ 'DNS server')</td>
  943. <td><input type="text" name="dns"     value="$DNS_SERVER" $PAR/></td>
  944. </tr>
  945. <tr id="st5"><td>$(_ 'Metrics')</td>
  946. <td><input type="number" name="metrics"  value="$METRICS" $PAR/></td>
  947. </tr>
  948. </table>
  949. <button form="conf" type="submit" name="apply_wlan" data-icon="">Apply</button>
  950. </div>
  951. </form>
  952. <footer>
  953.  
  954. <!--
  955. --></footer>
  956. </section>
  957. <script type="text/javascript">
  958. function check_change() {
  959. enabled = document.getElementById('staticip').checked;
  960. for (i = 1; i < 5; i++) {
  961. document.getElementById('st' + i).style.display = enabled ? '' : 'none';
  962. }
  963. }
  964. document.getElementById('staticip').onchange = check_change;
  965. check_change();
  966. </script>
  967. EOT
  968.  
  969. fi
  970.  
  971. for wl in $xWLAN
  972. do
  973.  
  974. cat <<EOT
  975. <section>
  976. <header>
  977. $(_ 'Configuration file %s' $wl; edit_button /etc/network-config/$wl.conf)
  978. </header>
  979. EOT
  980.  
  981.  cat <<EOT
  982. <div>$(_ "These values are the wifi settings in the main /etc/network-config/%s.conf configuration file" "$wl")</div>
  983. <div style="overflow-y:scroll; height:153px;"><pre>$(cat /etc/network-config/$wl.conf | sed 's|WIFI_KEY=.*|WIFI_KEY="********"|' | syntax_highlighter conf)</pre></div>
  984. </section>
  985. EOT
  986.  
  987. done
  988.  
  989.  cat <<EOT
  990. <section>
  991. <header>$(_ 'Output of iwconfig')</header>
  992. <pre>$(iwconfig)</pre>
  993. </section>
  994. EOT
  995.  
  996. else
  997. echo "<br><br><center><h4>No wireless adapters found</h4></center><br><br>"
  998. fi
  999.  
  1000.  
  1001. ;;
  1002. *)
  1003.  
  1004. xhtml_header "$(_ 'Manage network connections and services')"
  1005.  
  1006. stop_disabled=''; start_disabled=''
  1007.  
  1008. act1=0
  1009.  
  1010. for lan2 in $ALL_INTF
  1011. do
  1012. if [ "$(cat /sys/class/net/$lan2/operstate 2>/dev/null | grep "down")" != "" ]; then
  1013.   echo "" > /dev/null
  1014. else
  1015.    act1=`expr $act1 + 1`
  1016. fi
  1017. done
  1018.  
  1019.   if [ $act1 -ne 0 ]; then
  1020.    start_disabled="disabled"
  1021.   else
  1022.    stop_disabled="disabled"
  1023.   fi
  1024.  
  1025.  
  1026. if [ "$xWLAN" == "" ]; then
  1027. wl_disabled='disabled'
  1028. else
  1029. wl_disabled=''
  1030. fi
  1031.  
  1032. if [ "$xETH" == "" ]; then
  1033. eth_disabled='disabled'
  1034. else
  1035. eth_disabled=''
  1036. fi
  1037.  
  1038. if [ ! -w '/etc/network.conf' ]; then
  1039. start_disabled='disabled'; stop_disabled='disabled'
  1040. fi
  1041.  
  1042. cat <<EOT
  1043. <form action="index.cgi" id="indexform"></form>
  1044. <form id="mainform">
  1045. Network Service
  1046. <!--
  1047. --><button name="start"   data-icon=""   $start_disabled>$(_ 'Start')</button><!--
  1048. --><button name="stop"    data-icon=""    $stop_disabled >$(_ 'Stop')</button><!--
  1049. --><button name="restart" data-icon="" $stop_disabled >$(_ 'Restart')</button>
  1050. </form>
  1051. <div class="float-right"><!--
  1052. -->$(_ 'Configuration:')<!--
  1053. --><button form="indexform" name="file" value="/etc/network.conf" data-icon="">network.conf</button><!--
  1054. --><button form="mainform" name="eth" data-icon="" $eth_disabled>Ethernet</button><!--
  1055. --><button form="mainform" name="wifi" data-icon="" $wl_disabled>Wireless</button>
  1056. </div>
  1057. <section>
  1058. <header>$(_ 'Network interfaces')</header>
  1059. $(list_network_interfaces)
  1060. <footer>
  1061. <input form="mainform" type="checkbox" name="opt" value="ipforward" $(
  1062. [ "$REMOTE_USER" != 'root' ] && echo ' disabled' ;
  1063. [ $(cat $ip_forward) -eq 1 ] && echo ' checked')/>
  1064. EOT
  1065. _ 'forward packets between interfaces'
  1066. [ "$REMOTE_USER" == 'root' ] && cat <<EOT
  1067. <button form="mainform" name="toggleipforward" data-icon="">$(_ 'Change')</button>
  1068. EOT
  1069. cat <<EOT
  1070. </footer>
  1071. </section>
  1072. <section>
  1073. <header id="hosts">$(_ 'Hosts'; edit_button /etc/hosts)</header>
  1074. <span data-icon="">$(r=$(getdb hosts | wc -l);
  1075. _p '%d record in the hosts DB' \
  1076. '%d records in the hosts DB' "$r" \
  1077. "$r")</span>
  1078. <pre class="scroll">$(getdb hosts | fgrep -v 0.0.0.0)</pre>
  1079. <footer>
  1080. <form action="hosts.cgi">
  1081. <button data-icon="" data-root>$(_ 'Configure')</button>
  1082. $(_ 'Use hosts file as Ad blocker')
  1083. </form>
  1084. </footer>
  1085. </section>
  1086. <section>
  1087. <header>$(_ 'Hostname')</header>
  1088. <footer>
  1089. EOT
  1090. if [ -w '/etc/hostname' ]; then
  1091. cat <<EOT
  1092. <form>
  1093. <input type="text" name="hostname" value="$(hostname)"/><!--
  1094. --><button type="submit" data-icon="">$(_ 'Change')</button>
  1095. </form>
  1096. EOT
  1097. else
  1098. cat /etc/hostname
  1099. fi
  1100. cat <<EOT
  1101. </footer>
  1102. </section>
  1103. EOT
  1104. devs="$(for i in $(sed '/:/!d;s/:.*//' /proc/net/dev); do
  1105. [ -e /proc/net/vlan/$i ] && continue
  1106. [ -e /sys/class/net/$i/flags ] || continue
  1107. [ $(($(cat /sys/class/net/$i/flags) & 0x1080)) -eq 4096 ] &&
  1108. echo $i
  1109. done)"
  1110. if [ "$REMOTE_USER" == "root" -a -n "$devs" ]; then
  1111. cat <<EOT
  1112. <section>
  1113. <header id="vlan">$(_ 'VLAN')</header>
  1114. <footer>
  1115. <form>
  1116. EOT
  1117. vlans="$(ls /proc/net/vlan/ 2> /dev/null | sed '/config/d')"
  1118. if [ -n "$vlans" ]; then
  1119. cat <<EOT
  1120. <table class="wide zebra center">
  1121. <thead>
  1122. <tr>
  1123. <td>$(_ 'Interface')</td>
  1124. <td>id</td>
  1125. <td>$(_ 'priority')</td>
  1126. </tr>
  1127. </thead>
  1128. <tbody>
  1129. EOT
  1130. for i in $vlans ; do
  1131. cat <<EOT
  1132. <tr>
  1133. <td><input type="radio" name="vlan" value="$i"/>$i</td>
  1134. <td>$(sed '/VID/!d;s/.*VID: \([^ ]*\).*/\1/' /proc/net/vlan/$i)</td>
  1135. <td>$(sed '/EGRESS/!d;s/.*: 0:\([^: ]*\).*/\1/' /proc/net/vlan/$i)</td>
  1136. <td></td>
  1137. </tr>
  1138. EOT
  1139. done
  1140. cat <<EOT
  1141. </tbody>
  1142. </table>
  1143. <button type="submit" data-icon="" name="delvlan">$(_ 'Remove')</button> $(_ 'or')
  1144. EOT
  1145. fi
  1146. cat <<EOT
  1147. <button type="submit" data-icon="" name="addvlan">$(_ 'Add')</button>
  1148. $(_ 'on') <select name="if">
  1149. $(for i in $devs; do echo "<option>$i</option>"; done)
  1150. </select> id
  1151. <input type="text" name="id" value="1" size="4" title="1..4095" />
  1152. $(_ 'priority') <select name="prio">
  1153. $(for i in $(seq 0 7); do echo "<option>$i</option>"; done)
  1154. </select>
  1155. </form>
  1156. </footer>
  1157. </section>
  1158. EOT
  1159. fi
  1160. cat <<EOT
  1161. <section>
  1162. <header id="ifconfig">$(_ 'Output of ifconfig')</header>
  1163. <pre>$(ifconfig)</pre>
  1164. </section>
  1165. <section>
  1166. <header id="routing">$(_ 'Routing table')</header>
  1167. <pre>$(route -n)</pre>
  1168. </section>
  1169. <section>
  1170. <header id="dns">$(_ 'Domain name resolution'; edit_button /etc/resolv.conf)</header>
  1171. <pre>$(cat /etc/resolv.conf)</pre>
  1172. </section>
  1173. <section>
  1174. <header id="arp">$(_ 'ARP table')</header>
  1175. EOT
  1176. if [ "$REMOTE_USER" == "root" ]; then
  1177. echo "<table>"
  1178. arp -n | while read line ; do
  1179. cat <<EOT
  1180. <form>
  1181. <tr><td>
  1182. <input type="hidden" name="entry" value="$(urlencode "$(echo $line | \
  1183. sed 's/) .* on/ -i/;s/.*(//')")">
  1184. <button type="submit" data-icon="" name="rmarp"></button>
  1185. </td><td><pre>$line</pre></td></tr>
  1186. </form>
  1187. EOT
  1188. done
  1189. cat <<EOT
  1190. </table>
  1191. <footer>
  1192. <form>
  1193. IP <input type="text" name="ip" value="10.20.30.40" size="12" /> $(_ 'on') $(select_if)<!--
  1194. --><button type="submit" data-icon="" name="proxyarp">$(_ 'Proxy')</button>
  1195. $(_ 'or') <button type="submit" data-icon="" name="addarp">$(_ 'Add')</button>
  1196. MAC <input type="text" name="mac" value="11:22:33:44:55:66" size="16" />
  1197. </form>
  1198. EOT
  1199. else
  1200. echo "<pre>$(arp -n)</pre>"
  1201. fi
  1202. cat <<EOT
  1203. </footer>
  1204. </section>
  1205. <section>
  1206. <header id="connections">$(_ 'IP Connections')</header>
  1207. <pre>$(netstat -anp 2>/dev/null | sed -e '/UNIX domain sockets/,$d' \
  1208. -e 's#\([0-9]*\)/#<a href="boot.cgi?daemons=pid=\1">\1</a>/#')</pre>
  1209. </section>
  1210. EOT
  1211. [ "$REMOTE_USER" == "root" -a "$(which iptables-save)" ] && cat <<EOT
  1212. <section>
  1213. <header id="iptables">$(_ 'Firewall')
  1214. $(edit_button /etc/knockd.conf "$(_ 'Port knocker')")
  1215. </header>
  1216. <pre>$(iptables-save)</pre>
  1217. </section>
  1218. EOT
  1219. ;;
  1220. esac
  1221. xhtml_footer
  1222. exit 0
RAW Paste Data