Articles Comments

{ Berbagi, Menulis, Dan Mengajar } Ilmu… » 7. Operating System » Installing Gammu (SMS Gateway) pada Linux

Installing Gammu (SMS Gateway) pada Linux

Installing Gammu (SMS Gateway) pada Linux

Gammu adalah sebuah software gratis (open source) yang dapat mengolah dan mengontrol pesan dari modem GSM atau pun HP, sehingga software Gammu bisa digunakan dan diaplikasikan menjadi sms gateway. Daftar telepon dan modem yang didukung oleh Gammu bisa dilihat di database Gammu.

Tahapan-tahapan yang dilakukan sebagai berikut:

1. Sistem operasi linux wajib di install webserver (apache) yang didukung oleh php dan database (mysql). Jika belum diinstall silahkan di install terlebih dahulu .. :D

2. Pasang modem yang akan digunakan ke komputer, di pastikan sudah terdetect di mesin linux (serial ataupun usb).

3. Download source Gammu di http://wammu.eu/download/gammu/source/

wget http://nchc.dl.sourceforge.net/project/gammu/gammu/1.30.0/gammu-1.30.0.tar.bz2

4. Setelah selesai download source Gammu, extract source tersebut kemudian lakukan installasi.

tar -jxvf gammu-1.30.0.tar.bz2

cd gammu-1.30.0

./configure

make all

make install

5. Masuk ke direktori docs pada master Gammu dan copy smsdrc dan gammurc ke direktori etc/

cd gammu-1.30.0/docs/config

cp gammurc smsdrc /etc/

6. Edit config file smsdrc dan gammurc yang barusan kita copy

mcedit /etc/smsdrc

# This is a sample Gammu SMSD configuration file. It’s required for gammu-smsd,
# see gammu-smsdrc(5) for documentation.

# Gammu configuration, this section is like section “gammu” in “gammurc” file,
# see gammurc(5) for documentation.
[gammu]
device = /dev/ttyS0 # Port yang digunakan modem
#model = 6110
connection = at115200 # Lihat pada telephone dan modem 
#synchronizetime = yes
#logfile = gammulog # this is not used at all in SMSD mode
#logformat = textall
#use_locking = yes
#gammuloc = gammu.us
#startinfo = yes

# When uncomment this section and insert numbers here, smsd will process
# incoming sms only from numbers written here (incoming sms from all other
# numbers will be deleted)
#[include_numbers]
#number1 = 1234

# When uncomment this section and insert numbers here, smsd will process
# incoming sms from all numbers not written here (incoming sms from numbers
# written here will be deleted). This is “black” list.
# Note: after using “include_numbers” section this one will be ignored
#[exclude_numbers]
#number1 = 1234

# General SMSD settings, see gammu-smsdrc(5) for detailed description.
[smsd]
# SMSD service to use, one of FILES, MYSQL, PGSQL, DBI
#service = files
service = sql
driver = native_mysql
# PIN for SIM card
PIN = 1234
# File (or stderr, syslog, eventlog) where information will be logged
logfile = /var/log/gammu/gammu-star.log
# Amount of information being logged, each bit mean one level
debuglevel = 1
# Configuration for using more phones on same database
#phoneid = Line1
# Script to be executed when new message has been received

#runonreceive = /some/script

# Commication frequency settings
commtimeout = 20
sendtimeout = 30
#receivefrequency = 0

#
# gaus insert
maxretries = 2
multiparttimeout = 300

# Phone communication settings
checksecurity = 0

#
# Edited
resetfrequency = 3000

# Delivery report configuration
deliveryreport = no
#deliveryreportdelay = 10

# Ignoring broken SMSC
#skipsmscnumber = +48602123456

# Database backends congfiguration
user = gammu
password =
pc = localhost
# pc can also contain port or socket path after colon (eg. localhost:/path/to/socket)
#database = smsd
database = gammu-1.30

# DBI configuration
#driver = sqlite
# driverspath = /usr/lib/dbd/
# Database directory for sqlite
# dbdir = /var/lib/smsd

# Files backend configuration
#inboxpath = /var/spool/sms/inbox/
#outboxpath = /var/spool/sms/outbox/
#sentsmspath = /var/spool/sms/sent/

#errorsmspath = /var/spool/sms/error/
#inboxformat = unicode
#transmitformat = auto
#outboxformat = detail

mcedit /etc/gammurc

