Sunday, November 2, 2014

How to Configure SMS Gateway (SMS Komunitas MK160)

MK160 was developed by Community Media Angkringan.

Before run the setup of application, necessary to ensure few things setup instructions. Among others, your username server that will be used are: angkringan. And automatically, the location of the home directory is /home/angkringan. This is the location where we will do a Django application setup sms-komunitas.

In the example, the password for the username above is: 123456 (but do not use easily guessed passwords like this. So please be replaced with a more unpredictable).

For the MySQL root user password database: 123456 (use this also should be avoided, and replaced it with a more unpredictable).

Here are the installation steps for Debian:

-------------------------------------------------------------
1. Run the application in TERMINAL - [type alt+ctrl+T]
run the command:

sudo apt-get install -y gammu gammu-smsd mysql-server apache2 libapache2-mod-wsgi python-virtualenv build-essential libmysqlclient-dev python-dev git nmap jwhois mlocate

If setup a new server, then in the middle of the process, we are asked to use the MySQL PASSWORD. fill: password 123456 for example setup here.

-------------------------------------------------------------

2. run the command: pwd [ENTER], and make sure the result is /home/angkringan , then run the command:

Type:

git clone https://github.com/lantip/sms-komunitas.git sms-komunitas

If no error, then there will be a new directory called sms-komunitas /home/angkringan. This can be seen with the command:

ls -al

-------------------------------------------------------------

3. Create a database with name "angkringan" :

Type:

mysqladmin -u root -p123456 create angkringan

-------------------------------------------------------------

4. Create a database to be used by gammu & gammu-smsd:

Type:

cp /usr/share/doc/gammu-smsd/examples/mysql.sql.gz ~angkringan/sms-komunitas/sql/

Type:  

gunzip -d ~angkringan/sms-komunitas/sql/mysql.sql.gz

Type:

mysql -u root -p123456 angkringan < ~angkringan/sms-komunitas/sql/mysql.sql

Type:

mysql -u root -p123456 angkringan < ~angkringan/sms-komunitas/sql/sms-komunitas.sql

-------------------------------------------------------------

5. Run the command:
Type:  

sudo nano /etc/gammu-smsdrc


**************

[gammu]
port = /dev/ttyUSB0
model =
connection = at115200
synchronizetime = yes
logfile =
logformat = nothing
use_locking =
gammuloc =

[smsd]
service = mysql
logfile = /var/log/smsdlog
debuglevel = 0
commtimeout = 30
sendtimeout = 30
user = root
password = 12345
pc = localhost
database = angkringan


***************


-------------------------------------------------------------

6. Setup Django & Python:

type:  

cd /home/angkringan/sms-komunitas

or

type:

cd ~angkringan/sms-komunitas

type:  

virtualenv djangoenv

after running the above command, the new directory will appear in the directory named djangoenv /home/angkringan/sms-komunitas.

type:

source ~angkringan/sms-komunitas/djangoenv/bin/activate

Type:

pip install --upgrade distribute

Type:

pip install -r requirements.txt

-------------------------------------------------------------

7. change the configuration file WEB SMS komunitas:

type:

vim ~angkringan/sms-komunitas/medkom/medkom/settings.py

Customize as follows:

************************************
DATABASES = {
 'default': {
 'ENGINE': 'django.db.backends.mysql',
 'NAME': 'angkringan',
 'USER': 'root',
 'PASSWORD': '12345',
 'HOST': 'localhost',
 'PORT': '3306',
 }
 }

***********************************

Port 3306  is the default port of MySQL that can be viewed with the command:

sudo nmap -v localhost



--------------------------------------------------------------

8. Run syncdb :

Type:

cd /home/angkringan/sms-komunitas/medkom/

Type:

./manage.py syncdb

When question arises:
Would you like to create one now? (yes/no):

Answer: yes, then create a username and password to login to the web.

Username: angkringan
password: 123456

---------------------------------------------------------------

9. settings WSGI (Web for Python):

Type:

nano /home/angkringan/sms-komunitas/medkom/medkom/wsgi.py

then edit the line sys.path.append become as:

sys.path.append('/home/username/sms-komunitas/djangoenv/lib/python2.7/site-packages')
sys.path.append('/home/username/sms-komunitas/medkom')


----------------------------------------------------------------

10. Change the configuration file for Apache2:

Type:

vim /home/angkringan/sms-komunitas/misc/httpd-sms-komunitas.conf

replace the word 'username' to 'angkringan' (in accordance with the username we use the example of this setup). So at the end configuration:


*************************************

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
WSGIScriptAlias / /home/angkringan/sms-komunitas/medkom/medkom/wsgi.py
WSGIDaemonProcess medkom python-path=/home/angkringan/sms-komunitas/medkom
Alias /robots.txt /home/angkringan/sms-komunitas/medkom/medkom/static/robots.txt
Alias /favicon.ico /home/angkringan/sms-komunitas/medkom/medkom/static/ico/favicon.ico
Alias /media/ /home/angkringan/sms-komunitas/medkom/medkom/media/
Alias /static/ /home/angkringan/sms-komunitas/medkom/medkom/static/
Alias /admin/css/dashboard.css /home/angkringan/sms-komunitas/medkom/medkom/static/admin/css/dashboard.css


*************************************


TIPS:

If using vi or vim editor, an easy way to edit at once is to type:

(press the button ESC)

:%s/username/angkringan/

Furthermore, the original Apache2 configuration file backup and copy files that already we edit above to Apache2 directory:

Type:

sudo mv /etc/apache2/sites-available/default /etc/apache2/sites-available/default.original

Type:

sudo cp /home/angkringan/sms-komunitas/misc/httpd-sms-komunitas.conf /etc/apache2/sites-available/default

----------------------------------------------------------------------------

11. Start Apache2 and Gammu:

Type:

sudo service apache2 restart

Type:

sudo service gammu-smsd restart

----------------------------------------------------------------------------

12. Setup smsbot (program to detect new sms messages) by first editing the file db.py:

Type:

vim ~angkringan/sms-komunitas/smsbot/db.py

[Press i to edit].

Then make as follows:

engine = create_engine('mysql://root:123456@localhost/angkringan')

on that line we enter a user for MySQL, in this example: root password: 123456, localhost server, and database name: angkringan.

[When finished press ESC then: wq to exit]

------------------------------------------------------------------------------

13. So smsbot program is still running even though we are already out of the server, we will use the screen:

Type:  

screen -S smsbot

after it goes into virtualenv and run smsbot:

Type:

cd ~angkringan/sms-komunitas

Type:

source djangoenv/bin/activate

Type:

cd ~angkringan/sms-komunitas/smsbot

Type:

./smsbot.py &

and done, you can check the running aplication.