#!/usr/local/bin/perl $user = $ARGV[0]; $reason = $ARGV[1]; $junk = $ARGV[2]; # # 15-Apr-1999 pdr Removed majordomo code # 15-Feb-2000 pdr Delete credit cards after they cancel # use Postgres; use Strict; if ($> != 0) { print "You gotta be root!!!! Use su and try again.\n\n"; exit; } if (($user eq "") || ($reason eq "")){ print "usage: cancel_service \n"; print " should be enclosed in \" if there is more than one word.\n"; exit; } if ($junk ne "") { print "Put the reason in double quotes dummy!\n"; exit; } $email = 0; $found = 0; open(PASSWD, "/etc/master.passwd") || die "couldn't open passwd file (1): $!"; if (!flock(PASSWD,2|4)) { print "Password file is locked; try again later; no action taken.\n"; exit; } open(CANCPASSWD, ">>/etc/master.passwd.cancelled") || die "couldn't open cancelled passwd file: $!"; if (!flock(CANCPASSWD,2|4)) { print "The cancelled password file is locked; try again later; no action taken.\n"; exit; } @passwd=; foreach $i (0 .. $#passwd) { ($username, $p, $u, $g, $cl, $ch, $e, $ge, $dir, $shell, $r) = split(/:/, $passwd[$i], 11); if (($user eq $username) || ('#'.$user eq $username)) { $found = 1; chop $shell ; # print "shell=$shell\n"; # print "dir=$dir\n"; } } if ($shell eq "E") { $email = 1 ; } if ($found == 0) { print "$user doesn't exist or no home directory; no action taken.\n"; exit; } $dbh = db_connect("uam", "liver.infocom.com", "5432"); if (!$dbh) { print "Error connecting to uam database: $Postgres::error\n"; print "Let Charlie know about this, no action taken!\n"; exit; } $sql = "select subscriber_id, username, real_name, stype " . "from service " . "where username = '$user' " ; $result = $dbh->execute("$sql"); if (!$result) { print "Select from service failed: $Postgres::error\n"; print "Let Charlie know about this, no action taken!\n"; exit; } $how_many = $result->ntuples(); if ($how_many == 0) { print "Warning - no matching row for $user in service table, will do Unix only.\n"; goto unix_cleanup; } if ($how_many > 1) { print "Found multipule rows for $user in the service table. This is\n"; print "a problem. Let Charlie know about this, no action taken!\n"; exit; } @array = $result->fetchrow(); $sid = @array[0]; $username = @array[1]; $real_name = @array[2]; $stype = @array[3]; # # Make sure they're not flagged dont_cancel # $sql1 = "select last_name from subscriber " . "where subscriber_id = $sid " . "and not dont_cancel " ; $result1 = $dbh->execute("$sql1"); if (!$result1) { print "Select from subscriber failed: $Postgres::error\n"; print "Let Charlie know about this, no action taken!\n"; exit; } $count = $result1->ntuples(); if ($count == 0) { print "This subscriber appears to be flagged as dont_cancel, check on this.\n"; print "No action taken!\n"; exit; } if ($stype eq "Email") { $email++; } $today = `date "+%b %d %Y"`; $sql = "update service set end_date = '$today', dont_bill = null " . "where username = '$user' "; $result = $dbh->execute("$sql"); if (!$result) { print "Update of service failed: $Postgres::error\n"; print "Let Charlie know about this, no action taken!\n" ; exit; } $reason =~ s/'/\\'/g; $sql = "insert into history values ($sid, 'Cancelled', " . "'$today', '$user, $reason') "; $result = $dbh->execute("$sql"); if (!$result) { print "Insert into history failed: $Postgres::error\n"; print "Let Charlie know about this, no action taken!\n"; exit; } $sql = "select subscriber_id from credit_account " . "where subscriber_id = $sid "; $result = $dbh->execute("$sql"); if ($result) { $sql = "delete from credit_account where subscriber_id = $sid "; $result = $dbh->execute("$sql"); if (!$result) { print "Delete from credit_account failed: $Postgres::error\n"; print "Let Paul know about this, no action taken!\n"; exit; } } # xxx # # Check their balance, if it's greater than 0 ask if a credit memo should # be issued or if a letter asking for the payment should be generated. # One or the other. # unix_cleanup: if ($email == 0) { `/bin/rm -rf $dir`; } else { print "Service type of Email, not removing $dir\n"; } `/bin/rm -rf /var/mail/$user`; `/bin/rm -rf /var/mail/.$user.pop`; open(PASSWD, ">/etc/master.passwd") || die "couldn't open new passwd file: $!"; if (!flock(PASSWD,2|4)) { print "Password file is locked; you are seriously screwed because the postgress\n"; print "portion has completed but the unix cleanup is not complete. Talk to somebody\n"; print "that knows what the hell they are doing. (Like Paul)\n" } foreach $i (0 .. $#passwd) { ($username, $remainder) = split(/:/, $passwd[$i], 2); if (($user eq $username) || ('#'.$user eq $username)) { print CANCPASSWD $passwd[$i]; } else { print PASSWD $passwd[$i]; } } close(PASSWD); close(CANCPASSWD); `pwd_mkdb -p /etc/master.passwd`; open (MAILTO, "|mail -s cancelled_subscriber staff"); print MAILTO "username=${user}, real name=${real_name}\n"; print MAILTO "${reason}"; close(MAILTO); exit;