Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"submitter" cgi script:doesn't work...

Status
Not open for further replies.

Perlwannabe

Technical User
Mar 7, 2006
57
IT
Hello,

I made a short cgi script in order to submit automatically new pages on my web site;what that script should do,is to "pick up" a random number of titles from a text file called key_list.txt and submit them to a specific form on a control panel(cgi)that "transforms" them in real html pages.
Also,it should be "cronned", in order to get constant daily submission.
Really what happens is that the script itself seems to work fine, the cron job output confirm the number and the name of the new submitted pages, but when I enter the control panel, no new page is added...
I already checked the script a million of times but I'm not able to understand where is the error.
Seems like if the script is not ableto enter the cpanel...
Could someone help me,please?

Here is the script I'm trying in localhost at the moment (already tested unsuccessfully on a real server):

Code:
#!perl


#	Configuration

#	cpanel psw

$password = 'blabla';

#	cpanel url

$admin_url_base = '[URL unfurl="true"]http://localhost/cgi-bin/sector/test/control.cgi';[/URL]

#	cpanel data folder

$data_dir = 'data';


# 	minimum pages number

$minpages = 1;

#	maximum pages number
$maxpages = 5;

#       path to this script (for cron job)

$fullpath = '/indigoperl/apache/cgi-bin/sector/test/';


##### script #####

use CGI::Carp qw (fatalsToBrowser);
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;

$keywords = 'key_list.txt';
$klist = '';
$admin_url = $admin_url_base . '?createpages';
open (KEYS, "<$fullpath$keywords");
@kd = <KEYS>;
close (KEYS);

srand();
$range = $maxpages - $minpages;
$random_number = int(rand($range)) + $minpages;

for ($a=1;$a<=$random_number;$a++){
	$klist .= shift(@kd);
}
chomp($klist);

@completed = split(/\n/,$klist);

open (KEYS, ">$fullpath$keywords");
print KEYS @kd;
close (KEYS);

$req = (POST $admin_url,
    [ 
		'pass' => $password,
		'dataflag' => '1',
		'pagenames' => $klist
    ]);

$response = $ua->request($req);

print "Content-type: text/html\n\n";
print "Number of pages created: $random_number<br>\n";
foreach(@completed){
	print $_."<br>\n";

Thanks in advance for any help

Sincerely
 
it looks like you are building a query string here:

Code:
$admin_url = $admin_url_base . '?createpages';


but then it looks like you are using POST to try and send data to the sctipt:

Code:
$req = (POST $admin_url,
    [
        'pass' => $password,
        'dataflag' => '1',
        'pagenames' => $klist
    ]);

maybe it should be:

Code:
$req = (POST $admin_url_base,
    [
        'createpages' => '', 
        'pass' => $password,
        'dataflag' => '1',
        'pagenames' => $klist
    ]);

- Kevin, perl coder unexceptional!
 
It doesn't work...

The script seems to fail to login at $admin_url_base

The script should work in this way:

-open the key_list.txt file
-pick up a number of titles
-close key_list.txt file
-Open the cpanel at $amin_url_base
-login with password
-Open the text file to copy the new page titles at $amin_url_base.'?newpage';
-close the text file to confirm the copy at $admin_url_base.'?createpages';

Seems so straight, but I don't understand...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top