#!/usr/bin/perl 
# Connect to UCCS with PPP

# Setup list with numbers to call 
# 593-2894 528-1028 is 28k8, the others are 14k4
@number = (
  '593-2894', '528-1028', '260-5911', '594-9850', 
  '593-2894', '528-1028', '260-5911', '594-9850', 
  '593-2894', '528-1028', '260-5911', '594-9850', 
  '593-2894', '528-1028', '260-5911', '594-9850', 
  '593-2894', '528-1028', '260-5911', '594-9850', 
);

# First part of "chat" expect/response pairs
@chat1 = (
  "ABORT \"BUSY\"\n",
  "ABORT \"NO CARRIER\"\n",
  "ABORT \"NO DIAL TONE\"\n",
  "\"\" \"at&d0&c1\"\n",

);

# Second part, one of the numbers above will be slipped between @chat
# and @chat2a  for terminal servers use username: password: annex:ppp
#                  such as 593-2894
#     @chat2b  for terminal servers use host:ppp login: password: 
#                  such as 538-1028 260-5911 594-9850
# different terminal servers have different login sequence
#
@chat2a = (
   "host: ppp",
   "name: <your login on the terminal server\n",
   "word: <your password>\n",
);
@chat2b = (
   "name: <your login on the terminal server>\n",
   "word: <your password>\n",
   "nnex: ppp\n",
);

# for dial up to a linux box with attached modem
#  "ogin: jhjulkun\n",
#  "word: xxxxx\n",
#  "mpc7 /usr/sbin/pppd\n",
#

chdir("/usr/local/bin");
$i = 0;

eval `/sbin/route del default`;
while (1) {
  open(CHAT, ">pppuccs.chat"); 
  print(CHAT @chat1);
  print(CHAT "SAY \"Dialing", $number[$i], "...\"\n");
  print(CHAT "OK \"atdt", $number[$i], "\"\n");
  print(CHAT "TIMEOUT 120\n");
  print(CHAT "CONNECT \"\"\n");
  if ($number[$i] eq "593-2894" || $number[$i] eq "594-9850") {
    print(CHAT @chat2a);
  } else {
    print(CHAT @chat2b);
  }
  close(CHAT);
  print "Trying ", $number[$i], "\n";
  system("/usr/sbin/pppd connect '/usr/sbin/chat -v -V -f pppuccs.chat -t 240' /dev/cua1 38400 -detach crtscts modem defaultroute"); 

  $i++;
  if ($i > $#number) {
    $i = 0;
  }
}

