Exemplo n.º 1
0
/**
 * Intercept on after-process stage for incoming SMS and forward it to selected user's inbox
 *
 * @param $sms_datetime incoming
 *        SMS date/time
 * @param $sms_sender incoming
 *        SMS sender
 * @param $message incoming
 *        SMS message before interepted
 * @param $sms_receiver receiver
 *        number that is receiving incoming SMS
 * @param $feature feature
 *        managed to hook current incoming SMS
 * @param $status recvsms()
 *        status, 0 or FALSE for unhandled
 * @param $uid keyword
 *        owner
 * @return array $ret
 */
function incoming_hook_recvsms_intercept_after($sms_datetime, $sms_sender, $message, $sms_receiver, $feature, $status, $uid, $smsc)
{
    global $core_config;
    $ret = array();
    $users = array();
    $is_routed = FALSE;
    // continue only if its sandbox
    if ($status) {
        return $ret;
    }
    // get settings
    $settings = incoming_settings_get();
    // get post rules
    $post_rules = incoming_post_rules_get();
    // sandbox match receiver number and sender ID
    if (!$is_routed) {
        // route sandbox if receiver number matched with default sender ID of users
        if ($post_rules['match_sender_id']) {
            $s = array();
            if ($settings['match_all_sender_id']) {
                // get all approved sender ID
                $s = sender_id_getall();
            } else {
                $data = user_search($sms_receiver, 'sender');
                foreach ($data as $user) {
                    // get default sender ID
                    if ($user['sender']) {
                        $s[] = $user['sender'];
                        // in case an error occured where multiple users own the same sender ID
                        break;
                    }
                }
            }
            // start matching
            foreach ($s as $sender_id) {
                if ($sender_id && $sms_receiver && $sender_id == $sms_receiver) {
                    unset($usernames);
                    unset($username);
                    if ($settings['match_all_sender_id']) {
                        // get $username who owns $sender_id
                        $uids = sender_id_owner($sender_id);
                        foreach ($uids as $uid) {
                            $usernames[] = user_uid2username($uid);
                        }
                    } else {
                        $usernames[] = $user['username'];
                    }
                    $usernames = array_unique($usernames);
                    foreach ($usernames as $username) {
                        if ($username) {
                            _log("sandbox match sender start u:" . $username . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "]", 3, 'incoming recvsms_intercept_after');
                            recvsms_inbox_add($sms_datetime, $sms_sender, $username, $message, $sms_receiver);
                            _log("sandbox match sender end u:" . $username, 3, 'incoming recvsms_intercept_after');
                            $is_routed = TRUE;
                            // single match only
                            // break;
                        }
                    }
                }
            }
        }
        // sandbox prefix
        if (!$is_routed) {
            // route sandbox by adding a prefix to message and re-enter it to recvsms()
            //if ($post_rules['insert_prefix'] && trim($message)) {
            //	$message = $post_rules['insert_prefix'] . ' ' . trim($message);
            //	_log("sandbox add prefix start keyword:" . $post_rules['insert_prefix'] . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept_after');
            //	recvsms($sms_datetime, $sms_sender, $message, $sms_receiver, $smsc);
            //	_log("sandbox add prefix end keyword:" . $post_rules['insert_prefix'], 3, 'incoming recvsms_intercept_after');
            //	$is_routed = TRUE;
            //}
        }
        // sandbox forward to users
        if (!$is_routed) {
            foreach ($post_rules['forward_to'] as $uid) {
                $c_username = user_uid2username($uid);
                if ($c_username) {
                    $users[] = $c_username;
                }
            }
            // route sandbox to users inbox
            foreach ($users as $username) {
                _log("sandbox to user start u:" . $username . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "]", 3, 'incoming recvsms_intercept_after');
                recvsms_inbox_add($sms_datetime, $sms_sender, $username, $message, $sms_receiver);
                _log("sandbox to user end u:" . $username, 3, 'incoming recvsms_intercept_after');
                $is_routed = TRUE;
            }
        }
        // sandbox forward to URL
        if ($url = trim($post_rules['forward_to_url'])) {
            $payload = array('datetime' => core_get_datetime(), 'sms_datetime' => $sms_datetime, 'sms_sender' => $sms_sender, 'message' => $message, 'sms_receiver' => $sms_receiver, 'smsc' => $smsc);
            $json = json_encode($payload);
            $url = str_replace('{SANDBOX_PAYLOAD}', urlencode($json), $url);
            $url = str_replace('{SANDBOX_DATETIME}', urlencode($sms_datetime), $url);
            $url = str_replace('{SANDBOX_SENDER}', urlencode($sms_sender), $url);
            $url = str_replace('{SANDBOX_MESSAGE}', urlencode($message), $url);
            $url = str_replace('{SANDBOX_RECEIVER}', urlencode($sms_receiver), $url);
            $url = str_replace('{SANDBOX_SMSC}', urlencode($smsc), $url);
            _log("sandbox forward to URL start url:[" . $url . "]", 3, 'incoming recvsms_intercept_after');
            $response = @file_get_contents($url);
            _log("sandbox forward to URL end response:[" . $response . "]", 3, 'incoming recvsms_intercept_after');
        }
    }
    // flag the hook if is_routed
    if ($is_routed) {
        $ret['param']['feature'] = 'incoming';
        if ($settings['leave_copy_sandbox']) {
            $ret['param']['status'] = 0;
        } else {
            $ret['param']['status'] = 1;
        }
        $ret['param']['uid'] = 1;
        $ret['modified'] = TRUE;
    }
    return $ret;
}
Exemplo n.º 2
0
 */
