我有这样的cgi shell脚本
#!/bin/sh
# show the page
echo Content-type: text/html
echo
echo "<html><b>Hello world!</b></html>"
# the task I want to do in background
sleep 100
echo $(date) >> log
Run Code Online (Sandbox Code Playgroud)
我希望页面显示在最后一个之后echo,而不是在脚本执行结束时.我已经尝试将代码放在另一个文件中并像这样执行它./background.sh &.它适用于控制台,但不适用于浏览器.
我用lighttpd
我有一个大型数组,h它包含一个被调用的参数的几个实例,startingParam后面总是跟着两个相关但不总是相同的参数.我需要查找startingParam数组中的每个实例,并将它和接下来的两个参数推送到一个单独的数组中holdingArray.
以下代码无效,因为我对Ruby很新.有谁知道我做错了什么?有没有更好的方法来解决这个问题?
h.each do |param|
if param == 'startingParam'
holdingArray << h.[param],
holdingArray << h.[param + 1],
holdingArray << h.[param + 2]
end
end
Run Code Online (Sandbox Code Playgroud)
非常感谢.
我正在使用Perl CGI.我在后台通过Perl CGI运行SCP命令.喜欢
system("scp -r machinename:/PathOfFile/ /Path/WhereToCopyIt/ &")
Run Code Online (Sandbox Code Playgroud)
这个复制过程需要一些时间,比方说15分钟.现在我希望在此复制过程完成后再发送电子邮件给我.但我的问题是这个命令在后台运行.那我怎么发邮件呢?我知道如何发送邮件但我不知道当进程在后台运行时如何发送邮件.
我有此CGI脚本,但是如何在浏览器中开始下载?
#!/bin/bash
echo "Content-Type: text/plain"
echo
CUR=$(ls -t /var/www/html/certs/*$AUTHENTICATE_UID* | head -1)
if [ "$CUR" != "" ]; then
# start download in the browser
fi
Run Code Online (Sandbox Code Playgroud) #!/usr/bin/perl
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $files_location;
my $ID;
my @fileholder;
$files_location = "C:\Users\user\Documents\hello\icon.png";
open(DLFILE, "<$files_location") ;
@fileholder = <DLFILE>;
close (DLFILE) ;
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder;
Run Code Online (Sandbox Code Playgroud)
当我运行这个脚本时,icon.png它不返回文件,而是返回download.pl(上面给出的脚本的名称),里面没有内容.有什么问题?
我目前使用的脚本.
#!C:\Perl64\bin\perl.exe -w
use CGI qw(:standard);
use File::Copy qw( copy );
use File::Spec::Functions qw( catfile );
use constant IMG_DIR => catfile(qw( D:\ ));
serve_logo(IMG_DIR);
sub serve_logo {
my ($dir) = @_;
my $cgi = CGI->new;
my $file = "icon.png";
#print $file;
defined …Run Code Online (Sandbox Code Playgroud) 当我学习CGI时,我了解到任何编程语言都可以用来将它的输出挂钩到http响应消息,它的输入是http请求消息.我在Perl的上下文中有很多关于CGI的文章,这是因为Perl是与CGI结合使用的最常用的语言吗?
我想知道的是,如果CGI连接到用C/C++编写的程序,它还会比使用PHP慢吗?
我只是创建了一个python服务器:
python -m SimpleHTTPServer
Run Code Online (Sandbox Code Playgroud)
我有一个.htaccess(我不知道它对python服务器是否有用):
AddHandler cgi-script .py
Options +ExecCGI
Run Code Online (Sandbox Code Playgroud)
现在我正在编写一个简单的python脚本:
#!/usr/bin/python
import cgitb
cgitb.enable()
print 'Content-type: text/html'
print '''
<html>
<head>
<title>My website</title>
</head>
<body>
<p>Here I am</p>
</body>
</html>
'''
Run Code Online (Sandbox Code Playgroud)
我使用以下命令使test.py(我的脚本名称)成为执行文件:
chmod +x test.py
Run Code Online (Sandbox Code Playgroud)
我在这个地址的firefox中启动:(http://)0.0.0.0:8000/test.py
问题,脚本没有执行...我看到网页中的代码...而服务器错误是:
localhost - - [25/Oct/2012 10:47:12] "GET / HTTP/1.1" 200 -
localhost - - [25/Oct/2012 10:47:13] code 404, message File not found
localhost - - [25/Oct/2012 10:47:13] "GET /favicon.ico HTTP/1.1" 404 -
Run Code Online (Sandbox Code Playgroud)
如何简单地管理python代码的执行?是否有可能在python服务器中编写执行python脚本,就像这样:
import BaseHTTPServer
import CGIHTTPServer
httpd = BaseHTTPServer.HTTPServer(\
('localhost', 8123), \ …Run Code Online (Sandbox Code Playgroud) 我是perl编程的初学者
我想在fetch中的值为null时执行代码的一部分意味着没有cookie存在,如果有cookie则是另一部分.
但我面临的错误是:
Can't call method "value" on an undefined value at /net/rtulmx0100/fs7/www/LabelMeDev_Student/annotationTools/perl/session_test.cgi line 93, <FP> line 3.
这是我的代码:
%cookies = CGI::Cookie->fetch;
$id = $cookies{'name'}->value;
if($id == null)
{
print "Content-Type: text/plain\n\n" ;
print "hahahah";
}
else{
print "Content-Type: text/plain\n\n" ;
print $id;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将HTTP标头从请求写入文件.单独执行的perl脚本运行正常并写入文件.但是当我从http请求调用脚本时,我收到http 500错误并且错误日志说..'无法打开文件'我在脚本中评论了"打开文件"行,并且从浏览器调用时它完全正常.请告诉我我在这里做错了什么?以下是代码:
#!/usr/bin/perl
use CGI qw(:standard);
use strict;
use warnings;
use Carp;
use LWP::Simple;
my $query = CGI->new;
my $file = '/home/suresh/clientrequest.txt';
chmod 644, $file;
sleep(1);
open my $flh, '+>>', "$file" or die "Cannot open file";
$flh->autoflush();
# Read the data here
print $flh my @keywords = $query->keywords;
print $flh $query->header(-domain=>'testdomain');
print $flh my @names= $query->param;
close $flh;
print header;
print start_html("Welcome");
print $ENV{QUERY_STRING};
print end_html;
Run Code Online (Sandbox Code Playgroud) 我正在使用Nginx和uWSGI来服务Mercurial; 它通过SSL执行基本身份验证(Nginx是SSL终结器;它不会传递给Hg),但由于基本身份验证的安全性甚至超过SSL,如在包括此站点在内的各个地方所讨论的,我想允许用户也可以连接客户端证书,例如TortoiseHg支持的东西.
ssl_verify_client optional;
...
map $ssl_client_s_dn $ssl_client_s_dn_cn
{
default "";
~/CN=(?<CN>[^/]+) $CN;
};
...
location /
{
uwsgi_pass unix:/run/uwsgi/app/hgweb/socket;
include uwsgi_params;
uwsgi_param SERVER_ADDR $server_addr;
uwsgi_param REMOTE_USER $ssl_client_s_dn_cn;
#uwsgi_param REMOTE_USER $remote_user;
#auth_basic "Mercurial repositories";
#auth_basic_user_file /srv/hg/.htpasswd;
Run Code Online (Sandbox Code Playgroud)
}
所以我将CN视为用户名.但是,当没有客户端证书时,如何使其回退到基本身份验证(最好不是在有证书但验证失败时 - 在这种情况下只是错误)?我找到的一个例子是通过让一个单独的服务器块监听另一个端口,我想避免它:https://github.com/winne27/nginx-cert-and-basic-auth/blob/master/nginx-example .conf文件
此外,在一些例子中,我看到了以下检查location; 他们有必要吗?if ($ssl_client_verify != SUCCESS) { return 496; } if ($ssl_client_s_dn_cn !~ "^[a-z0-9]{1,10}$") { return 496; }鉴于http://wiki.nginx.org/IfIsEvil,我认为最好避免使用if.