Using Python as CGI scripting language in CloudNEO - Forum

Forum Navigation
VisualNEO Products: Web, Win and PixelNEO
You need to log in to create posts and topics.

Using Python as CGI scripting language in CloudNEO

Python is a very powerful tool, used for the development of several of the most complex web applications. Here is how a Python script can be executed on CloudNEO:

  • Upload the .py file into a folder
  • Create an .htaccess file into the same folder and include the following line:
AddHandler cgi-script .py
  • Edit the .py file(s) by adding in the first line
#!/usr/bin/python
  • The permissions for .py file(s) should be 755

And you’re done. Now you can successfully execute Python scripts.

@luishp

Thanks for the step by step instructions.

This is very timely.

During the last few days, after an absence of about a decade, I revisited Python (and its capabilities as a web scripting facility) ... command syntax seems a lot easier than php (or even nodeJS).

I am going to create a VisualNEOWeb plugin that calls .py scripts on a specified website, to request creation, update and deletion text/json files on the website ... the plugin commands will call python scripts (which I will also supply) that will need to be installed by developers on their websites.

If that works out, I will tackle scripts to manage databases ... looks like Python can handle mySQL, but I am partial to MongoDB.

I am going to create a VisualNEOWeb plugin that calls .py scripts

Great! @gaev note that you can choose the desired Python version under the "Advanced" menu within CloudNEO.
You can also include your .py file(s) within the plugin and they will be deployed automaticaly on the root folder of the compiled application if any of the plugin commands are used.

For local development I would recommend using Laragon as webserver.

Thanks!

@luishp

You can also include your .py file(s) within the plugin and they will be deployed automatically on the root folder of the compiled application if any of the plugin commands are used.

Perhaps I was not clear ... the .py script files would be resident on the server side (and service http/https requests from Apps) ... in other words, perform the same functions (and access control) as php/asp/nodeJS scripts would ... the plugin commands would just be there to make it easy for (citizen) developers to make the requests e.g. something like ...

neoPyFileAppend [onMyWebsiteURL] [thisText] [toThisTextFile]
neoPyFileReadLine [onMyWebsiteURL] [fromThisTextFile] 8 [intoThisVariable]

... these plugin commands would be written in javascript.

Hopefully, VisualNEOWin applications can access the same data files by calling the same PyScript files using InternetGet/InternetPost commands e.g.

InternetGet "[myWebsiteURL]/readLine.py?LineNumber=8" "[intoThisVariable]" "HideProgress+Async"

... could be made simpler with the use of Call's to external Functions.

@gaev

Perhaps I was not clear ... the .py script files would be resident on the server side (and service http/https requests from Apps) ... in other words, perform the same functions (and access control) as php/asp/nodeJS scripts would ... the plugin commands would just be there to make it easy for (citizen) developers to make the requests e.g. something like ...

Yes, it's the same way neoPHP plugin works. Usually you should host your webapp in the same server your .php or .py script is hosted, but of course you can host your webapp locally or even in another server. In this last case, it's necessary to use the CORS header in the server script:

Access-Control-Allow-Origin: *

Although it's possible (as shown on the FormSubmit sample app) as you know it's necessary to be very carefull regarding security as anyone can invoke the script from anywhere. neoPHP plugin could be quite more easy to use if not taking security into account. That's the reason it's necessary manually edit the config.php file.

@luishp

Thanks for the tips.

Yes, it's the same way neoPHP plugin works. Usually you should host your webapp in the same server your .php or .py script is hosted, but of course you can host your webapp locally or even in another server. In this last case, it's necessary to use the CORS header in the server script:

Access-Control-Allow-Origin: *

I plan on placing the py scripts on my website (to be hosted on neoCloud).

The initial version will only be as a Proof of Concept.

After that, I will add authentication features.

Although it's possible (as shown on the FormSubmit sample app) as you know it's necessary to be very carefull regarding security as anyone can invoke the script from anywhere. neoPHP plugin could be quite more easy to use if not taking security into account. That's the reason it's necessary manually edit the config.php file.

My current thoughts are to respond to a successful SignIn with a SessionID (SID) that would be passed back with every subsequent access request. SIDs will be saved on the server as well (optionally with an expiry time).

Each py script will call an authentication function (so developers can develop what ever access control scheme they want) that will return a true or false value.

My objective is to offer the (client side) plugin and the py scripts (text files) to the VisualNEO community ... no charge ... and let them deploy them where ever they wish (hopefully neoCloud).

Additionally, perhaps for a small fee, you can offer (citizen) developers who do not wish to get into the techy techy stuff, a slice of a common website on neoCloud ... a sort of serverless computing facility for secure shared access to files/databases.

Additionally, perhaps for a small fee, you can offer (citizen) developers who do not wish to get into the techy techy stuff, a slice of a common website on neoCloud ... a sort of serverless computing facility for secure shared access to files/databases.

That's on my mind :)
Too many things to do, but it will be done soon or later. Thanks!

Hi @gaev and @Luishp,

I saw Luis is recomending to use Laragon as a webserver for local testing. I just do some test using the default webserver that comes with python 3.8, and from cmd i executed py -m http.server --cgi and that brings up the webserver, after that just created a new directory under root with name cgi-bin and puted there the .py files. Later is as simple as to go http://localhost:8000/cgi-bin/test.py

file test.py contents:

#!/usr/bin/env python3
import cgi
cgi.test ()

i hope this serves, it's to simple is someone wants to try a rapid solution to testing.

Regars,

Sam

Uploaded files:
  • You need to login to have access to uploads.
Quote from Gaev on February 24, 2020, 3:07 am

@luishp

.....If that works out, I will tackle scripts to manage databases ... looks like Python can handle mySQL, but I am partial to MongoDB.

By the way @Gaev, i can help you with Oracle databases connectivity or anything regarded Oracle databases for the plugin if you needed. For me will be a great solution because i need it.

Regards,

Sam

 

Open chat
1
Do you need more info?
Hi, do you have any doubt?