Similar to technologies like ASP.NET, PHP, JSP and some other web languages which run on the server side are often called within a web pages code. For instance a web server may parse through a file hit
I don't have any difficulty writing server / client programs, only I am unsure where to tie in to web servers such that it will realize my own tag, run it through my software and output the resulting text to the requested file (most likely a web page.)
What does one need to do in order to accomplish this tie-in with a simple custom language?
The software is coded in C++.
To implement your own simple custom language you would need to do the following under Apache and something very similar under IIS.
For example for an Apache server to process PHP the following configuration is required.
LoadModule php5_module modules/libphp5.so
ScriptAlias /php/ "/usr/local/php/bin/"
AddType application/x-httpd-php .php
Action application/x-httpd-php /php/php
This directs the server to pass all calls to the server with the file extension .php to the php processor and replaces and execute the tags in the file.
IIS has a similar mechanism which I think is configured through 'Handler Mappings'
I don't personally think that creating a custom tag language is the correct route to go. You would be better served by writing a wrapper in either ASP or PHP to your C++ application. This would give you full access to the range of function in PHP or ASP that you will probably need e.g. Request parameter handling, etc.
Related
I've designed a desktop app using PyQt GUI toolkit and now I need to embed this app on my Django website. Do I need to clone it using django's own logic or is there a way to get it up on website using some interface. Coz I need this to work on my website same way it works as desktop. Do I need to find out packages in django to remake it over the web or is there way to simplify the task?
Please help.
I'm not aware of any libraries to port a PyQT desktop app to a django webapp. Django certainly does nothing to enable this one way or another. I think, you'll find that you have to rewrite it for the web. Django is a great framework and depending on the complexity of your app, it might not be too difficult. If you haven't done much with web development, there is a lot to learn!
If it seemed like common sense to you that you should be able to run a desktop app as a webapp, consider this:
Almost all web communication that you likely encounter is done via HTTP. HTTP is a protocol for passing data between servers and clients (often, browsers). What this means is that any communication that takes place must be resolved into discrete chunks. Consider an example flow:
You go to google in your browser.
Your browser then hits a DNS server (or cache) that resolves the name google.com to some IP address.
Cool, now your browser makes a request to that IP address and says "get me some stuff".
Google decides to send you back a minimal amount of HTML and lots of minified JavaScript in the page.
Your browser realizes that there are some image links in the HTML and so it makes additional requests to google to get each of the images so that it can display them.
Now all the content is loaded on your browser so it starts to execute the JavaScript code, and that code needs some more data from google so it starts sending requests to google too.
This is just a small example of how fundamentally different a web application operates than how a desktop application does. On a desktop app you have the added convenience that any operation doesn't need to be "packaged up" and sent, then have an action taken, etc (unless you're using a messaging architecture, but that's relatively uncommon outside of enterprise apps).
I have some experience with php / python programming and i am curious to know how actually servers like apache / light httpd gives data to the script?
Can it be bypassed to a c/c++ program ? and handled via that?
Sorry for this kinds of question. I am too much curious. Googled it but can not find a really good answer.
Today, probably the most used and with less overhead is SAPI:
http://en.wikipedia.org/wiki/Server_Application_Programming_Interface
Some examples of SAPI is ISAPI that is mostly for IIS, Apache modules for Apache,
and the list extends with Servers.
ISAPI:
Uses a system dynamic linked library (DLL) so it "attach" to the webserver and functions
can be called direct on it.
http://en.wikipedia.org/wiki/Internet_Server_Application_Programming_Interface
CGI: http://www.w3.org/CGI/
normally a new process is created for each request, the data from the server is normally passed in stdin and the program writes to stdout, some information is passed as environment variables.
FastCGI: http://www.fastcgi.com/drupal/
As the name suggest, its like CGI but does not need to run the program every time a request is made, being faster and using less resources.
Xitami have their own too, called LRWP http://legacy.imatix.com/html/xitami/index12.htm
But each server can implement their own.
Note: The module or external program is what parses the script. The SAPI, CGI, FastCGI and whatever will integrate with the interpreter of the script, a binary. The interpreter then receive the request path, find the script file, and parse it.
Ex: PHP has its apache and IIS modules.
These things follow a request-response pattern where a request is made to a web server. The web server will process the request and execute any server side code (script) associated with the url that the request resolves to (web service or web page typically). The script will execute and result in a response that is sent back to the caller.
I want to use AWS products to build some application on it. For now, i want to test this -
1) Create a webpage hosted at AWS with a simple text box and a submit button, for checking if a number is prime.
2) Compile a C++ program on EC2 to accept a number and reply if it is prime.
Can someone list the steps involved in doing this?
(The above example mirrors simplistically the actual application that i have in mind, with a http frontend and a c++ backend)
If you use the default Linux AMI, you will gave a standard Apache installation ready to go. It sounds like the invocation style of your app is request-response, so at least to begin with, you could just use CGI to get Apache to run your app.
To achieve this, you would do something like this:
Create a static html page with a form and a submit button which passes the form data to your app via CGI
Install your app into an appropriate directory (see the Apache config for details) to run it via CGI, taking care to ensure the correct permissions are set
Have your app parse the CGI environment variables to gather the input
Perform the processing required
Generate the resulting output as an HTTP response (to get started, just use text/plain).
Please note that there are many security issues to keep in mind here, so it is very important to perform strict validation on all data supplied by the web user for escaping issues, buffer overflows and so on.
If you aren't familiar with the above, you will need to read up on HTML forms, Apache configuration and basic HTTP headers at at minimum. There are plenty of examples out there, and some great books covering the topic.
To this end, various libraries have been developed to facilitate this:
Which C++ Library for CGI Programming?
There are also many other options for interfacing your app with Apache, such as FastCGI.
I am hosting my website on a linux server with php5 (no mySQL). Now I am the administrator, and I'm building my first website. I want to know about security, how do I secure my site from malicious injections and hackers? With the htaccess file? And what do I need to put in there?
Any help appreciated.
Thank you
If you have no SQL, you don't have to worry about injection attacks.
Security for your site depends on what you have running on your site. If it's only PHP, I suggest keeping important code which may reveal things such as passwords and authentication keys or functions in a separate php file outside of your wwwroot and include them.
Example:
Your website runs in /home/wwwroot/
Put your php files with important data or functions in /home/privatephp/
Now in all your php files where you want to use those private functions or call on data that you want hidden, you simply use
include (../privatephp/privatestuff.php); at the top of each php file.
Your privatestuff.php file can contain such things as
$adminusername="imtheadmin"; or $adminpassword="adminpassword";
Then you can simply reference those variables in any PHP file where you have used the include command.
I am trying to create simple flex application, which uses django as a back-end part. Have a question:
Usually when I run my application Flex Builder creates a file in a directory on my local PC and then opens a browser and points to it. Everything was fine, but when I decided to link django server to flex applications via xml data providers I started to get security errors. (Related to absence of crossdomain.xml). When I created the file and put it on the server:
<?xml version="1.0"?>
<!-- http://www.foo.com/crossdomain.xml -->
<cross-domain-policy>
<allow-access-from domain="http://127.0.0.1:8000"/>
<allow-access-from domain="127.0.0.1"/>
</cross-domain-policy>
Then tried the application again, I got error in console of my FB Error: Request for resource at http://127.0.0.1:8000/go/active/ by requestor from file:///Users/oleg/Documents/FB3/usersList/bin-debug/usersList.swf is denied due to lack of policy file permissions.
I don't know how to fix the error. But also the question is there a way to configure FB3 to put my swf files to the server directly, so I will not need any crossdomain?
Thanks
Oleg
We struggled with this a lot. The Flex security stuff didn't strike me as well built, but perhaps we just had different approaches in mind than Adobe's developers. The solution that worked for us was to serve both the SWF and the dynamic data from the same host and port.
On our development boxes, we tell Apache to serve the SWF from a directory in the workspace, and the dynamic data from a local copy of the app. When we push to production, SWF and app get pushed simultaneously to the same virtual host.
If that's inconvenient for you, the Apache ProxyPass directive can be used to make Apache front for other servers. I've not used that in production, but it's been very handy for developer setups.
I don't know a way to get FlexBuilder to automatically deploy your changed SWF; you could certainly look into an automation approach (like Maven and Flex-Mojos) to make that happen.
That said, getting rid of that error is usually just a matter of adding a policy file to the server.
The second error is caused because you're trying to fetch http resources from a "file" location. My recommendation is that you change your Flex Builder project so it outputs to a location within the Django web site, rather than to the flex-bin directory. This setting can be changed in the properties dialog of the project. Then, you should be able to have your front-end and back-end share the same protocol and domain.