function webservices_bc($c_username, $c_gcode, $msg, $type = 'text', $unicode = 0) { if (($c_uid = username2uid($c_username)) && $c_gcode && $msg) { $c_gpid = phonebook_groupcode2id($c_uid, $c_gcode); // sendsms_bc($c_username,$c_gpid,$message,$sms_type='text',$unicode=0) list($ok, $to, $smslog_id) = sendsms_bc($c_username, $c_gpid, $msg, $type, $unicode); if ($ok[0]) { $ret = "OK"; } else { $ret = "ERR 300"; } } else { $ret = "ERR 301"; } return $ret; }
function recvsms_process($sms_datetime, $sms_sender, $message, $sms_receiver = '', $smsc = '') { global $core_config; // blacklist if (blacklist_mobile_isexists(0, $sms_sender)) { logger_print("incoming SMS discarded sender is in the blacklist datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:[" . $message . "] smsc:" . $smsc, 3, "recvsms_process"); return false; } // incoming sms will be handled by plugins first $ret_intercept = recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver, $smsc); if ($ret_intercept['modified']) { $sms_datetime = $ret_intercept['param']['sms_datetime'] ? $ret_intercept['param']['sms_datetime'] : $sms_datetime; $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender; $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message; $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver; $smsc = $ret_intercept['param']['smsc'] ? $ret_intercept['param']['smsc'] : $smsc; } // set active gateway module as default gateway // if (!$smsc) { // $smsc = core_smsc_get(); // } // log it logger_print("dt:" . $sms_datetime . " sender:" . $sms_sender . " m:" . $message . " receiver:" . $sms_receiver . ' smsc:' . $smsc, 3, "recvsms_process"); // if hooked function returns cancel=true then stop the processing incoming sms, return false if ($ret_intercept['cancel']) { logger_print("cancelled datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:[" . $message . "] smsc:" . $smsc, 3, "recvsms_process"); return false; } $c_uid = 0; $c_feature = ""; $ok = false; $keyword_separator = $core_config['main']['keyword_separator'] ? $core_config['main']['keyword_separator'] : ' '; $array_target_keyword = explode($keyword_separator, $message); $target_keyword = strtoupper(trim($array_target_keyword[0])); $raw_message = $message; $message = $array_target_keyword[1]; for ($i = 2; $i < count($array_target_keyword); $i++) { $message .= " " . $array_target_keyword[$i]; } switch ($target_keyword) { case "BC": $c_uid = user_mobile2uid($sms_sender); $c_username = user_uid2username($c_uid); $c_feature = 'core'; $array_target_group = explode(" ", $message); $target_group = strtoupper(trim($array_target_group[0])); $list = phonebook_search_group($c_uid, $target_group, '', TRUE); $c_gpid = $list[0]['gpid']; $message = $array_target_group[1]; for ($i = 2; $i < count($array_target_group); $i++) { $message .= " " . $array_target_group[$i]; } logger_print("bc username:"******" gpid:" . $c_gpid . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message . " raw:" . $raw_message, 3, "recvsms_process"); if ($c_username && $c_gpid && $message) { list($ok, $to, $smslog_id, $queue) = sendsms_bc($c_username, $c_gpid, $message); $ok = true; } else { _log('bc has failed due to missing option u:' . $c_username . ' gpid:' . $c_gpid . ' m:[' . $message . ']', 3, 'recvsms_process'); } break; default: for ($c = 0; $c < count($core_config['plugins']['list']['feature']); $c++) { $c_feature = $core_config['plugins']['list']['feature'][$c]; $ret = core_hook($c_feature, 'recvsms_process', array($sms_datetime, $sms_sender, $target_keyword, $message, $sms_receiver, $smsc, $raw_message)); if ($ok = $ret['status']) { $c_uid = $ret['uid']; logger_print("feature:" . $c_feature . " datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " keyword:" . $target_keyword . " message:" . $message . " raw:" . $raw_message . " smsc:" . $smsc, 3, "recvsms_process"); break; } } } $c_status = $ok ? 1 : 0; if ($c_status == 0) { $c_feature = ''; $target_keyword = ''; $message = $raw_message; // from recvsms_intercept(), force status as 'handled' if ($ret_intercept['hooked']) { $c_status = 1; if ($ret_intercept['uid']) { $c_uid = $ret_intercept['uid']; } logger_print("intercepted datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "recvsms_process"); } else { logger_print("unhandled datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "recvsms_process"); } } // incoming sms intercept after unset($ret_intercept); $ret_intercept = recvsms_intercept_after($sms_datetime, $sms_sender, $message, $sms_receiver, $c_feature, $c_status, $c_uid, $smsc); if ($ret_intercept['modified']) { $sms_datetime = $ret_intercept['param']['sms_datetime'] ? $ret_intercept['param']['sms_datetime'] : $sms_datetime; $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender; $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message; $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver; $c_feature = $ret_intercept['param']['feature'] ? $ret_intercept['param']['feature'] : $c_feature; $c_status = $ret_intercept['param']['status'] ? $ret_intercept['param']['status'] : $c_status; $c_uid = $ret_intercept['param']['uid'] ? $ret_intercept['param']['uid'] : $c_uid; $smsc = $ret_intercept['param']['smsc'] ? $ret_intercept['param']['smsc'] : $smsc; } // fixme anton - all incoming messages set to user with uid=1 if no one owns it $c_uid = $c_uid ? $c_uid : 1; $db_query = "\n\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSIncoming\n\t\t(in_uid,in_feature,in_gateway,in_sender,in_receiver,in_keyword,in_message,in_datetime,in_status)\n\t\tVALUES\n\t\t('{$c_uid}','{$c_feature}','{$smsc}','{$sms_sender}','{$sms_receiver}','{$target_keyword}','{$message}','" . core_adjust_datetime($sms_datetime) . "','{$c_status}')"; $db_result = dba_query($db_query); return $ok; }
$gpid = $_POST['gpid_text']; } */ $msg_flash = $_POST['msg_flash']; $msg_unicode = $_POST['msg_unicode']; $message = $_POST['message']; if ($gpid && $message) { $sms_type = "text"; if ($msg_flash == "on") { $sms_type = "flash"; } $unicode = "0"; if ($msg_unicode == "on") { $unicode = "1"; } list($ok, $to, $smslog_id) = sendsms_bc($username, $gpid, $message, $sms_type, $unicode); // minimize delivery reports on web, actual status can be seen from outgoing SMS menu (emmanuel) $sms_sent = 0; $sms_failed = 0; for ($i = 0; $i < count($ok); $i++) { if ($ok[$i]) { // $error_string .= _('Your SMS has been delivered to queue')." ("._('to').": `".$to[$i]."`)<br>"; $sms_sent++; } else { // $error_string .= _('Fail to sent SMS')." ("._('to').": `".$to[$i]."`)<br>"; $sms_failed++; } } // fixme anton - we dont need to add new lang entry, just use available phrase $error_string = _('Your SMS has been delivered to queue') . " (" . _('sent') . ": " . $sms_sent . ", " . _('failed') . ": " . $sms_failed . ")"; $errid = logger_set_error_string($error_string);
function setsmsincomingaction($sms_datetime, $sms_sender, $message, $sms_receiver = "") { global $gateway_module, $core_config; // make sure sms_datetime is in supported format and in GMT+0 $sms_datetime = core_adjust_datetime($sms_datetime); // incoming sms will be handled by plugin/tools/* first $ret_intercept = interceptincomingsms($sms_datetime, $sms_sender, $message, $sms_receiver); if ($ret_intercept['modified']) { $sms_datetime = $ret_intercept['param']['sms_datetime'] ? $ret_intercept['param']['sms_datetime'] : $sms_datetime; $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender; $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message; $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver; } // if hooked function returns cancel=true then stop the processing incoming sms, return false if ($ret_intercept['cancel']) { logger_print("cancelled datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction"); return false; } $c_uid = 0; $c_feature = ""; $ok = false; $array_target_keyword = explode(" ", $message); $target_keyword = strtoupper(trim($array_target_keyword[0])); $message_full = $message; $message = $array_target_keyword[1]; for ($i = 2; $i < count($array_target_keyword); $i++) { $message .= " " . $array_target_keyword[$i]; } switch ($target_keyword) { case "BC": $c_uid = mobile2uid($sms_sender); $c_username = uid2username($c_uid); $c_feature = 'core'; $array_target_group = explode(" ", $message); $target_group = strtoupper(trim($array_target_group[0])); $c_gpid = phonebook_groupcode2id($c_uid, $target_group); $message = $array_target_group[1]; for ($i = 2; $i < count($array_target_group); $i++) { $message .= " " . $array_target_group[$i]; } logger_print("username:"******" gpid:" . $c_gpid . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction bc"); list($ok, $to, $queue) = sendsms_bc($c_username, $c_gpid, $message); $ok = true; break; case "PV": $c_feature = 'core'; $array_target_user = explode(" ", $message); $target_user = strtoupper(trim($array_target_user[0])); $c_uid = username2uid($target_user); $message = $array_target_user[1]; for ($i = 2; $i < count($array_target_user); $i++) { $message .= " " . $array_target_user[$i]; } logger_print("datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user . " message:" . $message, 3, "setsmsincomingaction pv"); if (insertsmstoinbox($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver)) { $ok = true; } break; default: for ($c = 0; $c < count($core_config['featurelist']); $c++) { $c_feature = $core_config['featurelist'][$c]; $ret = x_hook($c_feature, 'setsmsincomingaction', array($sms_datetime, $sms_sender, $target_keyword, $message, $sms_receiver)); if ($ok = $ret['status']) { $c_uid = $ret['uid']; logger_print("feature:" . $c_feature . " datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " keyword:" . $target_keyword . " message:" . $message, 3, "setsmsincomingaction"); break; } } } $c_status = $ok ? 1 : 0; if ($c_status == 0) { $c_feature = ''; $target_keyword = ''; $message = $message_full; // from interceptincomingsms(), force status as 'handled' if ($ret_intercept['hooked']) { $c_status = 1; logger_print("intercepted datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction"); } else { logger_print("unhandled datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction"); } } $db_query = "\n INSERT INTO " . _DB_PREF_ . "_tblSMSIncoming \n (in_uid,in_feature,in_gateway,in_sender,in_receiver,in_keyword,in_message,in_datetime,in_status)\n VALUES\n ('{$c_uid}','{$c_feature}','{$gateway_module}','{$sms_sender}','{$sms_receiver}','{$target_keyword}','{$message}','{$sms_datetime}','{$c_status}')\n "; $db_result = dba_query($db_query); return $ok; }
/** * 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; }
/** * 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; }