#!/usr/bin/perl -Tw # # $Id: cgi-test,v 1.3 2001-08-21 02:32:54 ivan Exp $ # # This is the beginning of a test suite for the web interface. # It's also excellent for populating your database with some meaningful test # data. (a derivative is used by the web demo) # It only works on an empty database (probably need empty counters too, and # no arbirary RADIUS attributes). # Usage: cgi-test http://base.freeside.url/with/path/ username password # (Yes, if you were properly paranoid and are using SSL, you'll need to get # libwww-perl working with SSL to use this.) use strict; #use diagnostics; use subs qw( big_ugly_data_structure ); use CGI; use LWP::UserAgent; my ( $base_url, $username, $password ) = ( shift, shift, shift ); #trust 'em $base_url =~ /^(.*)$/; $base_url = $1; $username =~ /^(.*)$/; $username = $1; $password =~ /^(.*)$/; $password = $1; my @data = &big_ugly_data_structure; my $ua = new LWP::UserAgent; { local $^W = 0; eval ' sub LWP::UserAgent::get_basic_credentials { #my $self = shift; ( $username, $password ); } '; } my $data; while ( $data = shift @data ) { my $cgi = new CGI ( $data->{'params'} ); my $full_url = $base_url. $data->{'url'}. '?'. $cgi->query_string; #my $request = new HTTP::Request( 'POST', $full_url ); my $request = new HTTP::Request( 'GET', $full_url ); my $response = $ua->request( $request ); if ( $response->is_redirect ) { die "Unexpected redirect!\n". "URL: $full_url\n". "To: ". $response->base. "\n" ; } elsif ( $response->is_success ) { my $location = $response->base; my $expected_location = $data->{'location'}; #if ( $location =~ /^$base_url$expected_location$/ ) { if ( $location eq $base_url. $expected_location ) { #warn "cool, got expected response $location from $full_url\n"; } else { die "Strange, regular response, but unexpected base!\n". "URL: $full_url\n". "Base : ". $response->base. "\n". "Expected: $base_url$expected_location\n". "Output: ". $response->content. "\n" ; } } elsif ( $response->is_error ) { die "Strange, I got an error\n". "URL: $full_url\n". "Error: ". $response->error_as_HTML. "\n". "Output: ". $response->content. "\n" ; } elsif ( $response->is_info ) { die "Strange, I got an info reponse\n". "URL: $full_url\n". "Output: ". $response->content. "\n" ; } else { die "Really strange, got an unrecognized response from LWP::UserAgent!\n"; } } #--- sub big_ugly_data_structure { ( { 'url' => 'edit/process/part_svc.cgi', 'params' => { 'svcpart' => '', 'svc' => 'Shell', 'svcdb' => 'svc_acct', 'svc_acct__popnum_flag' => '', 'svc_acct__popnum' => '', 'svc_acct__dir_flag' => '', 'svc_acct__dir' => '', 'svc_acct__username_flag' => '', 'svc_acct__username' => '', 'svc_acct__uid_flag' => '', 'svc_acct__uid' => '', 'svc_acct__quota_flag' => 'F', 'svc_acct__quota' => '10', 'svc_acct__slipip_flag' => 'F', 'svc_acct__slipip' => '', 'svc_acct___password_flag' => '', 'svc_acct___password' => '', 'svc_acct__gid_flag' => '', 'svc_acct__gid' => '', 'svc_acct__shell_flag' => 'D', 'svc_acct__shell' => '/bin/sh', 'svc_acct__finger_flag' => '', 'svc_acct__finger' => '', 'svc_domain__domain_flag' => '', 'svc_domain__domain' => '', 'svc_acct_sm__domuser_flag' => '', 'svc_acct_sm__domuser' => '', 'svc_acct_sm__domuid_flag' => '', 'svc_acct_sm__domuid' => '', 'svc_acct_sm__domsvc_flag' => '', 'svc_acct_sm__domsvc' => '', }, 'location' => 'browse/part_svc.cgi', }, { 'url' => 'edit/process/part_svc.cgi', 'params' => { 'svcpart' => '', 'svc' => 'SLIP/PPP', 'svcdb' => 'svc_acct', 'svc_acct__popnum_flag' => '', 'svc_acct__popnum' => '', 'svc_acct__dir_flag' => '', 'svc_acct__dir' => '', 'svc_acct__username_flag' => '', 'svc_acct__username' => '', 'svc_acct__uid_flag' => '', 'svc_acct__uid' => '', 'svc_acct__quota_flag' => 'F', 'svc_acct__quota' => '10', 'svc_acct__slipip_flag' => 'D', 'svc_acct__slipip' => '0.0.0.0', 'svc_acct___password_flag' => '', 'svc_acct___password' => '', 'svc_acct__gid_flag' => '', 'svc_acct__gid' => '', 'svc_acct__shell_flag' => 'D', 'svc_acct__shell' => '/bin/sh', 'svc_acct__finger_flag' => '', 'svc_acct__finger' => '', 'svc_domain__domain_flag' => '', 'svc_domain__domain' => '', 'svc_acct_sm__domuser_flag' => '', 'svc_acct_sm__domuser' => '', 'svc_acct_sm__domuid_flag' => '', 'svc_acct_sm__domuid' => '', 'svc_acct_sm__domsvc_flag' => '', 'svc_acct_sm__domsvc' => '', }, 'location' => 'browse/part_svc.cgi', }, { 'url' => 'edit/process/part_svc.cgi', 'params' => { 'svcpart' => '', 'svc' => 'POP Mailbox', 'svcdb' => 'svc_acct',, 'svc_acct__popnum_flag' => 'F', 'svc_acct__popnum' => '', 'svc_acct__dir_flag' => '', 'svc_acct__dir' => '', 'svc_acct__username_flag' => '', 'svc_acct__username' => '', 'svc_acct__uid_flag' => '', 'svc_acct__uid' => '', 'svc_acct__quota_flag' => 'F', 'svc_acct__quota' => '10', 'svc_acct__slipip_flag' => 'F', 'svc_acct__slipip' => '', 'svc_acct___password_flag' => '', 'svc_acct___password' => '', 'svc_acct__gid_flag' => '', 'svc_acct__gid' => '', 'svc_acct__shell_flag' => 'F', 'svc_acct__shell' => '/bin/passwd', 'svc_acct__finger_flag' => '', 'svc_acct__finger' => '', 'svc_domain__domain_flag' => '', 'svc_domain__domain' => '', 'svc_acct_sm__domuser_flag' => '', 'svc_acct_sm__domuser' => '', 'svc_acct_sm__domuid_flag' => '', 'svc_acct_sm__domuid' => '', 'svc_acct_sm__domsvc_flag' => '', 'svc_acct_sm__domsvc' => '', }, 'location' => 'browse/part_svc.cgi', }, { 'url' => 'edit/process/part_svc.cgi', 'params' => { 'svcpart' => '', 'svc' => 'Domain', 'svcdb' => 'svc_domain',, 'svc_acct__popnum_flag' => '', 'svc_acct__popnum' => '', 'svc_acct__dir_flag' => '', 'svc_acct__dir' => '', 'svc_acct__username_flag' => '', 'svc_acct__username' => '', 'svc_acct__uid_flag' => '', 'svc_acct__uid' => '', 'svc_acct__quota_flag' => '', 'svc_acct__quota' => '', 'svc_acct__slipip_flag' => '', 'svc_acct__slipip' => '', 'svc_acct___password_flag' => '', 'svc_acct___password' => '', 'svc_acct__gid_flag' => '', 'svc_acct__gid' => '', 'svc_acct__shell_flag' => '', 'svc_acct__shell' => '', 'svc_acct__finger_flag' => '', 'svc_acct__finger' => '', 'svc_domain__domain_flag' => '', 'svc_domain__domain' => '', 'svc_acct_sm__domuser_flag' => '', 'svc_acct_sm__domuser' => '', 'svc_acct_sm__domuid_flag' => '', 'svc_acct_sm__domuid' => '', 'svc_acct_sm__domsvc_flag' => '', 'svc_acct_sm__domsvc' => '', }, 'location' => 'browse/part_svc.cgi', }, { 'url' => 'edit/process/part_svc.cgi', 'params' => { 'svcpart' => '', 'svc' => 'Domain email alias', 'svcdb' => 'svc_acct_sm',, 'svc_acct__popnum_flag' => '', 'svc_acct__popnum' => '', 'svc_acct__dir_flag' => '', 'svc_acct__dir' => '', 'svc_acct__username_flag' => '', 'svc_acct__username' => '', 'svc_acct__uid_flag' => '', 'svc_acct__uid' => '', 'svc_acct__quota_flag' => '', 'svc_acct__quota' => '', 'svc_acct__slipip_flag' => '', 'svc_acct__slipip' => '', 'svc_acct___password_flag' => '', 'svc_acct___password' => '', 'svc_acct__gid_flag' => '', 'svc_acct__gid' => '', 'svc_acct__shell_flag' => '', 'svc_acct__shell' => '', 'svc_acct__finger_flag' => '', 'svc_acct__finger' => '', 'svc_domain__domain_flag' => '', 'svc_domain__domain' => '', 'svc_acct_sm__domuser_flag' => '', 'svc_acct_sm__domuser' => '', 'svc_acct_sm__domuid_flag' => '', 'svc_acct_sm__domuid' => '', 'svc_acct_sm__domsvc_flag' => '', 'svc_acct_sm__domsvc' => '', }, 'location' => 'browse/part_svc.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'Personal SLIP/PPP', 'comment' => '$30/setup, $19.99/month', 'setup' => '30', 'recur' => '19.99', 'freq' => '1', 'pkg_svc1' => '0', 'pkg_svc2' => '1', 'pkg_svc3' => '0', 'pkg_svc4' => '0', 'pkg_svc5' => '0', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'Personal SLIP/PPP', 'comment' => '$0/setup, $179.88/year', 'setup' => '0', 'recur' => '179.88', 'freq' => '12', 'pkg_svc1' => '0', 'pkg_svc2' => '1', 'pkg_svc3' => '0', 'pkg_svc4' => '0', 'pkg_svc5' => '0', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'Personal POP mailbox', 'comment' => '$10/setup, $5/month', 'setup' => '10', 'recur' => '5', 'freq' => '1', 'pkg_svc1' => '0', 'pkg_svc2' => '0', 'pkg_svc3' => '1', 'pkg_svc4' => '0', 'pkg_svc5' => '0', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'Business SLIP/PPP', 'comment' => '$30/setup, $29.99/month', 'setup' => '30', 'recur' => '29.99', 'freq' => '1', 'pkg_svc1' => '0', 'pkg_svc2' => '1', 'pkg_svc3' => '0', 'pkg_svc4' => '1', 'pkg_svc5' => '1', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'Business SLIP/PPP', 'comment' => '$0/setup, $299.88/year', 'setup' => '0', 'recur' => '299.88', 'freq' => '12', 'pkg_svc1' => '0', 'pkg_svc2' => '1', 'pkg_svc3' => '0', 'pkg_svc4' => '1', 'pkg_svc5' => '1', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'Business POP mailbox', 'comment' => '$10/setup, $5/month', 'setup' => '10', 'recur' => '5', 'freq' => '1', 'pkg_svc1' => '0', 'pkg_svc2' => '0', 'pkg_svc3' => '1', 'pkg_svc4' => '0', 'pkg_svc5' => '1', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'UNIX shell', 'comment' => '$20/setup, $9.99/month', 'setup' => '20', 'recur' => '9.99', 'freq' => '1', 'pkg_svc1' => '1', 'pkg_svc2' => '0', 'pkg_svc3' => '0', 'pkg_svc4' => '0', 'pkg_svc5' => '0', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'Point-to-point T1', 'comment' => '$1000/setup, $1000/month', 'setup' => '1000', 'recur' => '1000', 'freq' => '1', 'pkg_svc1' => '0', 'pkg_svc2' => '0', 'pkg_svc3' => '5', 'pkg_svc4' => '1', 'pkg_svc5' => '5', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/part_pkg.cgi', 'params' => { 'pkgpart' => '', 'pkg' => 'Cisco 2501 Router', 'comment' => '$2500', 'setup' => '2500', 'recur' => '0', 'freq' => '0', 'pkg_svc1' => '0', 'pkg_svc2' => '0', 'pkg_svc3' => '0', 'pkg_svc4' => '0', 'pkg_svc5' => '0', }, 'location' => 'browse/part_pkg.cgi', }, { 'url' => 'edit/process/agent_type.cgi', 'params' => { 'typenum' => '', 'atype' => 'Internal Sales', 'pkgpart1' => 'ON', 'pkgpart2' => 'ON', 'pkgpart3' => 'ON', 'pkgpart4' => 'ON', 'pkgpart5' => 'ON', 'pkgpart6' => 'ON', 'pkgpart7' => 'ON', 'pkgpart8' => 'ON', 'pkgpart9' => 'ON', }, 'location' => 'browse/agent_type.cgi', }, { 'url' => 'edit/process/agent.cgi', 'params' => { 'agentnum' => '', 'agent' => 'Internal Sales', 'typenum' => '1', 'freq' => '', 'prog' => '', }, 'location' => 'browse/agent.cgi', }, { 'url' => 'edit/process/part_referral.cgi', 'params' => { 'refnum' => '', 'referral' => 'Another customer', }, 'location' => 'browse/part_referral.cgi', }, { 'url' => 'edit/process/part_referral.cgi', 'params' => { 'refnum' => '', 'referral' => 'Newspaper ad', }, 'location' => 'browse/part_referral.cgi', }, { 'url' => 'edit/process/svc_acct_pop.cgi', 'params' => { 'popnum' => '', 'city' => 'Line Lexington', 'state' => 'PA', 'ac' => '215', 'exch' => '996', }, 'location' => 'browse/svc_acct_pop.cgi', }, { 'url' => 'edit/process/svc_acct_pop.cgi', 'params' => { 'popnum' => '', 'city' => 'Oakland', 'state' => 'CA', 'ac' => '510', 'exch' => '208', }, 'location' => 'browse/svc_acct_pop.cgi', }, { 'url' => 'edit/process/cust_main.cgi', 'params' => { 'custnum' => '', 'agentnum' => '1', 'refnum' => '1', 'last' => 'Hogan', 'first' => 'Shawn D.', 'ss' => '', 'company' => 'Digital Point Solutions', 'address1' => '3570 Tony Drive', 'address2' => '', 'city' => 'San Diego', 'state' => 'CA / US', 'zip' => '92122-2307', 'daytime' => '', 'night' => '', 'fax' => '', 'tax' => '', 'invoicing_list_POST' => '', 'invoicing_list' => '', 'payby' => 'BILL', 'CARD_payinfo' => '', 'CARD_month' => '1', 'CARD_year' => '1999', 'CARD_payname' => '', 'BILL_payinfo' => '', 'BILL_month' => '12', 'BILL_year' => '2037', 'BILL_payname' => 'Accounts Payable', 'COMP_payinfo' => '', 'COMP_month' => '1', 'COMP_year' => '1999', 'pkgpart_svcpart' => '1_2', 'username' => 'cyborg', '_password' => '', 'popnum' => '1', 'otaker' => 'example', }, 'location' => 'view/cust_main.cgi?1', }, { 'url' => 'edit/process/cust_main.cgi', 'params' => { 'custnum' => '', 'agentnum' => '1', 'refnum' => '2', 'last' => 'Ford', 'first' => 'Bill', 'ss' => '', 'company' => 'Boardtown Corporation', 'address1' => '116 East Main Street', 'address2' => '', 'city' => 'Starkville', 'state' => 'MS / US', 'zip' => '39759', 'daytime' => '', 'night' => '', 'fax' => '', 'tax' => '', 'invoicing_list_POST' => '', 'invoicing_list' => '', 'payby' => 'BILL', 'CARD_payinfo' => '', 'CARD_month' => '1', 'CARD_year' => '1999', 'CARD_payname' => '', 'BILL_payinfo' => '', 'BILL_month' => '12', 'BILL_year' => '2037', 'BILL_payname' => 'Accounts Payable', 'COMP_payinfo' => '', 'COMP_month' => '1', 'COMP_year' => '1999', 'pkgpart_svcpart' => '3_3', 'username' => 'billf', '_password' => '', 'popnum' => '', 'otaker' => 'example', }, 'location' => 'view/cust_main.cgi?2', }, ); }