Esempio n. 1
0
/**
 * Intercept on before-process stage for incoming SMS
 *
 * @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 $reference_id reference_id
 *        data
 * @return array $ret
 */
function incoming_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver, $reference_id)
{
    $ret = array();
    $found_bc = FALSE;
    $found_pv = FALSE;
    // continue only when keyword does not exists
    $m = explode(' ', $message);
    if (!keyword_isavail($m[0])) {
        return $ret;
    }
    // get settings
    $settings = incoming_settings_get();
    // get post rules
    $pre_rules = incoming_pre_rules_get();
    // scan for #<sender's phonebook group code> and @<username> according to pre rules
    $msg = explode(' ', $message);
    if (count($msg) > 0) {
        $bc = array();
        $pv = array();
        for ($i = 0; $i < count($msg); $i++) {
            $c_text = trim($msg[$i]);
            // scan message for @username
            if ($pre_rules['match_username']) {
                if (substr($c_text, 0, 1) === '@') {
                    $pv[] = strtolower(substr($c_text, 1));
                    $found_pv = TRUE;
                }
            }
            // scan message for #groupcode
            if ($pre_rules['match_groupcode']) {
                if (substr($c_text, 0, 1) === '#') {
                    $bc[] = strtoupper(substr($c_text, 1));
                    $found_bc = TRUE;
                }
            }
        }
    }
    if ($found_bc || $found_pv) {
        _log("recvsms_intercept dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
    }
    if ($found_bc) {
        $groups = array_unique($bc);
        foreach ($groups as $key => $c_group_code) {
            $c_uid = user_mobile2uid($sms_sender);
            $list = phonebook_search_group($c_uid, $c_group_code, '', TRUE);
            $c_gpid = $list[0]['gpid'];
            if ($c_uid && $c_gpid) {
                $c_username = user_uid2username($c_uid);
                _log("bc g:" . phonebook_code_clean($c_group_code) . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                sendsms_bc($c_username, $c_gpid, $message);
                _log("bc end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            }
        }
    }
    if ($found_pv) {
        $users = array_unique($pv);
        foreach ($users as $key => $c_username) {
            $c_username = core_sanitize_username($c_username);
            if ($c_uid = user_username2uid($c_username)) {
                _log("pv u:" . $c_username . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "] reference_id:" . $reference_id, 3, 'incoming recvsms_intercept');
                recvsms_inbox_add($sms_datetime, $sms_sender, $c_username, $message, $sms_receiver, $reference_id);
                _log("pv end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            }
        }
    }
    return $ret;
}
Esempio n. 2
0
 * playSMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * 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/>.
 */
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);
Esempio n. 3
0
/**
 * Intercept on before-process stage for incoming SMS
 *
 * @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 $reference_id reference_id
 *        	data
 * @return array $ret
 */
function incoming_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver, $reference_id)
{
    $ret = array();
    $found_bc = FALSE;
    $found_pv = FALSE;
    // continue only when keyword does not exists
    $m = explode(' ', $message);
    if (!checkavailablekeyword($m[0])) {
        return $ret;
    }
    // get settings
    $settings = incoming_settings_get();
    // get post rules
    $pre_rules = incoming_pre_rules_get();
    // scan for #<sender's phonebook group code> and @<username> according to pre rules
    $msg = explode(' ', $message);
    if (count($msg) > 0) {
        $bc = array();
        $pv = array();
        for ($i = 0; $i < count($msg); $i++) {
            $c_text = trim($msg[$i]);
            // scan message for @username
            if ($pre_rules['match_username']) {
                if (substr($c_text, 0, 1) === '@') {
                    $pv[] = strtolower(substr($c_text, 1));
                    $found_pv = TRUE;
                }
            }
            // scan message for #groupcode
            if ($pre_rules['match_groupcode']) {
                if (substr($c_text, 0, 1) === '#') {
                    $bc[] = strtoupper(substr($c_text, 1));
                    $found_bc = TRUE;
                }
            }
        }
    }
    if ($found_bc || $found_pv) {
        _log("recvsms_intercept dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
    }
    if ($found_bc) {
        $groups = array_unique($bc);
        foreach ($groups as $key => $c_group_code) {
            $c_group_code = strtoupper($c_group_code);
            $c_group_code = core_sanitize_alphanumeric($c_group_code);
            $c_uid = user_mobile2uid($sms_sender);
            if ($c_uid && ($c_gpid = phonebook_groupcode2id($c_uid, $c_group_code))) {
                $c_username = user_uid2username($c_uid);
                _log("bc g:" . $c_group_code . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                sendsms_bc($c_username, $c_gpid, $message);
                _log("bc end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            } else {
                // check the group_code for flag_sender<>0
                $db_query = "SELECT id,uid,flag_sender FROM " . _DB_PREF_ . "_featurePhonebook_group WHERE code='{$c_group_code}' AND flag_sender<>0";
                $db_result = dba_query($db_query);
                if ($db_row = dba_fetch_array($db_result)) {
                    $c_gpid = $db_row['id'];
                    $c_uid = $db_row['uid'];
                    $c_flag_sender = $db_row['flag_sender'];
                    if ($c_flag_sender == 2) {
                        $c_username = user_uid2username($c_uid);
                        _log("bc mobile flag_sender:" . $c_flag_sender . " username:"******" uid:" . $c_uid . " g:" . $c_group_code . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                        $sender = trim(phonebook_number2name($sms_sender, $c_username));
                        $sender = $sender ? $sender : $sms_sender;
                        sendsms_bc($c_username, $c_gpid, $sender . ":" . $message);
                        _log("bc mobile end", 3, 'incoming recvsms_intercept');
                        $ret['uid'] = $c_uid;
                        $ret['hooked'] = true;
                    } else {
                        if ($c_flag_sender == 1) {
                            // check whether sms_sender belongs to c_group_code
                            $db_query = "SELECT B.id AS id FROM " . _DB_PREF_ . "_featurePhonebook AS A\n\t\t\t\t\t\t\t\tLEFT JOIN playsms.playsms_featurePhonebook_group_contacts AS C ON A.id=C.pid\n\t\t\t\t\t\t\t\tLEFT JOIN playsms.playsms_featurePhonebook_group AS B ON B.id=C.gpid\n\t\t\t\t\t\t\t\tWHERE A.mobile LIKE '%" . substr($sms_sender, 3) . "' AND B.code='" . $c_group_code . "'";
                            $db_result = dba_query($db_query);
                            if ($db_row = dba_fetch_array($db_result)) {
                                $c_username = user_uid2username($c_uid);
                                _log("bc mobile flag_sender:" . $c_flag_sender . " username:"******" uid:" . $c_uid . " g:" . $c_group_code . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                                $sender = trim(phonebook_number2name($sms_sender, $c_username));
                                $sender = $sender ? $sender : $sms_sender;
                                sendsms_bc($c_username, $c_gpid, $sender . ":" . $message);
                                _log("bc mobile end", 3, 'incoming recvsms_intercept');
                                $ret['uid'] = $c_uid;
                                $ret['hooked'] = true;
                            }
                        }
                    }
                }
            }
        }
    }
    if ($found_pv) {
        $users = array_unique($pv);
        foreach ($users as $key => $c_username) {
            $c_username = core_sanitize_username($c_username);
            if ($c_uid = user_username2uid($c_username)) {
                _log("pv u:" . $c_username . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "] reference_id:" . $reference_id, 3, 'incoming recvsms_intercept');
                recvsms_inbox_add($sms_datetime, $sms_sender, $c_username, $message, $sms_receiver, $reference_id);
                _log("pv end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            }
        }
    }
    return $ret;
}