IIS cgi: what's the meaning of "%s" %s - iis-6

I am fiddling a bit with v8cgi on an IIS6 server. Does anyone know what the "%s" %s parameters in a (cgi) service mapping and application path actually mean/do? I really can't find anything on that on the internet. Additionaly, if someone knows, is there a way to get v8cgi running using iis fastcgi extension?

Found here
To run Perl as a CGI application, type the full path to Perl.EXE followed by %s %s. When a script is executed, the first %s will be replaced by the full path to the script, and the second %s will be replaced by the script parameters.
They did not include quotes around the first %s but they should be there in case there are spaces in the filename.

Related

ImageMagic Permission denied on IIS

I have ImageMagick-6.9.2-8-Q16-x64-dll.exe installed with GhostScript on Windows Server 2012 R2.
Executing convert "document.pdf" "thumbnail.jpg" command line from PHP using shell_exec or exec fails by returning a value of 1. If I ran the same command manually in Command Prompt(cmd.exe) it creates the pdf file seamlessly.
After going through many articles and forums, these are the steps I followed to make ImageMagic work on IIS environment.
Temp directory permission:
Whenever PHP uploads a file to the server, IIS will place the file to C:\Windows\Temp directory and move it to the destination directory. In this process the uploaded file will inherent ownership and permission from the Temp directory. By default this inheritance will prevent ImageMagic from accessing it. To overcome this limitation the IUSR and IIS_USRS need to have read/write permission on the Temp directory.
For detail explanation read this article.
Image Magic permission/Application Pool Identity: Since PHP is not allowed to execute convert.exe while being served under the IIS user, you have to create/use default application pool in IIS. Once this pool is configured, you have to grant permission to this pool on the ImageMagic directory and the directory where in the pdf file is placed. For detail explanation read this thread. Note: some articles suggest IUSR or IIS_IUSR should be given permission to execute cmd.exe. This is highly discouraged as it could create a window for the security breach.
Source and destination directory permission: Both of this directories need to have IUSR and IIS_IUSR read/write permissions
Command line syntax: common mistakes while passing arguments to the command line from PHP are paths, back slash need to escaped. For instance instead of passing C:\Inetpub\vhosts\... it should be passed as C:\\Inetpub\\vhosts\\....
Here is an example of a working snippet:
$cmd = 'convert "C:\\Inetpub\\vhosts\\a\\doc.pdf[0]" "C:\\Inetpub\\vhosts\\b\\thumb\\a.jpg"';
$output = "";
$result = exec($cmd, $output);
print_r($output); //var_dump($output);
Notice that the whole command is wrapped with single quote and source and destination files are wrapped with double quotes.
Debugging:
PHP doesn't report any error that might occur during executing command line. If error is encountered it fails silently. To debug output sent from the command line, its recommended to use exec. This function let you pass an output variable that will be populated with an array containing response from the command line. From here you can use var_dump, print_r to display the output. If this value has a value of 1 or 4, it implies you still have permission issue you have to resolve :(
Hopefully this helps.
We observed the same issue in ASP.NET application. We resolved it by making sure that we have disposed the ImageMagick object properly
Note: We wrapped the ImageMagick object inside Using Statement. It didn't work.
We have explicity closed that object.

Can openshift/rhcloud variables be used in an .htaccess file

Openshift sets several environment variables that can be used.
See here (variables: OPENSHIFT_*) https://developers.openshift.com/en/managing-environment-variables.html
Has anyone used these variables in their .htaccess file or can anyone assist in doing so?
My use specifically applies to a Mojolicious app as getting it to work on Openshift requires the following line in the .htaccess file. [ID HERE] refers to the OPENSHIFT_APP_UUID value. I manually type the value there now, and in theory, it should not change but I'd like to allow the app to be deployed by different users without needing them to look for their ID and edit the .htaccess file.
PerlSetVar psgi_app /var/lib/openshift/[ID HERE]/app-root/runtime/repo/perl/index.pl
You might be best off using an action_hook to write that .htaccess file post deploy and have it dynamically include the values of the environment variables that you want, something like this in your .openshift/action_hooks/post_deploy
echo "PassEnv ${OPENSHIFT_REPO_DIR}" >> ${OPENSHIFT_REPO_DIR}.htaccess
echo "PerlSetVar psgi_app ${OPENSHIFT_REPO_DIR}perl/index.pl" >> ${OPENSHIFT_REPO_DIR}.htaccess

cron cannot read outside of account folder

I have a folder on my websites calld /administrator/cron - in it I place php files and then in the cron tab I have something like:
* * * * * php -f "/home/cpm394/public_html/administrator/cron/mailqueue.php"
which USED TO WORK a few months ago.
(BTW this is on a dedicated Linux server with Hostgator)
in the website I have some symbolic links as follows:
ln -s /home/phplib/public_html/functions functions
SO... here's the problem:
the script in mailqueue.php requires a file as follows:
require('/home/cpm394/public_html/functions/config.php');
In response, I get a message that the file does not exist (and it does, I have checked it).
Is this a permission problem? I would normally expect to get "permission denied" vs. "file does not exist"
Cronjobs are often sensitive to relative paths. If you are using them anywhere, try using the full absolute paths instead.

method for getting correct system path on windows

I have made up a simple http server using libevent. The way the resource (folders in my case) are accessed is
http://serverAddress:port/path/to/resouce/
the path to resource is extracted using the decoded url . It works fine on Linux as request would be something like this
http://severAddress:port/home/vickey/folder
but on window$ request is
http://serverAddress:port/c:/users/vickey/folder
which results in decoded url as /c:/users/vickey/folder. Its manually possible to remove the leading slash to correct the problem. However since I m using and learning boost libraries in my code I was wondering if there was some implementation of this sort ? I tried using native() and relative_path(). Thanks.
Its definitely possible to do as you're asking, but I would suggest a different approach. How about creating a configuration property for the server which could be called RESOURCE_BASE_PATH. The resource path received in the URL would be appended to the RESOURCE_BASE_PATH to create the complete path.
This is pretty standard for FTP and HTTP servers and the like. On Windows, it could be set to "c:" and on Linux, left blank which would default to "/".
Also remember on Windows the slashes (\) are different than those on Unix (/).

'Invalid argument' error when using 'chown apache' on web server folder

On a mac in terminal when executing:
chown apache uploads/
I get the error:
chown: apache: Invalid argument
The foder is on a shared web server. I need to change the owner of the folder because otherwise my PHP script for creating simple text files will return a permission denied error. Please don't suggest chmodding the folder to 777 (which does work), since almost all advice against it.
Is it possible that the server doesn't run scripts as the user 'apache'? How can I find this out?
"Invalid argument" makes me think this directory is on an HFS+ volume with owners disabled; you won't be able to change it in that case. You may be able to switch owners on, although it's possible that requires reformatting.
(The advice to check /etc/passwd is wrong, or at least inaccurate, on OS X; you need dscl . list /Users.)
There are two things you might want to check:
1) Is there a user called apache? Maybe it's httpd. You can search /etc/passwd. (Or whatever your platform uses to store user names, you didn't mention your operating system.)
2) What user do scripts run as? You can check this by running a test script. For example:
#/bin/bash
echo Content-Type: text/plain
echo
id -a
If you save this as test.cgi and put it in a CGI directory, you should be able to run it and get it to tell you what user it's running as.