qwell: branch aadk r777 - /branches/aadk/scripts/networking.sh
asterisk-gui-commits at lists.digium.com
asterisk-gui-commits at lists.digium.com
Thu Apr 26 13:14:06 MST 2007
Author: qwell
Date: Thu Apr 26 15:14:05 2007
New Revision: 777
URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=777
Log:
Fix up networking script - most of the work done by bkruse, cleanup and default handling modified by me.
Modified:
branches/aadk/scripts/networking.sh
Modified: branches/aadk/scripts/networking.sh
URL: http://svn.digium.com/view/asterisk-gui/branches/aadk/scripts/networking.sh?view=diff&rev=777&r1=776&r2=777
==============================================================================
--- branches/aadk/scripts/networking.sh (original)
+++ branches/aadk/scripts/networking.sh Thu Apr 26 15:14:05 2007
@@ -1,111 +1,119 @@
-#!/bin/bash
-################################################################
-# Copyright Digium && Brandon Kruse <bkruse at digium.com> (c)#####
-# ##############################################################
-# This is a bash script to apply network settings from the GUI.#
-################################################################
+#!/bin/sh
+
+# Copyright (C) 2007, Digium, Inc.
+#
+# Brandon Kruse <bkruse at digium.com>
+#
+# Script to apply network settings from the GUI.
+
+WAN_INTERFACE="eth0"
+LAN_INTERFACE="eth1"
+DNS_CONFIG="/etc/config/resolv.conf"
+DHCP_CONFIG="/etc/udhcpd.conf"
+DHCP_BIN="`which udhcpd`"
+DHCP_SERVER="udhcpd"
+
ARG_FILE="/etc/asterisk/scripts/network.params"
-. $ARG_FILE # Include the file that has the variables in it, written from the GUI.
-WAN_INTERFACE="eth0"
-LAN_INTERFACE="eth1"
-DNS_CONFIG="/etc/config/resolv.conf"
-DHCP_CONFIG="/etc/udhcpd.conf"
-DHCP_BIN="`which udhcpd`"
-DHCP_SERVER="udhcpd"
-####################################################################
-####################################################################
-# #
-# Now for the real logic in the script. #
-# (Note: You CANNOT use functions with msh/busybox.) #
-####################################################################
-############### Set our hostname real quick
-if [ "$HOSTNAME" != "" ]
-then
-hostname $HOSTNAME &
+# We are going to set default values for the appliance
+if [ -f ${ARG_FILE} ]; then
+ echo "Configuring with network.params"
+ . ${ARG_FILE} # Include the file that has the variables in it, written from the GUI.
+else
+ echo "Configuring interface for the first time, or after configuration loss."
+ HOSTNAME=asteriskpbx
+ IP_LAN=192.168.69.1
+ SSHACCESS=no
+ DHCP_WAN=on
+ DHCP_LAN=on
+ GATEWAY_LAN=192.168.69.0
+ SUBNET_LAN=255.255.255.0
+ START_RANGE_LAN=192.168.69.51
+ END_RANGE_LAN=192.168.69.150
+ MAX_LEASE=100
+ DNS_LAN=${IP_LAN}
+fi
+
+ifconfig lo 127.0.0.1
+
+# Now for the real logic in the script.
+# Note: You CANNOT use functions with msh/busybox.
+
+# Set our hostname
+if [ "${HOSTNAME}" == "" ]; then
+ HOSTNAME=asteriskpbx
+fi
+hostname ${HOSTNAME}
+
+# Set our time server
+if [ "${NTP_LAN}" != "" ]; then
+ killall -9 ntpdate
+ ntpdate ${NTP_LAN} &
+fi
+
+# Turn on our ssh server
+if [ "${SSHACCESS}" = "yes" ]; then
+ inetd &
+fi
+
+# Setup the WAN interface.
+if [ "${DHCP_WAN}" = "on" ]; then
+ # If dhcp_wan is set from the gui
+ killall -9 dhcpcd
+ killall -9 dhcpcd.real
+ dhcpcd ${WAN_INTERFACE} &
+else
+ echo "WAN interface is ${WAN_INTERFACE} WAN IP is ${IP_WAN} WAN subnet is ${SUBNET_WAN}"
+ echo "DNS config file is ${DNS_CONFIG}"
+ ifconfig ${WAN_INTERFACE} ${IP_WAN} netmask ${SUBNET_WAN}
+ echo "`cat ${DNS_CONFIG} | grep search`" > ${DNS_CONFIG}.tmp # Save the previous "search" field
+ mv ${DNS_CONFIG}.tmp ${DNS_CONFIG}
+ echo "nameserver ${DNS_WAN}" >> ${DNS_CONFIG} # Add the IP/hostname of the nameserver
+ route -n add ${GATEWAY_WAN} ${WAN_INTERFACE} # Add our default gateway for the WAN interface
+fi
+
+# Setup the LAN interface(s).
+echo ${IP_LAN} ${HOSTNAME} > /etc/hosts
+ifconfig ${LAN_INTERFACE} ${IP_LAN} netmask ${SUBNET_LAN}
+route -n add ${GATEWAY_LAN} ${LAN_INTERFACE} # Add our default gateway for the LAN interface
+iptables -F
+dnsmasq &
+# XXX This will pretty much only work for a /24 XXX
+NETWORK_LAN=`echo "${IP_LAN}" | cut -d '.' -f 1,2,3`
+iptables -t nat -A POSTROUTING -s ${NETWORK_LAN}.0/${SUBNET_LAN} -d 0.0.0.0/0 -j MASQUERADE
+echo 1 > /proc/sys/net/ipv4/ip_forward
+echo "LAN network is ${NETWORK_LAN}"
+if [ "${DHCP_LAN}" != "off" ]; then
+ # Now we will edit /etc/udhcpd.conf
+ echo "start ${START_RANGE_LAN}" > ${DHCP_CONFIG}
+ echo "end ${END_RANGE_LAN}" >> ${DHCP_CONFIG}
+ echo "interface ${LAN_INTERFACE}" >> ${DHCP_CONFIG}
+ echo "max_leases ${MAX_LEASE}" >> ${DHCP_CONFIG}
+ echo "remaining yes" >> ${DHCP_CONFIG}
+ echo "opt subnet ${SUBNET_LAN}" >> ${DHCP_CONFIG}
+ if [ "${DNS_LAN}" != "" ]; then
+ echo "opt dns ${DNS_LAN}" >> ${DHCP_CONFIG}
+ fi
+ if [ "${ROUTER_LAN}" != "" ]; then
+ echo "opt router ${ROUTER_LAN}" >> ${DHCP_CONFIG}
+ else
+ echo "opt router ${IP_LAN}" >> ${DHCP_CONFIG}
+ fi
+ if [ "${DOMAIN_LAN}" != "" ]; then
+ echo "opt domain ${DOMAIN_LAN}" >> ${DHCP_CONFIG}
+ fi
+ if [ "${LEASE_LAN}" != "" ]; then
+ echo "opt lease ${LEASE_LAN}" >> ${DHCP_CONFIG}
+ else
+ echo "opt lease 8640000" >> ${DHCP_CONFIG}
+ fi
+ if [ "${TFTP_LAN}" != "" ]; then
+ echo "opt tftp ${TFTP_LAN}" >> ${DHCP_CONFIG}
+ fi
+ if [ "${NTP_LAN}" != "" ]; then
+ echo "opt ntpsrv ${NTP_LAN}" >> ${DHCP_CONFIG}
+ fi
+ # Stop and restart our dhcp server.
+ killall -9 ${DHCP_SERVER}
+ ${DHCP_BIN} &
fi
-
-############### Set our time server
-if [ "$NTP_LAN" != "" ]
-then
-killall -9 ntpdate
-ntpdate $NTP_LAN &
-fi
-
-############### Possibly turn our ssh server on
-if [ "$SSHACCESS" = "yes" ]
-then
- inetd&
-fi
-
-####################################################################
-# #
-# First we will do the WAN interface. #
-# #
-####################################################################
-
-if [ "$DHCP_WAN" = "on" ] #If dhcp_wan is set from the gui
-then
- killall -9 dhcpcd ; killall -9 dhcpcd.real
- dhcpcd.real $WAN_INTERFACE &
-else
- ifconfig $WAN_INTERFACE $IP_WAN netmask $SUBNET_WAN # Add our basic values to ifconfig
- echo "`cat $DNS_CONFIG | grep search`" > ${DNS_CONFIG}.tmp # Save the previous "search" field
- mv ${DNS_CONFIG}.tmp $DNS_CONFIG # you cannot cat from the same file your writing to.
- echo "nameserver $DNS_WAN" > $DNS_CONFIG # Add the ip/hostname of the nameserver
- route -n add $GATEWAY_WAN $WAN_INTERFACE # Add our default gateway for the wan interface
-fi
-
-####################################################################
-# #
-# Now we will do the LAN interface(s). #
-# #
-####################################################################
-
-if [ "$DHCP_LAN" = "off" ] # They do not want to use dhcp on the network
-then
- # We could exit now? Since we arent going to be distributing any IP's, clients are on their own.
- echo "dhcp for lan is off"
-else
- ifconfig $LAN_INTERFACE $IP_LAN netmask $SUBNET_LAN # Add our basic values to ifconfig
- route -n add $GATEWAY_LAN $LAN_INTERFACE # Add our default gateway for the Lan interface
-
- # Now we will edit /etc/udhcpd.conf
- echo "start $START_RANGE_LAN" > $DHCP_CONFIG
- echo "end $END_RANGE_LAN" >> $DHCP_CONFIG
- echo "interface $LAN_INTERFACE" >> $DHCP_CONFIG
- echo "max_leases $MAX_LEASE" >> $DHCP_CONFIG
- if [ "$DNS_LAN" != "" ]
- then
- echo "opt dns $DNS_LAN" >> $DHCP_CONFIG
- fi
- if [ "$ROUTER_LAN" != "" ]
- then
- echo "opt router $ROUTER_LAN" >> $DHCP_CONFIG
- fi
- if [ "$DOMAIN_LAN" != "" ]
- then
- echo "opt domain $DOMAIN_LAN" >> $DHCP_CONFIG
- fi
- if [ "$LEASE_LAN" != "" ]
- then
- echo "opt lease $LEASE_LAN" >> $DHCP_CONFIG
- else
- echo "opt lease 8640000" >> $DHCP_CONFIG
- fi
- if [ "$TFTP_LAN" != "" ]
- then
- echo "opt tftp $TFTP_LAN" >> $DHCP_CONFIG
- fi
- if [ "$NTP_LAN" != "" ]
- then
- echo "opt ntpsrv $NTP_LAN" >> $DHCP_CONFIG
- fi
- ########Stop and restart our dhcp server.################
- killall -9 $DHCP_SERVER; $DHCP_BIN&
- ##########Done###########################################
-fi
-
-
-
-
More information about the asterisk-gui-commits
mailing list