#!/usr/bin/php -q
<?php
ob_implicit_flush(true);
set_time_limit(6);
$in = fopen("php://stdin","r");
$stdlog = fopen("/var/log/asterisk/my_agi.log", "w");
// toggle debugging output (more verbose)
$debug = false;
function read() {
global $in, $debug, $stdlog;
$input = str_replace("\n", "", fgets($in, 4096));
if ($debug) fputs($stdlog, "read: $input\n");
return $input;
}
function errlog($line) {
global $err;
echo "VERBOSE \"$line\"\n";
}
function write($line) {
global $debug, $stdlog;
if ($debug) fputs($stdlog, "write: $line\n");
echo $line."\n";
}
// parse agi headers into array
while ($env=read()) {
$s = split(": ",$env);
$agi[str_replace("agi_","",$s[0])] = trim($s[1]);
if (($env == "") || ($env == "\n")) {
break;
}
}
class deset_gateway
{
var $login;
var $pass;
var $nummern;
var $message;
var $sender_id;
var $TEXT;
var $send;
var $text_length;
var $fp;
var $rawreply;
var $replyarray;
var $result;
function deset_gateway($login,$pass)
{
$this->login = $login;
$this->pass = $pass;
}
function send_message($numbers,$message,$sender_id)
{
$this->nummern = implode (",", $numbers);
$this->message = $message;
$this->sender_id = $sender_id;
$this->nummern = urlencode ($this->nummern);
$this->message = urlencode ($this->message);
$this->sender_id = urlencode ($this->sender_id);
$this->TEXT = "log=$this->login&pas=$this->pass&num=$this->nummern&mess=$this->message&sender=$this->sender_id";
$this->text_length = strlen($this->TEXT);
$this->senden();
}
function send_flash_message($numbers,$message,$sender_id,$flash)
{
$this->nummern = implode (",", $numbers);
$this->message = $message;
$this->sender_id = $sender_id;
$this->nummern = urlencode ($this->nummern);
$this->message = urlencode ($this->message);
$this->sender_id = urlencode ($this->sender_id);
$this->TEXT = "log=$this->login&pas=$this->pass&num=$this->nummern&mess=$this->message&sender=$this->sender_id";
if ($flash) {
$this->TEXT .= '&datentyp=flashsms';
}
$this->text_length = strlen($this->TEXT);
$this->senden();
}
function senden(){
$this->send = "POST /main.php HTTP/1.0\r\n";
$this->send.= "Host: deset-mobile.com\r\n";
$this->send.= "Content-type: application/x-www-form-urlencoded\r\n";
$this->send.= "Content-length: $this->text_length\n\n";
$this->send.= "$this->TEXT\n";
$this->send.= "\r\n";
$this->fp = fsockopen ("deset-mobile.com", 80, &$errno, &$errstr, 60);
if ($this->fp) {
fputs ($this->fp,$this->send);
$this->rawreply = fread ($this->fp,5120);
fclose($this->fp);
$this->replyarray = explode ("\n", $this->rawreply);
$this->result = $this->replyarray[7];
//$result = substr($replyarray[0], 0, 2);
}
else
{
$this->result = "Connection Error!!";
}
print $this->result;
//echo '<hr><pre>';
//print_r($this->replyarray);
//echo '</pre>';
}
}
$login = "LOGIN";
$pass = "PASS";
$user = "LOGIN";//<-- sms kaufen
$pass = "USER";//<-- sms kaufen
//deset_gateway
//$gateway = new deset_gateway($login,$pass);
//$numbers = array($argv[2]);
$numbers = $argv[2];
$message = "$argv[3]";
$sender_id = "$argv[1]";
//$gateway->send_message($numbers,$message,$sender_id);
//smskaufen.de
$text = urlencode($message);
$to = urlencode($numbers);
$url = "http://smskaufen.de/" . "?id=" . $user . "&pw=" . $pass . "&absender=" . $sender_id . "&empfaenger=" . $to . "&text=" . $text . "&type=3";
$fp = fopen($url, "r");
$reply = fgets($fp, 1024);
#echo "reply:'$reply'";
if ($reply == 100)
{
echo "Die SMS wurde erfolgreich ausgeliefert";
} else {
echo "Leider konnte die SMS nicht versendet werden, es trat ein Fehler auf.
Fehlercode: " . $reply;
}
exit;
?>