#!/usr/bin/perl -w
##
## printenv -- demo CGI program which just prints its environment
##
use CGI::Carp 'fatalsToBrowser';
$ok="exists and ready for changes";
$wrn="WARNING!!! NOT exists, but it will be created";
sub checkfile {
if(-e $_[0]) {
print "File: ", $_[0], "$ok\n";
}
else {
print "File: ", $_[0], "$wrn\n";
}
}
print "Checking files...\n";
#/etc/rc.local
&checkfile("/etc/rc.local");
#/etc/ppp/options.pptp
&checkfile("/etc/ppp/options.pptp");
#/etc/ppp/chap-secrets
&checkfile("/etc/ppp/chap-secrets");
#/etc/ppp/peers/inet
&checkfile("/etc/ppp/peers/inet");
print "Enter your IP address in format like 66,66,66,66:\n";
$line=<STDIN>;
chomp $line;
#chomp $line;
#print "Your ip is: \n";
@ip=split(/,/, "$line");
#print "$ip[2]";
$gw="10.0.$ip[2].254";
print "Your gateway is: $gw\n";
print "Select your packet type:\n1 for unlimited;\n2 for limited;\n";
print "print 1 or 2:";
$choice=<STDIN>;
#print "$choice";
if ($choice==1) {
print "unlimited type selected.\nContinue...\n";
$server="10.0.0.253";
$serverhost="unlimited.telesweet.net";
print "Server address: $server\n";
}
if($choice==2) {
print "limited type selected.\nContinue...\n";
$server="10.0.0.8";
$serverhost="10.0.0.8";
print "Server address: $server\n";
}
print "Enter your VPN login:";
$login=<STDIN>;
chomp $login;
#print "$login";
print "Enter your VPN Password:";
$pass=<STDIN>;
chomp $pass;
#Configuring VPN now
open(CHAP, ">/etc/ppp/chap-secrets")|| print "Not opened CHAP-SECRETS";
open(OPTIONS, ">/etc/ppp/options.txt")|| print "Not opened options.pptp";
open(RC, ">/etc/rc.local")|| print "Not opened rc.local";
print "default peer is: inet\n If you want another VPN connection name - correct in in script on line 60.\n";
open(PR, "/etc/ppp/peers/inet")|| print "Not opened peer file";
if (print RC "route del default\nroute add -net 10.0.0.0 netmask 255.0.0.0 gw $gw\nip r a $server via $gw\n\nexit 0") {
print "rc.local configured\n";
close(RC);
}
else {
print"Error writing RC.LOCAL, maybe you not root?\n";
close(RC);
}
if(print CHAP "# Secrets for authentication using CHAP\n# client server secret IP addresses\n$login * $pass\n$login * $pass $serverhost") {
print "chap-secrets configured\n";
close(CHAP);
}
else {
print "Error writing CHAP-SECRETS\n";
close(CHAP);
}
if(print OPTIONS "lock\nnoauth\nrefuse-eap\nrefuse-chap\nrefuse-mschap\nnobsdcomp\nnodeflate\nnomppe\n#nomppc\npersist\nholdoff 10\nconnect /bin/true\ndefaultroute") {
print "options.pptp configured\n";
close(OPTIONS);
}
else {
print "Error writing OPTIONS.PPTP\n";
}
if(print PR "remotename $serverhost\nlinkname internet\npty \"/usr/sbin/pptp gw.vpn.telesweet.net --nolaunchpppd\"\nname $login\nfile /etc/ppp/options.pptp") {
print "peer configured\n";
close(PR);
}
else {
#print "Error writing OPTIONS.PPTP\n";
close(PR);
}
print "Configurating vpn complete\n";
print "Now, type under root: /etc/rc.local and than pon inet(if you using default peer name)\n";
print "Press enter or control+c to exit this script\n";
$last=<STDIN>;
chomp $last;
print "Script author - Noxx\n\n";
exit 0;