#!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Response; use Term::ReadKey; $| = 1; my $ua = LWP::UserAgent->new(); $ua->cookie_jar({}); my $loginurl="https://adminws.wlu.edu/servlet/com.datatel.server.servlets.webadvisor.WebAdvisor?MENU=fc&MNEMONIC=WCLR&APPLICATION=ST&"; my $appurl="https://adminws.wlu.edu/servlet/com.datatel.server.servlets.webadvisor.WebAdvisor"; my $shortterm=shift; ($shortterm =~ m/([W|F|S])(\d\d)/) || die ("Usage: registrar W05\n"); my $term = $2."/U".$1; # $term now has something like 05/UW $ua->agent("ArcticFox/v1.0.1"); my $userid; my $password; print "\nUser ID: "; $userid = ReadLine 0; chomp $userid; print "Password: "; ReadMode 'noecho'; $password = ReadLine 0; chomp $password; ReadMode 'normal'; print "\n\n"; my %fields=("USERID"=>$userid, "PASSWORD"=>$password, "APPLICATION"=>"APPLICATION", "MNEMONIC"=>"MNEMONIC", "ACTION"=>"ACTION", "SESSION"=>"SESSION"); my $loginattempt = $ua->post( $loginurl, \%fields); print "Logged in.\n"; my $loginresponse=$loginattempt->content; my $var1; %fields = (); my @lines = split(/\n/,$loginresponse); foreach (@lines) { if (/option value[\s=]+($term[^<]+)>/i) { $var1=$term; $fields{"VAR1"}=$var1; }; if (/HIDDEN/) { #this should probably use NAME instead of ID if (/id[\s=]+"([^"]+)".*value[\s=]+"([^"]+)"/i) { $fields{$1}=$2; }; }; }; #Send the term, hopefully receive a list of sections in reply $appurl="https://adminws.wlu.edu/servlet/com.datatel.server.servlets.webadvisor.WebAdvisor"; my $termselection = $ua->post( $appurl, \%fields); print "Sent term request.\n"; #Now, clear the fields hash; scrape out the names of checkboxes, and catch any hidden fields. #Checkbox names get stored in @chex %fields = (); @lines = split(/\n/,$termselection->content); my @chex = (); foreach (@lines) { if (/checkbox/i) { m/NAME[\s=]+"([^"]*)"/i; push (@chex,$1); }; if (/HIDDEN/) { if (/id[\s=]+"([^"]+)".*value[\s=]+"([^"]+)"/i) { $fields{$1}=$2; }; }; }; my $section; my $filename; my $csvline; my $rollresponse; my @buffer = (); my $opentd="]*>"; my $closetd="<\/TD"; my $opena="]*>"; my $closea="<\/a"; for $section (@chex) { $fields{$section}="on"; $rollresponse = $ua->post( $appurl, \%fields ); delete($fields{$section}); @lines = split(/\n/,$rollresponse->content); @buffer = (); $filename = ""; for (@lines) { if (/TD.*Course_Name_and_Title[^>]*>([^<]*)".$filename; print ROLL @buffer; close ROLL; }; };