How to host CGI application? - clojure

Up to now i have tested hunchentoot-cgi(CL), mighttpd2(Haskell), ocsigen(OCaml), yaws(erlang) to host an old python CGI application. Except hunchentoot-cgi, all work great. I like Lisp-style programming, so i really want to host the application in a Lisp style web server.
In erlang, i just need to config it as below:
>cat ~/yaws.conf
...
<server 192.168.1.2>
port = 8000
listen = 0.0.0.0
docroot = /media/G/www/qachina/
access_log = false
appmods = <cgi-bin, yaws_appmod_cgi>
</server>
...
then the python CGI application can work.
How about Noir/Ring ?

Ring (and, consequently, Noir) is not a web server in the sense you seem to think. It is a framework for creating web applications. It does not provide access to external applications; rather it allows you to write your own dynamic web applications in Clojure. Then these applications can be deployed to standard Java servlet container or run manually using embedded Jetty web server.
It is of course possible to create such web application which would take an output of an external CGI program, process it and feed the results to the client, but you have to write all CGI processing by yourself (e.g. parse HTTP headers and construct standard Ring response map). As far as I know, there are no CGI wrappers for Ring stack.

Related

Qt+wasm client-server communication

In Qt webassembly documentation there is a mention, than one can use QNetworkAccessManager for HTTP communication with the server that hosts my website. The problem is, that I can't hard-code URL for the server as it should be able to be deployed on any server. Is there a simple way to receive it somehow?
The problem is, that I can't hard-code URL for the server as it should be able to be deployed on any server. Is there a simple way to receive it somehow?
Yes. Your server program runs a QApplication, and the single instance of that class could get that URL.
In other words, you'll document that your C++ program (the executable file obtained by compilation, e.g. with GCC) foo would accept some --server-url argument, and you would start foo --server-url http://example.com/somestrangeurl/
Please notice that WebAssembly is often running inside Web browsers (that is, inside Web or HTTP clients). Most HTTP servers (e.g. lighttpd) are running on Linux OS (and you might use Wt or libonion or some other HTTP server library for them, if you have to code your HTTP server from scratch).

Communicating Between Two EC2 Servers - AWS

I have two EC2 servers. One runs Windows Server 2012 R2 and the other runs on Amazon's Linux build. The Linux box is used as a web server with PHP doing the scripting. I would like the Linux server to send a string to the Windows server every time a PHP file (acting as a RESTful end-point) is processed.
I've never done anything similar and was wondering where to start. From the research I've done so far, it seems like using Netcat to create a Telnet connection might do the job. If so, what would the boilerplate code look like? Netcat is a pretty old platform and there's not much to be found in terms of examples from a Google search.
I am also open to other solutions that could solve this problem.
The workflow of what I am trying to do looks like:
A user hits PHP file end-point -> PHP or the server it runs on sends a string to the Windows Server -> Windows server receives the string and starts a script
You could think of exposing this as an endpoint on your Windows server using either of:
IIS + PHP
IIS + CGi/Perl
IIS + Asp
or anything else.
Expose a simple page on IIS (Windows web server) and hit that from within your webservice login (Linux server) whenever the Linux server receives a request. The script/page that is exposed by your Windows server could execute the desired script then.
The page/endpoint that is exposed on the Windows server should be protected so that not anyone could execute it (disabling public ips. Restricting only the Linux server Ip in your firewall rules etc.)
Sample
Within your php webservice - $my_var = file_get_contents('http://WinServerPrivateIp/runScript.pl'); // Make it asynchronous if needed
runScript.pl in Windows - Would execute your actual script.
You could look at calling winexe from within PHP. I haven't done it myself but I've read that this should do the trick.
winexe Sourceforge
Some sample code from within PHP here
I hope that this is of some help to you
Regards
Liam

c++ how to listen HTTP requests

