Beispiel #1
0
function openvox_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "openvox_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($plugin_config['openvox']['gateway_host'] && $plugin_config['openvox']['gateway_port'] && $sms_to && $sms_msg) {
        $query_string = "username="******"&password="******"&phonenumber=" . urlencode($sms_to) . "&message=" . urlencode($sms_msg) . "&report=JSON&smslog_id=" . $smslog_id;
        $url = 'http://' . $plugin_config['openvox']['gateway_host'] . ":" . $plugin_config['openvox']['gateway_port'] . '/sendsms?' . $query_string;
        _log("url:[" . $url . "]", 3, "openvox outgoing");
        $resp = json_decode(file_get_contents($url), true);
        $data = $resp['report'][0][0][0];
        $data['message'] = $resp['message'];
        _log('response result:' . $data['result'] . ' port:' . $data['port'] . ' to:' . $data['phonenumber'] . ' time:' . $data['time'], 3, 'openvox_hook_sendsms');
        if ($data['result'] == 'success') {
            $p_status = 1;
            dlr($smslog_id, $uid, $p_status);
        } else {
            $p_status = 2;
            dlr($smslog_id, $uid, $p_status);
        }
    }
    return TRUE;
}
Beispiel #2
0
function nexmo_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "nexmo_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['nexmo']['module_sender']) {
        $sms_sender = $plugin_config['nexmo']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_sender && $sms_to && $sms_msg) {
        $unicode = "";
        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 = "&type=unicode";
                // added at the of query string if unicode
            }
        }
        $query_string = "api_key=" . $plugin_config['nexmo']['api_key'] . "&api_secret=" . $plugin_config['nexmo']['api_secret'] . "&to=" . urlencode($sms_to) . "&from=" . urlencode($sms_sender) . "&text=" . urlencode($sms_msg) . $unicode . "&status-report-req=1&client-ref=" . $smslog_id;
        $url = $plugin_config['nexmo']['url'] . "?" . $query_string;
        _log("url:[" . $url . "]", 3, "nexmo outgoing");
        // fixme anton
        // rate limit to 1 second per submit - nexmo rule
        sleep(1);
        $resp = json_decode(file_get_contents($url), true);
        if ($resp['message-count']) {
            $c_status = $resp['messages'][0]['status'];
            $c_message_id = $resp['messages'][0]['message-id'];
            $c_network = $resp['messages'][0]['network'];
            $c_error_text = $resp['messages'][0]['error-text'];
            _log("sent smslog_id:" . $smslog_id . " message_id:" . $c_message_id . " status:" . $c_status . " error:" . $c_error_text, 2, "nexmo outgoing");
            $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayNexmo (local_smslog_id,remote_smslog_id,status,network,error_text)\n\t\t\t\tVALUES ('{$smslog_id}','{$c_message_id}','{$c_status}','{$c_network}','{$c_error_text}')";
            $id = @dba_insert_id($db_query);
            if ($id && $c_status == 0) {
                $ok = true;
                $p_status = 1;
                dlr($smslog_id, $uid, $p_status);
            }
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $resp = str_replace("\n", " ", $resp);
            $resp = str_replace("\r", " ", $resp);
            _log("failed smslog_id:" . $smslog_id . " resp:" . $resp, 2, "nexmo outgoing");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Beispiel #3
0
function blocked_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "blocked_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $p_status = 2;
    dlr($smslog_id, $uid, $p_status);
    return TRUE;
}
Beispiel #4
0
function uplink_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    // global $plugin_config; // global all variables needed, eg: varibles from config.php
    // ...
    // ...
    // return true or false
    // return $ok;
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "uplink_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['uplink']['module_sender']) {
        $sms_sender = $plugin_config['uplink']['module_sender'];
    }
    $sms_footer = $sms_footer ? $sms_footer : stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg) . $sms_footer;
    $ok = false;
    if ($sms_to && $sms_msg) {
        $unicode = trim($unicode) ? 1 : 0;
        $nofooter = $plugin_config['uplink']['try_disable_footer'] ? 1 : 0;
        $ws = new Playsms\Webservices();
        $ws->url = $plugin_config['uplink']['master'] . '/index.php?app=ws';
        $ws->username = $plugin_config['uplink']['username'];
        $ws->token = $plugin_config['uplink']['token'];
        $ws->to = $sms_to;
        $ws->from = $sms_sender;
        $ws->msg = $sms_msg;
        $ws->unicode = $unicode;
        $ws->nofooter = $nofooter;
        $ws->sendSms();
        // _log('url:'.$ws->getWebservicesUrl(), 3, 'uplink sendsms');
        if ($ws->getStatus()) {
            $response = $ws->getData();
            $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayUplink (up_local_smslog_id,up_remote_smslog_id,up_status,up_remote_queue_code,up_dst)\n\t\t\t\tVALUES ('{$smslog_id}','" . $response->smslog_id . "','0','" . $response->queue . "','{$sms_to}')";
            if ($up_id = @dba_insert_id($db_query)) {
                $ok = true;
            }
            _log('sendsms success. smslog_id:' . $smslog_id . ' remote_smslog_id:' . $response->smslog_id . ' remote_queue:' . $response->queue, 3, 'uplink sendsms');
        } else {
            _log('sendsms failed. error:' . $ws->getError() . ' error_string:' . $ws->getErrorString(), 3, 'uplink sendsms');
        }
    }
    if ($ok && ($response->smslog_id || $response->queue)) {
        $p_status = 0;
    } else {
        $p_status = 2;
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
Beispiel #5
0
function dev_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    $ok = false;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "dev_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    if ($plugin_config['dev']['enable_outgoing']) {
        $p_status = 3;
        dlr($smslog_id, $uid, $p_status);
        $ok = true;
    }
    return $ok;
}
Beispiel #6
0
function gnokii_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "gnokii_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $sms_id = "{$gpid}.{$uid}.{$smslog_id}";
    if (empty($sms_id)) {
        $sms_id = mktime();
    }
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    $sms_msg = str_replace("\n", " ", $sms_msg);
    $sms_msg = str_replace("\r", " ", $sms_msg);
    $the_msg = "{$sms_to}\n{$sms_msg}";
    $fn = $plugin_config['gnokii']['path'] . "/out.{$sms_id}";
    logger_print("saving outfile:" . $fn, 2, "gnokii 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("saved outfile:" . $fn, 2, "gnokii outgoing");
    } else {
        $p_status = 2;
        logger_print("fail to save outfile:" . $fn, 2, "gnokii outgoing");
    }
    dlr($smslog_id, $uid, $p_status);
    @unlink($fn);
    return $ok;
}
Beispiel #7
0
function smstools_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log('enter smsc:' . $smsc . ' smslog_id:' . $smslog_id . ' uid:' . $uid . ' to:' . $sms_to, 3, 'smstools_hook_sendsms');
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    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 ($sms_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);
    }
    // final message file content
    $the_msg .= "\n" . $sms_msg;
    // outfile
    $gpid = (int) $gpid ? (int) $gpid : 0;
    $uid = (int) $uid ? (int) $uid : 0;
    $smslog_id = (int) $smslog_id ? (int) $smslog_id : 0;
    $sms_id = $gpid . '.' . $uid . '.' . $smslog_id;
    $outfile = 'out.' . $sms_id;
    $fn = $plugin_config['smstools']['queue'] . '/' . $outfile;
    if ($fd = @fopen($fn, 'w+')) {
        @fputs($fd, $the_msg);
        @fclose($fd);
        _log('saving outfile:' . $fn . ' smsc:[' . $smsc . ']', 3, 'smstools_hook_sendsms');
    }
    $ok = false;
    if (file_exists($fn)) {
        $ok = true;
        $p_status = 0;
        _log('saved outfile:' . $fn . ' smsc:[' . $smsc . ']', 2, 'smstools_hook_sendsms');
    } else {
        $p_status = 2;
        _log('fail to save outfile:' . $fn . ' smsc:[' . $smsc . ']', 2, 'smstools_hook_sendsms');
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
Beispiel #8
0
function bulksms_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    // Based on http://www.bulksms.com/int/docs/eapi/submission/send_sms/
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "bulksms_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['bulksms']['module_sender']) {
        $sms_sender = $plugin_config['bulksms']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $sms_from = $sms_sender;
    $sms_dca = "7bit";
    $sms_class = "2";
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    switch ($sms_type) {
        case "flash":
            $sms_class = "0";
            break;
        case "logo":
        case "picture":
        case "ringtone":
        case "rtttl":
            $sms_dca = "8bit";
            break;
        default:
            $sms_dca = "7bit";
            $sms_class = "2";
    }
    // Automatically setting the unicode flag if necessary
    //if (!$unicode) {
    //	$unicode = core_detect_unicode($sms_msg);
    //}
    if ($unicode) {
        $unicode = 1;
        $sms_dca = "16bit";
    }
    // fixme anton - if sms_from is not set in gateway_number and global number, we cannot pass it to bulksms
    $set_sms_from = $sms_from == $sms_sender ? '' : "&sender=" . urlencode($sms_from);
    // $query_string = "submission/send_sms/2/2.0?username="******"&password="******"&msisdn=" . urlencode($sms_to) . "&msg_class=$sms_class&message=" . urlencode($sms_msg) . "&dca=" . $sms_dca . $set_sms_from;
    // $url = $plugin_config['bulksms']['send_url'] . "/" . $query_string;
    // if ($additional_param = $plugin_config['bulksms']['additional_param']) {
    // 	$additional_param = "&" . $additional_param;
    // } else {
    // 	$additional_param = "routing_group=1&repliable=0";
    // }
    // $url .= $additional_param;
    // $url = str_replace("&&", "&", $url);
    // logger_print("url:" . $url, 3, "bulksms outgoing");
    // $fd = @implode('', file($url));
    $fd = buklsms_multiple_sms($sms_to, $sms_class, $sms_msg, $sms_dca, $set_sms_from, $unicode);
    $ok = false;
    // failed
    $p_status = 2;
    if ($fd) {
        $response = explode("|", $fd);
        if (count($response) == 3) {
            $status_code = trim($response[0]);
            $apimsgid = trim($response[2]);
            bulksms_setsmsapimsgid($smslog_id, $apimsgid);
            if ($status_code == '1') {
                list($c_sms_credit, $c_sms_status) = bulksms_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] . " " . $response[2], 2, "bulksms 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("smslog_id:" . $smslog_id . " response:" . $fd, 2, "bulksms outgoing");
        }
        $ok = true;
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
Beispiel #9
0
function kannel_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $core_config, $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "kannel_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['kannel']['module_sender']) {
        $sms_sender = $plugin_config['kannel']['module_sender'];
    }
    $sms_footer = stripslashes(htmlspecialchars_decode($sms_footer));
    $sms_msg = stripslashes(htmlspecialchars_decode($sms_msg));
    $ok = false;
    $account = user_uid2username($uid);
    $msg_type = 1;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_type == 'flash') {
        $msg_type = 0;
        // flash
    } else {
        $msg_type = 1;
        // text, default
    }
    // this doesn't work properly if kannel is not on the same server with playSMS
    // $dlr_url = $core_config['http_path']['base'] . "/plugin/gateway/kannel/dlr.php?type=%d&smslog_id=$smslog_id&uid=$uid";
    // prior to 0.9.5.1
    // $dlr_url = $plugin_config['kannel']['playsms_web'] . "/plugin/gateway/kannel/dlr.php?type=%d&smslog_id=".$smslog_id."&uid=".$uid;
    // since 0.9.5.1
    $dlr_url = $plugin_config['kannel']['playsms_web'] . "/index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&smslog_id=" . $smslog_id . "&uid=" . $uid;
    $URL = "/cgi-bin/sendsms?username="******"&password="******"&from=" . urlencode($sms_sender) . "&to=" . urlencode($sms_to);
    // Handle DLR options config (emmanuel)
    // $URL .= "&dlr-mask=31&dlr-url=".urlencode($dlr_url);
    $URL .= "&dlr-mask=" . $plugin_config['kannel']['dlr'] . "&dlr-url=" . urlencode($dlr_url);
    // end of Handle DLR options config (emmanuel)
    if ($sms_type == 'flash') {
        $URL .= "&mclass=" . $msg_type;
    }
    // Automatically setting the unicode flag if necessary
    if (!$unicode) {
        $unicode = core_detect_unicode($sms_msg);
    }
    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 .= "&account=" . $account;
    $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 = htmlspecialchars_decode($plugin_config['kannel']['additional_param'])) {
        $additional_param = "&" . $additional_param;
    }
    $URL .= $additional_param;
    $URL = str_replace("&&", "&", $URL);
    logger_print("URL: http://" . $plugin_config['kannel']['sendsms_host'] . ":" . $plugin_config['kannel']['sendsms_port'] . $URL, 3, "kannel_hook_sendsms");
    // 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; dlr($smslog_id, $uid, $p_status); } }
     */
    // fixme anton - deprecated when using PHP5
    // $connection = fsockopen($plugin_config['kannel']['sendsms_host'],$plugin_config['kannel']['sendsms_port'],&$error_number,&$error_description,60);
    $connection = fsockopen($plugin_config['kannel']['sendsms_host'], $plugin_config['kannel']['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") {
                logger_print("smslog_id:" . $smslog_id . " response:" . $rv, 3, "kannel outgoing");
                // set pending
                $p_status = 0;
                $ok = true;
            }
        }
        fclose($connection);
    }
    if (!$ok) {
        // set failed
        $p_status = 2;
        $ok = true;
        // return true eventhough failed
    }
    dlr($smslog_id, $uid, $p_status);
    logger_print("end smslog_id:" . $smslog_id . " p_status:" . $p_status, 3, "kannel outgoing");
    // good or bad, print it on the log
    return $ok;
}
Beispiel #10
0
function msgtoolbox_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    // global $plugin_config; // global all variables needed, eg: varibles from config.php
    // ...
    // ...
    // return true or false
    // return $ok;
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "msgtoolbox_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['msgtoolbox']['module_sender']) {
        $sms_sender = $plugin_config['msgtoolbox']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    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_sender) . "&message=" . urlencode($sms_msg) . $unicode . "&route=" . $plugin_config['msgtoolbox']['route'];
        $url = $plugin_config['msgtoolbox']['url'] . "?" . $query_string;
        /*
         * not used if ($additional_param = $plugin_config['msgtoolbox']['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 = explode(",", $fd);
            if (trim($response[0]) == "1") {
                $remote_smslog_id = trim($response[1]);
                if ($remote_smslog_id) {
                    // this is for callback, if callback not used then the status would be sent or failed only
                    // local_smslog_id is local SMS log id (local smslog_id)
                    // remote_smslog_id 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_smslog_id,remote_smslog_id,status)\n\t\t\t\t\t\tVALUES ('{$smslog_id}','{$remote_smslog_id}','10')\n\t\t\t\t\t    ";
                    $id = @dba_insert_id($db_query);
                    if ($id) {
                        $ok = true;
                        $p_status = 1;
                        // sms sent
                        dlr($smslog_id, $uid, $p_status);
                    }
                }
            }
            logger_print("sent smslog_id:" . $smslog_id . " response:" . $fd, 2, "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, 2, "msgtoolbox outgoing");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Beispiel #11
0
function uplink_hook_getsmsstatus($gpid = 0, $uid = "", $smslog_id = "", $p_datetime = "", $p_update = "")
{
    // global $plugin_config;
    // p_status :
    // 0 = pending
    // 1 = delivered
    // 2 = failed
    // dlr($smslog_id,$uid,$p_status);
    global $plugin_config;
    $smscs = gateway_getall_smsc_names($plugin_config['uplink']['name']);
    foreach ($smscs as $smsc) {
        $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
        $db_query = "SELECT * FROM " . _DB_PREF_ . "_gatewayUplink WHERE up_local_smslog_id='{$smslog_id}'";
        $db_result = dba_query($db_query);
        if ($db_row = dba_fetch_array($db_result)) {
            $local_smslog_id = $db_row['up_local_smslog_id'];
            $remote_smslog_id = $db_row['up_remote_smslog_id'];
            $remote_queue_code = $db_row['up_remote_queue_code'];
            $dst = $db_row['up_dst'];
            if ($local_smslog_id && ($remote_smslog_id || $remote_queue_code && $dst)) {
                $ws = new Playsms\Webservices();
                $ws->url = $plugin_config['uplink']['master'] . '/index.php?app=ws';
                $ws->username = $plugin_config['uplink']['username'];
                $ws->token = $plugin_config['uplink']['token'];
                $ws->smslog_id = $remote_smslog_id;
                $ws->queue = $remote_queue_code;
                $ws->count = 1;
                $ws->getOutgoing();
                // _log('getsmsstatus url:[' . $ws->getWebservicesUrl() . '] smsc:[' . $smsc . ']', 3, 'uplink_hook_getsmsstatus');
                $response = $ws->getData()->data[0];
                if ($response->status == 2) {
                    $p_status = 2;
                    dlr($local_smslog_id, $uid, $p_status);
                } else {
                    if ($p_status = (int) $response->status) {
                        dlr($local_smslog_id, $uid, $p_status);
                    }
                }
            }
        }
    }
}
Beispiel #12
0
function clickatell_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "clickatell_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['clickatell']['module_sender']) {
        $sms_sender = $plugin_config['clickatell']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $sms_from = $sms_sender;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    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";
    }
    // Automatically setting the unicode flag if necessary
    if (!$unicode) {
        $unicode = core_detect_unicode($sms_msg);
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
        }
        $sms_msg = core_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 ? "&from=" . urlencode($sms_from) : '';
    // fixme anton - temporary solution #385 Unable to send messages when clickatell password contains &
    $password = urlencode(htmlspecialchars_decode($plugin_config['clickatell']['password']));
    $query_string = "sendmsg?api_id=" . $plugin_config['clickatell']['api_id'] . "&user="******"&password="******"&to=" . urlencode($sms_to) . "&msg_type={$sms_type}&text=" . urlencode($sms_msg) . "&unicode=" . $unicode . $set_sms_from;
    $url = $plugin_config['clickatell']['send_url'] . "/" . $query_string;
    if ($additional_param = $plugin_config['clickatell']['additional_param']) {
        $additional_param = "&" . htmlspecialchars_decode($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;
    if ($fd) {
        $response = explode(":", $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], 2, "clickatell 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("smslog_id:" . $smslog_id . " response:" . $fd, 2, "clickatell outgoing");
        }
        $ok = true;
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
Beispiel #13
0
function infobip_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    $ok = false;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "infobip_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['infobip']['module_sender']) {
        $sms_sender = $plugin_config['infobip']['module_sender'];
    }
    $sms_from = $sms_sender;
    $smsType = "&SMSText";
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    switch ($sms_type) {
        case "flash":
            $sms_type = 1;
            break;
        case "text":
        default:
            $sms_type = 0;
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
        }
        $sms_msg = core_str2hex($sms_msg);
        $unicode = 8;
        $smsType = "&binary";
    }
    // fixme anton - if sms_from is not set in gateway_number and global number, we cannot pass it to infobip
    $set_sms_from = $sms_from == $sms_sender ? '' : urlencode($sms_from);
    // query_string = "sendmsg?api_id=".$plugin_config['infobip']['api_id']."&user="******"&password="******"&to=".urlencode($sms_to)."&msg_type=$sms_type&text=".urlencode($sms_msg)."&unicode=".$unicode.$set_sms_from;
    $query_string = "sendsms/plain?user="******"&password="******"&GSM=" . urlencode($sms_to) . $smsType . "=" . urlencode($sms_msg) . "&sender=" . $sms_from;
    $query_string .= "&IsFlash=" . $sms_type . "&DataCoding=" . $unicode;
    $url = $plugin_config['infobip']['send_url'] . "/" . $query_string;
    $dlr_nopush = $plugin_config['infobip']['dlr_nopush'];
    if ($dlr_nopush == '0') {
        $additional_param = "&nopush=0";
    } elseif ($dlr_nopush == '1') {
        $additional_param = "&nopush=1";
    }
    if ($additional_param = $plugin_config['infobip']['additional_param']) {
        $additional_param .= "&" . $additional_param;
    }
    $url .= $additional_param;
    $url = str_replace("&&", "&", $url);
    logger_print("url:" . $url, 3, "infobip outgoing");
    $xml = file_get_contents($url);
    $response = core_xml_to_array($xml);
    if ($response) {
        if ($response['result']['status'] == 0) {
            if ($apimsgid = trim($response['result']['messageid'])) {
                infobip_setsmsapimsgid($smslog_id, $apimsgid);
                list($c_sms_credit, $c_sms_status) = infobip_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 . " p_status:" . $p_status . " response:" . $response['result']['status'], 2, "infobip outgoing");
        } elseif ($response['result']['status'] == -2) {
            logger_print("smslog_id:" . $smslog_id . " response:" . $response['result']['status'] . " NOT_ENOUGH_CREDIT", 2, "infobip 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("smslog_id:" . $smslog_id . " response:" . $response['result']['status'] . " UNKNOWN_CODE", 2, "infobip outgoing");
        }
        $ok = true;
    } else {
        logger_print("no response smslog_id:" . $smslog_id, 3, "infobip outgoing");
    }
    if (!$ok) {
        $p_status = 2;
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
Beispiel #14
0
function telerivet_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    $ok = false;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 2, "telerivet_hook_sendsms");
    # Initialize CURL context
    $api_key = $plugin_config['telerivet']['api_key'];
    $project_id = $plugin_config['telerivet']['project_id'];
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://api.telerivet.com/v1/projects/{$project_id}/messages/outgoing");
    curl_setopt($curl, CURLOPT_USERPWD, "{$api_key}:");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    # override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    # Pre-process parameters
    $sms_sender = stripslashes($sms_sender);
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg) . $sms_footer;
    # Build data array
    $data = array();
    $data['to_number'] = $sms_to;
    $data['content'] = $sms_msg;
    if (trim($plugin_config['telerivet']['status_url'])) {
        $data['status_url'] = trim($plugin_config['telerivet']['status_url']);
    }
    if (trim($plugin_config['telerivet']['status_secret'])) {
        $data['status_secret'] = trim($plugin_config['telerivet']['status_secret']);
    }
    # Build API query
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data, '', '&'));
    _log('building http query', 3, 'telerivet_query');
    # Send query to API and get result
    $json = curl_exec($curl);
    $network_error = curl_error($curl);
    curl_close($curl);
    # Catch query error
    if ($network_error) {
        _log('curl error:' . $network_error, 2, 'telerivet_query');
        dlr($smslog_id, $uid, 2);
    } else {
        # Save JSON reply
        $res = json_decode($json, true);
        if (is_array($res)) {
            foreach ($res as $key => $val) {
                $log .= $key . ':' . $val . ' ';
            }
            _log('api response:' . $log, 3, 'telerivet_query');
        }
        # Catch API errors
        if (isset($res['error'])) {
            _log('api error' . $res['error_message'], 2, 'telerivet_query');
            dlr($smslog_id, $uid, 2);
        } else {
            _log('api success: id:' . $res['id'] . ' status:' . $res['status'] . ' source:' . $res['source'], 2, 'telerivet_query');
        }
        $c_remote_id = $res['id'];
        $c_status = $res['status'];
        $c_phone_id = $res['phone_id'];
        $c_message_type = $res['message_type'];
        $c_source = $res['source'];
        $c_error = $res['error_message'];
        # Ref: https://telerivet.com/api/webhook#send_status
        # Available status:
        #   sent    the message has been successfully sent to the mobile network
        #   queued  the message has not been sent yet
        #   failed  the message has failed to send
        #   failed_queued   the message has failed to send, but Telerivet will try to send it again later
        #   delivered   the message has been delivered to the recipient phone (if delivery reports are enabled)
        #   not_delivered   the message could not be delivered (if delivery reports are enabled)
        #   cancelled   the message was cancelled by the user
        # Reminder delivery status
        # $p_status = 0 --> pending
        # $p_status = 1 --> sent
        # $p_status = 2 --> failed
        # $p_status = 3 --> delivered
        if ($c_remote_id && $c_status) {
            $db_query = '
                INSERT INTO ' . _DB_PREF_ . '_gatewayTelerivet (local_slid, remote_slid, status, phone_id, message_type, source, error_text)
                VALUES (' . $smslog_id . ',"' . $c_remote_id . '","' . $c_status . '","' . $c_phone_id . '","' . $c_message_type . '","' . $c_source . '","' . $c_error . '")';
            _log('sql:' . $db_query, 3, 'telerivet query');
            if ($id = @dba_insert_id($db_query) && $c_status) {
                switch ($c_status) {
                    case "queued":
                        $ok = true;
                        $p_status = 0;
                        break;
                    case "sent":
                        $ok = true;
                        $p_status = 1;
                        break;
                    case "delivered":
                        $ok = true;
                        $p_status = 3;
                        break;
                    case "failed":
                    case "failed_queued":
                    case "not_delivered":
                    case "cancelled":
                    default:
                        $p_status = 2;
                        break;
                        // failed
                }
            }
            dlr($smslog_id, $uid, $p_status);
        }
    }
    return $ok;
}
Beispiel #15
0
function twilio_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "twilio_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['twilio']['module_sender']) {
        $sms_sender = $plugin_config['twilio']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    logger_print("sendsms start", 3, "twilio_hook_sendsms");
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_sender && $sms_to && $sms_msg) {
        $url = $plugin_config['twilio']['url'] . '/2010-04-01/Accounts/' . $plugin_config['twilio']['account_sid'] . '/SMS/Messages.json';
        $data = array('To' => $sms_to, 'From' => $sms_sender, 'Body' => $sms_msg);
        if (trim($plugin_config['twilio']['callback_url'])) {
            $data['StatusCallback'] = trim($plugin_config['twilio']['callback_url']);
        }
        if (function_exists('curl_init')) {
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_USERPWD, $plugin_config['twilio']['account_sid'] . ':' . $plugin_config['twilio']['auth_token']);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            $returns = curl_exec($ch);
            curl_close($ch);
            logger_print("url:" . $url . " callback:" . $plugin_config['twilio']['callback_url'], 3, "twilio outgoing");
            $resp = json_decode($returns);
            if ($resp->status) {
                $c_status = $resp->status;
                $c_message_id = $resp->sid;
                $c_error_text = $c_status . '|' . $resp->code . '|' . $resp->message;
                logger_print("sent smslog_id:" . $smslog_id . " message_id:" . $c_message_id . " status:" . $c_status . " error:" . $c_error_text, 2, "twilio outgoing");
                $db_query = "\n\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayTwilio (local_smslog_id,remote_smslog_id,status,error_text)\n\t\t\t\t\tVALUES ('{$smslog_id}','{$c_message_id}','{$c_status}','{$c_error_text}')";
                $id = @dba_insert_id($db_query);
                if ($id && $c_status == 'queued') {
                    $ok = true;
                    $p_status = 0;
                } else {
                    $p_status = 2;
                }
                dlr($smslog_id, $uid, $p_status);
            } else {
                // even when the response is not what we expected we still print it out for debug purposes
                $resp = str_replace("\n", " ", $resp);
                $resp = str_replace("\r", " ", $resp);
                logger_print("failed smslog_id:" . $smslog_id . " resp:" . $resp, 2, "twilio outgoing");
            }
        } else {
            logger_print("fail to sendsms due to missing PHP curl functions", 3, "twilio_hook_sendsms");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    logger_print("sendsms end", 3, "twilio_hook_sendsms");
    return $ok;
}
Beispiel #16
0
function gammu_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "gammu_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $date = date('Ymd', time());
    $time = date('Gis', time());
    if ($plugin_config['gammu']['dlr']) {
        $option_dlr = 'd';
    } else {
        $option_dlr = '';
    }
    // OUT<priority><date>_<time>_<serialno>_<phone_number>_<anything>.<ext><options>
    $sms_id = 'A' . $date . '_' . $time . '_00_' . $sms_to . '_' . $smslog_id . '10001' . $uid . '10001' . $gpid . '.txt' . $option_dlr;
    if ($sms_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 = $plugin_config['gammu']['path'] . "/outbox/OUT" . $sms_id;
    logger_print("saving outfile:" . $fn, 2, "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("saved outfile:" . $fn, 2, "gammu outgoing");
    } else {
        $p_status = 2;
        logger_print("fail to save outfile:" . $fn, 2, "gammu outgoing");
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
Beispiel #17
0
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with playSMS. If not, see <http://www.gnu.org/licenses/>.
 */
if (!$called_from_hook_call) {
    chdir("../../../");
    // ignore CSRF
    $core_config['init']['ignore_csrf'] = TRUE;
    include "init.php";
    include $core_config['apps_path']['libs'] . "/function.php";
    chdir("plugin/gateway/kannel");
}
if ($smsc = $requests['smsc']) {
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
}
$remote_addr = $_SERVER['REMOTE_ADDR'];
// srosa 20100531: added var below
$remote_host = $_SERVER['HTTP_HOST'];
// srosa 20100531: changed test below to allow hostname in bearerbox_host instead of ip
// if ($remote_addr != $plugin_config['kannel']['bearerbox_host'])
if ($remote_addr != $plugin_config['kannel']['bearerbox_host'] && $remote_host != $plugin_config['kannel']['bearerbox_host']) {
    _log("unable to process incoming SMS. remote_addr:[" . $remote_addr . "] or remote_host:[" . $remote_host . "] does not match with your bearerbox_host config:[" . $plugin_config['kannel']['bearerbox_host'] . "] smsc:[" . $smsc . "]", 2, "kannel incoming");
    exit;
}
// if the arrival time is in UTC then we need to adjust it with this:
if ($plugin_config['kannel']['local_time']) {
    $t = trim($_REQUEST['t']);
} else {
    // in UTC
Beispiel #18
0
function playnet_hook_playsmsd()
{
    global $core_config, $plugin_config;
    if (!core_playsmsd_timer($plugin_config['playnet']['poll_interval'])) {
        return;
    }
    $smscs = gateway_getall_smsc_names('playnet');
    foreach ($smscs as $smsc) {
        $c_plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
        $is_master = (bool) ($c_plugin_config['playnet']['local_playnet_username'] && $c_plugin_config['playnet']['local_playnet_password']);
        if ((int) $c_plugin_config['playnet']['remote_on'] && !$is_master) {
            // fetch from remote
            $ws = $c_plugin_config['playnet']['remote_playsms_url'] . '/index.php?app=ws&op=playnet';
            $ws .= '&go=get_outgoing';
            $ws .= '&s=' . $c_plugin_config['playnet']['remote_playnet_smsc'];
            $ws .= '&u=' . $c_plugin_config['playnet']['remote_playnet_username'];
            $ws .= '&p=' . $c_plugin_config['playnet']['remote_playnet_password'];
            $response_raw = @file_get_contents($ws);
            $response = json_decode($response_raw, 1);
            // validate response
            if (strtoupper($response['status']) == 'OK') {
                if (is_array($response['data'])) {
                    foreach ($response['data'] as $data) {
                        $remote_smsc = $data['smsc'];
                        $remote_smslog_id = $data['smslog_id'];
                        $remote_uid = $data['uid'];
                        $username = $c_plugin_config['playnet']['sendsms_username'];
                        $sms_to = $data['sms_to'];
                        $message = $data['message'];
                        $unicode = core_detect_unicode($message);
                        $sms_type = $data['sms_type'];
                        $sms_sender = $data['sender_id'];
                        _log('sendsms remote_smsc:' . $remote_smsc . ' remote_smslog_id:' . $remote_smslog_id . ' remote_uid:' . $remote_uid . ' u:' . $username . ' sender_id:' . $sms_sender . ' to:' . $sms_to . ' m:[' . $message . '] unicode:' . $unicode, 3, 'playnet_hook_playsmsd');
                        sendsms_helper($username, $sms_to, $message, $sms_type, $unicode, '', 1, '', $sms_sender);
                    }
                }
            }
        }
    }
}
Beispiel #19
0
function generic_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "generic_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['generic']['module_sender']) {
        $sms_sender = $plugin_config['generic']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_sender && $sms_to && $sms_msg) {
        $unicode_query_string = '';
        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");
                // $sms_msg = mb_convert_encoding($sms_msg, "UTF-8", "auto");
                $unicode_query_string = "&coding=8";
                // added at the of query string if unicode
            }
        }
        // $plugin_config['generic']['default_url'] = 'http://example.api.url/handler.php?user={GENERIC_API_USERNAME}&pwd={GENERIC_API_PASSWORD}&sender={GENERIC_SENDER}&msisdn={GENERIC_TO}&message={GENERIC_MESSAGE}&dlr-url={GENERIC_CALLBACK_URL}';
        $url = htmlspecialchars_decode($plugin_config['generic']['url']);
        $url = str_replace('{GENERIC_API_USERNAME}', urlencode($plugin_config['generic']['api_username']), $url);
        $url = str_replace('{GENERIC_API_PASSWORD}', urlencode($plugin_config['generic']['api_password']), $url);
        $url = str_replace('{GENERIC_SENDER}', urlencode($sms_sender), $url);
        $url = str_replace('{GENERIC_TO}', urlencode($sms_to), $url);
        $url = str_replace('{GENERIC_MESSAGE}', urlencode($sms_msg), $url);
        $url = str_replace('{GENERIC_CALLBACK_URL}', urlencode($plugin_config['generic']['callback_url']), $url);
        _log("send url:[" . $url . "]", 3, "generic_hook_sendsms");
        // send it
        $response = file_get_contents($url);
        // 14395227002806904200 SENT
        // 0 User Not Found
        $resp = explode(' ', $response, 2);
        // a single non-zero respond will be considered as a SENT response
        if ($resp[0]) {
            $c_message_id = (int) $resp[0];
            _log("sent smslog_id:" . $smslog_id . " message_id:" . $c_message_id . " smsc:" . $smsc, 2, "generic_hook_sendsms");
            $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayGeneric_log (local_smslog_id, remote_smslog_id)\n\t\t\t\tVALUES ('{$smslog_id}', '{$c_message_id}')";
            $id = @dba_insert_id($db_query);
            if ($id) {
                $ok = true;
                $p_status = 1;
                dlr($smslog_id, $uid, $p_status);
            } else {
                $ok = true;
                $p_status = 0;
                dlr($smslog_id, $uid, $p_status);
            }
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            if ($resp[0] === '0') {
                $resp = trim($resp[1]);
            } else {
                $resp = $response;
            }
            _log("failed smslog_id:" . $smslog_id . " resp:[" . $resp . "] smsc:" . $smsc, 2, "generic_hook_sendsms");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Beispiel #20
0
function jasmin_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "jasmin_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['jasmin']['module_sender']) {
        $sms_sender = $plugin_config['jasmin']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_sender && $sms_to && $sms_msg) {
        $unicode_query_string = '';
        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");
                // $sms_msg = mb_convert_encoding($sms_msg, "UTF-8", "auto");
                $unicode_query_string = "&coding=8";
                // added at the of query string if unicode
            }
        }
        $query_string = "username="******"&password="******"&to=" . urlencode($sms_to) . "&from=" . urlencode($sms_sender) . "&content=" . urlencode($sms_msg) . $unicode_query_string;
        $query_string .= "&dlr=yes&dlr-level=2&dlr-url=" . urlencode($plugin_config['jasmin']['callback_url']);
        $url = $plugin_config['jasmin']['url'] . "?" . $query_string;
        _log("send url:[" . $url . "]", 3, "jasmin_hook_sendsms");
        // new way
        $opts = array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($query_string) . "\r\nConnection: close\r\n", 'content' => $query_string));
        $context = stream_context_create($opts);
        $response = file_get_contents($plugin_config['jasmin']['url'], FALSE, $context);
        // Success "07033084-5cfd-4812-90a4-e4d24ffb6e3d"
        // Error "No route found"
        $resp = explode(' ', $response, 2);
        if ($resp[0] == 'Success') {
            $c_message_id = $resp[1];
            $c_message_id = str_replace('"', '', $c_message_id);
            _log("sent smslog_id:" . $smslog_id . " message_id:" . $c_message_id . " smsc:" . $smsc, 2, "jasmin_hook_sendsms");
            $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayJasmin_log (local_smslog_id, remote_smslog_id)\n\t\t\t\tVALUES ('{$smslog_id}', '{$c_message_id}')";
            $id = @dba_insert_id($db_query);
            if ($id) {
                $ok = true;
                $p_status = 1;
                dlr($smslog_id, $uid, $p_status);
            }
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            if ($resp[0] == 'Error') {
                $resp = $resp[1];
            } else {
                $resp = $response;
            }
            _log("failed smslog_id:" . $smslog_id . " resp:[" . $resp . "] smsc:" . $smsc, 2, "jasmin_hook_sendsms");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Beispiel #21
0
function smstools_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "smstools_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $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 ($sms_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}";
    // try to backup outgoing file first
    $fn_bak = $plugin_config['smstools']['spool_bak'] . "/outgoing/out.{$sms_id}";
    if (is_dir($plugin_config['smstools']['spool_bak'] . '/outgoing')) {
        umask(0);
        $fd = @fopen($fn_bak, 'w+');
        @fputs($fd, $the_msg);
        @fclose($fd);
    }
    // copy from backup if exists, or create new one in spool dir
    $fn = $plugin_config['smstools']['spool_dir'] . "/outgoing/out.{$sms_id}";
    if (file_exists($fn_bak)) {
        logger_print("outfile backup:" . $fn_bak, 2, "smstools outgoing");
        @shell_exec('cp ' . $fn_bak . ' ' . $fn);
    } else {
        umask(0);
        $fd = @fopen($fn, 'w+');
        @fputs($fd, $the_msg);
        @fclose($fd);
    }
    logger_print("saving outfile:" . $fn, 2, "smstools outgoing");
    $ok = false;
    if (file_exists($fn)) {
        $ok = true;
        $p_status = 0;
        logger_print("saved outfile:" . $fn, 2, "smstools outgoing");
    } else {
        $p_status = 2;
        logger_print("fail to save outfile:" . $fn, 2, "smstools outgoing");
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}