#!/bin/bash

libexec=/usr/local/share/ebox

ppp_iface=$1
eth_iface=$2
local_address=$4
remote_address=$5

LOG=/var/log/ebox/pppoe.log

TIMESTAMP=$(date +"%Y-%m-%d %T")
echo "$TIMESTAMP> ppp-up script called with the following values:" >> $LOG
echo "ppp_iface: $ppp_iface" >> $LOG
echo "eth_iface: $eth_iface" >> $LOG
echo "local_address: $local_address" >> $LOG
echo "remote_address: $remote_address" >> $LOG
echo "full_args: $@" >> $LOG
echo "dns: $USEPEERDNS $DNS1 $DNS2" >> $LOG

$libexec/ppp-set-iface.pl $eth_iface $ppp_iface $local_address

$libexec/dhcp-address.pl $eth_iface $local_address 255.255.255.255

if [ $USEPEERDNS -eq 1 ]
then
    $libexec/dhcp-nameservers.pl $eth_iface $DNS1 $DNS2
fi

# Regenerate firewall rules
firewall_script=$libexec/dhcp-firewall.pl
[ -x $firewall_script ] && $firewall_script

TIMESTAMP=$(date +"%Y-%m-%d %T")
echo "$TIMESTAMP> ppp-up script for $eth_iface ended" >> $LOG
