#!/bin/bash # brezular v0.1 function show_choices { echo -e "\n*** Script configures pppoe connection, select from options below ***\n" echo -e "a) Change pppoe username" echo -e "b) Change pppoe password" echo -e "c) Enable pppoe" echo -e "d) Disable pppoe" echo -e "q) Quit script\n" } function get_credentials { user="$(cat /etc/ppp/chap-secrets | awk '{print $1}')" id="$(cat /etc/ppp/chap-secrets | awk '{print $2}')" pass="$(cat /etc/ppp/chap-secrets | awk '{print $3}')" } function change_nat { /usr/local/sbin/iptables -t nat -F /usr/local/sbin/iptables --table nat -A POSTROUTING -o "$1" --jump MASQUERADE /usr/local/sbin/iptables-save > /usr/local/etc/iptables/iptables.rules } uid="$UID" [ "$uid" != 0 ] && echo -e "\nRun '$0' as root, exiting" && exit 1 while true; do show_choices read val case $val in a) get_credentials echo -en "\nEnter pppoe username: " read newuser echo "$newuser $id $pass" > /etc/ppp/chap-secrets sed -i "s/$user/$newuser/g" /etc/ppp/peers/my_ISP echo -e "\n*** Username successfully changed ***" /usr/bin/filetool.sh -b 1>/dev/null ;; b) get_credentials echo -en "\nEnter pppoe password: " read newpass echo "$user $id $newpass" > /etc/ppp/chap-secrets echo -e "\n*** Password successfully changed ***" /usr/bin/filetool.sh -b 1>/dev/null ;; c) ### Enable pppoe #### grep -q "^/usr/local/sbin/pppd" /opt/bootsync.sh if [ "$?" == 0 ]; then # pppd configured to run after boot ps -ef | grep pppd | grep -v grep 1>/dev/null # check if pppd is running if [ "$?" == 1 ]; then # pppd daemon isn't running /usr/local/sbin/pppd call my_ISP &>/dev/null # start pppd daemon ps -ef | grep pppd | grep -v grep 1>/dev/null # check if we started pppd if [ "$?" == 0 ]; then echo -e "\n*** pppoe successfully started ****" else echo -e "\n*** pppoe cannot be started, reboot router ****" fi fi else # pppd is disabled to run after boot sed -i "s/#\/usr\/local\/sbin\/pppd/\/usr\/local\/sbin\/pppd/g" /opt/bootsync.sh # enable pppd after boot change_nat ppp0 # NAT LAN behind ppp0 ps -ef | grep pppd | grep -v grep 1>/dev/null # check if pppd is running if [ "$?" == 1 ]; then # no pppd daemon is running /usr/local/sbin/pppd call my_ISP &>/dev/null # so we will start it elif [ "$?" == 0 ]; then # old pppd daemon is running pppdpid="$(ps -ef | grep pppd | grep -v grep | awk '{print $1}')" # we get its pid and kill it kill -9 $pppdpid /usr/local/sbin/pppd call my_ISP 1>/dev/null # restat ppp daemon fi echo -e "\n*** pppoe successfully enabled, reboot router ***" /usr/bin/filetool.sh -b 1>/dev/null fi ;; d) ### Disable pppoe ### grep -q "^#/usr/local/sbin/pppd" /opt/bootsync.sh if [ "$?" == 1 ]; then # pppd is disabled after start sed -i "s/\/usr\/local\/sbin\/pppd/#\/usr\/local\/sbin\/pppd/g" /opt/bootsync.sh # so we have to disable it change_nat eth0 # change NAT back from ppp0 to eth0 fi ps -ef | grep pppd | grep -v grep 1>/dev/null # check if pppd is running if [ "$?" == 0 ]; then # pppd daemon is running pppdpid="$(ps -ef | grep pppd | grep -v grep | awk '{print $1}')" # we get its pid and kill it kill -9 $pppdpid fi echo -e "\n*** pppoe successfully disabled, reboot router ***" /usr/bin/filetool.sh -b 1>/dev/null ;; q) exit 0 ;; *) echo -e "\n*** Please, enter valid option ***" ;; esac done