function teltree_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $teltree_keyword, $teltree_param = '', $smsc = '', $raw_message = '') { $ps = explode(" ", $raw_message, 2); $kk = strtoupper($ps[0]); $username = "******"; if ($teltree_keyword == 'DAFTAR') { $pecah = preg_split("/#/", $ps[1], null, PREG_SPLIT_NO_EMPTY); $data = array(); $data['name'] = trim($pecah[0]); $data['username'] = trim($pecah[0]); $data['mobile'] = $sms_sender; $data['email'] = str_replace(' ', '', $data['name']) . "@noreply.org"; $data['parent_uid'] = 1; //----- ini parentnya admin $data['status'] = 4; //---ini artinya ditambahkan ke sub user $ret = user_add($data); $ok = $ret['status'] ? TRUE : FALSE; if ($ok) { echo "okee"; $items = array('uid' => 1, 'name' => $data['name'], 'mobile' => $data['mobile'], 'email' => $data['email'], 'tags' => $tags); if ($c_pid = dba_add(_DB_PREF_ . '_featurePhonebook', $items)) { $save_to_group = TRUE; _log('Success to add contact pid:' . $c_pid . ' m:' . $data['mobile'] . ' n:' . $data['name'] . ' e:' . $data['email'] . ' tags:[' . $data['tags'] . ']', 2, 'teltree'); } else { _log('Fail to add contact pid:' . $c_pid . ' m:' . $data['mobile'] . ' n:' . $data['name'] . ' e:' . $data['email'] . ' tags:[' . $data['tags'] . ']', 2, 'teltree'); } $balasan = "Selamat anda telah terdaftar di Telephone Tree"; $gagal = "Maaf Sistem sedang mengalami gangguan, silahkan coba beberapa saat lagi"; if ($save_to_group) { $unicode = core_detect_unicode($balasan); $balasan = addslashes($balasan); // $username = "******"; //$smsc = "dev"; _log("returns:" . $balasan, 2, "teltree"); sendsms_helper($username, $sms_sender, $balasan, 'text', $unicode, $smsc); } else { $unicode = core_detect_unicode($gagal); $balasan = addslashes($gagal); _log("returns:" . $gagal, 2, "teltree"); sendsms_helper($username, $sms_sender, $balasan, 'text', $unicode, $smsc); _log_print("returns empty", 2, "teltree"); } } else { echo "gagal"; } return $ret; //$ok = true; } elseif ($kk == 'GABUNG') { /*$gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group','code',array( ));*/ $uid = user_mobile2uid($sms_sender); $group_code = strtoupper($ps[1]); $list = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array('uid' => 1, 'mobile' => $sms_sender)); if ($group_code && $sms_sender) { /*--dummy code--*/ $c_pid = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array('uid' => 1, 'mobile' => $sms_sender)); $gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'id', array('uid' => 1, 'code' => $group_code)); foreach ($gpids as $gpid) { foreach ($gpid as $key => $val) { $items = array('gpid' => $val, 'pid' => $c_pid[0]['id']); if (dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', $items, 'AND')) { if (dba_add(_DB_PREF_ . '_featurePhonebook_group_contacts', $items)) { $list = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'code', array('uid' => 1)); _log('contact added to group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'phonebook_edit'); if ($iid = $c_pid[0]['id']) { $bal_grup = "selamat anda telah tergabung di grup" . $list[$iid]['code']; $unicode = core_detect_unicode($bal_grup); $bal_grup = addslashes($bal_grup); _log("returns:" . $bal_grup, 2, "telek"); sendsms_helper($username, $sms_sender, $bal_grup, 'text', $unicode, $smsc); _log("returns empty", 2, "sms custom"); } } else { _log('contact edited but fail to save in group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'phonebook_edit'); } } } } } //$ok = true; } elseif ($kk == 'KELUAR') { $uid = user_mobile2uid($sms_sender); $group_code = strtoupper($ps[1]); //_log($sms_sender . ' '. $group_code, 2 , 'test'); if ($group_code && $sms_sender) { // _log($sms_sender . ' '. $group_code, 2 , 'test'); $c_pid = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array('uid' => 1, 'mobile' => $sms_sender)); $gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'id', array('uid' => 1, 'code' => $group_code)); foreach ($gpids as $gpid) { foreach ($gpid as $key => $val) { $items = array('gpid' => $val, 'pid' => $c_pid[0]['id']); // _log($sms_sender . ' '. $group_code, 2 , 'test'); if (!dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', $items, 'AND')) { if (dba_remove(_DB_PREF_ . '_featurePhonebook_group_contacts', $items)) { if ($iid = $c_pid[0]['id']) { $bal_grup = "anda telah keluar dari grup" . $list[$iid]['code']; $unicode = core_detect_unicode($bal_grup); $bal_grup = addslashes($bal_grup); _log("returns:" . $bal_grup, 2, "telek"); sendsms_helper($username, $sms_sender, $bal_grup, 'text', $unicode, $smsc); _log("returns empty", 2, "sms custom"); } _log('contact removed from group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'teltree_phonebook_edit'); } else { _log('contact fail to remove from group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'teltree_phonebook_edit'); } } else { _log('failed ' . $val . ' ' . $c_pid[0]['id'], 2, 'test'); } } } } } }
function webservices_pv($c_username, $to, $msg, $type = 'text', $unicode = 0, $nofooter = FALSE, $footer = '', $from = '', $schedule = '') { $ret = ''; if ($c_username && $to && $msg) { // send SMS, note that we can't let user to define SMSC for now list($ok, $to, $smslog_id, $queue_code, $counts, $sms_count, $sms_failed) = sendsms_helper($c_username, $to, $msg, $type, $unicode, '', $nofooter, $footer, $from, $schedule); for ($i = 0; $i < count($to); $i++) { if (($ok[$i] == 1 || $ok[$i] == true) && $to[$i] && ($queue_code[$i] || $smslog_id[$i])) { $json['data'][$i]['status'] = 'OK'; $json['data'][$i]['error'] = '0'; } elseif ($ok[$i] == 2) { // this doesn't work, but not much an issue now $json['data'][$i]['status'] = 'ERR'; $json['data'][$i]['error'] = '103'; } else { $json['data'][$i]['status'] = 'ERR'; $json['data'][$i]['error'] = '200'; } $json['data'][$i]['smslog_id'] = $smslog_id[$i]; $json['data'][$i]['queue'] = $queue_code[$i]; $json['data'][$i]['to'] = $to[$i]; } } else { $json['status'] = 'ERR'; $json['error'] = '201'; } return $json; }
function sms_quiz_handle($list, $sms_datetime, $sms_sender, $quiz_keyword, $quiz_param = '', $sms_receiver = '', $smsc = '', $raw_message = '') { global $core_config; $ok = false; $sms_to = $sms_sender; // we are replying to this sender $quiz_keyword = strtoupper(trim($quiz_keyword)); $quiz_param = strtoupper(trim($quiz_param)); if (($quiz_enable = $list['quiz_enable']) && $quiz_param) { if (strtoupper($list['quiz_answer']) == $quiz_param) { $message = $list['quiz_msg_correct']; } else { $message = $list['quiz_msg_incorrect']; } $quiz_id = $list['quiz_id']; $answer = strtoupper($quiz_param); $db_query = "INSERT INTO " . _DB_PREF_ . "_featureQuiz_log (quiz_id,quiz_answer,quiz_sender,in_datetime) VALUES ('{$quiz_id}','{$answer}','{$sms_to}','" . core_get_datetime() . "')"; if ($logged = @dba_insert_id($db_query)) { if ($message && ($username = user_uid2username($list['uid']))) { $unicode = core_detect_unicode($message); $message = addslashes($message); list($ok, $to, $smslog_id, $queue) = sendsms_helper($username, $sms_to, $message, 'text', $unicode, $smsc); } $ok = true; } } return $ok; }
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 autorespond_hook_recvsms_intercept_after($sms_datetime, $sms_sender, $message, $sms_receiver, $feature, $status, $uid, $smsc) { $ret = array(); $hooked = FALSE; // process only when the previous feature is not 'incoming' if ($feature != 'incoming' && $status) { return $ret; } if ($message) { $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureAutorespond WHERE flag_deleted='0'"; $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $continue = TRUE; // only check sms receiver if set if ($db_row['sms_receiver']) { if ($sms_receiver != $db_row['sms_receiver']) { $continue = FALSE; } } if ($continue) { // match SMS with regex if (preg_match($db_row['regex'], $message)) { // match found, send respond $c_uid = $db_row['uid']; $c_username = user_uid2username($c_uid); $c_message = $db_row['message']; if (core_detect_unicode($c_message)) { $unicode = 1; } $smsc = gateway_decide_smsc($smsc, $db_row['smsc']); _log("match found dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " uid:" . $c_uid . " username:"******" service:[" . $db_row['service_name'] . "] regex:[" . $db_row['regex'] . "] m:[" . $message . "] smsc:" . $smsc, 3, "autorespond"); sendsms_helper($c_username, $sms_sender, $c_message, 'text', $unicode, $smsc); // log it $hooked = TRUE; // found then stop break; } } } } if ($c_uid && $hooked) { _log("hooked dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " uid:" . $c_uid . " username:"******" service:[" . $db_row['service_name'] . "] regex:[" . $db_row['regex'] . "] m:[" . $message . "] smsc:" . $smsc, 3, "autorespond"); $ret['modified'] = TRUE; $ret['param']['feature'] = 'autorespond'; $ret['param']['status'] = 1; $ret['uid'] = $c_uid; $ret['hooked'] = $hooked; } return $ret; }
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 schedule_hook_playsmsd() { global $core_config; // fetch every minutes if (!core_playsmsd_timer(60)) { return; } // mark a start //_log('start scheduler', 2, 'schedule_hook_playsmsd'); // get current server time $current_datetime = core_display_datetime(core_get_datetime()); $current_timestamp = strtotime($current_datetime); // collect active schedules $conditions = array('flag_active' => 1, 'flag_deleted' => 0); $schedules = dba_search(_DB_PREF_ . '_featureSchedule', '*', $conditions); foreach ($schedules as $sch) { $schedule_id = $sch['id']; $uid = $sch['uid']; $schedule_name = $sch['name']; $schedule_rule = (int) $sch['schedule_rule']; // collect destinations $conditions = array('schedule_id' => $schedule_id); $destinations = dba_search(_DB_PREF_ . '_featureSchedule_dst', '*', $conditions, '', $extras); foreach ($destinations as $dst) { $id = $dst['id']; $name = $dst['name']; $schedule_message = str_ireplace('#NAME#', $name, $sch['message']); $destination = $dst['destination']; $schedule = $dst['schedule'] ? core_display_datetime($dst['schedule']) : '0000-00-00 00:00:00'; $scheduled = $dst['scheduled'] ? core_display_datetime($dst['scheduled']) : '0000-00-00 00:00:00'; if (!$scheduled || $scheduled == '0000-00-00 00:00:00') { $scheduled = $schedule; } $scheduled_timestamp = strtotime($scheduled); //_log('uid:' . $uid . ' schedule_id:' . $schedule_id . ' id:' . $id . ' rule:' . $schedule_rule . ' current:[' . $current_datetime . '] schedule:[' . $schedule . '] scheduled:[' . $scheduled . ']', 2, 'schedule_hook_playsmsd'); $continue = FALSE; if ($current_timestamp >= $scheduled_timestamp) { switch ($schedule_rule) { // once case '0': //$scheduled = '2038-01-19 10:14:07'; $scheduled = '2030-01-19 10:14:07'; $scheduled = core_adjust_datetime($scheduled); $scheduled_timestamp = strtotime($current_datetime); $scheduled_display = $current_datetime; $continue = TRUE; break; // Annually // Annually case '1': $current_schedule = date('Y', $current_timestamp) . '-' . date('m-d H:i:s', strtotime($schedule)); $next = ''; if ($current_timestamp > strtotime($current_schedule)) { $next = '+1 year'; } $scheduled = date($core_config['datetime']['format'], strtotime($next . ' ' . $current_schedule)); $scheduled = core_adjust_datetime($scheduled); $scheduled_timestamp = strtotime($scheduled); $scheduled_display = core_display_datetime($scheduled); $continue = TRUE; break; // Monthly // Monthly case '2': $current_schedule = date('Y-m', $current_timestamp) . '-' . date('d H:i:s', strtotime($schedule)); $next = ''; if ($current_timestamp > strtotime($current_schedule)) { $next = '+1 month'; } $scheduled = date($core_config['datetime']['format'], strtotime($next . ' ' . $current_schedule)); $scheduled = core_adjust_datetime($scheduled); $scheduled_timestamp = strtotime($scheduled); $scheduled_display = core_display_datetime($scheduled); $continue = TRUE; break; // Weekly // Weekly case '3': $current_schedule = date('Y-m-d', $current_timestamp) . ' ' . date('H:i:s', strtotime($schedule)); $current_day = date('l', strtotime($current_schedule)); $next = ''; if ($current_timestamp > strtotime($current_schedule)) { $next = 'next ' . $current_day; } $scheduled = date($core_config['datetime']['format'], strtotime($next . ' ' . $current_schedule)); $scheduled = core_adjust_datetime($scheduled); $scheduled_timestamp = strtotime($scheduled); $scheduled_display = core_display_datetime($scheduled); $continue = TRUE; break; // Daily // Daily case '4': $current_schedule = date('Y-m-d', $current_timestamp) . ' ' . date('H:i:s', strtotime($schedule)); $next = ''; if ($current_timestamp > strtotime($current_schedule)) { $next = '+1 day'; } $scheduled = date($core_config['datetime']['format'], strtotime($next . ' ' . $current_schedule)); $scheduled = core_adjust_datetime($scheduled); $scheduled_timestamp = strtotime($scheduled); $scheduled_display = core_display_datetime($scheduled); $continue = TRUE; break; } } if ($continue) { // set scheduled to next time $items = array('c_timestamp' => mktime(), 'scheduled' => $scheduled); $conditions = array('schedule_id' => $schedule_id, 'id' => $id); if (dba_update(_DB_PREF_ . '_featureSchedule_dst', $items, $conditions, 'AND')) { // if the interval is under an hour then go ahead, otherwise expired $interval = $current_timestamp - $scheduled_timestamp; if ($interval <= 3600) { _log('sendsms uid:' . $uid . ' schedule_id:' . $schedule_id . ' id:' . $id . ' rule:' . $schedule_rule . ' schedule:[' . $schedule . '] scheduled:[' . $scheduled_display . ']', 2, 'schedule_hook_playsmsd'); $username = user_uid2username($uid); sendsms_helper($username, $destination, $schedule_message, 'text', $unicode); } else { _log('expired uid:' . $uid . ' schedule_id:' . $schedule_id . ' id:' . $id . ' rule:' . $schedule_rule . ' schedule:[' . $schedule . '] scheduled:[' . $scheduled_display . '] interval:' . $interval, 2, 'schedule_hook_playsmsd'); } } else { _log('fail update uid:' . $uid . ' schedule_id:' . $schedule_id . ' id:' . $id . ' rule:' . $schedule_rule . ' schedule:[' . $schedule . '] scheduled:[' . $scheduled_display . ']', 2, 'schedule_hook_playsmsd'); } } } } // mark an end //_log('end scheduler', 2, 'schedule_hook_playsmsd'); }
$db_row = dba_fetch_array($db_result); $message = addslashes($db_row['msg']); $counter = $db_row['counter']; $db_query = "SELECT member_number FROM " . _DB_PREF_ . "_featureSubscribe_member WHERE subscribe_id='{$subscribe_id}'"; $db_result = dba_query($db_query); $sms_to = ''; if ($message && $subscribe_id) { while ($db_row = dba_fetch_array($db_result)) { if ($member_number = $db_row['member_number']) { $sms_to[] = $member_number; } } if ($sms_to[0]) { $unicode = core_detect_unicode($message); $message = addslashes($message); list($ok, $to, $smslog_id, $queue) = sendsms_helper($username, $sms_to, $message, 'text', $unicode, $smsc); if ($ok[0]) { $counter++; dba_update(_DB_PREF_ . '_featureSubscribe_msg', array('counter' => $counter), array('subscribe_id' => $subscribe_id, 'msg_id' => $msg_id)); $_SESSION['error_string'] .= _('Your SMS has been delivered to queue') . "<br>"; } else { $_SESSION['error_string'] .= _('Fail to send SMS') . "<br>"; } } else { $_SESSION['error_string'] = _('You have no member'); } } else { $_SESSION['error_string'] = _('You must fill all fields'); } header("Location: " . _u('index.php?app=main&inc=feature_sms_subscribe&op=msg_view&msg_id=' . $msg_id . '&subscribe_id=' . $subscribe_id)); exit;
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); } } } } } }
$sms_schedule = trim($_REQUEST['sms_schedule']); // type of SMS, text or flash $msg_flash = $_REQUEST['msg_flash']; $sms_type = "text"; if ($msg_flash == "on") { $sms_type = "flash"; } // unicode or not $msg_unicode = $_REQUEST['msg_unicode']; $unicode = "0"; if ($msg_unicode == "on") { $unicode = "1"; } // SMS message $message = $_REQUEST['message']; // save it in session for next form $_SESSION['tmp']['message'] = $message; // destination numbers if ($sms_to = trim($_REQUEST['p_num_text'])) { $sms_to = explode(',', $sms_to); } if ($sms_to[0] && $message) { list($ok, $to, $smslog_id, $queue, $counts, $sms_count, $sms_failed) = sendsms_helper($user_config['username'], $sms_to, $message, $sms_type, $unicode, '', $nofooter, $sms_footer, $sms_sender, $sms_schedule, $reference_id); $_SESSION['error_string'] = _('Your message has been delivered to queue') . " (" . _('queued') . ":" . (int) $sms_count . " " . _('failed') . ":" . (int) $sms_failed . ")"; } else { $_SESSION['error_string'] = _('You must select receiver and your message should not be empty'); } header("Location: " . _u('index.php?app=main&inc=core_sendsms&op=sendsms')); exit; break; }
function sms_autoreply_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $autoreply_id, $autoreply_keyword, $autoreply_param = '', $smsc = '', $raw_message = '') { $ok = false; $autoreply_keyword = strtoupper(trim($autoreply_keyword)); $autoreply_param = strtoupper(trim($autoreply_param)); $autoreply_request = $autoreply_keyword . " " . $autoreply_param; $array_autoreply_request = preg_split('/[\\s]+/', $autoreply_request); for ($i = 0; $i < count($array_autoreply_request); $i++) { $autoreply_part[$i] = trim($array_autoreply_request[$i]); $tmp_autoreply_request .= trim($array_autoreply_request[$i]) . " "; } $autoreply_request = trim($tmp_autoreply_request); for ($i = 1; $i < 7; $i++) { $autoreply_scenario_param_list .= "autoreply_scenario_param{$i}='" . $autoreply_part[$i] . "' AND "; } $db_query = "\n\t\tSELECT autoreply_scenario_result FROM " . _DB_PREF_ . "_featureAutoreply_scenario \n\t\tWHERE autoreply_id='{$autoreply_id}' AND {$autoreply_scenario_param_list} 1=1"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); if ($autoreply_scenario_result = $db_row['autoreply_scenario_result']) { $ok = false; $c_username = user_uid2username($c_uid); $unicode = core_detect_unicode($autoreply_scenario_result); $autoreply_scenario_result = addslashes($autoreply_scenario_result); list($ok, $to, $smslog_id, $queue) = sendsms_helper($c_username, $sms_sender, $autoreply_scenario_result, 'text', $unicode, $smsc); $ok = $ok[0]; } return $ok; }
function email2sms_hook_playsmsd_once($param) { $c_param = explode('_', $param); if ($c_param[0] == 'email2sms') { if ($c_param[1] == 'uid') { $uid = (int) $c_param[2]; } } // get username $username = user_uid2username($uid); // _log('fetch uid:' . $uid . ' username:'******'email2sms_hook_playsmsd_once'); if ($uid && $username) { $items = registry_search($uid, 'features', 'email2sms'); $enable = $items['features']['email2sms']['enable']; if (!$enable) { return; } $ssl = $items['features']['email2sms']['ssl'] == 1 ? "/ssl" : ""; $novalidate_cert = $items['features']['email2sms']['novalidate_cert'] == 1 ? "/novalidate-cert" : ""; $email_hostname = '{' . $items['features']['email2sms']['server'] . ':' . $items['features']['email2sms']['port'] . '/' . $items['features']['email2sms']['protocol'] . $ssl . $novalidate_cert . '}INBOX'; $email_username = $items['features']['email2sms']['username']; $email_password = $items['features']['email2sms']['password']; // _log('fetch ' . $email_username . ' at ' . $email_hostname, 3, 'email2sms_hook_playsmsd_once'); // open mailbox $inbox = imap_open($email_hostname, $email_username, $email_password); if (!$inbox) { $errors = imap_errors(); foreach ($errors as $error) { // _log('error:' . $error, 3, 'email2sms_hook_playsmsd_once'); } return; } $emails = imap_search($inbox, 'UNSEEN'); if (count($emails)) { rsort($emails); foreach ($emails as $email_number) { $overview = imap_fetch_overview($inbox, $email_number, 0); $email_subject = trim($overview[0]->subject); $email_sender = trim($overview[0]->from); $email_body = trim(imap_fetchbody($inbox, $email_number, 1)); _log('email from:[' . $email_sender . '] subject:[' . $email_subject . '] body:[' . $email_body . ']', 3, 'email2sms_hook_playsmsd'); // destination numbers is in array and retrieved from email body // remove email footer/signiture $sms_to = preg_replace('/--[\\r\\n]+.*/s', '', $email_body); $sms_to = explode(',', $sms_to); // Check "from" email before checking PIN if option "Check email sender" is TRUE if ($items['features']['email2sms']['check_sender']) { preg_match('#\\<(.*?)\\>#', $email_sender, $match); if (user_email2uid($match[1]) == "") { continue; } } // message is from email subject // $message = trim($email_subject); $message = trim(preg_replace('/' . $items['features']['email2sms']['pin'] . '/', '', $email_subject, -1, $count)); if ($count <= 0) { _log('PIN does not match. Subject: ' . $email_subject, 2, 'email2sms_hook_playsmsd'); } // sendsms if ($username && count($sms_to) && $message && $count > 0) { _log('email2sms username:'******'email2sms_hook_playsmsd_once'); list($ok, $to, $smslog_id, $queue, $counts, $sms_count, $sms_failed) = sendsms_helper($username, $sms_to, $message, '', '', '', '', '', '', $reference_id); } } } // close mailbox imap_close($inbox); } }
function mailsms_hook_playsmsd_once($param) { if ($param != 'mailsms_fetch') { return; } // get username $username = user_uid2username($uid); // _log('fetch uid:' . $uid . ' username:'******'mailsms_hook_playsmsd_once'); $items_global = registry_search(0, 'features', 'mailsms'); $enable_fetch = $items_global['features']['mailsms']['enable_fetch']; if (!$enable_fetch) { return; } $ssl = $items_global['features']['mailsms']['ssl'] == 1 ? "/ssl" : ""; $novalidate_cert = $items_global['features']['mailsms']['novalidate_cert'] == 1 ? "/novalidate-cert" : ""; $email_hostname = '{' . $items_global['features']['mailsms']['server'] . ':' . $items_global['features']['mailsms']['port'] . '/' . $items_global['features']['mailsms']['protocol'] . $ssl . $novalidate_cert . '}INBOX'; $email_username = $items_global['features']['mailsms']['username']; $email_password = $items_global['features']['mailsms']['password']; // _log('fetch ' . $email_username . ' at ' . $email_hostname, 3, 'mailsms_hook_playsmsd_once'); // open mailbox $inbox = imap_open($email_hostname, $email_username, $email_password); if (!$inbox) { $errors = imap_errors(); foreach ($errors as $error) { // _log('error:' . $error, 3, 'mailsms_hook_playsmsd_once'); } return; } $emails = imap_search($inbox, 'UNSEEN'); if (count($emails)) { rsort($emails); foreach ($emails as $email_number) { $overview = imap_fetch_overview($inbox, $email_number, 0); $email_subject = trim($overview[0]->subject); $email_sender = trim($overview[0]->from); $email_body = trim(imap_fetchbody($inbox, $email_number, 1)); _log('email from:[' . $email_sender . '] subject:[' . $email_subject . '] body:[' . $email_body . ']', 3, 'mailsms_hook_playsmsd'); $e = preg_replace('/\\s+/', ' ', trim($email_subject)); $f = preg_split('/ +/', $e); $sender_username = str_replace('@', '', $f[0]); // in case user use @username $sender_pin = $f[1]; //$message = str_replace($sender_username . ' ' . $sender_pin . ' ', '', $email_subject); $c_message = preg_split("/[\\s]+/", $email_subject, 3); $message = $c_message[2]; $sender = user_getdatabyusername($sender_username); if ($sender['uid']) { $items = registry_search($sender['uid'], 'features', 'mailsms_user'); $pin = $items['features']['mailsms_user']['pin']; if ($sender_pin && $pin && $sender_pin == $pin) { if ($items_global['features']['mailsms']['check_sender']) { preg_match('#\\<(.*?)\\>#', $email_sender, $match); $sender_email = $match[1]; if ($sender['email'] != $sender_email) { _log('check_sender:1 unknown sender from:' . $sender_email . ' uid:' . $sender['uid'] . ' e:' . $sender['email'], 3, 'mailsms_hook_playsmsd_once'); continue; } } } else { _log('invalid pin uid:' . $sender['uid'] . ' sender_pin:[' . $sender_pin . ']', 3, 'mailsms_hook_playsmsd_once'); continue; } } else { _log('invalid username sender_username:[' . $sender_username . ']', 3, 'mailsms_hook_playsmsd_once'); continue; } // destination numbers is in array and retrieved from email body // remove email footer/signiture $sms_to = preg_replace('/--[\\r\\n]+.*/s', '', $email_body); $sms_to = explode(',', $sms_to); // sendsms if ($sender_username && count($sms_to) && $message) { _log('mailsms uid:' . $sender['uid'] . ' from:[' . $sender_email . '] username:[' . $sender_username . ']', 3, 'mailsms_hook_playsmsd_once'); list($ok, $to, $smslog_id, $queue, $counts, $sms_count, $sms_failed) = sendsms_helper($sender_username, $sms_to, $message, '', '', '', '', '', '', $reference_id); } } } // close mailbox imap_close($inbox); }
function sms_poll_handle($list, $sms_datetime, $sms_sender, $poll_keyword, $poll_param = '', $sms_receiver = '', $smsc = '', $raw_message = '') { $ok = false; $smsc = gateway_decide_smsc($smsc, $list['smsc']); $poll_keyword = strtoupper(trim($poll_keyword)); $poll_param = strtoupper(trim($poll_param)); $choice_keyword = $poll_param; if ($sms_sender && $poll_keyword && $choice_keyword) { $poll_id = $list['poll_id']; // if poll disabled then immediately return, just ignore the vote if (!$list['poll_enable']) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' poll disabled', 2, 'sms_poll'); return TRUE; } $db_query = "SELECT choice_id FROM " . _DB_PREF_ . "_featurePoll_choice WHERE choice_keyword='{$choice_keyword}' AND poll_id='{$poll_id}'"; $db_result = dba_query($db_query); $db_row = dba_fetch_array($db_result); $choice_id = (int) $db_row['choice_id']; $db_table = _DB_PREF_ . "_featurePoll_log"; $items = array('poll_id' => $poll_id, 'choice_id' => $choice_id, 'poll_sender' => $sms_sender, 'in_datetime' => core_get_datetime(), 'status' => 0); // status 0 = failed/unknown // status 1 = valid // status 2 = out of vote option // status 3 = invalid $log_id = dba_add($db_table, $items); if ($poll_id && $choice_id) { $continue = sms_poll_check_option_vote($list, $sms_sender, $poll_keyword, $choice_keyword); if ($continue) { // send message valid if (dba_update($db_table, array('status' => 1), array('log_id' => $log_id))) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' log_id:' . $log_id . ' valid vote', 2, 'sms_poll'); if (($poll_message_valid = trim($list['poll_message_valid'])) && ($c_username = user_uid2username($list['uid']))) { $unicode = core_detect_unicode($poll_message_valid); $poll_message_valid = addslashes($poll_message_valid); list($ok, $to, $smslog_id, $queue_code) = sendsms_helper($c_username, $sms_sender, $poll_message_valid, 'text', $unicode, $smsc); } } } else { // send message out of vote option if (dba_update($db_table, array('status' => 2), array('log_id' => $log_id))) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' log_id:' . $log_id . ' out of vote option', 2, 'sms_poll'); if (($poll_message_option = trim($list['poll_message_option'])) && ($c_username = user_uid2username($list['uid']))) { $unicode = core_detect_unicode($poll_message_option); $poll_message_option = addslashes($poll_message_option); list($ok, $to, $smslog_id, $queue_code) = sendsms_helper($c_username, $sms_sender, $poll_message_option, 'text', $unicode, $smsc); } } } $ok = true; } else { // send message invalid if (dba_update($db_table, array('status' => 3), array('log_id' => $log_id))) { logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' log_id:' . $log_id . ' invalid vote', 2, 'sms_poll'); if (($poll_message_invalid = trim($list['poll_message_invalid'])) && ($c_username = user_uid2username($list['uid']))) { $unicode = core_detect_unicode($poll_message_invalid); $poll_message_invalid = addslashes($poll_message_invalid); list($ok, $to, $smslog_id, $queue_code) = sendsms_helper($c_username, $sms_sender, $poll_message_invalid, 'text', $unicode, $smsc); } } } } return $ok; }
$_SESSION['error_string'] = _('Invalid session ID'); } header("Location: " . _u('index.php?app=main&inc=feature_sendfromfile&op=list')); exit; break; case 'upload_process': set_time_limit(600); if ($sid = $_REQUEST['sid']) { $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureSendfromfile WHERE sid='{$sid}'"; $db_result = dba_query($db_query); while ($db_row = dba_fetch_array($db_result)) { $c_sms_to = $db_row['sms_to']; $c_sms_msg = addslashes($db_row['sms_msg']); $c_username = $db_row['sms_username']; if ($c_sms_to && $c_sms_msg && $c_username) { $type = 'text'; $unicode = '0'; $c_sms_msg = addslashes($c_sms_msg); list($ok, $to, $smslog_id, $queue) = sendsms_helper($c_username, $c_sms_to, $c_sms_msg, $type, $unicode); } } $db_query = "DELETE FROM " . _DB_PREF_ . "_featureSendfromfile WHERE sid='{$sid}'"; $db_result = dba_affected_rows($db_query); $_SESSION['error_string'] = _('SMS has been sent to valid numbers in uploaded file'); } else { $_SESSION['error_string'] = _('Invalid session ID'); } header("Location: " . _u('index.php?app=main&inc=feature_sendfromfile&op=list')); exit; break; }
function _sms_subscribe_member_expired($subscribe, $member) { $c_username = user_uid2username($subscribe['uid']); if ($c_username && $member['member_id']) { if (sms_subscribe_member_remove($member['member_id'])) { _log('removed k:' . $subscribe['subscribe_keyword'] . ' member_id:' . $member['member_id'] . ' number:' . $member['member_number'], 3, '_sms_subscribe_member_expired'); if ($subscribe['expire_msg']) { _log('SMS k:' . $subscribe['subscribe_keyword'] . ' member_id:' . $member['member_id'] . ' number:' . $member['member_number'] . ' message:[' . $subscribe['expire_msg'] . ']', 3, '_sms_subscribe_member_expired'); sendsms_helper($c_username, $member['member_number'], $subscribe['expire_msg'], 'text', '', $subscribe['smsc'], TRUE); } } } }