Having issues running a script via cgi in lighttpd - shell

I have the following piece in my config file:
cgi.assign = ( ".sh" => "" )
$HTTP["url"] =~ "^/urlpath/" {
$HTTP["querystring"] =~ "cams=on" {
cgi.assign = ( "" => "/scriptpath/CamsOn" )
}
$HTTP["querystring"] =~ "cams=off" {
cgi.assign = ( "" => "/scriptpath/CamsOff" )
}
url.redirect = ( "^/urlpath/" => "http://somewebsite" )
}
I have the cgi module loaded:
server.modules = (
"mod_redirect",
"mod_access",
"mod_cgi",
"mod_accesslog" )
Now "CamsOn" and "CamsOff" are shebanged shell scripts. To be honest I had done this before and had it working but my server crashed and I lost my configs. For some reason I can't figure for the life of me how to get it working. I do the redirect so I don't have to actually create the "urlpath" page. The redirect works fine inside the $HTTP["url"] piece, and I've even tested the querystring portion by nesting a redirect inside that just takes it to google.com; urlpath/?cams=on sent me to google accordingly.
What am I doing wrong?
Update:
I was to get it to work using
$HTTP["url"] =~ "^/urlpath/" {
$HTTP["querystring"] =~ "cams=on" {
cgi.assign = ( "" => "/scriptpath/CamsOn" )
}
$HTTP["querystring"] =~ "cams=off" {
cgi.assign = ( "" => "/scriptpath/CamsOff" )
}
}
I'm thinking that the redirect was getting parsed first, so when the address changed, it no longer fit the URL and querystring comparisons. Can I change this? The idea is to make the urlpath dynamic and updated in the conf file dynamically. This is why I have the redirect send you to another address. This way I also don't need to do html editing or create additional folders.

What am I doing wrong?
a) did not make backups
b) did not make backups
c) did not make backups
d) did not look in your own stackoverflow post history
See Can't figure out how to receive http requests using lighttpd
If you want to reduce the number of places you edit in your config file, you can assign a value to a variable in lighttpd.conf and use the variable in lighttpd.conf. See var.* in
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_Configuration
var.camsurlpath = "/urlpath/"
$HTTP["url"] =~ "^" + var.camsurlpath {
...
}

Related

Mongo gem how to db.currentOp

How can I do db.currentOp() via the ruby Mongo gem?
Cant seem to find that in the gem api and documentation
Is it supported?
if not Is there a gem that does support that?
Looking at the definition of currentOp in the JS console, it looks very internal to me.
> db.currentOp
function ( arg ){
var q = {}
if ( arg ) {
if ( typeof( arg ) == "object" )
Object.extend( q , arg );
else if ( arg )
q["$all"] = true;
}
return this.$cmd.sys.inprog.findOne( q );
}
Besides, official mongo ruby driver doesn't contain "currentOp", "current_op", "inprog" or any other similar term. Based on this I must conclude that it's not supported.
You can send manual commands to the driver using the command call:
conn.command(currentOp: 1)
Should do that for you.

lighttpd configuration to proxy/rewrite from one domain to another

i need to setup proxy/rewrite on lighttpd!
i have server1, which serves via http 2 different web app paths:
* http://server1/path1
* http://server1/path2
also, i have lighttpd server in front of server1
i want to setup rewriting and/or proxing on lighttpd, so that each of the 2 paths would be served as root path on different domains:
* requests to http://server2.com/* are proxied/rewrited to http://server1/path1/*
* requests to http://server3.com/* are proxied/rewrited to http://server1/path2/*
important:
server2.com and server3.com can access server1 only via http
redirects are not the option, users of server2.com & server3.com shouldn't not know that the actual web apps are served from different paths of server1.
Is it possible?
Your need is known by lighttpd developers from several years.
It is answered by a workaround or new feature depending on the version.
Lighttpd 1.4
A workaround is explained in the bugtracker : bug #164
$HTTP["url"] =~ "(^/path1/)" {
proxy.server = ( "" => ("" => ( "host" => "127.0.0.1", "port" => 81 )))
}
$SERVER["socket"] == ":81" {
url.rewrite-once = ( "^/path1/(.*)$" => "/$1" )
proxy.server = ( "" => ( "" => ( "host" => "server2.com", "port" => 80 )))
}
Lighttpd 1.5
They added this feature with this command (official documentation) :
proxy-core.rewrite-request : rewrite request headers or request uri.
$HTTP["url"] =~ "^/path1" {
proxy-co...
proxy-core.rewrite-request = (
"_uri" => ( "^/path1/?(.*)" => "/$1" ),
"Host" => ( ".*" => "server2.com" ),
)
}
Update: lighttpd 1.4.46 (released in 2017) introduced proxy.header which can perform limited URL-prefix rewriting. More info at lighttpd mod_proxy

preg_match fails with simple pattern

I'm trying to analyze the content of an uploaded file (which is supposed to be an image), in order to stop any malicious tampering. So, before processing, I want to detect if the file contains PHP code for instance.
$patern = "/<?php/" ;
$handle = fopen ($_FILES['image']['tmp_name'], "r");
if ($handle)
{
while (($buffer = fgets($handle, 4096)) !== false)
{
if ( preg_match ( $patern , $buffer ) );
{
echo "PHP files are forbidden";
}
}
if (!feof($handle))
{
echo "Error: fgets() failed\n";
}
fclose($handle);
}
After sending an image, the result is "PHP files are forbidden" echoed a 180 times.
Ok normal, it's in the loop, but there is not a single php pattern in mi pic ...
What's the problem ? The patern ? preg_match ? The handel ?
Thanks a lot.
Sorry,
The mistake is : syntax error : semicolon at the end of :
if ( preg_match ( $patern , $buffer ) );
Otherwise it works fine

Mod rewrite for opencart in lighttpd

These are the rules in lighttpd.conf
$HTTP["host"] =~ "^(www\.)?mysite.com" {
url.rewrite-once = ( "^/$" => "/index.php?route=common/home" )
url.rewrite-if-not-file = ( "^/(.*)" => "/index.php?_route_=$1" )
url.access-deny = ( ".tpl", ".ini", ".log" )
server.error-handler-404 = "/index.php?route=error/not_found"
index-file.names = ( "index.php" )
}
Everything works fine. When i open www.mysite.com/adidas it works, but when i try to open www.mysite.com/adidas?page=2 it gives me error404.
And when i try to open www.mysite.com/admin it gives me again error404, but when i open www.mysite.com/admin/index.php it works...
How can i fix it..
Found this article which seems to answer your first issue. For the admin issue, I'm assuming you need to at least use /admin/ including the second forward slash

How to create a link in Sinatra that points to a directory of files?

I have an application that calls an other application that populates a directory. Once it is finished I want to provide a link to the directory that contains the created files and people can examine or download them via the browser:
For example this works to provide a link to a single file: (Note this uses HAML) but the idea is the same
%p
- output_href = File.join("..","..","test_runs",File.basename(#dealclick_test_run.result_filename) )
Result file =
%a{:id => "result-file", :href => "#{output_href}"}
= File.basename(#dealclick_test_run.result_filename)`
The corresponding code for the directory doesn't work:
%p
Results:
- output_href = File.join("..","..","test_runs",File.basename(#dp_test_run.result_filename) )
%a( id = "dealprocessor_results" href = "#{output_href}" )
= File.basename(#dp_test_run.result_filename)
What am I doing wrong?
%a( id = "dealprocessor_results" href = "#{output_href}" )
should be
%a(:id = "dealprocessor_results" :href = "#{output_href}" )

Resources