[gammu]

port = /dev/ttyUSB0 # Port modem jika menggunakan USB
model =
connection = at115200 # Lihat pada telephone dan modem 
synchronizetime = yes
logfile =
logformat = nothing
use_locking =
gammuloc =

[gammu1]
port = /dev/ttyS0 # Port modem jika menggunakan Serial
model =
connection = at115200 # Lihat pada telephone dan modem 
synchronizetime = yes
logfile =
logformat = nothing
use_locking =
gammuloc =

Bisa menggunakan perintah gammu-config pada konsole!

7. Simpan smsdrc dan gammurc yang sudah kita edit, kemudian lakukan test pada konfigurasi Gammu dengan mengetikkan perintah :

gammu –identify

8. Jika modem sudah terdekteksi, selanjutnya buat database mysql, masuk ke direktori sql yg ada di source Gammu.

cd gammu-1.30.0/docs/sql

– Membuat databases Gammu;

mysqladmin –u root –p create gammu-1.30-H

– Buat table Gammu dari file mysql.sql;

mysql -u root -p gammu-1.30-H < mysql.sql

9. Periksa kembali config smsdrc untuk setting database yang baru kita buat.

mcedit /etc/smsdrc

# Database backends congfiguration
user = gammu    # user yang digunakan
password = *** # password
pc = localhost
# pc can also contain port or socket path after colon (eg. localhost:/path/to/socket)
database = gammu-1.30-H # database yang dibuat

10 . Jalankan perintah pada konsole linux.

gammu-smsd –config /etc/smsdrc –daemon

11. Berikut script PHP sms gateway yang dulu entah dapet’nya dari mana, maap klo gak di cantumkan sumber .. :)

mcedit sms.php

<html>
<head>
<title>SMS Center</title>
<meta http-equiv=Refresh content=”30″>
<meta name=”description” content=”SMS” />
<meta name=”keywords” content=”SMS” />

