#!/usr/bin/perl -w

#----------------------------------------------------------------------
# copyright (C) 1999-2003 Mitel Networks Corporation
# 
# 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
# 
# Technical support for this program is available from Mitel Networks 
# Please visit our web site www.mitel.com/sme/ for details.
#----------------------------------------------------------------------
package esmith;

use strict;
use Errno;
use esmith::config;
use esmith::util;

my %conf;
tie %conf, 'esmith::config';

exit (0) unless ($conf{'AccessType'} eq "dialup");

# Remove bogus diald shutdown symlink from runlevel 6
# Shutting down diald too early causes probs, especially with squid
unlink ("/etc/rc.d/rc6.d/K05diald");

#------------------------------------------------------------
# Update files related to dialup Internet access.
#------------------------------------------------------------
esmith::util::processTemplate ({
	CONFREF => \%conf,
	TEMPLATE_PATH => "/etc/rc.d/init.d/diald",
	PERMS => 0755,
	});

unlink ("/dev/modem");
symlink ($conf{'DialupModemDevice'}, "/dev/modem");

esmith::util::processTemplate (\%conf,
	"/etc/sysconfig/network-scripts/ifcfg-ppp0");

esmith::util::processTemplate ({
	CONFREF => \%conf,
	TEMPLATE_PATH  => "/etc/sysconfig/network-scripts/chat-ppp0",
	PERMS => 0600,
	});

esmith::util::processTemplate ({
	CONFREF => \%conf,
	TEMPLATE_PATH => "/etc/ppp/ip-up.local",
	UID => "root",
	GID => "daemon",
	PERMS => 0755,
	});

esmith::util::processTemplate ({
	CONFREF => \%conf,
	TEMPLATE_PATH => "/etc/ppp/ip-down.local",
	UID => "root",
	GID => "daemon",
	PERMS => 0755,
	});

esmith::util::processTemplate ({
	CONFREF => \%conf,
	TEMPLATE_PATH => "/etc/ppp/options",
	UID => "root",
	GID => "root",
	});

esmith::util::processTemplate (\%conf, "/etc/diald.conf");
esmith::util::processTemplate (\%conf, "/etc/diald.filter");

esmith::util::processTemplate (\%conf, "/etc/diald/link");
esmith::util::processTemplate (\%conf, "/etc/ippp.conf");
esmith::util::processTemplate (\%conf, "/etc/ppp/ioptions");

exit (0);
