I am setting up environment for CGI script. For that I am following this link: http://help.cs.umn.edu/web/cgi-tutorial
I have written sample CGI script in my Ubuntu environment which is hosted in other server. I am connecting this server using PuTTY. I have successfully given permission to script file and directory. Now to test it, as mentioned in above link.
Below is the code of CGI script i have used:
#!/usr/bin/perl -w
use CGI;
$cgi = new CGI();
print $cgi->header();
print '<?xml version="1.0" encoding="UTF-8"?>';
print '<!DOCTYPE html>
<html>
<head>
<title>Perl CGI test</title>
</head>
<body>';
print '
<p>
Hello world!
</p>';
print '
</body>
</html>
';
I am opening http://www-users.cselabs.umn.edu/~ <your_username>/test-cgi.cgi in my own system in Chrome and Firefox browsers.
Below error is displayed:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
www-users.cselabs.umn.edu
Thu Jun 11 01:56:35 2015
Apache.
How should I execute it successfully?
Note: CGI script is written on server which is accessed by PuTTY and WinSCP. And I am opening test URL on my own system i.e. windows in Chrome and Firefox.
Related
I am trying to install a Let's Encrypt SSL certificate to a subscription held on a Plesk install.
I am running the following version of Plesk;
Plesk Onyx Version 17.8.11 Update #11
I then navigate to
Subscriptions > Domain > Lets Encrypt
From the setup screen I do not change anything, so
'Include a "www" subdomain for the domain and each selected alias'
and
'Secure webmail on this domain'
Remain unchecked. However, when I try to install the cert I get the following error;
Error: Could not issue a Let's Encrypt SSL/TLS certificate for domain.org.
The authorization token is not available at http://example.com/.well-known/acme-challenge/key.
The token file 'C:\Inetpub\vhosts\example.com\httpdocs\\.well-known\acme-challenge\key' is either unreadable or does not have the read permission.
To resolve the issue, correct the permissions on the token file to make it is possible to download it via the above URL.
See the related Knowledge Base article for details.
Details
Invalid response from https://acme-v01.api.letsencrypt.org/acme/authz/umis0L7-OVlu7SrSjMFHBsu-T7Cx0hwFS-WMxHgZgNA.
Details:
Type: urn:acme:error:unauthorized
Status: 403
Detail: Invalid response from http://example.com/.well-known/acme-challenge/key: "<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-sc"
It give a link to the following KB;
Plesk Suggested KB article
Which suggest I check the DNS resovles, so ipconfig shows me that the domain is pointing to the right IP.
However I dont have the ability for IPv6 and when i go to
domains > example.com> Web Hosting Access
I do not have the ability to select this.
Now from RDP to the server and looking I can see the directory structure is created i..e
.well-known > acme-challenge > key file
is created? Can anyone help with what the issue could be here please?
Check if the domain name resolves to IPv6 or not:
dig AAAA google.com #8.8.8.8
Check permissions for token file well-known > acme-challenge > key file
Try to access this file via browser, or create a new test text file inside of the acme-challenge folder and try to access it. There is a possibility that web.config file can cause the issue.
I'm not sure if this the correct place to be asking this question. But I am having trouble getting my cgi scripts to run on my XAMPP Server (using windows 8 and apache) here is my cgi script:
#!usr/bin/perl
use warnings;
use diagnostics;
use strict;
my $time = localtime;
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};
my $admin_email = $ENV{SERVER_ADMIN};
print <<END_OF_PAGE;
<HTML>
<HEAD>
<TITLE>Welcome to Mike's Mechanics Database</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<IMG SRC="/images/mike.jpg" ALT="Mike's Mechanics">
<P>Welcome from $remote_host! What will you find here? You'll find a list of mechanics
from around the country and the type of service to expect -- based on user input and
suggestions.</P>
<P>What are you waiting for? Click here
to continue.</P> <HR> <P>The current time on this server is: $time.</P>
<P>If you find any problems with this site or have any suggestions,
please email $admin_email.</P>
</BODY>
</HTML>
END_OF_PAGE
and here is the full error I am getting:
**Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
couldn't create child process: 720002: welcome.cgi
If you think this is a server error, please contact the webmaster.
Error 500
localhost
Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
finally, here is the entries in the apache error log, corresponding to the problem
[Mon Aug 21 20:46:19.403512 2017] [cgi:error] [pid 1436:tid 1724] (OS 2)The system cannot find the file specified. : [client ::1:61381] couldn't create child process: 720002: welcome.cgi, referer: http://localhost/Perl/
[Mon Aug 21 20:46:19.404515 2017] [cgi:error] [pid 1436:tid 1724] (OS 2)The system cannot find the file specified. : [client ::1:61381] AH01223: couldn't spawn child process: C:/xampp/htdocs/Perl/welcome.cgi, referer: http://localhost/Perl/
I see two problems.
Your CGI script isn't actually CGI compliant -- it needs to output headers before the document body. Consider using the CGI module to handle some of this for you.
You're missing a leading slash in the shebang. It should be #!/usr/bin/perl. (And make sure that Perl is actually installed at that path.)
Please don't learn CGI programming in 2017. Take a look at CGI::Alternatives for a gentle introduction to some modern ways to write web programs in Perl.
Having said that, the solutions to your immediate problem are to:
Fix the shebang line in your code
Output the CGI header before your HTML.
I'm using the CGI module to produce the header. I've also updated your HTML to look like something that was written in the last ten years (lower-case tags, using CSS rather than presentation attributes, HTML5 doctype, indentation).
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics; # Remove before putting into production
use CGI 'header';
my $time = localtime;
my $remote_id = $ENV{REMOTE_HOST} || $ENV{REMOTE_ADDR};
my $admin_email = $ENV{SERVER_ADMIN};
print header;
print <<END_OF_PAGE;
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {
background-color: #ffffff;
}
</style>
<title>Welcome to Mike's Mechanics Database</title>
</head>
<body>
<img src="/images/mike.jpg" ALT="Mike's Mechanics">
<p>Welcome from $remote_host! What will you find here? You'll
find a list of mechanics from around the country and the type
of service to expect -- based on user input and suggestions.</p>
<p>What are you waiting for?
Click here to continue.</p>
<hr>
<p>The current time on this server is: $time.</p>
<p>If you find any problems with this site or have any
suggestions, please email
$admin_email.</p>
</body>
</html>
END_OF_PAGE
I have a perl script in my cgi-bin. It first prints out the following statements
print "Status: 200 OK\nContent-Type: text/html\n\n";
It generates a html form on the terminal perfectly but when I try running it on the browser it gives the following error
Internal Server Error The server encountered an internal error or
misconfiguration and was unable to complete your request. Please
contact the server administrator at [no address given] to inform them
of the time this error occurred, and the actions you performed just
before this error.
I have enabled cgi-bin in the apache configuration, the error log prints the following error
End of script output before headers
What could be the problem and how should I resolve it
You must have the Content-Type be the first thing printed back to the screen. Also make sure the script is set as executable.
print "Status: 200 OK\nContent-Type: text/html\n\n";
Should be:
print "Content-Type: text/html\n\nStatus: 200 OK\n";
The script also needs to be executable by Apache for it to work
chmod a+x YourScript.pl
I've tested with the following script and once I fixed the permissions it works just fine. You also only need to set the status if it isn't 200 as that's the default.
#!/usr/bin/perl
use strict;
print "Status: 200\nContent-Type: text/html\n\n";
print "<p>Foo</p>";
I want to use PHP to run a shell script that sends a file from server 1 to server 2. I have the server 1 public key written to the server 2 authorized_keys and it works perfectly.
For some reason the following script doesn't actually send the file from server 1 to server 2:
// This is a webpage at http://server1.com/sendfile.php
<?php
if($_POST['a'])
{
echo '<pre>';
echo passthru('./scp.sh');
echo '</pre>';
}
?>
<form method="post">
<button name="a" value="Af">Send File</button>
</form>
//This is the contents of scp.sh
scp ../dbexport/db.txt someuser#server2.net:
So when I execute from scp.sh from terminal, everything works fine - the file actually gets sent and received.
But when I go to http://server1.com/sendfile.php and press the button, the php file actually executes the shell file (i confirmed this by putting echo statements before and after scp command), but the file is never successfully received by server2.com
Does anyone know why this might be?
Marc B answered my question with a comment...posting here
did you add the key to the webserver's account's authorized_keys? Just because it works from a shell running under YOUR permissions means absolutely nothing to a shell running under the webserver's ID. – Marc B Jan 9 at 19:47
ooooh yeahhhhh....i forgot about that – John Jan 9 at 19:57
yup it worked. thanks Marc! – John Jan 9 at 20:42
I am using this code:-
<?php // Load and parse the XML document
$rss = simplexml_load_file('http://partners.userland.com/nytRss/nytHomepage.xml');
$title = $rss->channel->title;
?>
<html xml:lang="en" lang="en">
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<?php
// Here we'll put a loop to include each item's title and description
foreach ($rss->channel->item as $item) {
echo "<h2><a href='" . $item->link . "'>" . $item->title . "</a></h2>";
echo "<p>" . $item->description . "</p>";
}
?>
</body>
</html>
Which I got from this site www.ibm.com/developerworks/library/x-simplexml.html
I have one puzzling issue.
When I run the code on my development server it works with no problem.
When I run it on my web host server I get this error report:-
Warning: Invalid argument supplied for foreach() in /web1/............../test3.php on line 15
My development server is a TurnKey Linux LAMP server with PHP 5.3.2.
My web host has PHP 5.2.17 running on Linux.
Looking up the error message on the web seems to indicate that the data read from the XML feed is not being treated as an array by PHP 5.2.17.
The solutions on here under 'Invalid argument....foreach()' that I have tried do not resolve the issue.
Any ideas as to how to get around this?
It looks as though Torstein's instincts are 'on the button'; my webhost seems to be blocking downloading files from the internet.
I used this code segment to try to load the distant file to a local copy:-
if(!#copy('http://partners.userland.com/nytRss/nytHomepage.xml','./buffer.xml'))
The resulting file buffer.xml contained this:-
The URL you requested has been blocked. URL = partners.userland.com/nytRss/nytHomepage.xml
This is not specific to this url, I get the same on a BBC newsfeed url.
So, indications are that it is not a PHP problem!
I have raised the issue with my webhost provider.
One thing this problem has reminded me of is that the PHP error message & line number may be far removed from the actual problem!
Thanks to Torstein, mario & GusDe Cool for helping me get my head around this problem.
BillP
It looks like your webhost has disabled opening of files on the internet.
I'm not sure how simplexml_load_file() works, but if you run phpinfo() on the website and options like allow_url_fopen and allow_url_include are disabled, thats a good indication.