SMSTools php frontend

Et stk php kode til at interface smstools fra ports med en hjemmeside/kalde noget fra nagios mm..

use at own risk

[code]

CREATE TABLE `sms` (
`user` varchar(30) NOT NULL,
`password` varchar(40) NOT NULL,
`count` int(11) NOT NULL,
`email` varchar(255) NOT NULL,
UNIQUE KEY `user` (`user`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT=’login info og antal smser der kan sendes igen’;

[/code]

[code]

// usage: user, password, message, phone
// Made by: Peter Larsen
// Beerware licens (c) 2007
//
// Messy, made in 10 mins :P

// login to database

$link = mysql_connect(‘localhost’, ‘smsgateway’, ‘passwordhere’);
if (!$link) {
die(‘FEJL:Could not connect: ‘ . mysql_error());
}

if (!isset($_REQUEST[user])) {

die(“FEJL:user not set”);
}

if (!isset($_REQUEST[password])) {

die(“FEJL:password not set”);
}

if (!isset($_REQUEST[phone])) {

die(“FEJL:phone not set”);
}

if (!isset($_REQUEST[message])) {

die(“FEJL:message not set”);
}

// check username and password

$user = mysql_real_escape_string($_REQUEST[user]);
$password = mysql_real_escape_string($_REQUEST[password]);

$result = mysql_query(“SELECT * from sms.sms WHERE user = ‘$user’ and password = ‘$password'”);
if (!$result) {
die(‘FEJL:Invalid query: ‘ . mysql_error());
}

$sms = mysql_fetch_array($result);

if ($sms[user] == “”) {
die(“FEJL:user or password error”);
}

// url decode message

$message = utf8_decode($_REQUEST[message]);

// urldecode($_REQUEST[message]);
// count size of msg

$messagesize = strlen($message);

// $sizeofmsg/160 = number messages

$messagecount = ($messagesize/160);

// check number messages is not above prepaid

if ($messagecount > $sms[‘count’]) {
die(‘FEJL:Account overdue’);
}

// check phonenumber

if ( (!ereg(“^45”, $_REQUEST[phone])) OR (ereg(“^451”, $_REQUEST[phone])) OR (ereg(“^4590”, $_REQUEST[phone])) ) {
die(‘FEJL:Phonenumer MUST start with 45 (Denmark) and NOT 451x nor 4590x’);
}

// createing message, all ok
// deduct messages count from account
$newcount = $sms[‘count’] – $messagecount;

settype($newcount, “integer”);

$result = mysql_query(“UPDATE sms.sms SET count = ‘$newcount’ WHERE user=’$sms[user]'”);

if (!$result) {
die(‘FEJL:Invalid query: ‘.mysql_error());
}

// create message
$time = time();

$phone = $_REQUEST[phone];
$filename = ‘outgoing/’.$user.’-‘.$phone.’-‘.$time.’-‘.md5($message);
$handle = fopen($filename, “w”);

fputs($handle, “To: +$phone\n”);

fputs($handle, “Alphabet: ISO8859-15\n”);

// if flash set, set flash flag
if (isset($_REQUEST[‘flash’])) {
fputs($handle, “Flash: yes\n”);
}
fputs($handle, “\n”);
fputs($handle, “$message”);
fclose($handle);

// send email hvis antal sms er under 20

if ($sms[count] < 20) { $donotreplyheader = "From: GratisDNS Robot \nReply-To: donotreply@gratisdns.dk\nReturn-Path: \nRemote-IP: ".$_SERVER['REMOTE_ADDR']."\nMIME-Version: 1.0\nContent-Type: text/plain;\n charset=\"iso-8859-1\"\nContent-Transfer-Encoding: 8bit\nContent-Disposition: inline"; mail($sms[email], "Only few SMS left on account", "Hi\n\nFew SMS left on account, write to salg@gratisdns.dk for more, please state numbers of sms's in 100's (22DKK for 100 sms's)\n\nregards, Larsen Data", $donotreplyheader); } // flag OK echo "OK:message for $phone sent, $newcount sms messages left ($newcount * 160 chars)"; ?>
[/code]

  1. Nokia n71 + SMSTools3 « ЗАПИСНИЧОК

    June 7, 2009 at 9:58 pm

    […] Приклад фронтенду тут. […]

Comments are closed.