#!/usr/bin/perl -T

###############################################################################
#
# Copyright 2002 Point Clark Networks.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
###############################################################################

use strict;
use Getopt::Long;
use lib '/usr/share/system/scripts';
require 'functions';

# Usual security measures... see "perlsec" manual page for details.
#------------------------------------------------------------------

$ENV {'PATH'} = '/sbin';
$ENV {'SHELL'} = '/bin/bash';
delete @ENV {'ENV', 'BASH_ENV'};

if ($< != 0) {
	print("You must be root to update system files... exiting.\n");
	exit;
}


my $username;
my $password;
my $f_pap = "/etc/ppp/pap-secrets";
my $f_chap = "/etc/ppp/chap-secrets";
my $f_eth0 = "/etc/sysconfig/network-scripts/ifcfg-eth0";
my $f_ppp0 = "/etc/sysconfig/network-scripts/ifcfg-ppp0";
my %opts;

GetOptions(
        "username=s" => \$username,
        "password=s" => \$password
);

# Main
#-----

print("Setting PPPoE username and password\n");

if (!$username || !$password) {
	print("... skipping, no username and/or password specified\n");
	exit;
}

SetPppoeFirewall();
KeyReplace($f_eth0, "ONBOOT", "=", "no");
open(TEMP, ">>$f_chap") or die "File open error $f_chap: $!";
print TEMP "\"$username\"	*	\"$password\"	*\n";
close (TEMP);
open(TEMP, ">>$f_pap") or die "File open error $f_pap: $!";
print TEMP "\"$username\"	*	\"$password\"	*\n";
close (TEMP);
open(TEMP, ">$f_ppp0") or die "File open error $f_ppp0: $!";
print TEMP "USERCTL=no
BOOTPROTO=xDSL
NAME=DSLppp0
DEVICE=ppp0
TYPE=xDSL
ONBOOT=yes
PIDFILE=/var/run/pppoe-adsl.pid
FIREWALL=NONE
DEMAND=no
PING=.
PPPOE_TIMEOUT=80
LCP_FAILURE=5
LCP_INTERVAL=20
CLAMPMSS=1412
CONNECT_POLL=6
CONNECT_TIMEOUT=80
DEFROUTE=yes
SYNCHRONOUS=no
ETH=eth0
PROVIDER=DSLppp0
USER=\"$username\"
PEERDNS=yes
";
