################################
# VoiceOne Vo-tools Methods
#  
# @package voiceone_webservices
# @subpackage network
################################
### 
# copyNetConfToSandbox: move network config files to sandbox
###
copyNetConfToSandbox () {
  cp "$SYS_CONF_NET" $1
  chmod 777 $1
  cp "$SYS_CONF_DHCP" $2
  chmod 777 $2
  cp "$SYS_CONF_VPN" $3
  chmod 777 $3
  cp "$SYS_CONF_HOSTS" $4
  chmod 777 $4
  cp "$SYS_CONF_NTP" $5
  chmod 777 $5
  if [ "$6" != "" ];then
    if [ -e "$SYS_PID_DHCP" ];then
      cp "$SYS_PID_DHCP" $6
    else
      touch $6
    fi
    chmod 777 $6
  fi
  if [ "$7" != "" ];then
      echo zoneinfo=$SYS_CONF_ZONEINFO >> $7
      echo localtime=`ls -l $SYS_CONF_LOCALTIME` >> $7
      chmod 777 $7
  fi
}
###
# copyNetConfFromSandbox: move network config files from sandbox to conf dir
###
copyNetConfFromSandbox () {
  #move conf file from sandbox to conf dir
  cat $1 > "$SYS_CONF_NET"
  rm -f $1
  cat $2 > "$SYS_CONF_DHCP"
  rm -f $2
  cat $3 > "$SYS_CONF_VPN"
  rm -f $3
  cat $4 > "$SYS_CONF_HOSTS"
  rm -f $4 
  cat $5 > "$SYS_CONF_NTP"
  rm -f $5
  #create the link for the local time zone
  ln -sf $SYS_CONF_ZONEINFO/$6 $SYS_CONF_LOCALTIME
  #edit hostname file
  $SYS_WRITE_CMD start >/dev/null 2>/dev/null
  echo "$7" > $SYS_CONF_HOSTNAME
  $SYS_WRITE_CMD stop >/dev/null 2>/dev/null
}
###
# copySmtpConfToSandbox: move smtp config file to sandbox
###
copySmtpConfToSandbox () {
  cp "$SYS_CONF_MSMTP" $1
  chmod 777 $1
}
###
# copySmtpConfFromSandbox: move smtp config file from sandbox to config dir
###
copySmtpConfFromSandbox () {
  #move conf file from sandbox to conf dir
  cat $1 > "$SYS_CONF_MSMTP"
  rm -f $1
}
###
# reloadNetConf: start/stop dhcp service and reload network configuration
###
reloadNetConf() {
  $SYS_NETWORK restart >/dev/null 2>/dev/null
  if [ $1 -eq 1 ]; then
  	if [ $(ps fax | grep [d]hcpd | wc -l) -ne "0" ]; then
    	$SYS_DHCP stop >/dev/null 2>/dev/null
      $SYS_DHCP start >/dev/null 2>/dev/null
    else
    	$SYS_DHCP start >/dev/null 2>/dev/null
      $SYS_WRITE_CMD start >/dev/null 2>/dev/null
      $SYS_DHCP_RCINSERT >/dev/null 2>/dev/null
      $SYS_WRITE_CMD stop >/dev/null 2>/dev/null
    fi
  else
  	if [ $(ps fax | grep [d]hcpd | wc -l) -ne "0" ]; then
  		$SYS_DHCP stop >/dev/null 2>/dev/null
      $SYS_WRITE_CMD start >/dev/null 2>/dev/null
      $SYS_DHCP_RCREMOVE >/dev/null 2>/dev/null
      $SYS_WRITE_CMD stop >/dev/null 2>/dev/null
    fi
  fi
}