Im new in C++.
I need to listen HTTP requests.
Please advice me some good tutorials or examples
Thanks
update:
Platform: Windows
Language: C++
I will explain more clearly what i need
when user clicks row on this page: http://ucp-anticheat.org/monitor.html applications is automatically starts on client machine.
I want to make same thing.
I think on client side is service which listens http requests and if url starts with steam:// service automatically runs application...
Do i need to listen http requests?
What is best solution for my problem?
You can listen to http requests through a web server like mongoose , which can be easily used in C++ http://code.google.com/p/mongoose/ , and here is a good example of using mongoose web server http://code.google.com/p/mongoose/source/browse/examples/hello.c
I m not sure what you mean 'client side', if you are meaning Browser as your client, you can't control nothing outside your browser. If you want to control a machine, you need your client machine to run your exe, that has the code to act based on your server instructions.
You should create a simple server program, create a SOCKET listening on default http, https etc, ports. Usually we do it inside a loop (at each one you make a read).
Now... would be easer if you specified if you are on Unix like OS or Windows, but from now on you can google it. Like sys/socket.h or try "man 7 socket" on almost all linux (at least the ones I know).
If you want to sniff something you can google some specific apps around web.
If i get your question right, you want to be able to launch an application when someone clicks a link with a custom protocol, like steam:// or telnet://. You are looking for an Protocol Handler.
A simple way to register such an application is using the ftype program, as described here.

Why do web frameworks serve via FastCGI/SCGI, rather than HTTP?

Major web frameworks (such as Django, Pyramid, Rails, etc) are often run as persistent servers, with a separate web server like nginx serving as a frontend. The web server connects via a protocol like FastCGI or SCGI:
browser --[http]--> nginx --[fastcgi]--> flup -> django
This seems convoluted to me; why is the request converted to an entirely different protocol, when the backend could just run its own HTTP server?
browser --[http]--> nginx --[http]--> wsgiref -> django
This approach appears to be both simpler and more flexible, since there's only one transport protocol and it's an RFC.
However, I don't think I've ever seen a web framework encourage the http-only design, so I assume there must be a reason for it.
What are the advantages of using a protocol like FastCGI/SCGI here?
HTTP is a large, complex protocol. Paring the interface down to the capabilities provided by FastCGI or WSGI allows the framework to handle requests faster than if it had to deal with the original.

apache httpd extension help for special protocol

I want to create a apache extension for my special protocol which listens on the same port as apache but on a specific directory or file like PHP. I need this to power my game with a custom server but not with PHP. I can't listen on a different port or different server.
I don't want to create a PHP file or something similar. I need a complete executable program where I can dynamically allocate memory etc. the program is completely outside of the apache server, but the apache 'passes-through' special requests to this program (for example the .foo files or the /foo/ directory.
I need a tutorial or a help to create a custom extension for apache.
UPDATE:
I want to create a daemon running in the background of my server, and then when apache sends a request, it forwarded this to my daemon, and then the daemon generates the request, and then send an answer. this is important that is not like a php script file or a perl because this is not executed once, the program is running all time, and waiting for the apache to send something. I don't know how to communicate with apache. But I think this is not a CGI, because if I read well, the CGI running is like: apache gets the request, and then START a new process for my php or perl file, sends the data through arguments and stdIN, and then when the process ends, reads the answer form the stdOut and send it back, the process then finished.
But my program still running. I need to run my program in the background all time because I need to store data in the memory which is loaded at startup.
like this.:
http://i53.tinypic.com/v45jzo.jpg
You don't need a special extension, just register a CGI handler that calls your processing code.
Edit
You can setup apache to proxy requests to your daemon.
You will need to return a properly formatted HTTP response or it wont work. You should read up on Apache and web based communications in general to get a better idea what is needed in your daemon.
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar
P.S. Writing an Apache extension is much more difficult an not portable.
To answer your second question about what CGI is
CGI stands for common gateway interface.
when you register a handler as Byron pointed out you tell apache to give the 'request' to your application. apache listens to the output stdout of your application and returns the result to the user.
The parameters for the application are all supplied via the environment which you can access from your application.
But if you don't understand this stuff you are going to run into problems. such as you must set certain headers.
DC