New version is coming soon!
As always this document is a draft and written as personal notes. This is not a definitive guide.
This SMS library supports two SMS Gateways and one SMS service:
The package can be downloaded here. WARNING!!! Use at your own risk!
First we need to create a new database table called prefix_sms_config, where "prefix" means
whatever prefix you've chosen when you installed moodle. For example mdl_.
In MySQL:
CREATE TABLE prefix_sms_config ( id int(10) unsigned not null auto_increment, name varchar(100) not null, value varchar(255) not null, PRIMARY KEY (id) );
And in PostgreSQL:
CREATE TABLE prefix_sms_config ( id SERIAL, name VARCHAR(100) NOT NULL, value VARCHAR(255) NOT NULL, PRIMARY KEY(id) );
Unzip the sms library package into your Moodle installation directory. The package has following structure:
lib/sms/
- smslib.php
- sms.class.php
/kannel/
- kannel.class.php
/nowsms/
- nowsms.class.php
/clickatell/
- clickatell.class.php
admin/
- sms.php
- sms.html
lang/en/
- sms.php
( If you'd like to have links in admin page edit admin/index.php and admin/configure.php in appropriate places )
Get kannel source code from kannel's site: http://kannel.org
Unzip the source code to some directory and compile it.
[janne@nutso janne#]cd /usr/local/src [janne@nutso src#]tar -xzvf ~janne/gateway-1.4.0.tar.gz [janne@nutso src#]cd gateway-1.4.0/ [janne@nutso gateway-1.4.0#]./configure --prefix=/usr/local/kannel Configure.... [janne@nutso gateway-1.4.0#]make >& make.log & [janne@nutso gateway-1.4.0#]tail -f make.log <all kinds of code is running on your screen at this point...> [janne@nutso gateway-1.4.0#]make install >& install.log & [janne@nutso gateway-1.4.0#]tail -f install.log
Create a configuration file into your /etc directory (The startup script uses: /etc/smskannel.conf).
Edit the configuration file so it matches your system and settings:
# CORE group = core admin-port = 13000 admin-password = yourpassword status-password = yourpassword log-file = "/var/log/kannel/kannel.log" log-level = 0 access-log = "/var/log/kannel/access.log" wapbox-port = 13002 smsbox-port = 13001 store-file = "/var/log/kannel/kannel.store" # SMSC Fake group = smsc smsc = at modemtype = auto device = /dev/ttyUSB0 speed = 57600 pin = 0000 #host = localhost #port = 13013 # MODEM DEFINITIONS group = modems id = nokia name = "Nokia" detect-string = "Nokia" # SMSBOX SETUP group = smsbox bearerbox-host = localhost sendsms-port = 13014 sendsms-chars = "0123456789+" global-sender = "+358401234567" log-file = "/var/log/kannel/smsbox.log" log-level = 0 access-log = "/var/log/kannel/access.log" # SEND-SMS USERS group = sendsms-user username = youruser password = yourpassword concatenation = 1 max-messages = 10 # SMS SERVICE 'default' group = sms-service keyword = nop text = "You asked nothing and I did it!" catch-all = true # SMS SERVICE for receiving sms messages # there should be default always group = sms-service keyword = yourkeyword get-url = http://server.domain/moodle/receivesms.php?q=%k&sender=%p&message=%a
Create a startup script ( this is for Fedora Core ) and place it in /etc/init.d/ directory:
#!/bin/sh
#
# gateway This shell script takes care of starting and stopping
# the Kannel WAP gateway (bearer/wapbox)
#
# chkconfig: 2345 97 03
# description: Start and stop the Kannel WAP gateway used to fetch \
# some WML content from a Web server & compile it \
# into WMLC mobile phone bytecode.
# probe: true
# Use start-stop-daemon
ver=1.40
BBOX=/usr/local/sbin/bearerbox
SBOX=/usr/local/sbin/smsbox
START="/usr/sbin/start-stop-daemon --start --background --quiet --exec"
STOP="/usr/sbin/start-stop-daemon --stop --quiet --oknodo --exec"
CONF=/etc/smskannel.conf
[ $# -eq 2 ] && ver=$2
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $BBOX ] || exit 0
[ -x $SBOX ] || exit 0
[ -f $CONF ] || exit 0
RETVAL=0
# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting bearer service (gateway kannel $ver): "
$START $BBOX -- $CONF
RETVAL1=$?
sleep 1 # Sleep for a while before we try to start smsbox
echo
echo -n "Starting smsbox service (gateway kannel $ver): "
$START $SBOX -- $CONF
RETVAL2=$?
echo
echo
[ $RETVAL1 -eq 0 -a $RETVAL2 -eq 0 ] && touch /var/lock/subsys/gateway ||\
RETVAL=1
;;
stop)
# Stop daemons.
echo -n "Shutting down smsbox (kannel $ver): "
$STOP $SBOX
RETVAL2=$?
echo
echo -n "Shutting down bearerbox (kannel $ver): "
$STOP $BBOX
RETVAL1=$?
echo
[ $RETVAL1 -eq 0 -a $RETVAL2 -eq 0 ] && rm -f /var/lock/subsys/gateway
echo ""
;;
status)
status bearerbox
status smsbox
exit $?
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: named {start|stop|status|restart}"
exit 1
esac
exit $RETVAL
Plug your mobilephone into your computers USB port and start kannel. Check your /var/log/kannel/kannel.log. If you can find
several AT command lines and line where it says AT SMSC successfully opened. Then all is fine.
Com'on!!! It's a Windows™ software!!! Click Yes or Next like a mad man...
There's a quite good configuration documentation in NowSMS's website.
Point your browser to http://yoursite/moodleinstalldir/admin/sms.php and provide necessary settings:
Create a test code somewhere in your moodle installation directory ( remove it when you're done with it).
<?php
include('config.php');
include($CFG->libdir .'/sms/smslib.php');
$to = '+35840123456'; // Receivers number.
$text = 'This is only test from SMS enabled Moodle site!';
$sms = newSmsClass();
if ($sms->send_sms_message($to, $text) ) {
echo "Message sent!!!";
} else {
echo "Could not send sms message...";
}
?>
Point your browser to this page and if it's printing "Message sent", you should get text message shortly after that.
Hopefully to be continued...
Back to top