Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Posts
    380
    Thanks
    36
    Thanked 25 Times in 25 Posts

    Running CGI-scripts (Python)

    How do I make it so that if I go to mysite.com, then it will run the file in cgi-bin/myprog.py?

    To add to it, how do I make it so that any file with the extension "py" are not directly viewable, but can be viewed if they go to mysite.com/file_without_extension?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Apothem View Post
    How do I make it so that if I go to mysite.com, then it will run the file in cgi-bin/myprog.py?

    To add to it, how do I make it so that any file with the extension "py" are not directly viewable, but can be viewed if they go to mysite.com/file_without_extension?
    assuming that your server is apache:

    general information about how to use cgi:
    http://httpd.apache.org/docs/2.2/howto/cgi.html

    more specific, how to wotk with files extensions:
    http://httpd.apache.org/docs/2.2/mod...tml#addhandler

    try this steps and post problems:
    1. check to have as first line starting with first column of myprog.py this line:
    Code:
    #!/usr/bin/env python
    2. move myprog.py in cgi-bin of the site
    3. in cgi-bin directory run from terminal this command:
    Code:
    chmod 755 myprog.py
    4. point your browser to this address: http://localhost/cgi-bin/myprog.py
    or http://yourserveraddress/cgi-bin/myprog.py

    best regards

  • #3
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Posts
    380
    Thanks
    36
    Thanked 25 Times in 25 Posts
    Is it possible to hide the "cgi-bin" part of the URL?

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Apothem View Post
    Is it possible to hide the "cgi-bin" part of the URL?
    yes, is usual, one way is to use a rewrite rules

    http://httpd.apache.org/docs/2.2/rewrite/

    best regards

  • #5
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Posts
    380
    Thanks
    36
    Thanked 25 Times in 25 Posts
    Well, I know a little bit about the rewrite rules, but I do not know of any way to make it so that if the user goes to "<any_file_or_folder>" they will be directed to "cgi-bin/<any_file_or_folder>"...


    Also, what is the benefit from having it in the cgi-bin versus outside of it? I have read that it is secure, but how?
    Last edited by Apothem; 02-14-2011 at 09:39 PM.

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Apothem View Post
    Well, I know a little bit about the rewrite rules, but I do not know of any way to make it so that if the user goes to "<any_file_or_folder>" they will be directed to "cgi-bin/<any_file_or_folder>"...

    Also, what is the benefit from having it in the cgi-bin versus outside of it? I have read that it is secure, but how?
    , you didn't read none of the pages from the links i give it to you, isn't it?

    best regards

  • #7
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Posts
    380
    Thanks
    36
    Thanked 25 Times in 25 Posts
    I skimmed it... :P

    I mean from what I can understand:
    RewriteRule ^/?(.+?) /cgi-bin/$1 [L]

    That -should- do what I want... but does that mean it should be in the first line? Last line? As before I thought this would cause an endless loop.

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Apothem View Post
    I skimmed it... :P

    I mean from what I can understand:
    RewriteRule ^/?(.+?) /cgi-bin/$1 [L]

    That -should- do what I want... but does that mean it should be in the first line? Last line? As before I thought this would cause an endless loop.
    rewriting depend on the server settings but usualy this will work:

    RewriteRule ^(.+)$ /cgi-bin/myprog.py

    now if you have a requests like http://yourserver/apage the cgi script will process the request and in browser address bar you will see http://yourserver/apage and not http://yourserver/cgi-bin/myprog.py.
    but, imo, this is only cosmetics and doesn't matter too much.

    best regards

  • #9
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Posts
    380
    Thanks
    36
    Thanked 25 Times in 25 Posts
    Well, I read from one of the URLs you gave me related to Python that having the files in the cgi-bin is more secure, though I do not know why. If it wasn't a problem, I would have probably just left the files in the root directory (public_html).

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Apothem View Post
    Well, I read from one of the URLs you gave me related to Python that having the files in the cgi-bin is more secure, though I do not know why. If it wasn't a problem, I would have probably just left the files in the root directory (public_html).
    you can't run cgi script outside of the cgi-bin directory without changing server setting. The document root of the server, public_html, is for everything you want except scripts.

    http://www.w3.org/Security/Faq/wwwsf4.html

    best regards

  • Users who have thanked oesxyl for this post:

    Apothem (02-15-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •