Esempio n. 1
0
function getsmsstatus()
{
    $smscs = gateway_getall_smsc_names();
    foreach ($smscs as $smsc) {
        $smsc_data = gateway_get_smscbyname($smsc);
        $gateway = $smsc_data['gateway'];
        $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing WHERE p_status='0' AND p_smsc='{$smsc}' AND flag_deleted='0'";
        $db_result = dba_query($db_query);
        while ($db_row = dba_fetch_array($db_result)) {
            $uid = $db_row['uid'];
            $smslog_id = $db_row['smslog_id'];
            $p_datetime = $db_row['p_datetime'];
            $p_update = $db_row['p_update'];
            $gpid = $db_row['p_gpid'];
            core_hook($gateway, 'getsmsstatus', array($gpid, $uid, $smslog_id, $p_datetime, $p_update));
        }
    }
}
Esempio n. 2
0
function getsmsinbox()
{
    $smscs = gateway_getall_smsc_names();
    foreach ($smscs as $smsc) {
        $smsc_data = gateway_get_smscbyname($smsc);
        $gateways[] = $smsc_data['gateway'];
    }
    if (is_array($gateways)) {
        $gateways = array_unique($gateways);
        foreach ($gateways as $gateway) {
            core_hook($gateway, 'getsmsinbox');
        }
    }
}
Esempio n. 3
0
function gateway_select_smsc($select_name, $default_smsc)
{
    $c_options = array(_('Supplied SMSC') => '_smsc_supplied_', _('Routed SMSC') => '_smsc_routed_') + gateway_getall_smsc_names();
    $ret = _select($select_name, $c_options, $default_smsc);
    return $ret;
}
Esempio n. 4
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);
                    }
                }
            }
        }
    }
}
Esempio n. 5
0
function webservices_output($operation, $requests, $returns)
{
    global $core_config;
    // default returns
    $returns = array('modified' => TRUE, 'param' => array('operation' => $operation, 'content' => '', 'content-type' => 'text/json', 'charset' => 'utf-8'));
    // plugin feature
    for ($c = 0; $c < count($core_config['plugins']['list']['feature']); $c++) {
        if ($ret_intercept = core_hook($core_config['plugins']['list']['feature'][$c], 'webservices_output', array($operation, $requests, $returns))) {
            if ($ret_intercept['modified']) {
                $returns['modified'] = TRUE;
                $returns['param']['operation'] = $ret_intercept['param']['operation'] ? $ret_intercept['param']['operation'] : $returns['param']['operation'];
                $returns['param']['content'] = $ret_intercept['param']['content'] ? $ret_intercept['param']['content'] : $returns['param']['content'];
                $returns['param']['content-type'] = $ret_intercept['param']['content-type'] ? $ret_intercept['param']['content-type'] : $returns['param']['content-type'];
                $returns['param']['charset'] = $ret_intercept['param']['charset'] ? $ret_intercept['param']['charset'] : $returns['param']['charset'];
            }
        }
    }
    // plugin gateway
    $smscs = gateway_getall_smsc_names();
    foreach ($smscs as $smsc) {
        $smsc_data = gateway_get_smscbyname($smsc);
        $gateways[] = $smsc_data['gateway'];
    }
    if (is_array($gateways)) {
        $gateways = array_unique($gateways);
        foreach ($gateways as $gateway) {
            if ($ret_intercept = core_hook($gateway, 'webservices_output', array($operation, $requests, $returns))) {
                if ($ret_intercept['modified']) {
                    $returns['modified'] = TRUE;
                    $returns['param']['operation'] = $ret_intercept['param']['operation'] ? $ret_intercept['param']['operation'] : $returns['param']['operation'];
                    $returns['param']['content'] = $ret_intercept['param']['content'] ? $ret_intercept['param']['content'] : $returns['param']['content'];
                    $returns['param']['content-type'] = $ret_intercept['param']['content-type'] ? $ret_intercept['param']['content-type'] : $returns['param']['content-type'];
                    $returns['param']['charset'] = $ret_intercept['param']['charset'] ? $ret_intercept['param']['charset'] : $returns['param']['charset'];
                }
            }
        }
    }
    // plugin themes
    if ($ret_intercept = core_hook(core_themes_get(), 'webservices_output', array($operation, $requests, $returns))) {
        if ($ret_intercept['modified']) {
            $returns['modified'] = TRUE;
            $returns['param']['operation'] = $ret_intercept['param']['operation'] ? $ret_intercept['param']['operation'] : $returns['param']['operation'];
            $returns['param']['content'] = $ret_intercept['param']['content'] ? $ret_intercept['param']['content'] : $returns['param']['content'];
            $returns['param']['content-type'] = $ret_intercept['param']['content-type'] ? $ret_intercept['param']['content-type'] : $returns['param']['content-type'];
            $returns['param']['charset'] = $ret_intercept['param']['charset'] ? $ret_intercept['param']['charset'] : $returns['param']['charset'];
        }
    }
    return $returns;
}
Esempio n. 6
0
function gammu_hook_getsmsinbox()
{
    // filename
    // IN20101017_091747_00_+628123423141312345_00.txt
    global $plugin_config;
    $smscs = gateway_getall_smsc_names($plugin_config['gammu']['name']);
    foreach ($smscs as $smsc) {
        $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
        $sms_receiver = $plugin_config['gammu']['sms_receiver'];
        $handle = @opendir($plugin_config['gammu']['path'] . "/inbox");
        $messages = array();
        $files = array();
        while ($sms_in_file = @readdir($handle)) {
            if ($sms_in_file != "." && $sms_in_file != "..") {
                $files[] = $sms_in_file;
            }
        }
        sort($files);
        foreach ($files as $sms_in_file) {
            $fn = $plugin_config['gammu']['path'] . "/inbox/{$sms_in_file}";
            $matches = array();
            preg_match('/IN(\\d{4})(\\d{2})(\\d{2})_(\\d{2})(\\d{2})(\\d{2})_(\\d+)_([\\w\\-\\+\\s]+)_(\\d+)/', basename($fn), $matches);
            list($s, $year, $month, $date, $hour, $minute, $second, $serial, $sms_sender, $seq) = $matches;
            $sms_datetime = $year . "-" . $month . "-" . $date . " " . $hour . ":" . $minute . ":" . $second;
            // message is in UTF-16, need to convert it to UTF-8
            $message = file_get_contents($fn);
            // if the message is unicode then convert it to UTF-8
            if (core_detect_unicode($message)) {
                $message = mb_convert_encoding($message, "UTF-8", "UTF-16");
            }
            @unlink($fn);
            // continue process only when incoming sms file can be deleted
            if (!file_exists($fn)) {
                if ($sms_sender && $sms_datetime) {
                    // adding message parts to existing array
                    if (array_key_exists($sms_sender, $messages) && (int) $seq > 0) {
                        $messages[$sms_sender][] = array("fn" => $fn, "message" => $message, "msg_datetime" => $sms_datetime);
                    } else {
                        if (!array_key_exists($sms_sender, $messages) || array_key_exists($sms_sender, $messages) && (int) $seq == 0) {
                            if (count($messages) > 0) {
                                // saving concatenated message parts
                                $parts_sender = 0;
                                foreach ($messages as $sender => $message_parts) {
                                    $parts_message = "";
                                    $parts_sender = $sender;
                                    foreach ($message_parts as $part) {
                                        $parts_message .= $part['message'];
                                    }
                                }
                                $parts_datetime = $messages[$parts_sender][0]['msg_datetime'];
                                $parts_message = addslashes($parts_message);
                                recvsms($parts_datetime, $parts_sender, $parts_message, $sms_receiver, $smsc);
                                _log("sender:" . $parts_sender . " receiver:" . $sms_receiver . " dt:" . $parts_datetime . " msg:[" . $parts_message . "] smsc:[" . $smsc . "]", 3, "gammu_hook_getsmsinbox");
                                unset($messages);
                            }
                            // new message parts array
                            $messages[$sms_sender] = array(array("fn" => $fn, "message" => $message, "msg_datetime" => $sms_datetime));
                        }
                    }
                }
            }
        }
        if (count($messages) > 0) {
            // saving last concatenated message parts
            $parts_sender = 0;
            foreach ($messages as $sender => $message_parts) {
                $parts_message = "";
                $parts_sender = $sender;
                foreach ($message_parts as $part) {
                    $parts_message .= $part['message'];
                }
            }
            $parts_datetime = $messages[$parts_sender][0]['msg_datetime'];
            $parts_message = addslashes($parts_message);
            recvsms($parts_datetime, $parts_sender, $parts_message, $sms_receiver, $smsc);
            _log("sender:" . $parts_sender . " receiver:" . $sms_receiver . " dt:" . $parts_datetime . " msg:[" . $_parts_message . "] smsc:[" . $smsc . "]", 3, "gammu_hook_getsmsinbox");
            unset($messages);
        }
        @closedir($handle);
    }
}
Esempio n. 7
0
function playsmsd_once($param)
{
    // plugin feature
    core_call_hook();
    // plugin gateway
    $smscs = gateway_getall_smsc_names();
    foreach ($smscs as $smsc) {
        $smsc_data = gateway_get_smscbyname($smsc);
        $gateways[] = $smsc_data['gateway'];
    }
    if (is_array($gateways)) {
        $gateways = array_unique($gateways);
        foreach ($gateways as $gateway) {
            core_hook($gateway, 'playsmsd_once', array($param));
        }
    }
    // plugin themes
    core_hook(core_themes_get(), 'playsmsd_once', array($param));
}
Esempio n. 8
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);
                    }
                }
            }
        }
    }
}