function pvat_hook_interceptincomingsms($sms_datetime, $sms_sender, $message, $sms_receiver) { $msg = explode(" ", $message); $ret = array(); if (count($msg) > 1) { $pv = trim($msg[0]); if (substr($pv, 0, 1) == '@') { $c_username = substr($pv, 1); $new_message = "PV " . $c_username . " "; if (username2uid($c_username)) { for ($i = 1; $i < count($msg); $i++) { $new_message .= $msg[$i] . " "; } $new_message = substr($new_message, 0, -1); // set 1 to param_modified to let parent function modify param values $ret['modified'] = true; // this time only message param changed $ret['param']['message'] = $new_message; $sms_datetime = core_display_datetime($sms_datetime); logger_print("dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message . " mod:" . $ret['param']['message'], 3, "pvat"); // do not forget to tell parent that this SMS has been hooked $ret['hooked'] = true; } } } return $ret; }
function xlate_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver) { global $core_config; $msg = explode(" ", $message); $ret = array(); if (count($msg) > 1) { $keyword = trim($msg[0]); if (substr($keyword, 0, 1) == '@') { $xlate = substr($keyword, 1); $xlate = explode('2', $xlate); $xlate_from = $xlate[0]; $xlate_to = $xlate[1]; if ($xlate_from && $xlate_to && strlen($xlate_from) == 2 && strlen($xlate_to) == 2) { for ($i = 1; $i < count($msg); $i++) { $words .= $msg[$i] . " "; } $words = trim($words); // contact google $lib = $core_config['apps_path']['plug'] . '/feature/xlate/lib/GoogleTranslate'; // load JSON.php for PHP version lower than 5.2.x require_once $lib . '/JSON.php'; require_once $lib . '/googleTranslate.class.php'; if ($gt = new GoogleTranslateWrapper()) { /* Translate */ $xlate_words = $gt->translate($words, $xlate_to, $xlate_from); // incoming sms is handled $ret['hooked'] = true; /* Was translation successful */ $sms_datetime = core_display_datetime($sms_datetime); if ($gt->isSuccess()) { $reply = '@' . $xlate_from . '2' . $xlate_to . ' ' . $words . ' => ' . $xlate_words; logger_print("success dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " w:" . $words . " from:" . $xlate_from . " to:" . $xlate_to . " xlate:" . $xlate_words, 2, "xlate"); } else { $reply = '@' . $xlate_from . '2' . $xlate_to . ' ' . _("unable to translate") . ': ' . $words; logger_print("failed dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " w:" . $words . " from:" . $xlate_from . " to:" . $xlate_to, 2, "xlate"); } // detect reply message, set unicode if not ASCII $unicode = core_detect_unicode($reply); // send reply SMS using admin account // should add a web menu in xlate.php to choose which account will be used to send reply SMS // usualy we inspect the result of sendsms, but not this time logger_print("send reply encoding:" . $encoding, 2, "xlate"); $reply = addslashes($reply); list($ok, $to, $smslog_id, $queue) = sendsms_helper('admin', $sms_sender, $reply, 'text', $unicode); // do not forget to tell parent that this SMS has been hooked $ret['hooked'] = true; } else { // unable to load the class, set incoming sms unhandled $ret['hooked'] = false; logger_print("class not exists or fail to load", 2, "xlate"); } } } } return $ret; }
function simplebilling_hook_billing_finalize($smslog_id) { $ok = false; logger_print("saving smslog_id:" . $smslog_id, 2, "simplebilling finalize"); $db_query = "UPDATE " . _DB_PREF_ . "_tblBilling SET status='1' WHERE smslog_id='{$smslog_id}'"; if ($db_result = dba_affected_rows($db_query)) { logger_print("saved smslog_id:" . $smslog_id, 2, "simplebilling finalize"); $ok = true; } return $ok; }
function dba_query($mystring, $from = "0", $count = "0") { global $dba_object, $dba_DB, $DBA_ROW_COUNTER, $DBA_LIMIT_FROM, $DBA_LIMIT_COUNT; // log all db query if (function_exists('logger_print')) { logger_print("q:" . $mystring, 4, "dba query"); } $DBA_ROW_COUNTER = 0; if ($DBA_LIMIT_COUNT > 0) { $from = $DBA_LIMIT_FROM; $count = $DBA_LIMIT_COUNT; } $DBA_LIMIT_FROM = 0; $DBA_LIMIT_COUNT = 0; if ($from == 0 && $count == 0) { $result = dba_query_simple($mystring); return $result; } $is_special = false; switch ($dba_DB) { case "mssql": $limit = $from + $count; if ($limit == $count) { $str_limit = "SELECT TOP {$limit}"; $mystring = str_replace("SELECT", $str_limit, $mystring); $is_special = true; } break; case "mysql": case "mysqli": $str_limit = " LIMIT {$from}, {$count}"; $mystring .= $str_limit; $is_special = true; break; default: break; } if ($is_special) { $result = $dba_object->query($mystring); } else { $result = $dba_object->limitQuery($mystring, $from, $count); } if (DB::isError($dba_object)) { // ob_end_clean(); // die ("<p align=left>".$dba_object->getMessage()."<br>".$dba_object->userinfo."<br>"); return ""; } if (!$is_special) { $result->limit_from = $from; $result->limit_count = $count; } return $result; }
function myauto_hook_interceptincomingsms($sms_datetime, $sms_sender, $message, $sms_receiver) { global $core_config; // reply message $reply = 'Thank you for your message'; // detect reply message, set unicode if not ASCII $unicode = core_detect_unicode($reply); // send reply list($ok, $to, $smslog_id, $queue) = sendsms('admin', $sms_sender, $reply, 'text', $unicode); // log it $sms_datetime = core_display_datetime($sms_datetime); logger_print("dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " autorespon:" . $reply, 2, "myauto"); }
function sendmail($mail_from, $mail_to, $mail_subject = "", $mail_body = "") { global $core_config; $ok = false; for ($c = 0; $c < count($core_config['toolslist']); $c++) { if (x_hook($core_config['toolslist'][$c], 'sendmail', array($mail_from, $mail_to, $mail_subject, $mail_body))) { logger_print("sent from:" . $mail_from . " to:" . $mail_to . " subject:" . $mail_subject, 3, "sendmail"); $ok = true; break; } } return $ok; }
function msgtemplate_hook_interceptsendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $sms_type, $unicode) { // parameters modified $ret['modified'] = true; // the modification to $sms_msg $text = $sms_msg; $text = str_replace('#NAME#', phonebook_number2name($sms_to), $text); $text = str_replace('#NUM#', $sms_to, $text); $ret['param']['sms_msg'] = $text; // log it logger_print("to:" . $sms_to . " msg:" . $sms_msg . " replacedby:" . $ret['param']['sms_msg'], 3, "msgtemplate"); return $ret; }
function simplebilling_hook_billing_getdata($smslog_id) { $ret = array(); logger_print("smslog_id:" . $smslog_id, 3, "simplebilling getdata"); $db_query = "SELECT id,rate,credit,status FROM " . _DB_PREF_ . "_tblBilling WHERE smslog_id='{$smslog_id}'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { $id = $db_row['id']; $post_datetime = $db_row['post_datetime']; $rate = $db_row['rate']; $credit = $db_row['credit']; $status = $db_row['status']; $ret = array('id' => $id, 'smslog_id' => $smslog_id, 'post_datetime' => $post_datetime, 'status' => $status, 'rate' => $rate, 'credit' => $credit); } return $ret; }
function dlrd() { global $core_config; $core_config['dlrd_limit'] = (int) $core_config['dlrd_limit'] ? (int) $core_config['dlrd_limit'] : 200; $list = dba_search(_DB_PREF_ . '_tblDLR', '*', array('flag_processed' => 1), '', array('LIMIT' => $core_config['dlrd_limit'])); $j = 0; for ($j = 0; $j < count($list); $j++) { if ($id = $list[$j]['id']) { $smslog_id = $list[$j]['smslog_id']; $p_status = $list[$j]['p_status']; $uid = $list[$j]['uid']; if (dba_update(_DB_PREF_ . '_tblDLR', array('flag_processed' => 2), array('id' => $id))) { logger_print("id:" . $id . " smslog_id:" . $smslog_id . " p_status:" . $p_status . " uid:" . $uid, 3, "dlrd"); setsmsdeliverystatus($smslog_id, $uid, $p_status); } } } }
function myauto_hook_interceptincomingsms($sms_datetime, $sms_sender, $message, $sms_receiver) { global $core_config; // reply message $reply = 'Thank you for your message'; // detect reply message, set unicode if not ASCII $unicode = 0; if (function_exists('mb_detect_encoding')) { $encoding = mb_detect_encoding($reply, 'auto'); if ($encoding != 'ASCII') { $unicode = 1; } } // send reply list($ok, $to, $smslog_id) = sendsms_pv('admin', $sms_sender, $reply, 'text', $unicode); // log it $sms_datetime = core_display_datetime($sms_datetime); logger_print("dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " autorespon:" . $reply, 3, "myauto"); }
/** * Update notification * @param integer $uid User ID * @param string $id Notification ID * @param array $data Updated data * @return boolean */ function notif_update($uid, $id, $data) { $ret = FALSE; $replaced = ''; $db_table = _DB_PREF_ . '_tblNotif'; $result = dba_search($db_table, '*', array('uid' => $uid, 'id' => $id)); foreach ($result[0] as $key => $val) { $items[$key] = $data[$key] ? $data[$key] : $val; if ($data[$key]) { $replaced = $key . ':' . $val . ' '; } } if ($items && trim($replaced)) { if (dba_update($db_table, $items, array('id' => $id))) { logger_print('uid:' . $uid . ' id:' . $id . ' ' . trim($replaced), 2, 'notif_update'); $ret = TRUE; } } return $ret; }
function sms_quiz_hook_recvsms_process($sms_datetime, $sms_sender, $quiz_keyword, $quiz_param = '', $sms_receiver = '', $smsc = '', $raw_message = '') { $ok = false; $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureQuiz WHERE quiz_keyword='{$quiz_keyword}'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { if ($db_row['uid'] && $db_row['quiz_enable']) { $smsc = gateway_decide_smsc($smsc, $db_row['smsc']); logger_print('begin k:' . $quiz_keyword . ' c:' . $quiz_param, 2, 'sms_quiz'); if (sms_quiz_handle($db_row, $sms_datetime, $sms_sender, $quiz_keyword, $quiz_param, $sms_receiver, $smsc, $raw_message)) { $ok = true; } $status = $ok ? 'handled' : 'unhandled'; logger_print('end k:' . $quiz_keyword . ' c:' . $quiz_param . ' s:' . $status, 2, 'sms_quiz'); } } $ret['uid'] = $db_row['uid']; $ret['status'] = $ok; return $ret; }
function myauto_hook_interceptincomingsms($sms_datetime, $sms_sender, $message, $sms_receiver) { global $core_config; // reply message $reply = 'Thank you for your message'; // detect reply message, set unicode if not ASCII $unicode = 0; if (function_exists('mb_detect_encoding')) { $encoding = mb_detect_encoding($reply, 'auto'); if ($encoding != 'ASCII') { $unicode = 1; } } // send reply with admin account $c_uid = username2uid('admin'); // send reply sendsms($core_config['main']['cfg_gateway_number'], '', $sms_sender, $reply, $c_uid, 0, 'text', $unicode); // log it logger_print("dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " autorespon:" . $reply, 3, "myauto"); }
function sms_custom_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $custom_keyword, $custom_param = '', $smsc = '', $raw_message = '') { $ok = false; $custom_keyword = strtoupper(trim($custom_keyword)); $custom_param = trim($custom_param); $db_query = "SELECT custom_url,uid,custom_return_as_reply FROM " . _DB_PREF_ . "_featureCustom WHERE custom_keyword='{$custom_keyword}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $custom_url = $db_row['custom_url']; $username = user_uid2username($db_row['uid']); $custom_return_as_reply = $db_row['custom_return_as_reply']; if ($custom_keyword && $custom_url && $username) { $sms_datetime = core_display_datetime($sms_datetime); $custom_url = str_replace("{SMSDATETIME}", urlencode($sms_datetime), $custom_url); $custom_url = str_replace("{SMSSENDER}", urlencode($sms_sender), $custom_url); $custom_url = str_replace("{CUSTOMKEYWORD}", urlencode($custom_keyword), $custom_url); $custom_url = str_replace("{CUSTOMPARAM}", urlencode($custom_param), $custom_url); $custom_url = str_replace("{CUSTOMRAW}", urlencode($raw_message), $custom_url); logger_print("custom_url:" . $custom_url, 3, "sms custom"); $parsed_url = parse_url($custom_url); $opts = array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'content' => $parsed_url['query'])); $context = stream_context_create($opts); $server_url = explode('?', $custom_url); $returns = file_get_contents($server_url[0], false, $context); if ($custom_return_as_reply == 1) { if ($returns = trim($returns)) { $unicode = core_detect_unicode($returns); $returns = addslashes($returns); logger_print("returns:" . $returns, 3, "sms custom"); sendsms_helper($username, $sms_sender, $returns, 'text', $unicode, $smsc); } else { logger_print("returns empty", 3, "sms custom"); } } $ok = true; } return $ok; }
function sms_command_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $command_keyword, $command_param = '', $smsc = '', $raw_message = '') { global $plugin_config; $ok = false; $command_keyword = strtoupper(trim($command_keyword)); $command_param = trim($command_param); $db_query = "SELECT command_exec,uid,command_return_as_reply FROM " . _DB_PREF_ . "_featureCommand WHERE command_keyword='{$command_keyword}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $command_exec = $db_row['command_exec']; $command_return_as_reply = $db_row['command_return_as_reply']; $username = user_uid2username($db_row['uid']); if ($command_keyword && $command_exec && $username) { $sms_datetime = core_display_datetime($sms_datetime); $command_exec = str_replace("{SMSDATETIME}", "\"{$sms_datetime}\"", $command_exec); $command_exec = str_replace("{SMSSENDER}", escapeshellarg($sms_sender), $command_exec); $command_exec = str_replace("{COMMANDKEYWORD}", escapeshellarg($command_keyword), $command_exec); $command_exec = str_replace("{COMMANDPARAM}", escapeshellarg($command_param), $command_exec); $command_exec = str_replace("{COMMANDRAW}", escapeshellarg($raw_message), $command_exec); $command_exec = str_replace("/", "", $command_exec); $command_exec = $plugin_config['sms_command']['bin'] . "/" . $db_row['uid'] . "/" . $command_exec; $command_exec = escapeshellcmd($command_exec); logger_print("command_exec:" . addslashes($command_exec), 3, "sms command"); $command_output = shell_exec($command_exec); if ($command_return_as_reply == 1) { $unicode = core_detect_unicode($command_output); if ($command_output = addslashes(trim($command_output))) { logger_print("command_output:" . $command_output, 3, "sms command"); sendsms_helper($username, $sms_sender, $command_output, 'text', $unicode, $smsc); } else { logger_print("command_output is empty", 3, "sms command"); } } $ok = true; } return $ok; }
function recvsms_inbox_add($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver = "", $reference_id = '') { global $core_config; // sms to inbox will be handled by plugins first $ret_intercept = recvsms_inbox_add_intercept($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver, $reference_id); if ($ret_intercept['param_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; $target_user = $ret_intercept['param']['target_user'] ? $ret_intercept['param']['target_user'] : $target_user; $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message; $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver; $reference_id = $ret_intercept['param']['reference_id'] ? $ret_intercept['param']['reference_id'] : $reference_id; } $ok = FALSE; if ($sms_sender && $target_user && $message) { $user = user_getdatabyusername($target_user); if ($uid = $user['uid']) { // discard if banned if (user_banned_get($uid)) { logger_print("user banned, message ignored uid:" . $uid, 2, "recvsms_inbox_add"); return FALSE; } // get name from target_user's phonebook $c_name = ''; if (substr($sms_sender, 0, 1) == '@') { $c_username = str_replace('@', '', $sms_sender); $c_name = user_getfieldbyusername($c_username, 'name'); } else { $c_name = phonebook_number2name($uid, $sms_sender); } $sender = $c_name ? $c_name . ' (' . $sms_sender . ')' : $sms_sender; // forward to Inbox if ($fwd_to_inbox = $user['fwd_to_inbox']) { $db_query = "\n\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSInbox\n\t\t\t\t\t(in_sender,in_receiver,in_uid,in_msg,in_datetime,reference_id)\n\t\t\t\t\tVALUES ('{$sms_sender}','{$sms_receiver}','{$uid}','{$message}','" . core_adjust_datetime($sms_datetime) . "','{$reference_id}')\n\t\t\t\t"; logger_print("saving sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user . " reference_id:" . $reference_id, 2, "recvsms_inbox_add"); if ($inbox_id = @dba_insert_id($db_query)) { logger_print("saved id:" . $inbox_id . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user, 2, "recvsms_inbox_add"); $ok = TRUE; } } // forward to email, consider site config too if ($parent_uid = user_getparentbyuid($uid)) { $site_config = site_config_get($parent_uid); } $web_title = $site_config['web_title'] ? $site_config['web_title'] : $core_config['main']['web_title']; $email_service = $site_config['email_service'] ? $site_config['email_service'] : $core_config['main']['email_service']; $email_footer = $site_config['email_footer'] ? $site_config['email_footer'] : $core_config['main']['email_footer']; $sms_receiver = $sms_receiver ? $sms_receiver : '-'; if ($fwd_to_email = $user['fwd_to_email']) { if ($email = $user['email']) { $subject = _('Message from') . " " . $sender; $body = $web_title . "\n\n"; $body .= _('Message received at') . " " . $sms_receiver . " " . _('on') . " " . $sms_datetime . "\n\n"; $body .= _('From') . " " . $sender . "\n\n"; $body .= $message . "\n\n--\n"; $body .= $email_footer . "\n\n"; $body = stripslashes($body); logger_print("send email from:" . $email_service . " to:" . $email . " message:[" . $message . "]", 3, "recvsms_inbox_add"); $data = array('mail_from_name' => $web_title, 'mail_from' => $email_service, 'mail_to' => $email, 'mail_subject' => $subject, 'mail_body' => $body); sendmail($data); logger_print("sent email from:" . $email_service . " to:" . $email, 3, "recvsms_inbox_add"); } } // forward to mobile if ($fwd_to_mobile = $user['fwd_to_mobile']) { if ($mobile = $user['mobile']) { // fixme anton $c_message = $message . ' ' . $sender; if ($sender_uid = user_mobile2uid($sms_sender)) { if ($sender_username = user_uid2username($sender_uid)) { $c_message = $message . ' ' . '@' . $sender_username; } } $message = $c_message; $unicode = core_detect_unicode($message); $nofooter = TRUE; logger_print("send to mobile:" . $mobile . " from:" . $sms_sender . " user:"******" message:" . $message, 3, "recvsms_inbox_add"); list($ok, $to, $smslog_id, $queue) = sendsms($target_user, $mobile, $message, 'text', $unicode, '', $nofooter); if ($ok[0] == 1) { logger_print("sent to mobile:" . $mobile . " from:" . $sms_sender . " user:"******"recvsms_inbox_add"); } } } } } return $ok; }
/** * Send SMS to phonebook group * * @global array $core_config * @param string $username * @param integer $gpid * @param string $message * @param string $sms_type * @param integer $unicode * @param string $smsc * @param boolean $nofooter * @param string $sms_footer * @param string $sms_sender * @param string $sms_schedule * @return array array($status, $sms_to, $smslog_id, $queue) */ function sendsms_bc($username, $gpid, $message, $sms_type = 'text', $unicode = 0, $smsc = '', $nofooter = false, $sms_footer = '', $sms_sender = '', $sms_schedule = '') { global $core_config, $user_config; $user = $user_config; if ($username && $user['username'] != $username) { $user = user_getdatabyusername($username); } $uid = $user['uid']; // discard if banned if (user_banned_get($uid)) { logger_print("user banned, exit immediately uid:" . $uid, 2, "sendsms_bc"); return array(FALSE, '', '', '', ''); } // SMS sender ID $sms_sender = core_sanitize_sender($sms_sender); $sms_sender = $sms_sender && sender_id_isvalid($username, $sms_sender) ? $sms_sender : sendsms_get_sender($username); // SMS footer $sms_footer = core_sanitize_footer($sms_footer); $sms_footer = $sms_footer ? $sms_footer : $user['footer']; if ($nofooter) { $sms_footer = ''; } // a hack to remove \r from \r\n // the issue begins with ENTER being \r\n and detected as 2 chars // and since the javascript message counter can't detect it as 2 chars // thus the message length counts is inaccurate $message = str_replace("\r\n", "\n", $message); // just to make sure its length, we need to stripslashes message before enter other procedures $sms_sender = stripslashes($sms_sender); $message = stripslashes($message); $sms_footer = stripslashes($sms_footer); // fixme anton - fix #71 but not sure whats the correct solution for this // $max_length = ( $unicode ? $user['opt']['max_sms_length_unicode'] : $user['opt']['max_sms_length'] ); $max_length = $user['opt']['max_sms_length']; if (strlen($message) > $max_length) { $message = substr($message, 0, $max_length); } $sms_msg = $message; logger_print("start uid:" . $uid . " sender:" . $sms_sender, 2, "sendsms_bc"); // add a space infront of footer if exists $c_sms_footer = trim($sms_footer) ? ' ' . trim($sms_footer) : ''; logger_print("maxlen:" . $max_length . " footerlen:" . strlen($c_sms_footer) . " footer:[" . $c_sms_footer . "] msglen:" . strlen($sms_msg) . " message:[" . $sms_msg . "]", 3, "sendsms_bc"); // destination group should be an array, if single then make it array of 1 member if (is_array($gpid)) { $array_gpid = $gpid; } else { $array_gpid = explode(',', $gpid); } $j = 0; for ($i = 0; $i < count($array_gpid); $i++) { if ($c_gpid = trim($array_gpid[$i])) { logger_print("start gpid:" . $c_gpid . " uid:" . $uid . " sender:" . $sms_sender, 2, "sendsms_bc"); // create a queue $queue_code = sendsms_queue_create($sms_sender, $sms_footer, $sms_msg, $uid, $c_gpid, $sms_type, $unicode, $sms_schedule, $smsc); if (!$queue_code) { // when unable to create a queue then immediately returns FALSE, no point to continue logger_print("fail to finalize queue creation, exit immediately", 2, "sendsms_bc"); return array(FALSE, '', '', '', ''); } $queue_count = 0; $sms_count = 0; $failed_queue_count = 0; $failed_sms_count = 0; $rows = phonebook_getdatabyid($c_gpid); if (is_array($rows)) { foreach ($rows as $key => $db_row) { $p_num = trim($db_row['p_num']); if ($sms_to = sendsms_getvalidnumber($p_num)) { $sms_to = sendsms_manipulate_prefix($sms_to, $user); if ($smslog_id[$j] = sendsms_queue_push($queue_code, $sms_to)) { $ok[$j] = true; $queue_count++; $sms_count += $count; } else { $ok[$j] = FALSE; $failed_queue_count++; $failed_sms_count++; } $to[$j] = $sms_to; $queue[$j] = $queue_code; $counts[$j] = $count; $j++; } } } if (sendsms_queue_update($queue_code, array('flag' => '0', 'sms_count' => $sms_count))) { logger_print("end queue_code:" . $queue_code . " queue_count:" . $queue_count . " sms_count:" . $sms_count . " failed_queue:" . $failed_queue_count . " failed_sms:" . $failed_sms_count, 2, "sendsms_bc"); } else { logger_print("fail to prepare queue, exit immediately queue_code:" . $queue_code, 2, "sendsms_bc"); return array(FALSE, '', '', $queue_code, ''); } } } if (!$core_config['issendsmsd']) { unset($ok); unset($to); unset($queue); unset($counts); logger_print("sendsmsd off immediately process queue_code:" . $queue_code, 2, "sendsms_bc"); list($ok, $to, $smslog_id, $queue, $counts) = sendsmsd($queue_code); } return array($ok, $to, $smslog_id, $queue, $counts); }
$cb_timestamp = $_REQUEST['datetime'] ? strtotime($_REQUEST['datetime']) : mktime(); $cb_text = $_REQUEST['text']; $cb_status = $_REQUEST['status']; $cb_charge = $_REQUEST['charge']; $cb_apimsgid = $_REQUEST['apiMsgId']; $cb_smsc = $_REQUEST['smsc']; /* * $fc = "from: $cb_from - to: $cb_to - timestamp: $cb_timestamp - text: $cb_text - status: $cb_status - charge: $cb_charge - apimsgid: $cb_apimsgid\n"; $fn = "/tmp/infobip_callback"; umask(0); $fd = fopen($fn,"a+"); fputs($fd,$fc); fclose($fd); die(); */ if ($cb_timestamp && $cb_from && $cb_text) { $cb_datetime = date($datetime_format, $cb_timestamp); $sms_datetime = trim($cb_datetime); $sms_sender = trim($cb_from); $message = trim($cb_text); $sms_receiver = trim($cb_to); logger_print("sender:" . $sms_sender . " receiver:" . $sms_receiver . " dt:" . $sms_datetime . " msg:" . $message, 3, "infobip incoming"); // collected: // $sms_datetime, $sms_sender, $message, $sms_receiver setsmsincomingaction($sms_datetime, $sms_sender, $message, $sms_receiver, $cb_smsc); } if ($cb_status && $cb_apimsgid) { $db_query = "\n\tSELECT " . _DB_PREF_ . "_tblSMSOutgoing.smslog_id AS smslog_id," . _DB_PREF_ . "_tblSMSOutgoing.uid AS uid \n\tFROM " . _DB_PREF_ . "_tblSMSOutgoing," . _DB_PREF_ . "_gatewayInfobip_apidata\n\tWHERE \n\t " . _DB_PREF_ . "_tblSMSOutgoing.smslog_id=" . _DB_PREF_ . "_gatewayInfobip_apidata.smslog_id AND \n\t " . _DB_PREF_ . "_gatewayInfobip_apidata.apimsgid='{$cb_apimsgid}'\n "; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $uid = $db_row['uid']; $smslog_id = $db_row['smslog_id']; if ($uid && $smslog_id) { $c_sms_status = 0; switch ($cb_status) { case "001": case "002":
$cb_from = $_REQUEST['sender']; $cb_to = $_REQUEST['msisdn']; $cb_message = $_REQUEST['message']; $cb_completed_time = $_REQUEST['completed_time']; //r check format yy-MM-dd HH:mm:ss $cb_status = $_REQUEST['status']; $cb_apimsgid = $_REQUEST['batch_id']; $cb_smsc = trim($_REQUEST['smsc']) ? trim($_REQUEST['smsc']) : 'bulksms'; if ($cb_completed_time && $cb_from && ${$cb_apimsgid}) { $cb_datetime = date($datetime_format, strtotime($cb_completed_time)); $sms_datetime = trim($cb_datetime); $sms_sender = trim($cb_from); $sms_receiver = trim($cb_to); $message = trim(htmlspecialchars_decode(urldecode($cb_message))); $apimsgid = trim($cb_apimsgid); logger_print("sender:" . $sms_sender . " receiver:" . $sms_receiver . " dt:" . $sms_datetime . " batchid:" . $apimsgid . " message:[" . $message . "]", 3, "bulksms incoming"); // collected: // $sms_datetime, $sms_sender, $message, $sms_receiver $sms_sender = addslashes($sms_sender); $message = addslashes($message); recvsms($sms_datetime, $sms_sender, $message, $sms_receiver, $cb_smsc); } if ($cb_status && $cb_apimsgid) { $db_query = "\n\t\tSELECT " . _DB_PREF_ . "_tblSMSOutgoing.smslog_id AS smslog_id," . _DB_PREF_ . "_tblSMSOutgoing.uid AS uid\n\t\tFROM " . _DB_PREF_ . "_tblSMSOutgoing," . _DB_PREF_ . "_gatewayBulksms_apidata\n\t\tWHERE\n\t\t\t" . _DB_PREF_ . "_tblSMSOutgoing.smslog_id=" . _DB_PREF_ . "_gatewayBulksms_apidata.smslog_id AND\n\t\t\t" . _DB_PREF_ . "_gatewayBulksms_apidata.apimsgid='{$cb_apimsgid}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $uid = $db_row['uid']; $smslog_id = $db_row['smslog_id']; if ($uid && $smslog_id) { $c_sms_status = 0; switch ($cb_status) {
function gammu_hook_sendsms($mobile_sender, $sms_sender, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0) { global $gammu_param; $date = date('Ymd', time()); $time = date('Gis', time()); // OUT<priority><date>_<time>_<serialno>_<phone_number>_<anything>.<ext><options> $sms_id = 'A' . $date . '_' . $time . '_00_' . $sms_to . '_' . $smslog_id . '10001' . $uid . '10001' . $gpid . '.txtd'; if ($msg_type == "flash") { $sms_id .= 'f'; } if ($sms_sender) { $sms_msg = $sms_msg . $sms_sender; } // 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 = $gammu_param['path'] . "/outbox/OUT" . $sms_id; logger_print("outfile:" . $fn, 3, "gammu outgoing"); umask(0); $fd = @fopen($fn, "w+"); @fputs($fd, $sms_msg); @fclose($fd); $ok = false; if (file_exists($fn)) { $ok = true; logger_print("outfile saved", 3, "gammu outgoing"); } return $ok; }
/** * This file is part of playSMS. * * playSMS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 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 (_OP_ == 'block') { if (auth_isvalid()) { $_SESSION['dialog']['danger'][] = _('You have no access to this page'); logger_print("WARNING: no access or blocked. sid:" . $_SESSION['sid'] . " ip:" . $_SERVER['REMOTE_ADDR'] . " uid:" . $user_config['uid'] . " app:" . _APP_ . " inc:" . _INC_ . " op:" . _OP_ . " route:" . _ROUTE_, 2, "auth_block"); header("Location: " . _u('index.php?app=main&inc=core_auth&route=block')); } else { header("Location: " . _u('index.php?app=main&inc=core_auth&route=login')); } exit; } else { unset($tpl); $tpl = array('name' => 'auth_block', 'vars' => array('DIALOG_DISPLAY' => _dialog(), 'HTTP_PATH_BASE' => $core_config['http_path']['base'], 'Home' => _('Home'))); _p(tpl_apply($tpl)); }
function simplerate_hook_setsmsdeliverystatus($smslog_id, $uid, $p_status) { logger_print("start smslog_id:" . $smslog_id, 3, "simplerate setsmsdeliverystatus"); if ($p_status == 2) { // check in billing table smslog_id with status=0, status=1 is finalized, status=2 is rolled-back $db_query = "SELECT id FROM " . _DB_PREF_ . "_tblBilling WHERE status='0' AND smslog_id='{$smslog_id}'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { rate_refund($smslog_id); } } }
// delivered // delivered case "buffered": case "accepted": $p_status = 1; break; // sent // sent default: $p_status = 2; break; // failed } logger_print("dlr uid:" . $uid . " smslog_id:" . $smslog_id . " message_id:" . $remote_smslog_id . " status:" . $status, 2, "nexmo callback"); dlr($smslog_id, $uid, $p_status); ob_end_clean(); exit; } } // incoming message $sms_datetime = urldecode($requests['message-timestamp']); $sms_sender = $requests['msisdn']; $message = htmlspecialchars_decode(urldecode($requests['text'])); $sms_receiver = $requests['to']; $smsc = $requests['smsc']; if ($remote_smslog_id && $message) { logger_print("incoming smsc:" . $smsc . " message_id:" . $remote_smslog_id . " s:" . $sms_sender . " d:" . $sms_receiver, 2, "nexmo callback"); $sms_sender = addslashes($sms_sender); $message = addslashes($message); recvsms($sms_datetime, $sms_sender, $message, $sms_receiver, $smsc); }
function insertsmstoinbox($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver = "") { global $core_config, $web_title, $email_service, $email_footer; // sms to inbox will be handled by plugin/tools/* first $ret_intercept = interceptsmstoinbox($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver); if ($ret_intercept['param_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; $target_user = $ret_intercept['param']['target_user'] ? $ret_intercept['param']['target_user'] : $target_user; $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message; $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver; } $ok = false; if ($sms_sender && $target_user && $message) { $user = user_getdatabyusername($target_user); if ($uid = $user['uid']) { // forward to Inbox if ($fwd_to_inbox = $user['fwd_to_inbox']) { $db_query = "\n\t\t INSERT INTO " . _DB_PREF_ . "_tblUserInbox\n\t\t (in_sender,in_receiver,in_uid,in_msg,in_datetime) \n\t\t VALUES ('{$sms_sender}','{$sms_receiver}','{$uid}','{$message}','{$sms_datetime}')\n\t\t"; logger_print("saving sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user, 3, "insertsmstoinbox"); if ($cek_ok = @dba_insert_id($db_query)) { logger_print("saved sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user, 3, "insertsmstoinbox"); } } // forward to email if ($fwd_to_email = $user['fwd_to_email']) { if ($email = $user['email']) { // make sure sms_datetime is in supported format and in user's timezone $sms_datetime = core_display_datetime($sms_datetime); // get name from target_user's phonebook $c_name = phonebook_number2name($sms_sender, $target_user); $sender = $c_name ? $c_name . ' <' . $sms_sender . '>' : $sms_sender; // fixme anton - slash maddess $message = stripslashes($message); $subject = "[SMSGW-PV] " . _('from') . " {$sms_sender}"; $body = _('Forward Private WebSMS') . " ({$web_title})\n\n"; $body .= _('Date time') . ": {$sms_datetime}\n"; $body .= _('Sender') . ": {$sender}\n"; $body .= _('Receiver') . ": {$sms_receiver}\n\n"; $body .= _('Message') . ":\n{$message}\n\n"; $body .= $email_footer . "\n\n"; logger_print("send email from:" . $email_service . " to:" . $email, 3, "insertsmstoinbox"); sendmail($email_service, $email, $subject, $body); logger_print("sent email from:" . $email_service . " to:" . $email, 3, "insertsmstoinbox"); } $ok = true; } // forward to mobile if ($fwd_to_mobile = $user['fwd_to_mobile']) { if ($mobile = $user['mobile']) { $unicode = 0; if (function_exists('mb_detect_encoding')) { $encoding = mb_detect_encoding($message, 'auto'); if ($encoding != 'ASCII') { $unicode = 1; } } $message = $sender . ' ' . $message; logger_print("send to mobile:" . $mobile . " from:" . $sender . " user:"******"insertsmstoinbox"); list($ok, $to, $smslog_id) = sendsms_pv($target_user, $mobile, $message, 'text', $unicode); if ($ok[0]) { logger_print("sent to mobile:" . $mobile . " from:" . $sender . " user:"******"insertsmstoinbox"); } } } } } return $ok; }
function smstools_hook_sendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0) { global $smstools_param; $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 ($msg_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}"; $fn = $smstools_param['path'] . "/outgoing/out.{$sms_id}"; logger_print("outfile:" . $fn, 3, "smstools 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("outfile:" . $fn . " saved", 3, "smstools outgoing"); } else { $p_status = 2; logger_print("cannot save outfile:" . $fn, 3, "smstools outgoing"); } setsmsdeliverystatus($smslog_id, $uid, $p_status); return $ok; }
function messagemedia_hook_call($requests) { global $apps_path, $http_path, $core_config, $messagemedia_param; $called_from_hook_call = true; $access = $requests['access']; if ($access == 'callback') { $fn = $apps_path['plug'] . '/gateway/messagemedia/callback.php'; logger_print("start load:" . $fn, 3, "messagemedia call"); include $fn; logger_print("end load callback", 3, "messagemedia call"); } }
function _log($log, $level, $label) { return logger_print($log, $level, $label); }
$body .= _('Password') . "\t: " . $tmp_password . "\n\n--\n"; $body .= $core_config['main']['email_footer'] . "\n\n"; $data = array('mail_from_name' => $core_config['main']['web_title'], 'mail_from' => $core_config['main']['email_service'], 'mail_to' => $email, 'mail_subject' => $subject, 'mail_body' => $body); if (sendmail($data)) { $error_string = _('Password has been emailed') . " (" . _('Username') . ": " . $username . ")"; $_SESSION['dialog']['info'][] = $error_string; $ok = TRUE; } else { $error_string = _('Fail to send email'); $_SESSION['dialog']['danger'][] = $error_string; } } else { $error_string = _('Fail to save temporary password'); $_SESSION['dialog']['danger'][] = $error_string; } logger_print("u:" . $username . " email:" . $email . " ip:" . $_SERVER['REMOTE_ADDR'] . " error_string:[" . $error_string . "]", 2, "forgot"); } else { $_SESSION['dialog']['danger'][] = _('Fail to recover password'); } } else { $_SESSION['dialog']['danger'][] = _('Fail to recover password'); } } else { $_SESSION['dialog']['danger'][] = _('Fail to recover password'); } } else { $_SESSION['dialog']['danger'][] = _('Recover password disabled'); } } else { $_SESSION['dialog']['danger'][] = _('Please type the displayed captcha phrase correctly'); }
/** * Process register an account * */ function auth_register() { global $core_config; $ok = false; if ($core_config['main']['cfg_enable_register']) { $username = trim($_REQUEST['username']); $email = trim($_REQUEST['email']); $name = trim($_REQUEST['name']); $mobile = trim($_REQUEST['mobile']); $error_string = _('Fail to register an account'); if ($username && $email && $name && $mobile) { $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblUser WHERE username='******'"; $db_result = dba_query($db_query); if ($db_row = dba_fetch_array($db_result)) { $error_string = _('User is already exists') . " (" . _('username') . ": `" . $username . "`)"; } else { $password = substr(md5(time()), 0, 6); $sender = ' - ' . $username; if (ereg("^(.+)(.+)\\.(.+)\$", $email, $arr)) { // by default the status is 3 (normal user) $db_query = "\n\t\t\tINSERT INTO " . _DB_PREF_ . "_tblUser (status,username,password,name,mobile,email,sender,credit)\n\t\t\tVALUES ('3','{$username}','{$password}','{$name}','{$mobile}','{$email}','{$sender}','" . $core_config['main']['cfg_default_credit'] . "')\n\t\t "; if ($new_uid = @dba_insert_id($db_query)) { $ok = true; } } } if ($ok) { logger_print("u:" . $username . " email:" . $email . " ip:" . $_SERVER['REMOTE_ADDR'], 3, "register"); $subject = "[SMSGW] " . _('New account registration'); $body = $core_config['main']['cfg_web_title'] . "\n"; $body .= $core_config['http_path']['base'] . "\n\n"; $body .= _('Username') . "\t: {$username}\n"; $body .= _('Password') . "\t: {$password}\n\n"; $body .= $core_config['main']['cfg_email_footer'] . "\n\n"; $error_string = _('User has been added') . " (" . _('username') . ": `" . $username . "`)"; $error_string .= "<br />"; if (sendmail($core_config['main']['cfg_email_service'], $email, $subject, $body)) { $error_string .= _('Password has been sent to your email'); } else { $error_string .= _('Fail to send email'); } } } } else { $error_string = _('Public registration disabled'); } $errid = logger_set_error_string($error_string); header("Location: " . $core_config['http_path']['base'] . "?errid=" . $errid); exit; }
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; }