Domain Name Yahoo

Easy Help Troubleshoot Your Linux Box



  

Easy Help Troubleshoot Your Linux Box


Configuring SMS Gateway kannel

  

I posted installing kannel sms gateway using Centos and Ubuntu

Now, i want to share how to configure the kannel.
Kannel configuration file is in /etc/kannel.conf
Here is my kannel.conf :

group = core
admin-port = 13000
admin-password = bar
admin-deny-ip = “”
admin-allow-ip = “*.*.*.*”
smsbox-port = 13001
wapbox-port = 13002
wdp-interface-name = “*”
log-file = “/var/log/kannel/bearerbox.log”
box-deny-ip = “”
box-allow-ip = “*.*.*.*”
include = “/etc/modems.conf”

group = wapbox
bearerbox-host = localhost
log-file = “/var/log/kannel/wapbox.log”

group = smsbox
bearerbox-host = localhost
sendsms-port = 13013
# change global-sender to the appropriate cell service provider number
global-sender = +yournumberhere

group = smsc
smsc = at
device = /dev/ttyUSB0
modemtype = auto
my-number = “YourNumber”
sms-center = +your-sms-center-povider

speed = 9600
host = localhost
port = 13013
smsc-id = itegno

group = sendsms-user
username = smsgateway
password = password
group = sendsms-user

group = sms-service
keyword-regex= .*
catch-all = yes
max-messages = 1
get-url = “http://domain/sms/sms.php?phone=%p&text=%a”
Dont forget, you must copy file modems.conf into /etc/ the same directory as kannel.conf, Other way you have to copy all contents from modems.conf into kannel.conf

Modems.conf is included in the source gateway-1.4.3/doc/examples/modems.conf

There is group sms-service ( see above ), I need to know the server status by sending text messages into this number and kannel will reply me with the server status
group = sms-service
keyword-regex= .*
catch-all = yes
max-messages = 1
get-url = “http://domain/sms/sms.php?phone=%p&text=%a”
This group will catch all the incoming sms sent to this number, and process it in file http://domain/sms/sms.php
So, you have to make this file.
If you dont want this features, just simply remarked it all with #.

Here is sms.php
<?php
extract($_GET);
// phone=%p&text=%a”
// echo “telp :”.$phone.” “;
// echo “text :”.$text;
$info = ” Info From the server”;
if ( $phone!=”" || $text != “” ){
if (trim(strtolower($text)) == “status” ){
include(”jobs.include.php”);
echo urldecode($str_status);
}
echo $info;
}
?>

