Hello again Alex,

> 
> I have been reading the kannel user guide for the weekend and SORRY to 
> everybody on the newsgroup for asking stupid questions i.e. not reading 
> the userguide very well, now I understand that they were more stupid 
> than mentioned in the subject :-(.

no, yes, it's good to ask stupid questions
sorry for all the links to the manual! :)
I replied as I know it can be helpful to be pointed in the right direction.
Don't have loads of time but I hope reply was somewhat helpful anyway.

> 
> However,
> since I am admin and not a developer I am not going to code the incoming 
> and outgoing sms content, is it possible to get some html(php,jsp ...) 
> examples for code processing (can be web echo only, just to test if it 
> works), or are there any scrips on the web for testing purposes?

There is one, maybe are more examples that come with kannel.
Look in the contrib directory.
I see a python script.
smstomail.cgi

You'll need to be a teeny bit of an admin and developer I think if
 you want to test it.

You'll need apache configured and mod_perl or whatever also installed.
That's easy with suse's yast2.
 - on suse local apache settings go here I think:
   /etc/httpd/httpd.conf.local
e.g. 
ScriptAlias /cgi-bin-someone "/home/someone/public_html/cgi-bin/"
<Directory "/home/someone/public_html/cgi-bin/"
    AllowOverride All
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>


put script to receive sms in that cgi-bin directory
check logfile exists and apache user can write to it (watch apache's
  error_log)
point kannel at that script in the sms-service groups


I have an over-complicated test script that can send or receive sms and 
 also logs/selects to/from database and shows status information. I've
 hacked it to just log to file. I attached that here.
Script requires perl's CGI lib which should be there.


hmmm, seems over complicated but it is quite simple really.

James.
#!/usr/bin/perl -w

# receivesms.cgi
#  demo/prototype code
#  called by test user as web frontend or triggered by sms server receiving sms
#  receive sms and log details to a file
#
#  Doolin Technologies http://www.doolin.com
#
##############################################################################

use CGI qw(fatalsToBrowser); # send fatal error messages to the browser
use strict;

my $cgiq = new CGI; # create new CGI object and store it in $q
my $script = $cgiq->script_name;

#print html start, if we get errors look at /var/log/httpd
#print "content-type: text/html\n\n";
print $cgiq->header;

#get-url = 
"http://localhost/cgi-bin/receivesms.cgi?from=%p&to=%P&cmd=%k&text=%s&smscid=%i&dr1=%d&dr2=%A&user=%n&coding=%c&charset=%C&udh=%udh";
#mysql -u root dlr -e "create table rx ( fr varchar(50), t varchar(50), cmd 
varchar(50), text BLOB, smscid varchar(50), dr1 varchar(50), dr2 varchar(50), 
user varchar(50), coding varchar(50), charset varchar(50), udh varchar(50));"

print <<END;
<html><head><title>SMS rx test tool</title>
<link rel="shortcut icon" href="smsrx.png" type="image/x-icon"></head>
</head><body>

<h1>SMS rx test tool</h1>

<hr>
END

# much better to use LWP
sub getURL {
   my $url = shift;
   return `wget "$url" -o /tmp/wget.log -O -`;
}

################## get timestamp and cgi params #################

my $time = time;

my $forminFrom = $cgiq->param('from');
my $forminTo = $cgiq->param('to');
my $forminCmd = $cgiq->param('cmd');
my $forminText = $cgiq->param('text');
my $forminSmscid = $cgiq->param('smscid');
my $formindr1 = $cgiq->param('dr1');
my $formindr2 = $cgiq->param('dr2');
my $forminUser = $cgiq->param('user');
my $forminCoding = $cgiq->param('coding');
my $forminCharset = $cgiq->param('charset');
my $forminUdh = $cgiq->param('udh');

#get-url = 
"http://localhost/cgi-bin/receivesmshello.cgi?from=%p&to=%P&cmd=%k&text=%s&smscid=%i&dr1=%d&dr2=%A&user=%n&coding=%c&charset=%C&udh=%udh";

################### log script call / sms receive to file ######

sub logtofile {
    my $text = shift;
    my $logfile="/tmp/receivedsms.log";
    if ($logfile) {
        if (!open(OUTFILE, ">>$logfile")) {
            print "Can't open $logfile for writing: $!\n";
            die "Can't open $logfile for writing: $!\n";
        }
        print $text;
        print OUTFILE $text;
        close(OUTFILE);
    }
}


logtofile( "hello" );
logtofile( time().": script ".$script."\n" );
my $details="";
$details .= "From: " . $forminFrom . ", ";
$details .= "To: " . $forminTo . ", ";
$details .= "Cmd: " . $forminCmd . ", ";
$details .= "Text: " . $forminText . ", ";
$details .= "Smscid: " . $forminSmscid . ", ";
$details .= "dr1: " . $formindr1 . ", ";
$details .= "dr2: " . $formindr2 . ", ";
$details .= "User: " . $forminUser . ", ";
$details .= "Coding: " . $forminCoding . ", ";
$details .= "Charset: " . $forminCharset . ", ";
$details .= "Udh: " . $forminUdh . "\n";
logtofile( $details );

if ($forminFrom ne "") {

    # we can parse message and send sms as response or call other scripts
    #my $urltosend = 
"http://localhost:13013/cgi-bin/sendsms?username=$forminusername&password=$forminpassword&dlrurl=$formindlrurl&dlrmask=$formindlrmask&smsc=$forminsmsc&to=$forminto&from=$forminfrom&text=$message";;

    # register pin/serial with account/new account
    # very liberal regexp matches ANY number (before and after non numeric)
    if (my ($begg,$serial,$ing) = $forminText =~ 
m/([^0-9]|^)([0-9][0-9][0-9][0-9][0-9][0-9]*)([^0-9]|$)/) {
    #if (my ($serial) = $forminText =~ m/[^0-9]([0-9][0-9]*)[^0-9]/) {
        print "<p>Register serial number " . $serial . "\n" ;
        my $urltosend = 
"http://localhost/cgi-bin/addpintoaccount.cgi?phone=$forminFrom&serial=$serial&text=$forminText";;
        my $response = getURL $urltosend;
        print "<b>Result: ".$response."</b><hr>";
    } else { 
        print "no serial"; 
    }

}

print <<END;
</body></html>
END

exit;

Reply via email to