<style type=”text/css”>
body {background-color: #FFFFFF}
h1 {background-color: #FF8000}
h1 {color: #000066}
body
{
background-image:
url(‘sms_logo.jpg’);
background-repeat:
no-repeat;
background-position:
right;
}
</style>
</head>
<font face=”tahoma”>
<body>
<center><h1>SMS CENTER</h1></center>

<a href=”#” onclick=”window.open(‘send-sms.php’, ”, ‘width=300,height=200,toolbar=0,statusbar=0,location=0′);”>Kirim SMS / Balas SMS</a>

<FORM ACTION=sms.php method=”post”>
Search SMS-s by first entered chars:
<INPUT NAME=Char SIZE=20>
<INPUT TYPE=SUBMIT VALUE=”Search”><br/><br/>
</FORM>

<?
function mysql_timestamp_to_human($dt) //mysql timestamp to human readable
{
$yr=strval(substr($dt,0,4)); //year
$mo=strval(substr($dt,4,2)); //month
$da=strval(substr($dt,6,2)); //day
$hr=strval(substr($dt,8,2)); //hour
$mi=strval(substr($dt,10,2)); //minute
//$se=strval(substr($dt,12,2)); //sec

return date(“d M Y H:i”, mktime ($hr,$mi,0,$mo,$da,$yr)).””; //format of displayed date and time
}

mysql_connect(“localhost”, “***”, “***”) or die(mysql_error()); //connect to mysql
mysql_select_db(“gammu-1.30-H”) or die(mysql_error()); //select database
if ($Char!=””) //check if char was inserted
$If = “WHERE TextDecoded LIKE ‘”.AddSlashes($Char).”%’”; //if yes, change variable
else
$If = “”; //or do nothing

$result = mysql_query(“SELECT * FROM inbox $If ORDER BY ReceivingDateTime DESC”); //select data with variable and order it by time and date of the reception

echo “<table border=1>”; //begin creation of table
echo “<tr> <th>TANGGAL </th><th>NO. PENGIRIM</th> <th> MESSAGES</th> </tr>”; //header of the table
while($row = mysql_fetch_array( $result )) { //create variable row
// Print out the contents of each row into a table

echo “<tr><td>”; //begin of row and cell
$d= $row[‘ReceivingDateTime’]; //create variable for function at begin
//echo mysql_timestamp_to_human($d); //paste normal date
echo $row[‘ReceivingDateTime’];
echo “</td><td>”;// end and begin of cell
//echo substr($row[‘SenderNumber’], 0, strlen($row[‘SenderNumber’])-3).”XXX”; //show sender number
echo $row[‘SenderNumber’];
echo “</td><td>”; //end and begin of cell
echo $row[‘TextDecoded’]; //show text of the message
echo “</td></tr>”; //end of the cell and row
}
echo “</table>”; //end of table

?>

<p><B>Backup data SMS ke EXCEL Silahkan klik <a href=”excel.php”>disini!!</a></B></p>

<div style=”position: fixed; bottom: 0; left: 50%;”>Powered by <a href=”http://xf86config.wordpress.com”>xf86config</a></div>

<br><br><br>
</font>
</body>
</html>

mcedit send-sms.php

<?php

ob_start();

?>
<html>
<head></head>
<body>

<?php

function getPostVariable( $name ) {
return ( isset( $_POST[ $name ] ) ? trim( urldecode( get_magic_quotes_gpc() ? stripslashes( $_POST[ $name ] ) : $_POST[ $name ] ) ) : null );
}

if ( empty( $_GET[ ‘accepted’ ] ) ) {
if ( empty( $_POST[ ‘submit’ ] ) ) {
?>
<form method=”post”>
Destination: <input type=”text” name=”destination” /><br />
Message: <input type=”text” name=”message” /><br />
<input type=”submit” name=”submit” value=”  Send message  ” />
</form>
<?php
} else {
$destination = getPostVariable( ‘destination’ );
$message = getPostVariable( ‘message’ );
//system( ‘/usr/local/bin/gammu –sendsms EMS ‘ . escapeshellarg( $destination ) . ‘ -text ‘ . escapeshellarg( $message ) ); // try this one
system( sprintf( ‘/usr/local/bin/gammu –sendsms EMS %s -text %s’, escapeshellarg( $destination ), escapeshellarg( $message ) ) );
header( ‘Location: ‘ . $_SERVER[ ‘PHP_SELF’ ] . ‘?accepted=yes’ );
exit();
}
} else {
?>
<p>Your message was accepted.</p>
<?php
}

?>

</body>
</html>
<?php

$output = ob_get_contents();
ob_end_clean();

echo $output;
?>

mcedit excel.php

<?php
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
function cleanData(&$str)
{
$str = preg_replace(“/\t/”, “\\t”, $str);
$str = preg_replace(“/\r?\n/”, “\\n”, $str);
if(strstr($str, ‘”‘)) $str = ‘”‘ . str_replace(‘”‘, ‘””‘, $str) . ‘”‘;
}

$n = 1;
// menentukan timestamp 1 hari sebelumnya dari tanggal hari ini
$prevN = mktime(0, 0, 0, date(“m”), date(“d”) – $n, date(“Y”) );
// menampilkan tanggal 1 hari sebelumnya dari tanggal hari ini berdasarkan timestamp nya
//echo date(“d-m-Y”, $prevN);
$mtgl = date(“Y-m-d”, $prevN);
//echo $mtgl;
// file name for download
$filename = “Backup_SMS_” . date(“d-m-Y”, $prevN) . “.xls”;
header(“Content-Disposition: attachment; filename=\”$filename\””);
header(“Content-Type: application/vnd.ms-excel”);
$flag = false;
$conn = mysql_connect(“localhost”, “***”, “***”);
mysql_select_db(“gammu-1.30-H”);
//$result = mysql_query(“select * from INBOX where tgl=’$mtgl’ order by ID asc”) or die(‘Query failed!’);
//$result = mysql_query(“SELECT inbox.id, inbox.tgl, inbox.jam, inbox.no_hp, phonebook.nama_lengkap, inbox.isi FROM inbox LEFT JOIN phonebook ON inbox.no_hp=phonebook.no_hp wher
e inbox.tgl=’$mtgl’ order by ID DESC”) or die(‘Query failed!’);
$result = mysql_query(“SELECT * FROM inbox $If ORDER BY ReceivingDateTime DESC”) or die(‘Query failed!’);
while(false !== ($row = mysql_fetch_assoc($result))) {
if(!$flag) {
// display field/column names as first row
echo implode(“\t”, array_keys($row)) . “\n”;
$flag = true;
}
array_walk($row, ‘cleanData’);
echo implode(“\t”, array_values($row)) . “\n”;
}
?>

Selesai ..

 

Filed under: 7. Operating System

Leave a Reply

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>