I have large video files (~100GB) that are local on my machine. I have a non-local website where I enter information about the video file. In addition, I need to get the checksum of the video file (and I do not want to manually trigger the script locally and copy and paste the value). To get a checksum of the video file, I have a script I can run as $ checksum.py <video file>.
How would I trigger the local script through the web interface? In other words, I want to be able to enter the PATH of the video file and click Submit on the web app, and it will locally trigger the script, and (after the checksum has finished), insert that value into the web app/database. What would be the best way to do this?
You cannot trigger anything unless your local script is continuously listening for some kind of data feed (like a fixed URL serving an XML/JSON feed of paths) which is, IMHO, over-complicating your system.
You could also use a Java applet ran locally instead of a remote website, but you'll have to sign it to be able to read local files, and it might not be what you're looking for.
Think of it: it's all about security. Would you like any web server to trigger scripts in your local machine? I certainly wouldn't.
IMHO the best solution is to trigger the script manually which will send the data to your web server.
In general browsers run in a sandbox that has very limited access to the OS. In particular you can't run shell scripts from a browser. As I see it you have two options:
Adapt your checksum.py script to send the checksum info directly to your website using the urllib2 calls, or pipe the results to a "curl" command. (No browser involved.)
Rewrite checksum.py as JavaScript using the FileReader class. This will probably be convoluted, slow, and won't work in Internet Explorer.
Related
I am currently building a media website using node js. I would like to be able to control Kodi, which is installed of the server computer, remotely from the website browser.How would I go about doing this? My first idea was
to simply see if I could somehow pipe the entire Kodi GUI into the
browser such that the full program stays on the server
and just the GUI is piped to the browser, sending commands back to
the server;
however, I could find little documentation on how to do that.
Second, I thought of making a script (eg Python) that would be able to control Kodi and just interface node js with the Python script, but again,
I could find little documentation on that.
Any help would be much appreciated.
Thank You!
Can't you just go to settings -> services -> control and then the 'remote control via http' settings? I use this to login to my local ip e.g. 192.168.1.150:8080 (you can set the port on this page) from my browser and I can do anything from there
Fist of all, due to Company Policy, Paramiko, or installing anything that requires administrative access to local machine it right out; otherwise I would have just done that.
All I have to work with is python with standard libraries & putty.
I am attempting to automate some tedious work that involves logging into a network device (usually Cisco, occasionally Alcatel-Lucent, or Juniper), running some show commands, and saving the data. (I am planning on using some other scripts to pull data from this file, parse it, and do other things, but that should be irrelevant to the task of retrieving the data.) I know this can be done with telnet, however I need to do this via ssh.
My thought is to use putty's logging ability to record output from a session to a file. I would like to use Python to establish a putty session, send scripted log-in and show commands, and then close the session. Before I set out on this crusade, does anyone know of any way to do this? The closest answers I have found to this all suggest to use Paramiko, or other python ssh library; I am looking for a way to do this given the constraints I am under.
The end-result would ideal be able to be used as a function, so that I can iterate through hundreds of devices from a list of ip addresses.
Thank you for your time and consideration.
If you can't use paramiko, and Putty is all you get so the correct tool is actually not Putty - it's his little brother Plink - you can download it here
Plink is the command line tool for Putty and you can your python script to call it using os.system("plink.exe [options] username#server.com [command])
See MAN Page here
Hope it will help,
Liron
I have banged my head against the wall on this for days now, I need help.
I’m trying to create a geoprocessing service (which will be used via a flex viewer) that takes permit information from a GDB, writes it to a file, and then opens it on the user’s computer.
The script I have written works perfectly on local computers and when run from the server itself.
However, as soon as the script has been published as a geoprocessing service, it stops opening the file.
The file is created out on a webserver, and then opened via url so that the user can then make a local copy, print out for signature, etc. The file is still being created, named, and placed in the proper folder, it just isn’t being opened at end of the process. (The GP Service views as completed though, it doesn’t fail)
Here is the end of the code, which is the part relevant to my issue:
f = open(r'\\MyWebAddressHere\\Reports\\Permit' + str(PermitNumber) +'.html','w')
f.write(permitStart)
if (BasePermitFee > 0):
f.write(permitBaseFee)
if (PlumbingFee > 0):
f.write(permitPlumbingFee)
if (ElectricFee > 0):
f.write(permitElectricFee)
if (TotalFees > 0):
f.write(permitTotalFee)
f.write(permitEnd)
f.close()
webbrowser.open('MyWebAddressHere/Reports/Permit' + str(PermitNumber) +'.html')
Does anyone have a suggestion on why the open is failing once the GP service is published?
I don't see this as a bug - the webbrowser command makes no sense in the context of a GP Service. Think about what's being executed where.
If you run the code locally, Python is running on your actual computer - that computer has a login, a display, a set of installed programs. Telling it to open a web browser makes sense because you have one or more browsers installed on that computer.
Run it on the server, while logged into the server, and same thing - you still have a login, a set of installed programs. While you might lock down a server to reduce its vulnerability, it probably still has at least one program installed that is capable of browsing the internet.
But when you run a script as a GP Tool, you're in a different world. You're not running the code locally, and you're not logged into the server. If you execute the webbrowser command, where should it open the browser window?
On your PC? It can't - the server's GP environment can't execute random programs on your PC, that would be a massive security hole. Hey, I'll write a script that deletes everything in C:\Windows and publish it on ArcGIS Online!
On the server? Who would see it? No one's logged in.
Turns out that the webbrowser command flat out does not work in a server environment.
I managed to confuse the heck out of an ESRI server analyst with this one, because there is apparently no documentation saying this won't work in a server environment, it just doesn't. So it has been logged as a bug.
I'm about to finish a jquery plugin that should provide a progress-bar for file uploading using ajax and a python CGI script.
My plugin is inspired after this piece of software.
The idea is reading(with python CGI script) raw post data on the server while the browser is uploading, parse it, write file (in chunks) to disk and at the same time using ajax to ask the server about the currently written file size.
The plugin works on my server and on some other web hosting servers. But on Mochahost (using apache) it does not work properly. What that server does is that it calls my python CGI script after all upload is completely done, and not while the file is uploading (as expected). I verified the moment of calling by adding the very beginning of python script command to write a test file. That command should fire when python is called and does not involve reading sys.stdin.
Even on that server python CGI script works (almost) as intended. It reads sys.stdin in chunks, parses it and writes the file on disk. The problem is timing. The server does not provide python with input stream in real-time, but, after all, post from the browser was received, it calls python and populate sys.stdin with raw posted data that is already saved somewhere.
I don't know if it is relevant but I've noticed that their apache version is 2.0.x and SERVER_PROTOCOL is HTTP/1.0. On other web hosting servers SERVER_PROTOCOL is HTTP/1.1.
Can anybody say what things could make a server or specifically an apache server to call a CGI script after uploading is finished and not when the browser asked for it?
I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end.
I've been looking, therefore, for a lightweight web server that can execute python scripts, sitting in the background on a machine, ideally as a Windows service. Security and extensibility are not high priorities as it's all running internally on a small network.
Should I run a native python webserver as a Windows service (in which case, how)? Or is it just as easy to install Apache onto the user's machine and run as CGI? Since this is all local, performance is not an issue either.
Or am I missing something obvious?
Don't waste a lot of time creating Windows service.
Don't waste a lot of time on Windows Apache.
Just make a Python service that responds to HTTP requests.
Look at https://docs.python.org/2/library/basehttpserver.html
https://docs.python.org/3/library/http.server.html for version 3
Python offers an HTTP server that you can extend with your server-side methods.
Look at http://docs.python.org/library/wsgiref.html
Python offers a WSGI reference implementation that makes your server easy and standards-compliant.
Also http://fragments.turtlemeat.com/pythonwebserver.php
"I'm trying to avoid making the user run python stuff from the command prompt."
I don't see how clicking a web page is any different from clicking desktop icons.
Starting a web server based on Python is relatively easy, once you have the web server. First, build the server. Later, you can make sure the server starts. Let's look at some ways.
Your user can't use a random browser to open your local page. They need a bookmark to launch "localhost:8000/myspecialserverinsteadofthedestop/" That bookmark can be a .BAT file that (1) runs the server, (2) runs firefox with the proper initial URL.
You can put the server in the user's start-this menu.
You can make your Python program a windows "service".
Best way is to make your own local server by using command prompt.
Make a new folder say Project
Make a new folder inside project & name it as "cgi-bin"(without quotes)
Paste your .py file inside the cgi-bin folder
Open cmd and change to the directory from which you want to run the server and type "python -m CGIHTTPServer"(without quotes)
Minimize the cmd window & open your browser and type "localhost:8000/cgi-bin/yourpythonfilename.py"(without quotes).
The wasiest step would be navigate to folder where your files are located and running http.server module
cd /yourapp
python3 -m http.server
the you should see something like this in console
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Running a native python webserver as a windows service should be a no brainer. Check out the documentation for writing windows services (win32api, ActiveState python) in python and also the documentation for subclassing BaseHttpServer and SimpleHttpServer.
BTW: I had a similar question on stackoverflow: How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?
Basically, you subclass BaseHTTPServer (you have to anyway...) and then... but just read the accepted answer - it set me on the right track!