Controle UNIX systems via SMS using Python on a Raspberry Pi
- Audience level:
- Embedded Systems
A small recherches project that allows controlling UNIX systems using SMS . the project is developed entirely using python embedded on a RaspberryPI and a using 3G modem dongle for GSM operations.
> With the ongoing development of mobile networks, systems administration tasks can be performed remotely by having only a mobile phone. This concept was implemented by the establishment of an innovative embedded system called SMS-SHELL designed for Unix system administration using SMS commands. ---------- **I. Introduction** ------------------- Since the advent of UNIX system, the command SHELL is the most convenient tool to administer a UNIX server. Based on this principle and in a context of innovation, we designed an embedded system that allows an administrator to send UNIX Shell commands to a UNIX server from a phone mobile. This innovative system called SMS-SHELL Gateway is based on an intelligent architecture that can convert text messages to SHELL system commands. we will present the design and features offered by our targeted system. Then we will describe the prototype as part of our research work. **II. Features of the targeted system** --------------------------------------- The targeted system must meet the following features: - A mobile phone equipped with the GSM network that sends a Shell command to a gateway called SMS-SHELL Gateway - Upon receipt of the order and after checking security settings, the Gateway SMS-SHELL sends the command to a Unix server. - The server is running UNIX command and return a response to the SMS-SHELL gateway - The SMS-SHELL gateway sends a SMS reply to the mobile phone as a prior sender of the command. The design of the SMS-Shell Gateway is required to tackle the following issues: - Communication protocol between the SMS-SHELL Gateway and the UNIX server - Format of SMS commands passing between the mobile phone (the sender) and the Gateway - Secure access and control of the commands running. ![hhhhhhhhhhhhhhhhhh] Form 1. architecture of the targeted system In this architecture there are three layers of communication: - Communication between the phone for sending commands and shell-sms gateway is done via sending SMS containing syntax of commands that will be interpreted at the gateway. - Communication between the gateway and the server is done via unix SSH between an SSH client and service side gateway SSH UNIX server side. This architecture requires no additional agent on the phone side. This is a normal SMS sending that is interpreted as a Shell command on the side of the Gateway. That explains the origin of the flexibility and portability of the architecture. **III. Design of the SMS–SHELL Gateway:** ----------------------------------------- **III.1 Design of the operational parts** The SMS–SHELL Gateway is an embedded system has the following interfaces: - GSM Interface: to receive and send SMS interpreted as shell commands - Ethernet interface: to communicate over the LAN with the UNIX server via SSH. The Communication protocols are modeled as follows: ![hhhhhhhhhhhhhhhhhhhhhhhh] Form 2. modeling of communication protocols Upon receipt of an SMS on the GSM interface, the Gateway extracts the following parameters: - IP address of the server upon which we must run the command - The command and its arguments > Example: firstname.lastname@example.org is a command that will be interpreted by the Gateway as a request of server shutdown. The Gateway identifies the list of managed servers the server access parameters (login/password), and it initiates an ssh connection to that server. If the connection is successful, it sends the command shell in question. After executing the command the Gateway generates a text response that will be sent by SMS to the phone that sent the command. In the case of a not authorized or improperly formatted command, the Gateway sends a text response including the reasons for the failure. **III.2 Security Access:** The security layer is implemented at two levels: In the communication protocol between the phone and the Gateway with the identification of the SMS sending number. Only telephone numbers that are stored in the Gateway that are authorized to send commands. In the case of an order which is classified as a "high risk command" whose impact can be damaging or shutting down the system, the SMS Gateway requests to provide an access code before running the command. Checking the validity of the access code determines the run of the command on the UNIX system. **IV. A prototype implementation of the targeted system:** --------------------------------------------------------- As part of our research, we have implemented a prototype of the SMS-SHELL Gateway. ![hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh] Form 3. Overall architecture prototype The above diagram illustrates the overall architecture of our prototype. The SMS-SHELL GATEWAY is an embedded system based on the RaspberryPi board equipped with an external GSM modem. The operating system Raspbian embedded, in fact, is known for its stability, reliability and safety. GSM communication interfaces have been developed through GSM Python libraries. This is a system language. Indeed, the Python libraries offer strong integration and reuse of Unix tools. The following diagram describes the procedures performed by Python libraries.The execution of the SSH command uses SSH native client of Debian. ![hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh] Form 4. Mapping of procedures performed by Python-GSM librairies **V. Conclusion and further work** ---------------------------------- In this paper we have designed an innovative embedded system capable of administering a unix server using SMS commands. The prototype we have implemented is a first job that opens the door to other operation system in an industrial setting for controlling remote systems. We also plan to develop an SMS client to fix the problem of sending commands incorrectly formatted and to mitigate the limitation of the number of characters in the SMS based exchange. : http://farm4.staticflickr.com/3727/10599700775_f1d0deec76.jpg : http://farm8.staticflickr.com/7388/10599716884_ea82e613ae.jpg : http://farm6.staticflickr.com/5525/10599718064_aaf0bd920e_z.jpg : http://farm3.staticflickr.com/2850/10599909054_5ac0cfcfac.jpg