#!/usr/bin/perl5
# ppp-out.cgi
# Scott A. Hotes, 3 / 29 / 96
# Silicon Graphics
#
# User will only be allowed to edit (or add) entries to ppp.conf
# that correspond to existing configuration lines in the
# /etc/uucp/Systems file, thus insuring (we hope) that the
# hardware is set up correctly. Entries in ppp.conf that
# do not correspond to lines in the Systems file will be ignored.
#
# T1 is ignored for now.
# Also, does not deal with multiple isdn phone numbers!
#
# The following items are supported in the configuration file:
# - remotehost (both as IP number or qualified name)
# - localhost (same)
# - send_username
# - send_passwd
# - add_route
# - quiet
#
# Delete and edit both comment-out currently existing accounts.
require "/usr/OnRamp/lib/OnRamp.pm";
$confS = "/etc/uucp/Systems";
$conf = "/etc/ppp.conf";
$temp = "/etc/ppp.conf.temp";
$dummy = "/etc/ppp.conf.temp";
$myname = "ppp-out.cgi";
$title = "Dial-out PPP Accounts";
print "Content-type: text/html\n\n";
&title_block($title);
if ( ! -e "/usr/etc/ppp" ) {
&header_block($title);
print "PPP software not installed. Install subsystem
eoe.sw.ppp from the 6.2 CD.";
exit 0;
}
&get_fields;
&getAccounts;
if (%fld) {
$fld{'chosen'} =~ /(\w+)/;
$name = $1;
$help = $ENV{"DOCUMENT_ROOT"} . $ENV{"SCRIPT_NAME"};
$help =~ s/cgi$/hlp/;
exec $help if ($fld{'help'} eq "Help");
$hardware = &getHardware($name);
if ($fld{'edit'}) {
&error(2,"To edit, first choose account from list.") if !$fld{'chosen'};
&putEdit;
&editAccount;
}
if ($fld{'doedit'}) { &formValid_doedit; &doEdit; &getAccounts; &generic; }
} else { &generic; }
sub getHardware {
open(IN,"< $confS");
while() {
@items = split/\s+/;
if ($items[0] eq $_[0]) { $hw = $items[2]; last; }
}
close(IN);
if ($hw eq "ACU") { return "Modem"; }
elsif ($hw eq "ISDN") { return "ISDN"; }
else { return "T1"; }
}
sub formValid_doadd {
&error(0,"Invalid login name.") if &deluxe($fld{'login'});
&error(0,"Invalid password.") if &deluxe($fld{'password'});
&error(0,"Invalid remote IP address.") if &check_ipaddr($fld{'remote'});
}
sub formValid_doedit {
&error(1,"Invalid login name.") if deluxe($fld{'login'});
&error(1,"Invalid password.") if deluxe($fld{'password'});
if ($fld{'remote'} ne "") {
&error(1,"Invalid remote IP address.") if &check_ipaddr($fld{'remote'});
}
}
sub deluxe {
return 1 if $_[0] =~ /$METACHARS/;
return 1 if $_[0] =~ /\s/;
return 1 if length($_[0]) > 8;
0;
}
sub error {
&error_block($_[1]);
%val = %fld;
if ($_[0] == 0) { &addAccount; }
elsif ($_[0] == 1) { &editAccount; }
else { &generic; }
exit 0;
}
sub putEdit {
$val{'local'} = $local{$name};
$val{'remote'} = $remote{$name};
$val{'login'} = $login{$name};
$val{'password'} = $password{$name};
$val{'addRoute'} = $addRoute{$name};
$val{'quiet'} = $quiet{$name};
}
sub doEdit {
open(IN,"< $temp");
$name = ;
close(IN);
&clear($temp);
chop $name;
if ($name) { &delete($name); }
&doAdd;
$message = "Account edited.";
}
sub clear {
open(OUT_0,"> $_[0]");
close(OUT_0);
}
sub editAccount {
&header_block("Edit Dial-out PPP Account");
print "