Forum Moderators: coopster & phranque

Message Too Old, No Replies

perl script used in unix to be used in windows

what line do i need to change?

         

rominosj

6:57 am on Mar 4, 2005 (gmt 0)

10+ Year Member



Hello,

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,

Matt Probert

7:26 am on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You MAY need to change the first line (from #!/usr/bin/perl to #!/perl/bin) which says where to find the Perl interpreter, though you may find Perl is in the environment path already on the Windows box.

Matt

jorj

8:09 am on Mar 4, 2005 (gmt 0)

10+ Year Member



from #!/usr/bin/perl to #!c:/perl/bin/perl

kaled

10:49 am on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Depending on what perl system you are using, on Windows, this line should be utterly irrelevant.

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.

Moby_Dim

6:53 pm on Mar 4, 2005 (gmt 0)

10+ Year Member



#!perl may be enough as a rule.

You must also check if all the modules needed are installed on your server.

And a script may not work on Windows if there are some unix functions not supported by windows (like flock() e.g.) in required modules. This happens too.

rominosj

7:49 pm on Mar 4, 2005 (gmt 0)

10+ Year Member



Hi,

The script coder says it should work both on unix and windows, but that I should check where perl is in my windows server. So, I will try the suggestions above.

Thanks all,

IamStang

4:55 am on Mar 9, 2005 (gmt 0)

10+ Year Member



I have Apache set up on a W2K Pro machine and the only way I have been able to get cgi scripts to work is to change:

#!/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