Esempio n. 1
0
function infobip_hook_getsmsstatus($gpid = 0, $uid = "", $smslog_id = "", $p_datetime = "", $p_update = "")
{
    global $plugin_config;
    list($c_sms_credit, $c_sms_status) = infobip_getsmsstatus($smslog_id);
    // pending
    $p_status = 0;
    if ($c_sms_status) {
        $p_status = $c_sms_status;
    }
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
}
Esempio n. 2
0
function messagemedia_hook_sendsms($mobile_sender, $sms_sender, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $messagemedia_param;
    global $gateway_number;
    // Message media
    require_once "SmsInterface.inc";
    //logger_print("Messagemedia: Message sent to".$sms_to);
    logger_print($messagemedia_param['username']);
    logger_print($messagemedia_param['password']);
    $si = new SmsInterface(false, false);
    /*
    $si->addMessage (
    	$phone, // String
    	$messageText, // String
    	$messageID, // Integer, optional, default = 0
    	$delay, // Integer, optional, default = 0
    	$validityPeriod, // Integer, optional, default = 169
    	$deliveryReport // Boolean, optional, default = false
    );
    */
    $si->addMessage($sms_to, $sms_msg, $smslog_id, 0, 169, true);
    $ok = false;
    // failed
    $p_status = 2;
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    // API ID = SMS log ID - No return ID by Message Media, ID is provided by PlaySMS
    $apimsgid = $smslog_id;
    messagemedia_setsmsapimsgid($smslog_id, $apimsgid);
    if (!$si->connect($messagemedia_param['username'], $messagemedia_param['password'], true, false)) {
        //echo "failed. Could not contact server.\n";
        logger_print("Messagemedia: failed. Could not contact server.");
    } elseif (!$si->sendMessages()) {
        //echo "failed. Could not send message to server.\n";
        logger_print("Messagemedia: failed. Could not send message to server.");
        if ($si->getResponseMessage() !== NULL) {
            //echo "<BR>Reason: " . $si->getResponseMessage () . "\n";
            logger_print("Messagemedia: Reason: " . $si->getResponseMessage());
        }
    } else {
        //echo "OK.\n";
        logger_print("Messagemedia: OK. sent");
        // sent
        $p_status = 1;
        $ok = true;
    }
    logger_print("smslog_id:" . $smslog_id . " charge:" . $c_sms_credit . " sms_status:" . $p_status . " response:" . $response[0] . " " . $response[1], 3, "messagemedia outgoing");
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    return $ok;
}
Esempio n. 3
0
function dlrd()
{
    global $core_config;
    $core_config['dlrd_limit'] = (int) $core_config['dlrd_limit'] ? (int) $core_config['dlrd_limit'] : 200;
    $list = dba_search(_DB_PREF_ . '_tblDLR', '*', array('flag_processed' => 1), '', array('LIMIT' => $core_config['dlrd_limit']));
    $j = 0;
    for ($j = 0; $j < count($list); $j++) {
        if ($id = $list[$j]['id']) {
            $smslog_id = $list[$j]['smslog_id'];
            $p_status = $list[$j]['p_status'];
            $uid = $list[$j]['uid'];
            if (dba_update(_DB_PREF_ . '_tblDLR', array('flag_processed' => 2), array('id' => $id))) {
                logger_print("id:" . $id . " smslog_id:" . $smslog_id . " p_status:" . $p_status . " uid:" . $uid, 3, "dlrd");
                setsmsdeliverystatus($smslog_id, $uid, $p_status);
            }
        }
    }
}
Esempio n. 4
0
function gnokii_hook_getsmsstatus($gpid = 0, $uid = "", $smslog_id = "", $p_datetime = "", $p_update = "")
{
    global $gnokii_param;
    // p_status :
    // 0 = pending
    // 1 = delivered
    // 2 = failed
    if ($gpid) {
        $fn = $gnokii_param['path'] . "/out.{$gpid}.{$uid}.{$smslog_id}";
        $efn = $gnokii_param['path'] . "/ERR.out.{$gpid}.{$uid}.{$smslog_id}";
    } else {
        $fn = $gnokii_param['path'] . "/out.0.{$uid}.{$smslog_id}";
        $efn = $gnokii_param['path'] . "/ERR.out.0.{$uid}.{$smslog_id}";
    }
    // set delivered first
    $p_status = 1;
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    // and then check if its not delivered
    if (file_exists($fn)) {
        $p_datetime_stamp = strtotime($p_datetime);
        $p_update_stamp = strtotime($p_update);
        $p_delay = floor(($p_update_stamp - $p_datetime_stamp) / 86400);
        // set pending if its under 2 days
        if ($p_delay <= 2) {
            $p_status = 0;
            setsmsdeliverystatus($smslog_id, $uid, $p_status);
        } else {
            $p_status = 2;
            setsmsdeliverystatus($smslog_id, $uid, $p_status);
            @unlink($fn);
            @unlink($efn);
        }
        return;
    }
    // set if its failed
    if (file_exists($efn)) {
        $p_status = 2;
        setsmsdeliverystatus($smslog_id, $uid, $p_status);
        @unlink($fn);
        @unlink($efn);
        return;
    }
    return;
}
Esempio n. 5
0
function gw_send_sms($mobile_sender, $sms_sender, $sms_to, $sms_msg, $gp_code = "", $uid = "", $smslog_id = "", $flash = false)
{
    global $kannel_param;
    global $gateway_number;
    $ok = false;
    if ($gateway_number) {
        $sms_from = $gateway_number;
    } else {
        $sms_from = $mobile_sender;
    }
    if ($sms_sender) {
        $sms_msg = $sms_msg . $sms_sender;
    }
    // set failed first
    $p_status = 2;
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    $sms_type = 2;
    // text
    if ($flash) {
        $sms_type = 1;
        //flash
    }
    $URL = "/cgi-bin/sendsms?username="******"&password="******"&from=" . urlencode($sms_from) . "&to=" . urlencode($sms_to) . "&text=" . urlencode($sms_msg);
    $URL .= "&dlr-mask=31&dlr-url=" . urlencode($kannel_param['phpgwsms_web'] . "/plugin/gateway/kannel/dlr.php?type=%d&slid={$smslog_id}&uid={$uid}");
    $URL .= "&mclass={$sms_type}";
    $connection = fsockopen($kannel_param['bearerbox_host'], $kannel_param['sendsms_port'], &$error_number, &$error_description, 60);
    if ($connection) {
        socket_set_blocking($connection, false);
        fputs($connection, "GET {$URL} HTTP/1.0\r\n\r\n");
        while (!feof($connection)) {
            $myline = fgets($connection, 128);
            if ($myline == "Sent.") {
                $ok = true;
                // set pending
                $p_status = 0;
                setsmsdeliverystatus($smslog_id, $uid, $p_status);
            }
        }
    }
    fclose($connection);
    return $ok;
}
Esempio n. 6
0
function smstools_hook_getsmsstatus($gpid = 0, $uid = "", $smslog_id = "", $p_datetime = "", $p_update = "")
{
    global $smstools_param;
    // p_status :
    // 0 = pending
    // 1 = sent/delivered
    // 2 = failed
    if ($gpid) {
        $fn = $smstools_param['path'] . "/sent/out.{$gpid}.{$uid}.{$smslog_id}";
        $efn = $smstools_param['path'] . "/failed/out.{$gpid}.{$uid}.{$smslog_id}";
    } else {
        $fn = $smstools_param['path'] . "/sent/out.0.{$uid}.{$smslog_id}";
        $efn = $smstools_param['path'] . "/failed/out.0.{$uid}.{$smslog_id}";
    }
    $p_datetime_stamp = strtotime($p_datetime);
    $p_update_stamp = strtotime($p_update);
    $p_delay = floor(($p_update_stamp - $p_datetime_stamp) / 86400);
    // set pending first
    $p_status = 0;
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    // set failed if its at least 2 days old
    if ($p_delay >= 2) {
        $p_status = 2;
        setsmsdeliverystatus($smslog_id, $uid, $p_status);
    }
    // set if its sent/delivered
    if (file_exists($fn)) {
        $p_status = 1;
        setsmsdeliverystatus($smslog_id, $uid, $p_status);
    }
    // set if its failed
    if (file_exists($efn)) {
        $p_status = 2;
        setsmsdeliverystatus($smslog_id, $uid, $p_status);
    }
    @unlink($fn);
    @unlink($efn);
    return;
}
Esempio n. 7
0
function gw_set_delivery_status($gp_code = "", $uid = "", $smslog_id = "", $p_datetime = "", $p_update = "")
{
    global $gnokii_param;
    if ($gp_code) {
        $fn = "{$gnokii_param['path']}/cache/smsd/out.{$gp_code}.{$uid}.{$smslog_id}";
        $efn = "{$gnokii_param['path']}/cache/smsd/ERR.out.{$gp_code}.{$uid}.{$smslog_id}";
    } else {
        $fn = "{$gnokii_param['path']}/cache/smsd/out.PV.{$uid}.{$smslog_id}";
        $efn = "{$gnokii_param['path']}/cache/smsd/ERR.out.PV.{$uid}.{$smslog_id}";
    }
    // set delivered first
    setsmsdeliverystatus($smslog_id, $uid, DLR_SENT);
    // and then check if its not delivered
    if (file_exists($fn)) {
        $p_datetime_stamp = strtotime($p_datetime);
        $p_update_stamp = strtotime($p_update);
        $p_delay = floor(($p_update_stamp - $p_datetime_stamp) / 86400);
        // set pending if its under 2 days
        if ($p_delay <= 2) {
            setsmsdeliverystatus($smslog_id, $uid, DLR_PENDING);
        } else {
            setsmsdeliverystatus($smslog_id, $uid, DLR_FAILED);
            @unlink($fn);
            @unlink($efn);
        }
        return;
    }
    // set if its failed
    if (file_exists($efn)) {
        setsmsdeliverystatus($smslog_id, $uid, DLR_FAILED);
        @unlink($fn);
        @unlink($efn);
        return;
    }
    return;
}
Esempio n. 8
0
function gammu_hook_getsmsstatus($gpid = 0, $uid = "", $smslog_id = "", $p_datetime = "", $p_update = "")
{
    global $gammu_param;
    // p_status :
    // 0 = pending
    // 1 = sent/delivered
    // 2 = failed
    // OUT<priority><date>_<time>_<serialno>_<phone_number>_<anything>.<ext><options>
    // $fn = 'A'.$date.'_'.$time.'_00_'.$sms_to.'_'.$smslog_id.'10001'.$uid.'10001'.$gpid.'.txtd';
    $sms_id = $smslog_id . '10001' . $uid . '10001' . $gpid;
    // sent dir
    $dir[0] = $gammu_param['path'] . '/sent/';
    // error dir
    $dir[1] = $gammu_param['path'] . '/error/';
    // list all files in sent and error dir
    $fn = array();
    for ($i = 0; $i < count($dir); $i++) {
        $j = 0;
        if ($handle = @opendir($dir[$i])) {
            while ($file = @readdir($handle)) {
                if ($file != "." && $file != "..") {
                    $fn[$i][$j] = $file;
                    $j++;
                }
            }
            @closedir($handle);
        }
    }
    // check listed files above againts sms_id
    $the_fn = '';
    for ($i = 0; $i < count($dir); $i++) {
        for ($j = 0; $j < count($fn[$i]); $j++) {
            if (preg_match("/" . $sms_id . "/", $fn[$i][$j])) {
                $the_fn = $dir[$i] . $fn[$i][$j];
                if ($i == 0) {
                    // sms sent
                    $p_status = 1;
                    setsmsdeliverystatus($smslog_id, $uid, $p_status);
                } else {
                    if ($i == 1) {
                        // failed to sent sms
                        $p_status = 2;
                        setsmsdeliverystatus($smslog_id, $uid, $p_status);
                    }
                }
                break;
            }
        }
    }
    // if file not found
    if (!file_exists($the_fn)) {
        $p_datetime_stamp = strtotime($p_datetime);
        $p_update_stamp = strtotime($p_update);
        $p_delay = floor(($p_update_stamp - $p_datetime_stamp) / 86400);
        // set failed if its at least 2 days old
        if ($p_delay >= 2) {
            $p_status = 2;
            setsmsdeliverystatus($smslog_id, $uid, $p_status);
        }
    } else {
        // delete the file if exists
        logger_print("smslog_id:" . $smslog_id . " unlink the_fn:" . $the_fn . " p_status:" . $p_status, 3, "gammu getsmsstatus");
        @unlink($the_fn);
    }
    return;
}
Esempio n. 9
0
function smstools_hook_sendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $smstools_param;
    $sms_id = "{$gpid}.{$uid}.{$smslog_id}";
    if (empty($sms_id)) {
        $sms_id = mktime();
    }
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    $the_msg = "From: {$sms_sender}\n";
    $the_msg .= "To: {$sms_to}\n";
    $the_msg .= "Report: yes\n";
    if ($msg_type == "flash") {
        $the_msg .= "Flash: yes\n";
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $the_msg .= "Alphabet: UCS\n";
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
        }
        // $sms_msg = str2hex($sms_msg);
    }
    $the_msg .= "\n{$sms_msg}";
    $fn = $smstools_param['path'] . "/outgoing/out.{$sms_id}";
    logger_print("outfile:" . $fn, 3, "smstools outgoing");
    umask(0);
    $fd = @fopen($fn, "w+");
    @fputs($fd, $the_msg);
    @fclose($fd);
    $ok = false;
    if (file_exists($fn)) {
        $ok = true;
        $p_status = 0;
        logger_print("outfile:" . $fn . " saved", 3, "smstools outgoing");
    } else {
        $p_status = 2;
        logger_print("cannot save outfile:" . $fn, 3, "smstools outgoing");
    }
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    return $ok;
}
Esempio n. 10
0
function msgtoolbox_hook_sendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    // global $msgtoolbox_param;   // global all variables needed, eg: varibles from config.php
    // ...
    // ...
    // return true or false
    // return $ok;
    global $msgtoolbox_param;
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    /* not used
    	$sms_type = 2; // text
    	if ($msg_type=="flash") {
    		$sms_type = 1; // flash
    	}
    	*/
    if ($sms_to && $sms_msg) {
        if ($unicode) {
            if (function_exists('mb_convert_encoding')) {
                // $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
                $sms_msg = mb_convert_encoding($sms_msg, "UCS-2", "auto");
                $unicode = "&coding=unicode";
                // added at the of query string if unicode
            }
        }
        // fixme anton - from playSMS v0.9.5.1 references to input.php replaced with index.php?app=webservices
        // I should add autodetect, if its below v0.9.5.1 should use input.php
        $query_string = "username="******"&password="******"&to=" . urlencode($sms_to) . "&from=" . urlencode($sms_from) . "&message=" . urlencode($sms_msg) . $unicode . "&route=" . $msgtoolbox_param['route'];
        $url = $msgtoolbox_param['url'] . "?" . $query_string;
        /* not used
        		if ($additional_param = $msgtoolbox_param['additional_param']) {
        			$additional_param = "&".$additional_param;
        		}
        		$url .= $additional_param;
        		$url = str_replace("&&", "&", $url);
        		*/
        logger_print($url, 3, "msgtoolbox outgoing");
        $fd = @implode('', file($url));
        if ($fd) {
            $response = split(",", $fd);
            if (trim($response[0]) == "1") {
                $remote_slid = trim($response[1]);
                if ($remote_slid) {
                    // this is for callback, if callback not used then the status would be sent or failed only
                    // local_slid is local SMS log id (local smslog_id)
                    // remote_slid is remote SMS log id (in API doc its referred to smsid or messageid)
                    // status=10 delivered to gateway
                    $db_query = "\n\t\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayMsgtoolbox (local_slid,remote_slid,status)\n\t\t\t\t\t\tVALUES ('{$smslog_id}','{$remote_slid}','10')\n\t\t\t\t\t    ";
                    $id = @dba_insert_id($db_query);
                    if ($id) {
                        $ok = true;
                        $p_status = 1;
                        // sms sent
                        setsmsdeliverystatus($smslog_id, $uid, $p_status);
                    }
                }
            }
            logger_print("sent smslog_id:" . $smslog_id . " response:" . $fd, 3, "msgtoolbox outgoing");
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $fd = str_replace("\n", " ", $fd);
            $fd = str_replace("\r", " ", $fd);
            logger_print("failed smslog_id:" . $smslog_id . " response:" . $fd, 3, "msgtoolbox outgoing");
        }
    }
    if (!$ok) {
        $p_status = 2;
        setsmsdeliverystatus($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Esempio n. 11
0
function gw_set_delivery_status($gp_code = "", $uid = "", $smslog_id = "", $p_datetime = "", $p_update = "")
{
    // global $uplink_param;
    // p_status :
    // 0 = pending
    // 1 = delivered
    // 2 = failed
    // setsmsdeliverystatus($smslog_id,$uid,$p_status);
    global $uplink_param;
    $db_query = "SELECT * FROM phpgw_sms_gwmodUplink WHERE up_status='0' AND up_local_slid='{$smslog_id}'";
    $db_result = dba_query($db_query);
    while ($db_row = dba_fetch_array($db_result)) {
        $local_slid = $db_row[up_local_slid];
        $remote_slid = $db_row[up_remote_slid];
        $query_string = "ws.php?u=" . $uplink_param[username] . "&p=" . $uplink_param[password] . "&ta=ds&slid=" . $remote_slid;
        $url = $uplink_param[master] . "/" . $query_string;
        $response = @implode('', file($url));
        switch ($response) {
            case "1":
                $p_status = 1;
                setsmsdeliverystatus($local_slid, $uid, $p_status);
                $db_query1 = "UPDATE phpgw_sms_gwmodUplink SET up_status='1' WHERE up_remote_slid='{$remote_slid}'";
                $db_result1 = dba_query($db_query1);
                break;
            case "2":
            case "ERR 400":
                $p_status = 2;
                setsmsdeliverystatus($local_slid, $uid, $p_status);
                $db_query1 = "UPDATE phpgw_sms_gwmodUplink SET up_status='2' WHERE up_remote_slid='{$remote_slid}'";
                $db_result1 = dba_query($db_query1);
                break;
        }
    }
}
Esempio n. 12
0
function gw_send_sms($mobile_sender, $sms_to, $sms_msg, $gp_code = "", $uid = "", $smslog_id = "", $msg_type = "text", $unicode = "0")
{
    global $clktl_param;
    global $gateway_number;
    if ($gateway_number) {
        $sms_from = $gateway_number;
    } else {
        $sms_from = $mobile_sender;
    }
    switch ($msg_type) {
        case "flash":
            $sms_type = "SMS_FLASH";
            break;
        case "logo":
            $sms_type = "SMS_NOKIA_OLOGO";
            break;
        case "picture":
            $sms_type = "SMS_NOKIA_PICTURE";
            break;
        case "ringtone":
        case "rtttl":
            $sms_type = "SMS_NOKIA_RTTTL";
            break;
        case "text":
        default:
            $sms_type = "SMS_TEXT";
    }
    // $query_string = "sendmsg?api_id=".$clktl_param[api_id]."&user="******"&password="******"&to=$sms_to&msg_type=$sms_type&text=".rawurlencode($sms_msg)."&deliv_ack=1&callback=3&unicode=$unicode&concat=3&from=".rawurlencode($sms_from);
    // no concat
    if ($unicode) {
        $sms_msg = utf8_to_unicode($sms_msg);
        $query_string = "sendmsg?api_id=" . $clktl_param[api_id] . "&user="******"&password="******"&to={$sms_to}&msg_type={$sms_type}&text={$sms_msg}&deliv_ack=1&callback=3&unicode={$unicode}&from=" . rawurlencode($sms_from);
    } else {
        $query_string = "sendmsg?api_id=" . $clktl_param[api_id] . "&user="******"&password="******"&to={$sms_to}&msg_type={$sms_type}&text=" . rawurlencode($sms_msg) . "&deliv_ack=1&callback=3&unicode={$unicode}&from=" . rawurlencode($sms_from);
    }
    $url = $clktl_param[send_url] . "/" . $query_string;
    $fd = file($url);
    $ok = false;
    $p_status = DLR_FAILED;
    if ($fd) {
        $response = split(":", $fd);
        $err_code = trim($response[1]);
        if (strtoupper($response[0]) == "ID") {
            if ($apimsgid = trim($response[1])) {
                clktl_setsmsapimsgid($smslog_id, $apimsgid);
                list($c_sms_credit, $c_sms_status) = clktl_getsmsstatus($smslog_id);
                if ($c_sms_status) {
                    $p_status = $c_sms_status;
                } else {
                    $p_status = DLR_PENDING;
                }
            } else {
                $p_status = DLR_SENT;
            }
        }
        $ok = true;
    }
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    return $ok;
}
Esempio n. 13
0
function uplink_hook_getsmsstatus($gpid = 0, $uid = "", $smslog_id = "", $p_datetime = "", $p_update = "")
{
    // global $uplink_param;
    // p_status :
    // 0 = pending
    // 1 = delivered
    // 2 = failed
    // setsmsdeliverystatus($smslog_id,$uid,$p_status);
    global $uplink_param;
    $db_query = "SELECT * FROM " . _DB_PREF_ . "_gatewayUplink WHERE up_local_slid='{$smslog_id}'";
    $db_result = dba_query($db_query);
    while ($db_row = dba_fetch_array($db_result)) {
        $local_slid = $db_row['up_local_slid'];
        $remote_slid = $db_row['up_remote_slid'];
        // fixme anton - from playSMS v0.9.6 references to input.php replaced with index.php?app=webservices
        // I should add autodetect, if its below v0.9.6 should use input.php
        $query_string = "index.php?app=webservices&u=" . $uplink_param['username'] . "&p=" . $uplink_param['password'] . "&ta=ds&slid=" . $remote_slid;
        $url = $uplink_param['master'] . "/" . $query_string;
        $response = @implode('', file($url));
        switch ($response) {
            case "1":
                $p_status = 1;
                setsmsdeliverystatus($local_slid, $uid, $p_status);
                $db_query1 = "UPDATE " . _DB_PREF_ . "_gatewayUplink SET c_timestamp='" . mktime() . "',up_status='1' WHERE up_remote_slid='{$remote_slid}'";
                $db_result1 = dba_query($db_query1);
                break;
            case "3":
                $p_status = 3;
                setsmsdeliverystatus($local_slid, $uid, $p_status);
                $db_query1 = "UPDATE " . _DB_PREF_ . "_gatewayUplink SET c_timestamp='" . mktime() . "',up_status='3' WHERE up_remote_slid='{$remote_slid}'";
                $db_result1 = dba_query($db_query1);
                break;
            case "2":
            case "ERR 400":
                $p_status = 2;
                setsmsdeliverystatus($local_slid, $uid, $p_status);
                $db_query1 = "UPDATE " . _DB_PREF_ . "_gatewayUplink SET c_timestamp='" . mktime() . "',up_status='2' WHERE up_remote_slid='{$remote_slid}'";
                $db_result1 = dba_query($db_query1);
                break;
        }
    }
}
Esempio n. 14
0
function clickatell_hook_sendsms($mobile_sender, $sms_sender, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $clickatell_param;
    global $gateway_number;
    if ($clickatell_param['sender']) {
        $sms_from = $clickatell_param['sender'];
    } else {
        if ($gateway_number) {
            $sms_from = $gateway_number;
        } else {
            $sms_from = $mobile_sender;
        }
    }
    if ($sms_sender) {
        $sms_msg = $sms_msg . $sms_sender;
    }
    switch ($sms_type) {
        case "flash":
            $sms_type = "SMS_FLASH";
            break;
        case "logo":
            $sms_type = "SMS_NOKIA_OLOGO";
            break;
        case "picture":
            $sms_type = "SMS_NOKIA_PICTURE";
            break;
        case "ringtone":
        case "rtttl":
            $sms_type = "SMS_NOKIA_RTTTL";
            break;
        case "text":
        default:
            $sms_type = "SMS_TEXT";
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
        }
        $sms_msg = str2hex($sms_msg);
        $unicode = 1;
    }
    // fixme anton - if sms_from is not set in gateway_number and global number, we cannot pass it to clickatell
    $set_sms_from = $sms_from == $mobile_sender ? '' : "&from=" . urlencode($sms_from);
    $query_string = "sendmsg?api_id=" . $clickatell_param['api_id'] . "&user="******"&password="******"&to=" . urlencode($sms_to) . "&msg_type={$sms_type}&text=" . urlencode($sms_msg) . "&unicode=" . $unicode . $set_sms_from;
    $url = $clickatell_param['send_url'] . "/" . $query_string;
    if ($additional_param = $clickatell_param['additional_param']) {
        $additional_param = "&" . $additional_param;
    } else {
        $additional_param = "&deliv_ack=1&callback=3";
    }
    $url .= $additional_param;
    $url = str_replace("&&", "&", $url);
    logger_print("url:" . $url, 3, "clickatell outgoing");
    $fd = @implode('', file($url));
    $ok = false;
    // failed
    $p_status = 2;
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    if ($fd) {
        $response = split(":", $fd);
        $err_code = trim($response[1]);
        if (strtoupper($response[0]) == "ID") {
            if ($apimsgid = trim($response[1])) {
                clickatell_setsmsapimsgid($smslog_id, $apimsgid);
                list($c_sms_credit, $c_sms_status) = clickatell_getsmsstatus($smslog_id);
                // pending
                $p_status = 0;
                if ($c_sms_status) {
                    $p_status = $c_sms_status;
                }
            } else {
                // sent
                $p_status = 1;
            }
            logger_print("smslog_id:" . $smslog_id . " charge:" . $c_sms_credit . " sms_status:" . $p_status . " response:" . $response[0] . " " . $response[1], 3, "clickatell outgoing");
            setsmsdeliverystatus($smslog_id, $uid, $p_status);
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $fd = str_replace("\n", " ", $fd);
            $fd = str_replace("\r", " ", $fd);
            logger_print("smslog_id:" . $smslog_id . " response:" . $fd, 3, "clickatell outgoing");
        }
        $ok = true;
    }
    return $ok;
}
Esempio n. 15
0
        case 9:
            $stat = 4;
            break;
            // sent
        // sent
        case 12:
            $stat = 4;
            break;
            // sent
        // sent
        case 18:
            $stat = 5;
            break;
            // failed
    }
    $p_status = $stat;
    if ($stat) {
        $p_status = $stat - 3;
    }
    setsmsdeliverystatus($slid, $uid, $p_status);
    // log dlr
    $db_query = "SELECT kannel_dlr_id FROM " . _DB_PREF_ . "_gatewayKannel_dlr WHERE smslog_id='{$slid}'";
    $db_result = dba_num_rows($db_query);
    if ($db_result > 0) {
        $db_query = "UPDATE " . _DB_PREF_ . "_gatewayKannel_dlr SET c_timestamp='" . mktime() . "',kannel_dlr_type='{$type}' WHERE smslog_id='{$slid}'";
        $db_result = dba_query($db_query);
    } else {
        $db_query = "INSERT INTO " . _DB_PREF_ . "_gatewayKannel_dlr (smslog_id,kannel_dlr_type) VALUES ('{$slid}','{$type}')";
        $db_result = dba_query($db_query);
    }
}
Esempio n. 16
0
function kannel_gw_set_delivery_status($smslog_id, $uid, $kannel_dlr)
{
    $playsms_dlr = convertKannelDlrToPlaysmsDlr($kannel_dlr);
    setsmsdeliverystatus($smslog_id, $uid, $playsms_dlr);
    // log dlr
    $db_query = "SELECT kannel_dlr_id FROM playsms_gwmodKannel_dlr WHERE smslog_id='{$smslog_id}'";
    $db_result = dba_num_rows($db_query);
    if ($db_result > 0) {
        $db_query = "UPDATE playsms_gwmodKannel_dlr SET kannel_dlr_type='{$kannel_dlr}' WHERE smslog_id='{$smslog_id}'";
        $db_result = dba_query($db_query);
    } else {
        $db_query = "INSERT INTO playsms_gwmodKannel_dlr (smslog_id,kannel_dlr_type) VALUES ('{$smslog_id}','{$kannel_dlr}')";
        $db_result = dba_query($db_query);
    }
}
Esempio n. 17
0
function gammu_hook_sendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $gammu_param;
    $date = date('Ymd', time());
    $time = date('Gis', time());
    // OUT<priority><date>_<time>_<serialno>_<phone_number>_<anything>.<ext><options>
    $sms_id = 'A' . $date . '_' . $time . '_00_' . $sms_to . '_' . $smslog_id . '10001' . $uid . '10001' . $gpid . '.txtd';
    if ($msg_type == "flash") {
        $sms_id .= 'f';
    }
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    // no need to do anything on unicoded messages since InboxFormat and OutboxFormat is already set to unicode
    // meaning gammu will take care of it
    /*
    if ($unicode) {
    if (function_exists('mb_convert_encoding')) {
    $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
    }
    }
    */
    $fn = $gammu_param['path'] . "/outbox/OUT" . $sms_id;
    logger_print("outfile:" . $fn, 3, "gammu outgoing");
    umask(0);
    $fd = @fopen($fn, "w+");
    @fputs($fd, $sms_msg);
    @fclose($fd);
    $ok = false;
    if (file_exists($fn)) {
        $ok = true;
        $p_status = 0;
        logger_print("outfile:" . $fn . " saved", 3, "gammu outgoing");
    } else {
        $p_status = 2;
        logger_print("cannot save outfile:" . $fn, 3, "gammu outgoing");
    }
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    return $ok;
}
Esempio n. 18
0
function kannel_hook_sendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $kannel_param;
    global $http_path;
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    // set failed first
    $p_status = 2;
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    $msg_type = 1;
    // text, default
    if ($sms_type == "flash") {
        $msg_type = 0;
        //flash
    }
    // this doesn't work properly if kannel is not on the same server with playSMS
    // $dlr_url = $http_path['base'] . "/plugin/gateway/kannel/dlr.php?type=%d&slid=$smslog_id&uid=$uid";
    // prior to 0.9.5.1
    // $dlr_url = $kannel_param['playsms_web'] . "/plugin/gateway/kannel/dlr.php?type=%d&slid=".$smslog_id."&uid=".$uid;
    // since 0.9.5.1
    $dlr_url = $kannel_param['playsms_web'] . "/index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&slid=" . $smslog_id . "&uid=" . $uid;
    $URL = "/cgi-bin/sendsms?username="******"&password="******"&from=" . urlencode($sms_sender) . "&to=" . urlencode($sms_to);
    $URL .= "&dlr-mask=31&dlr-url=" . urlencode($dlr_url);
    $URL .= "&mclass=" . $msg_type;
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
            $URL .= "&charset=UTF-16BE";
        }
        $URL .= "&coding=2";
    }
    $URL .= "&text=" . urlencode($sms_msg);
    // fixme anton - patch 1.4.3, dlr requries smsc-id, you should add at least smsc=<your smsc-id in kannel.conf> from web
    if ($additional_param = $kannel_param['additional_param']) {
        $additional_param = "&" . $additional_param;
    } else {
        $additional_param = "&smsc=default";
    }
    $URL .= $additional_param;
    $URL = str_replace("&&", "&", $URL);
    logger_print("http://" . $kannel_param['bearerbox_host'] . ":" . $kannel_param['sendsms_port'] . $URL, 3, "kannel outgoing");
    // srosa 20100531: Due to improper http response from Kannel, file_get_contents cannot be used.
    // One issue is that Kannel responds with HTTP 202 whereas file_get_contents expect HTTP 200
    // The other is that a missing CRLF at the end of Kannel's message forces file_get_contents to wait forever.
    // reverting to previous way of doing things which works fine.
    /*
    if ($rv = trim(file_get_contents("$URL"))) {
    // old kannel responsed with Sent.
    // new kannel with the other 2
    if (($rv == "Sent.") || ($rv == "0: Accepted for delivery") || ($rv == "3: Queued for later delivery")) {
    $ok = true;
    // set pending
    $p_status = 0;
    setsmsdeliverystatus($smslog_id, $uid, $p_status);
    }
    }
    */
    // fixme anton - deprecated when using PHP5
    //$connection = fsockopen($kannel_param['bearerbox_host'],$kannel_param['sendsms_port'],&$error_number,&$error_description,60);
    $connection = fsockopen($kannel_param['bearerbox_host'], $kannel_param['sendsms_port'], $error_number, $error_description, 60);
    if ($connection) {
        socket_set_blocking($connection, false);
        fputs($connection, "GET " . $URL . " HTTP/1.0\r\n\r\n");
        while (!feof($connection)) {
            $rv = fgets($connection, 128);
            if ($rv == "Sent." || $rv == "0: Accepted for delivery" || $rv == "3: Queued for later delivery") {
                $ok = true;
                // set pending
                $p_status = 0;
                setsmsdeliverystatus($smslog_id, $uid, $p_status);
            }
        }
        fclose($connection);
        // good or bad, print it on the log
        logger_print("smslog_id:" . $smslog_id . " response:" . $rv, 3, "kannel outgoing");
    }
    return $ok;
}
Esempio n. 19
0
            // pending
            case "003":
            case "008":
                $c_sms_status = 1;
                break;
                // sent
            // sent
            case "005":
            case "006":
            case "007":
            case "009":
            case "010":
            case "012":
                $c_sms_status = 2;
                break;
                // failed
            // failed
            case "004":
                $c_sms_status = 3;
                break;
                // delivered
        }
        $c_sms_credit = ceil($cb_charge);
        // pending
        $p_status = 0;
        if ($c_sms_status) {
            $p_status = $c_sms_status;
        }
        setsmsdeliverystatus($smslog_id, $uid, $p_status);
    }
}
Esempio n. 20
0
    $message = trim($cb_text);
    //$message = strtolower($message);
    // Hack for Parking Service from Deisen
    //$r_message = explode("parking ", $message);
    //$message = $r_message[1]; // without parking
    $sms_receiver = trim($cb_to);
    // collected:
    // $sms_datetime, $sms_sender, $message, $sms_receiver
    logger_print("sender:" . $sms_sender . " receiver:" . $sms_receiver . " dt:" . $sms_datetime . " msg:" . $message, 3, "messagemedia incoming");
    setsmsincomingaction($sms_datetime, $sms_sender, $message, $sms_receiver);
    logger_print("sender:" . $sms_sender . " receiver:" . $sms_receiver . " dt:" . $sms_datetime . " msg:" . $message, 3, "messagemedia incoming");
}
if ($cb_status && $cb_apimsgid) {
    $db_query = "\n        SELECT " . _DB_PREF_ . "_tblSMSOutgoing.smslog_id AS smslog_id," . _DB_PREF_ . "_tblSMSOutgoing.uid AS uid\n        FROM " . _DB_PREF_ . "_tblSMSOutgoing," . _DB_PREF_ . "_gatewayMessagemedia_apidata\n        WHERE\n            " . _DB_PREF_ . "_tblSMSOutgoing.smslog_id=" . _DB_PREF_ . "_gatewayMessagemedia_apidata.smslog_id AND\n            " . _DB_PREF_ . "_gatewayMessagemedia_apidata.apimsgid='{$cb_apimsgid}'\n    ";
    $db_result = dba_query($db_query);
    $db_row = dba_fetch_array($db_result);
    $uid = $db_row['uid'];
    logger_print($db_query . " - " . $uid, "3", "DEBUG");
    setsmsdeliverystatus($cb_apimsgid, $uid, $cb_status);
    // log dlr
    /*    $db_query = "SELECT apidata_id FROM "._DB_PREF_."_gatewayMessagemedia_apidata WHERE smslog_id='$cb_apimsgid'";
        $db_result = dba_num_rows($db_query);
        if ($db_result > 0) {
            $db_query = "UPDATE "._DB_PREF_."_gatewayMessagemedia_apidata SET c_timestamp='".mktime()."' WHERE smslog_id='$cb_apimsgid'";
            $db_result = dba_query($db_query);
        } else {
            $db_query = "INSERT INTO "._DB_PREF_."_gatewayMessagemedia_apidata (smslog_id) VALUES ('$cb_apimsgid')";
            $db_result = dba_query($db_query);
        }
    */
}