defined('_SECURE_') or die('Forbidden');
if (!auth_isadmin()) {
    auth_block();
}
switch (_OP_) {
    case "incoming":
        // form pre rules
        $pre_rules = incoming_pre_rules_get();
        // scan message for @username
        $select_match_username = _yesno('incoming_match_username', $pre_rules['match_username'], '', '', '', 'playsms-incoming-match-username', 'form-control');
        // scan message for #groupcode
        $select_match_groupcode = _yesno('incoming_match_groupcode', $pre_rules['match_groupcode'], '', '', '', 'playsms-incoming-match-groupcode', 'form-control');
        $form_pre_rules = array(array('id' => 'playsms-incoming-match-username', 'label' => _('Scan incoming SMS for @username'), 'input' => $select_match_username, 'help' => _('Copy the message to user inbox when incoming SMS contains @username')), array('id' => 'playsms-incoming-match-groupcode', 'label' => _('Scan incoming SMS for #groupcode'), 'input' => $select_match_groupcode, 'help' => _('Send SMS to groups with found group codes in the incoming SMS')));
        // form post rules
        $post_rules = incoming_post_rules_get();
        // sandbox match receiver number and sender ID
        $select_match_sender_id = _yesno('sandbox_match_sender_id', $post_rules['match_sender_id'], '', '', '', 'playsms-sandbox-match-sender-id', 'form-control');
        // sandbox prefix
        unset($params);
        $params = array('size' => '100%', 'maxlength' => 30, 'placeholder' => _('Insert keyword'));
        $input_prefix = _input('text', 'sandbox_prefix', $post_rules['insert_prefix'], $params, 'playsms-sandbox-prefix', 'form-control');
        // sandbox forward to users
        unset($params);
        $params = array('width' => '100%', 'placeholder' => _('Select users'));
        $select_users = themes_select_users_multi('uids', $post_rules['forward_to'], $params, 'playsms-route-to-users');
        // sandbox forward to URL
        unset($params);
        $params = array('size' => '100%', 'maxlength' => 255, 'placeholder' => _('URL'));
        $input_url = _input('text', 'forward_to_url', $post_rules['forward_to_url'], $params, 'playsms-forward-to-url', 'form-control');
        $form_post_rules = array(array('id' => 'playsms-sandbox-match-sender-id', 'label' => _('Route all sandbox SMS with matched sender ID'), 'input' => $select_match_sender_id, 'help' => _('Route to user inbox if receiver number matched with user sender ID')), array('id' => 'playsms-route-to-users', 'label' => _('Route all sandbox SMS to users'), 'input' => $select_users, 'help' => _('Route all sandbox SMS to one or more users')), array('id' => 'playsms-forward-to-url', 'label' => _('Forward all sandbox SMS to a URL'), 'input' => $input_url, 'help' => _('Example') . ': <br />http://external.app/handler.php?json={SANDBOX_PAYLOAD}&dt={SANDBOX_DATETIME}&s={SANDBOX_SENDER}&m={SANDBOX_MESSAGE}&r={SANDBOX_RECEIVER}&smsc={SANDBOX_SMSC}'));
Exemplo n.º 3
0
/**
 * Intercept on after-process stage for incoming SMS and forward it to selected user's inbox
 *
 * @param $sms_datetime incoming
 *        SMS date/time
 * @param $sms_sender incoming
 *        SMS sender
 * @param $message incoming
 *        SMS message before interepted
 * @param $sms_receiver receiver
 *        number that is receiving incoming SMS
 * @param $feature feature
 *        managed to hook current incoming SMS
 * @param $status recvsms()
 *        status, 0 or FALSE for unhandled
 * @param $uid keyword
 *        owner
 * @return array $ret
 */
function incoming_hook_recvsms_intercept_after($sms_datetime, $sms_sender, $message, $sms_receiver, $feature, $status, $uid, $smsc)
{
    global $core_config;
    $ret = array();
    $users = array();
    $is_routed = FALSE;
    if (!$status) {
        // get settings
        $settings = incoming_settings_get();
        // get post rules
        $post_rules = incoming_post_rules_get();
        // sandbox match receiver number and sender ID
        if (!$is_routed) {
            // route sandbox if receiver number matched with default sender ID of users
            if ($post_rules['match_sender_id']) {
                $s = array();
                if ($settings['match_all_sender_id']) {
                    // get all approved sender ID
                    $s = sender_id_getall();
                } else {
                    $data = user_search($sms_receiver, 'sender');
                    foreach ($data as $user) {
                        // get default sender ID
                        if ($user['sender']) {
                            $s[] = $user['sender'];
                            // in case an error occured where multiple users own the same sender ID
                            break;
                        }
                    }
                }
                // start matching
                foreach ($s as $sender_id) {
                    if ($sender_id && $sms_receiver && $sender_id == $sms_receiver) {
                        unset($usernames);
                        unset($username);
                        if ($settings['match_all_sender_id']) {
                            // get $username who owns $sender_id
                            $uids = sender_id_owner($sender_id);
                            foreach ($uids as $uid) {
                                $usernames[] = user_uid2username($uid);
                            }
                        } else {
                            $usernames[] = $user['username'];
                        }
                        array_unique($usernames);
                        foreach ($usernames as $username) {
                            if ($username) {
                                _log("sandbox match sender start u:" . $username . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "]", 3, 'incoming recvsms_intercept_after');
                                recvsms_inbox_add($sms_datetime, $sms_sender, $username, $message, $sms_receiver);
                                _log("sandbox match sender end u:" . $username, 3, 'incoming recvsms_intercept_after');
                                $is_routed = TRUE;
                                // single match only
                                // break;
                            }
                        }
                    }
                }
            }
        }
        // sandbox prefix
        if (!$is_routed) {
            // route sandbox by adding a prefix to message and re-enter it to recvsms()
            /**
             * if ($post_rules['insert_prefix'] && trim($message)) {
             * $message = $post_rules['insert_prefix'] .
             *
             *
             * ' ' . trim($message);
             * _log("sandbox add prefix start keyword:" . $post_rules['insert_prefix'] . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept_after');
             * recvsms($sms_datetime, $sms_sender, $message, $sms_receiver, $smsc);
             * _log("sandbox add prefix end keyword:" . $post_rules['insert_prefix'], 3, 'incoming recvsms_intercept_after');
             * $is_routed = TRUE;
             * }
             */
        }
        // sandbox forward to users
        if (!$is_routed) {
            foreach ($post_rules['forward_to'] as $uid) {
                $c_username = user_uid2username($uid);
                if ($c_username) {
                    $users[] = $c_username;
                }
            }
            // route sandbox to users inbox
            foreach ($users as $username) {
                _log("sandbox to user start u:" . $username . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "]", 3, 'incoming recvsms_intercept_after');
                recvsms_inbox_add($sms_datetime, $sms_sender, $username, $message, $sms_receiver);
                _log("sandbox to user end u:" . $username, 3, 'incoming recvsms_intercept_after');
                $is_routed = TRUE;
            }
        }
        // flag the hook if is_routed
        if ($is_routed) {
            $ret['param']['feature'] = 'incoming';
            if ($settings['leave_copy_sandbox']) {
                $ret['param']['status'] = 0;
            } else {
                $ret['param']['status'] = 1;
            }
            $ret['param']['uid'] = 1;
            $ret['modified'] = TRUE;
        }
    }
    return $ret;
}