Here is jobs.include.php
<?
set_time_limit(0);
ini_set(’display_errors’,'0′);
function diffTime($bigTime,$smallTime)
{
list($h1,$m1,$s1)=split(”:”,$bigTime);
list($h2,$m2,$s2)=split(”:”,$smallTime);

$second1=$s1+($h1*3600)+($m1*60);//converting it into seconds
$second2=$s2+($h2*3600)+($m2*60);
if ($second1==$second2)
{
$resultTime=”00:00:00″;
return $resultTime;
exit;
}
if ($second1<$second2)
{$second1=$second1+(24*60*60);}
$second3=$second1-$second2;

//print $second3;
if ($second3==0) {$h3=0;}
else {$h3=floor($second3/3600);}

$remSecond=$second3-($h3*3600);//get remaining seconds
if ($remSecond==0){$m3=0;}
else
{$m3=floor($remSecond/60);}
$s3=$remSecond-(60*$m3);
if ($h3 < 10) $h3 = “0″.$h3;
if ($m3 < 10) $m3 = “0″.$m3;
if ($s3 < 10) $s3 = “0″.$s3;

if($h3==0){$h3=”00″;}
if($m3==0){$m3=”00″;}
if($s3==0){$s3=”00″;}

if (($h3 >= 1) or ($m3 >= 1))
{
$resultTime = “”;
if ($h3 >= 1) $resultTime .= “$h3 hours “;
if ($m3 >= 1) $resultTime .= “$m3 mins “;
if ($s3 >= 1) $resultTime .= “$s3 secs “;
$resultTime = “but WARNING “.$resultTime;
}else{
$resultTime = “”;
if ($h3 >= 1) $resultTime .= “$h3 hours “;
if ($m3 >= 1) $resultTime .= “$m3 mins “;
if ($s3 >= 1) $resultTime .= “$s3 secs “;
}
return $resultTime;
}

$start = date(”g:i:s”);
if (!file_get_contents(”http://domainnameyahoo.info”)) {$status=”FAILED”;} else {$status = “OK”;}
$end = date(”g:i:s”);
$status_conn = trim(substr(”Conn:”.$status.” “.diffTime($end,$start).” “,0,100));
$str_status = urlencode($status_conn.” “);
?>
With this php script I will know how long the server will take only to open the homepage.
You can also modify the scrip, so you will be notified every 2 hours, :
# cp jobs.include.php jobs.test.php

and append this below the contents
$your_cell_number = “478273728239″;
$url = “http://yourdomain:13013/cgi-bin/sendsms?username=smsgateway&password=password&text=”.$str_status.”&sender=Helpdesk&to=”.$your_cell_number;
file_get_contents($url);

?>

add the jobs.test.php into the crontab -e

Here is php script only will notify you if the connection is failed. Named it jobs.fail.php

<?
set_time_limit(0);
ini_set(’display_errors’,'0′);
function diffTime($bigTime,$smallTime)
{
list($h1,$m1,$s1)=split(”:”,$bigTime);
list($h2,$m2,$s2)=split(”:”,$smallTime);

$second1=$s1+($h1*3600)+($m1*60);//converting it into seconds
$second2=$s2+($h2*3600)+($m2*60);
if ($second1==$second2)
{
$resultTime=”00:00:00″;
return $resultTime;
exit;
}
if ($second1<$second2)
{$second1=$second1+(24*60*60);}
$second3=$second1-$second2;

//print $second3;
if ($second3==0) {$h3=0;}
else {$h3=floor($second3/3600);}

$remSecond=$second3-($h3*3600);//get remaining seconds
if ($remSecond==0){$m3=0;}
else
{$m3=floor($remSecond/60);}
$s3=$remSecond-(60*$m3);
if ($h3 < 10) $h3 = “0″.$h3;
if ($m3 < 10) $m3 = “0″.$m3;
if ($s3 < 10) $s3 = “0″.$s3;

if($h3==0){$h3=”00″;}
if($m3==0){$m3=”00″;}
if($s3==0){$s3=”00″;}

if (($h3 >= 1) or ($m3 >= 1))
{
$resultTime = “”;
if ($h3 >= 1) $resultTime .= “$h3 hours “;
if ($m3 >= 1) $resultTime .= “$m3 mins “;
if ($s3 >= 1) $resultTime .= “$s3 secs “;
$resultTime = “but WARNING “.$resultTime;
}else{
$resultTime = “”;
if ($h3 >= 1) $resultTime .= “$h3 hours “;
if ($m3 >= 1) $resultTime .= “$m3 mins “;
if ($s3 >= 1) $resultTime .= “$s3 secs “;
}
return $resultTime;
}

$start = date(”g:i:s”);
if (!file_get_contents(”http://domainnameyahoo.info”)) {$status=”FAILED”;} else {$status = “OK”;}
$end = date(”g:i:s”);
$str_status = “”;

if ($status == “FAILED”)
{
$status_conn = trim(substr(”Conn:”.$status.” “.diffTime($end,$start).” “,0,100));
$str_status .= urlencode($status_conn.” “);
echo urlencode($status_conn.” “);
}

if ( trim($str_status)!=”" ) {

$your_cell_number = “478273728239″;
$url = “http://yourdomain:13013/cgi-bin/sendsms?username=smsgateway&password=password&text=”.$str_status.”&sender=Helpdesk&to=”.$your_cell_number;
file_get_contents($url);

}
?>

Put jobs.fail.php into crontab -e with every 10 minutes.
It will check your server every 2 minutes, and notify you only if the connection is failed.

That is all the way I do to monitor my server.


April 14th, 2009 Posted by admin | SMS gateway | no comments

No Comments »

No comments yet.

Leave a comment