Please help. what should I change the first line to make this perl script work in Windwos server.
This is a help desk script that works on unix and it is said also on windows:
My hosting provider tells me perl is located at:
Perl Path: c:\perl\bin
----------------------------------------------------------
#!/usr/bin/perl
#
#
my $configfile;
# ==== NOTHING TO EDIT BELOW THIS LINE. PLS DO NOT CROSS =======================
BEGIN {
if ($^O eq 'MSWin32') {
eval "use FindBin";
eval "use lib $FindBin::Bin";
chdir($FindBin::Bin);
}
}
use strict;
use CGI;
use TTXConfig;
use TTXSetup;
use TTXData;
#
# Global vars
#
my $cfg;
my $query;
my %data;
print "Content-type: text/html\n\n";
header();
#
# Read config
#
$configfile = 'ttxcfg.cgi' if $configfile eq undef;
$cfg = TTXConfig->new($configfile);
my $freshsetup = 1 if $cfg->error() ne undef;
if ($cfg->get('cfgref') ne undef) {
my $regcfg = TTXConfig->new($cfg->get('cfgref'));
$cfg = $regcfg;
$freshsetup = 1 if $cfg->error() ne undef;
}
#
# Parse input
#
$query = new CGI;
#
# Validate user if not fresh setup and id provided
#
if (!$freshsetup) {
TTXData::set('CONFIG', $cfg);
if ($query->param('pwd') ne undef) {
if ($cfg->get('admpwd') ne $query->param('pwd')) {
login();
}
} elsif ($cfg->get('admpwd') ne undef) {
login();
} else {
$query->param(-name => 'cmd', -value => 'setup3');
}
}
#
# Execute command
#
my $cmd = $query->param('cmd');
$cmd = 'setup1' if $cmd eq undef;
if ($cmd eq 'setup1') {
TTXSetup::setup1($cfg, $query);
} elsif ($cmd eq 'setup2') {
TTXSetup::setup2($cfg, $query);
} elsif ($cmd eq 'setup3') {
TTXSetup::setup3($cfg, $query);
} elsif ($cmd eq 'setup4') {
TTXSetup::setup4($cfg, $query);
} elsif ($cmd eq 'setup5') {
TTXSetup::setup5($cfg, $query);
} elsif ($cmd eq 'login') {
dologin();
}
footer($ENV{'QUERY_STRING'}!~ /pwd=/? 1:0);
#======================================================================= dologin
sub dologin {
my $error;
if ($query->param('do')) {
if ($query->param('passwd') eq undef ¦¦ $query->param('passwd') ne $cfg->get('admpwd')) {
$error = "Invalid password";
} else {
$query->param(-name => 'pwd', -value => $query->param('passwd'));
$query->param(-name => 'do', -value => '');
TTXSetup::setup4($cfg, $query);
return;
}
}
$error = "<br><font color=red><b>Error: $error</b></font><br><br>" if $error ne undef;
print <<EOT;
<center><b>Please login</b>
<br><br>$error
<table cellpadding=3>
<form action=$ENV{SCRIPT_NAME} method=post>
<input type=hidden name=cmd value=login>
<input type=hidden name=do value=1>
<tr>
<td align=left class=lbl>Administrator password</td>
<td align=left><input type=password name=passwd></td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=submit>
</td>
</tr>
</form>
</table>
</center>
EOT
}
#========================================================================= login
sub login {
$query->param(-name => 'pwd', -value => '');
$query->param(-name => 'cmd', -value => 'login');
}
#==================================================================== fatalerror
sub fatalerror {
print <<EOT;
<html>
<head><title>Trouble Ticket Express</title></head>
<body>
<br><center><h1>Fatal Error: $_[0]</h1>
</body>
</html>
EOT
exit;
}
sub header {
print <<EOT;
<html>
<head>
<title>
Trouble Ticket Express Setup
</title>
<style type="text/css">
body, td { font-family: Verdana, Helvetica, sans-serif; font-size: 10pt;}
A { color : #2E3197; text-decoration : none; }
A:Hover { color : #C00; text-decoration : underline;}
.sm {font-size: 8pt;}
.tiny {font-size: 4pt;}
.heading {font-size: 13pt;font-weight: 700; color: #2E3197;}
.lbl {font-size: 9pt;font-weight: 700;}
</style>
</head>
<body>
<center>
<table width=700>
<tr>
<td align=left>
EOT
}
# ======================================================================= footer
sub footer {
print <<EOT;
</td></tr>
</table>
EOT
if ($_[0]) {
print <<EOT;
<!-- Live help code placeholder -->
EOT
}
print <<EOT;
</center>
</body>
</html>
EOT
}
--------------------------------------------------
Thanks,
I don't know Unix, but I believe that it is an instruction as to where to locate the program to run the script. Windows will locate the program (the perl interpreter) based solely on the file extension.
Kaled.
#!/usr/bin/perl to #!c:\perl\bin\perl.exe
and this is assuming that you installed perl to c:\perl
Another thing you will need to do while editing your scripts is this. Everywhere in your code that it calls for "print" you will need to insert a line above it that reads: print "Content-type: text/html\n\n"; (unless it is printing to a file).
Ex:
print "Content-type: text/html\n\n";
print "This is what would appear";
print "on the page when loaded";
print "in a browser";
However, to me, the script you show above looks to have covered that already. Just something to keep in mind on future scripts.
Hope it helps!
IamStang