Post by meagain on Dec 9, 2015 4:16:38 GMT 10
Hi, Does anyone here have any experience using CGI?
I need to have a simple HTML form which would then submit the details to the server, which the Python script (CGI) would run in the background using the details submitted.
So, again, what I need is a form with a few textboxes and checkbuttons with a submit button. This would then go to the CGI page with the details in the URL, for example example.com/cgi-bin/post.py and then pass the details on from the HTML page to the Python script on the server. This would then run a Linux command with the options. However the command has to run in the background too.
Would php be better or would CGI do the job?
Thanks guys, - meagain
|
|
Post by meagain on Dec 9, 2015 4:59:09 GMT 10
#!/usr/bin/python
import os print 'Content-Type: text/html' print print '<html>' #print '<head><title>loading</title></head>' print '<body>' print '<h2>Starting a remote session...</h2>' print '<h2>Details:</h2>' print '<p>Command executing...</p>' r = os.environ.get('HTTP_REFERER') if r: print '<p>You were referred by page:',r,'</p>' r = os.environ.get('REMOTE_ADDR') if r: print '<p>Your IP is',r,'</p>' print '</body></html>' import subprocess if subprocess.mswindows: su=subprocess.STARTUPINFO() su.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW # we can enter any script we want to run LOCALLY here on the server, using the CLIENT'S (user's) parameters process = subprocess.Popen(['file.bat'], bufsize=-1, stdout=subprocess.PIPE, startupinfo=su)
seems to work as a CGI script... any comments?
|
|
Post by Nathan Lecompte on Dec 9, 2015 14:59:59 GMT 10
Hey meagain, I prefer PHP to be honest, I'm not too familiar with Python so I can't really say which one's better; but if it works, go for it Hope this helps!
|
|
Post by meagain on Dec 14, 2015 5:50:02 GMT 10
Thanks a lot Nathan. I worked it out and the results are here (you need a forum account): forum.4tech.ml/virtual.phpOpinions? I know the design is a mess but I will fix that. If anyone wants my source I will be happy to share! - meagain
|
|
Post by Nathan Lecompte on Dec 14, 2015 12:03:14 GMT 10
Also, if your question has been answered please press the tick button next to the post which answered your question. Thanks!
|
|