Gregorius lets you monitor a webcam real-time over SMS.
Leave your computer equipped with a webcam, at your home or workplace and get live feed of images from the webcam
at your command (through SMS) from anywhere. All you need is a mobile device. If you're done with the monitoring, you can
kill the monitoring system on the computer remotely.
Access to the system is authentication based, so only you get to issue the commands remotely.
Steps involved:
- Send a SMS to a predefined number identifying yourself (with the authentication password).
- Gregorius will acknowledge the authentication with a reply SMS. You reply back with a command.
- If command was to capture, Gregorius will fetch a live image from the webcam (from your target) and reply back with a link to the image.
- If command was to kill, the Gregorius system running on the target PC is terminated.
- An authenticated session from a mobile device can be terminated with bye. Once terminated, the user has to authenticate again.
Fun. Curiosity. :)
Plus a small part of (what will hopefully be) a bigger project, Pranay and I are working on.
Gregorius runs a Python program which listens for commands on the target PC. PHP handles the data transactions on the web server.
On the target PC:
A Python program running on the target PC checks for updates to a command text-file (using URLlib) on the web-server at regular intervals of time. Please note, however that there's a better approach to 'listen for commands' as discussed in the improvements section.
The Python program then performs a series of actions depending on the refreshed content of the command text-file. If the file contains no commands to carry out, the program simply sleeps for a predefined interval of time, before attempting to listen again.
If however, the command text-file contains a pending capture request, the Python program performs its main function. First, a real-time image is obtained from the webcam connected (using VideoCapture module) and is saved as a file locally. Second a FTP connection is made to the web-server (with authentication credentials predefined in the Python code) using FTPlib; through which the locally saved image is uploaded on the web. To avoid any potential clashes with the filename of the image, the filename is dynamically determined to be the MD5 hash (using hashlib) of the timestamp at which the capture request is made. A separate capture-data text-file containing data about successful capture requests on the web-server is updated with the local URL of the image, timestamp of capture and the target PC's identifier (a friendly-name for the computer). A callback PHP URL file is called (using URLlib) to relay the capture data (URL, timestamp, PC identifier) from the new capture-data text-file to the phone from which the SMS request originated. Gregorius then waits for a predefined time again, before attempting to listen for new commands.
Alternatively, if the command text-file contains a kill request, the Python program running on the target PC is terminated immediately. To implement monitoring again, the program will have to be executed again manually on the target PC.
After completion of a kill or capture call, the Python program ensures to reset the command text-file being monitored back to its 'default, command-less' state through FTP calls to the web-server.
On the web-server:
Gregorius uses a PHP backend on the web-server which handles all the data transactions between the phone (through the SMS gateway) and the target-PC.
Phone -> Web-server front:
On receiving a SMS from a phone (see data transactions) the system first requests for an authentication string (a predefined password set to add a security layer, in an attempt to let only the appropriate user call commands). If the user replies back with a wrong password, the system replies back with an 'auth failure' message to the phone and resets its state back to the welcome message. On successful authentication, it replies back accordingly to the phone and waits for further commands. If a kill command is received from the SMS the command text-file on the web-sever is written with a kill value. For a capture command, the command text-file is written with a capture command and a unique key identifying the phone (from which the SMS texts are being originated) is written to a user text-file (to be later used by the PHP callback, see PHP-callback). Alternatively if the command is bye the current authenticated session with the phone is terminated and the termination is acknowledged to the phone (through SMS again) with the state being reset. Currently, the system is limited to these commands. Following this constraint the system will reply back with a 'malformed request' SMS back to the phone, if an unknown command is issued.
To prevent a flood of commands from a single authenticated session and to prevent a mass of unknown commands, Gregorius will throw a 'Mass malformed requests/limit exceed' message and reset its state back.
Web-server -> Phone (PHP-Callback)
Upon receiving a callback from the Python program running on the target PC, the PHP part of Gregorius reads the capture-data and user text-file. The former forms a dynamic string of message (with the URL to the captured image, timestamp and the PC identifier) which is to be sent as a reply through SMS to the phone. A PHPcURL session is established to the SMS Gateway API which is then used to send the reply SMS with the message formed. The unique key is also relayed with the message which acts as an identifier (to the requesting phone) for the API's backend.
Data transactions:
The communications between a phone interacting and the web-sever (accessible through the internet) takes place on a SMS Gateway (see
credits). The gateway converts incoming SMS texts (being sent to it's number) into
POST calls to the web-server.
For the communications between the web-server and the target PC Gregorius, completely interacts through an internet connection. The SMS messaging can be completely replaced with many IM bots, which in place send commands instead. These IM clients can be accessed on most of the smartphones, again providing complete mobility. (see
improvements).
Source code for the Python and PHP files:
Coming real soon :)
Possible with the help of:
Thanks to
Sandeep Menon for coming up with the name and
iconspedia for the icons used in the graphics.
Gregorius is far from being perfect on any level. It's just a quick implementation of what could be potentially improved on several levels. As noted earlier however, a significant change can be made to the current method of 'listening for commands' on the Python end. At the time when the idea turned into code, I was limited to having an internet connection behind a firewall with no access as such to the router's NAT (for port-forwarding). Thus my approach was pretty limited; by not being able to host and reach a server hosted on the target-PC from the internet. What would possibly be a better way is to create a SimpleHTTPServer instance on the Python end itself; which would run on a specific port on the target-PC and listen for commands from the internet instead of downloading and checking a file frequently. This would make the calls fully real-time with no dependency on files at the server's or target-PC's end (Does this implicitly state a possibility of an update in the future to Gregorius? Yes, indeed.)
Other improvements could include having a motion-sensing system in place instead of just linking an image and to give the user more commands on the SMS interface (say, to delete all images and refresh content). The Python end could become more stealth (as opposed to having a terminal open now), but that's beyond my knowledge as of now. The core of Gregorius has been derived from various bigger ideas (as stated earlier); some of these may come into existence in the near future.