
TsuTsu
Novice
Sep 29, 2008, 7:00 PM
Post #1 of 16
(1094 views)
|
|
Automated Customer Account Creation
|
Can't Post
|
|
While it is atypical of me to post to a forum for help, I am genuinely perplexed by this problem. Please forgive me if I mess up. Problem: My script creates new accounts, but fails to populate the data fields (name, number, etc.) Description: I have been attempting to write a script which will extract data from an email and post it into a secure form. The email extractor is currently working and writing the data to a "|" delimited file which the account creation script reads from. The account creation script correctly reads that file and splits them into individual variables (tested with "print $var" for each). With this data, the script then uses WWW::Mechanize to login to the secure site and passes the cookies to LWP (since the site uses javascript for navigation). LWP then writes new POST headers to simulate submitting the form. While this does create a new user, none of the data fields (name, phone, etc.) are populated, even though I include them. My Code:
#!/usr/bin/perl use strict; use WWW::Mechanize; use HTTP::Cookies; use LWP::UserAgent; use LWP::Simple; my $url = "http://www.storesonlinepro.com/account"; my $sendmail = "/usr/sbin/sendmail -t"; my $reply_to = "Reply-to: No-Reply\@1lwdropship.com\n"; my $userdir = "/home/XXXX/.newUsers"; my $usercount = 0; my $cookie_jar = HTTP::Cookies->new( File => "/tmp/1lw-cookie.txt", AutoSave => 1, ignore_discard => 1 ); my $errors = "\n\nScript Run on: "; $errors .= `date +%D-%H:%M`; my $FILE; my $i; my $userTitle; my $userFirst; my $userMiddle; my $userLast; my $userDisplay; my $userCompany; my $userAddress; my $userCity; my $userCounty; my $userState; my $userZip; my $userCountry; my $userDayPhone; my $userEvePhone; my $userEmail; my $userFile; my $ua = new LWP::UserAgent; my $mech = WWW::Mechanize->new(); $mech->cookie_jar($cookie_jar); $mech->cookie_jar->clear; $mech->get($url); $mech->form_number(1); $mech->field('license', "XXXXXXX"); $mech->field('password', "XXXXXXX"); $mech->click('login'); print "logging in\n"; $mech->cookie_jar->save; print "Counting New Users...\n"; opendir(DIR, $userdir); LINE: while($FILE = readdir(DIR)) { next LINE if($FILE =~ /^\.\.?/); if(-d "$FILE"){ $errors .= "Unexpected Directory: $FILE. Skipping.\n" } else { $usercount++; } print $usercount . "\n"; } closedir(DIR); print "Done Counting\n"; for($i=1;$i<=$usercount;$i++) { print "Processing user $i\n"; $userFile = $userdir."/user.".$i; open USER, $userFile or $errors .= "Can't open $userFile: $!\n"; while (<USER>) { chomp; ($userTitle,$userFirst,$userMiddle,$userLast,$userDisplay,$userCompany,$userAddress,$userCity,$userCounty,$userState,$userZip,$userCountry,$userDayPhone,$userEvePhone,$userEmail) = split /\|/; } close USER; my $userLastLower = lc($userLast); $ua->cookie_jar($cookie_jar); $ua->cookie_jar->load; #--- my $response = $ua->post('https://www.storesonlinepro.com/account', Content_Type => 'application/x-www-form-urlencoded', Content => [ source => 'Customer_Menu', destination => '', customerfield =>'1', customervalue => '', customergroup => '-1', customersortby => '6', customersortdir => 'd', customer_viewstart => '0', customer_viewsize => '20', customers_selected => '', customer_viewstart_b => '0', customer_viewsize_b => '20', add => 'Add', account_id => 'XXXXXXX', account_changed => '', ]); my $content = $response->content; $content =~ /Customer_Edit_(\d+)/; my $formnumber = $1; #-- $response = $ua->post('https://www.storesonlinepro.com/account', { source => "Customer_Edit_$formnumber", destination => "Customer_Access_$formnumber", title => "$userTitle", first_name => "$userFirst", middle_name => "$userMiddle", last_name => "$userLast", display_name => "$userDisplay", company => "$userCompany", address1 => "$userAddress", city => "$userCity", county => "$userCounty", state => "$userState", postal_code => "$userZip", country => "$userCountry", dayphone => "$userDayPhone", evephone => "$userEvePhone", email => "$userEmail", account_id => 'XXXXXXX', account_changed => 'destination%2Ctitle%2Cfirst_name%2Cmiddle_name%2Clast_name%2Cdisplay_name%2Ccompany%2Caddress1%2Caddress2%2Caddress3%2Ccity%2Ccounty%2Cstate%2Cpostal_code%2Ccountry%2Cdayphone%2Cevephone%2Cemail', }); $content = $response->content; #--- $response = $ua->post('https://www.storesonlinepro.com/account', { source => "Customer_Access_$formnumber", destination => '', email => $userEmail, "groups_$formnumber" => "123", "groups_$formnumber" => "105003", "groups_$formnumber" => "105040", new_password => $userLastLower, confirm_password => $userLastLower, done => 'Done', account_id => 'XXXXXXX', account_changed => 'groups_$formnumber%2Cgroups_$formnumber%2Cgroups_$formnumber%2Cnew_password%2Cconfirm_password', }); $content = $response->content; } print "Writing Event Log\n"; open DATA, '>>event.log' or $errors .= "Can't open file: $!\n"; print DATA $errors; close DATA; Mockups of the Website Forms http://digitaldata.securesites.net/~cscott/NewUserPage0.html http://digitaldata.securesites.net/~cscott/NewUserPage1.html I realize, I'm probably just overlooking something stupid, but I'm still overlooking it. Any help is much appreciated. Thank you very much. -TsuTsu
(This post was edited by TsuTsu on Sep 29, 2008, 9:54 PM)
|