Example #1
0
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 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;
}
Example #3
0
function msgtemplate_hook_sendsms_intercept($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $sms_type, $unicode, $smsc)
{
    // parameters modified
    $ret['modified'] = true;
    // the modification to $sms_msg, case insensitive
    $c_username = user_uid2username($uid);
    $text = $sms_msg;
    $text = str_ireplace('#NAME#', phonebook_number2name($sms_to, $c_username), $text);
    $text = str_ireplace('#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;
}
Example #4
0
/**
 * Add a mobile number to stoplist
 *
 * @param integer $uid
 *        User ID
 * @param string $mobile
 *        single mobile number
 * @return boolean TRUE on added
 */
function stoplist_hook_blacklist_mobile_add($uid, $mobile)
{
    $ret = FALSE;
    // if account exists
    $uid = user_uid2username((int) $uid) ? (int) $uid : 1;
    $items = array('uid' => $uid, 'mobile' => $mobile);
    if (!blacklist_mobile_isexists(0, $mobile)) {
        if ($new_id = dba_add(_DB_PREF_ . '_featureStoplist', $items)) {
            _log('added mobile number to stoplist id:' . $new_id . ' mobile:' . $mobile . ' uid:' . $uid, 2, 'stoplist_hook_blacklist_mobile_add');
            $ret = TRUE;
        }
    } else {
        _log('mobile number is already in stoplist mobile:' . $mobile . ' uid:' . $uid, 2, 'stoplist_hook_blacklist_mobile_remove');
        $ret = TRUE;
    }
    return $ret;
}
Example #5
0
function sms_board_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $board_keyword, $board_param = '', $smsc = '', $raw_message = '')
{
    global $web_title, $email_service, $email_footer;
    $ok = false;
    $board_keyword = strtoupper(trim($board_keyword));
    $board_param = trim($board_param);
    if ($sms_sender && $board_keyword && $board_param) {
        // masked sender sets here
        $masked_sender = substr_replace($sms_sender, 'xxxx', -4);
        $db_query = "\n\t\t\tINSERT INTO " . _DB_PREF_ . "_featureBoard_log\n\t\t\t(in_gateway,in_sender,in_masked,in_keyword,in_msg,in_datetime)\n\t\t\tVALUES ('{$smsc}','{$sms_sender}','{$masked_sender}','{$board_keyword}','{$board_param}','" . core_get_datetime() . "')";
        if ($cek_ok = @dba_insert_id($db_query)) {
            $db_query1 = "SELECT board_forward_email FROM " . _DB_PREF_ . "_featureBoard WHERE board_keyword='{$board_keyword}'";
            $db_result1 = dba_query($db_query1);
            $db_row1 = dba_fetch_array($db_result1);
            $email = $db_row1['board_forward_email'];
            if ($email) {
                // get name from c_uid's phonebook
                $c_username = user_uid2username($c_uid);
                $c_name = phonebook_number2name($sms_sender, $c_username);
                $sms_sender = $c_name ? $c_name . ' <' . $sms_sender . '>' : $sms_sender;
                $sms_datetime = core_display_datetime($sms_datetime);
                $subject = "[" . $board_keyword . "] " . _('SMS board from') . " {$sms_sender}";
                $body = $core_config['main']['web_title'] . "\n";
                $body .= $core_config['http_path']['base'] . "\n\n";
                $body .= _('Date and time') . ": {$sms_datetime}\n";
                $body .= _('Sender') . ": {$sms_sender}\n";
                $body .= _('Receiver') . ": {$sms_receiver}\n";
                $body .= _('SMS board keyword') . ": {$board_keyword}\n\n";
                $body .= _('Message') . ":\n{$board_param}\n\n";
                $body .= $core_config['main']['email_footer'] . "\n\n";
                $body = stripslashes($body);
                $email_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);
                sendmail($email_data);
            }
            $ok = true;
        }
    }
    return $ok;
}
Example #6
0
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;
}
Example #7
0
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;
}
Example #8
0
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with playSMS.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_SECURE_') or die('Forbidden');
if (!auth_isadmin()) {
    auth_block();
}
$uid = $_REQUEST['uid'];
// if ban/unban action
if (_OP_ == 'unban') {
    if (user_banned_remove($uid)) {
        $_SESSION['dialog']['info'][] = _('Account has been unbanned') . ' (' . _('username') . ': ' . user_uid2username($uid) . ')';
    } else {
        $_SESSION['dialog']['info'][] = _('Unable to unban account') . ' (' . _('username') . ': ' . user_uid2username($uid) . ')';
    }
    header('Location: ' . _u('index.php?app=main&inc=feature_report&route=banned'));
    exit;
}
// display whose online
if ($err = TRUE) {
    $error_content = _dialog();
}
$tpl = array('name' => 'report_banned', 'vars' => array('Report' => _('Report'), 'Banned users list' => _('Banned users list'), 'DIALOG_DISPLAY' => $error_content, 'User' => _('User'), 'Email' => _('Email'), 'Ban date/time' => _('Ban date/time'), 'Action' => 'Action'));
// display admin users
$users = report_banned_admin();
foreach ($users as $user) {
    $tpl['loops']['data'][] = array('tr_class' => $tr_class, 'username' => $user['username'], 'isadmin' => $user['icon_isadmin'], 'email' => $user['email'], 'bantime' => $user['bantime'], 'action' => $user['action_link']);
}
// display users
Example #9
0
switch (_OP_) {
    case "stoplist_list":
        $search_category = array(_('Mobile') => 'mobile', _('Username') => 'uid');
        $base_url = 'index.php?app=main&inc=feature_stoplist&op=stoplist_list';
        $search = themes_search($search_category, $base_url, array('uid' => 'user_username2uid'));
        $keywords = $search['dba_keywords'];
        $count = dba_count(_DB_PREF_ . '_featureStoplist', '', $keywords);
        $nav = themes_nav($count, $search['url']);
        $extras = array('ORDER BY' => 'uid', 'LIMIT' => $nav['limit'], 'OFFSET' => $nav['offset']);
        $list = dba_search(_DB_PREF_ . '_featureStoplist', '*', '', $keywords, $extras);
        $content = _dialog() . "\n\t\t\t<h2>" . _('Manage stoplist') . "</h2>\n\t\t\t<p>" . $search['form'] . "</p>\n\t\t\t<form name=fm_stoplist_list id=fm_stoplist_list action='index.php?app=main&inc=feature_stoplist&op=actions' method=post>\n\t\t\t" . _CSRF_FORM_ . "\n\t\t\t<div class=table-responsive>\n\t\t\t<table class=playsms-table-list>\n\t\t\t\t<thead>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan=3>\n\t\t\t\t\t\t\t<div class=actions_box>\n\t\t\t\t\t\t\t\t<div class=pull-left>\n\t\t\t\t\t\t\t\t\t<a href='" . _u('index.php?app=main&inc=feature_stoplist&op=stoplist_add') . "'>" . $icon_config['add'] . "</a>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t<script type='text/javascript'>\n\t\t\t\t\t\t\t\t\t\$(document).ready(function() {\n\t\t\t\t\t\t\t\t\t\t\$('#action_go').click(function(){\n\t\t\t\t\t\t\t\t\t\t\t\$('#fm_stoplist_list').submit();\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t</script>\n\t\t\t\t\t\t\t\t<div class=pull-right>\n\t\t\t\t\t\t\t\t\t<select name=go class=search_input_category>\n\t\t\t\t\t\t\t\t\t\t<option value=>" . _('Select') . "</option>\n\t\t\t\t\t\t\t\t\t\t<option value=delete>" . _('Delete') . "</option>\n\t\t\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t\t\t\t<a href='#' id=action_go>" . $icon_config['go'] . "</a>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<th width=45%>" . _('User') . "</th>\n\t\t\t\t\t\t<th width=50%>" . _('Blocked mobile') . "</th>\n\t\t\t\t\t\t<th width=5%><input type=checkbox onclick=CheckUncheckAll(document.fm_stoplist_list)></th>\n\t\t\t\t\t</tr>\n\t\t\t\t</thead>\n\t\t\t<tbody>";
        $i = $nav['top'];
        $j = 0;
        for ($j = 0; $j < count($list); $j++) {
            $pid = $list[$j]['id'];
            $username = user_uid2username($list[$j]['uid']);
            $mobile = $list[$j]['mobile'];
            $i--;
            $c_i = "<a href=\"" . _u('index.php?app=main&inc=feature_stoplist&op=stoplist_edit&id=' . $pid) . "\">" . $i . ".</a>";
            if ($list[$j]['uid'] == $user_config['uid']) {
                $name = "<a href='" . _u('index.php?app=main&inc=feature_stoplist&op=stoplist_edit&pid=' . $pid) . "'>" . $name . "</a>";
            }
            $content .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td>{$username}</td>\n\t\t\t\t\t<td>{$mobile}</td>\n\t\t\t\t\t<td>\n\t\t\t\t\t\t<input type=hidden name=itemid[" . $j . "] value=\"{$pid}\">\n\t\t\t\t\t\t<input type=checkbox name=checkid[" . $j . "]>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>";
        }
        $content .= "\n\t\t\t\t</tbody>\n\t\t\t</table>\n\t\t\t</div>\n\t\t\t<div class=pull-right>" . $nav['form'] . "</div>\n\t\t\t</form>";
        _p($content);
        break;
    case "actions":
        $checkid = $_REQUEST['checkid'];
        $itemid = $_REQUEST['itemid'];
        $items = array();
Example #10
0
 $db_result = dba_query($db_query);
 $db_row = dba_fetch_array($db_result);
 $manage_autoreply_keyword = $db_row['autoreply_keyword'];
 $o_uid = $db_row['uid'];
 $content .= "\n\t\t\t<h2>" . _('Manage autoreply') . "</h2>\n\t\t\t<p>" . _('SMS autoreply keyword') . ": " . $manage_autoreply_keyword . "</p>\n\t\t\t<p>" . _button('index.php?app=main&inc=feature_sms_autoreply&op=sms_autoreply_scenario_add&autoreply_id=' . $autoreply_id, _('Add SMS autoreply scenario')) . "</p>\n\t\t\t<div class=table-responsive>\n\t\t\t<table class=playsms-table-list>\n\t\t\t<thead><tr>";
 if (auth_isadmin()) {
     $content .= "\n\t\t\t\t<th width=20%>" . _('SMS') . " " . _hint(_('SMS is case-insensitive')) . "</th>\n\t\t\t\t<th width=50%>" . _('Reply') . "</th>\n\t\t\t\t<th width=20%>" . _('User') . "</th>\n\t\t\t\t<th width=10%>" . _('Action') . "</th>";
 } else {
     $content .= "\n\t\t\t\t<th width=20%>" . _('SMS') . " " . _hint(_('SMS is case-insensitive')) . "</th>\n\t\t\t\t<th width=70%>" . _('Reply') . "</th>\n\t\t\t\t<th width=10%>" . _('Action') . "</th>";
 }
 $content .= "</tr></thead><tbody>";
 $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureAutoreply_scenario WHERE autoreply_id='{$autoreply_id}' ORDER BY autoreply_scenario_param1";
 $db_result = dba_query($db_query);
 $j = 0;
 while ($db_row = dba_fetch_array($db_result)) {
     if ($owner = user_uid2username($o_uid)) {
         $list_of_param = "";
         for ($i = 1; $i <= 7; $i++) {
             $list_of_param .= $db_row['autoreply_scenario_param' . $i] . "&nbsp;";
         }
         $action = "<a href=\"" . _u('index.php?app=main&inc=feature_sms_autoreply&op=sms_autoreply_scenario_edit&autoreply_id=' . $autoreply_id . '&autoreply_scenario_id=' . $db_row['autoreply_scenario_id']) . "\">" . $icon_config['edit'] . "</a>";
         $action .= "<a href=\"javascript: ConfirmURL('" . _('Are you sure you want to delete this SMS autoreply scenario ?') . "','" . _u('index.php?app=main&inc=feature_sms_autoreply&op=sms_autoreply_scenario_del&autoreply_id=' . $autoreply_id . '&autoreply_scenario_id=' . $db_row['autoreply_scenario_id']) . "')\">" . $icon_config['delete'] . "</a>";
         if (auth_isadmin()) {
             $option_owner = "<td>" . $owner . "</td>";
         }
         $j++;
         $content .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . $manage_autoreply_keyword . " " . $list_of_param . "</td>\n\t\t\t\t\t\t<td align=left>" . $db_row['autoreply_scenario_result'] . "</td>\n\t\t\t\t\t\t" . $option_owner . "\n\t\t\t\t\t\t<td>" . $action . "</td>\n\t\t\t\t\t</tr>";
     }
 }
 $content .= "\n\t\t\t</tbody>\n\t\t\t</table>\n\t\t\t</div>\n\t\t\t</form>\n\t\t\t<p>" . _button('index.php?app=main&inc=feature_sms_autoreply&op=sms_autoreply_scenario_add&autoreply_id=' . $autoreply_id, _('Add SMS autoreply scenario')) . "\n\t\t\t<p>" . _back('index.php?app=main&inc=feature_sms_autoreply&op=sms_autoreply_list');
 if ($err = TRUE) {
Example #11
0
     $db_row = dba_fetch_array($db_result);
     $message = $db_row['msg'];
     $counter = $db_row['counter'];
     if ($err = $_SESSION['error_string']) {
         $content = "<div class=error_string>{$err}</div>";
     }
     $content .= "\n\t\t\t<h2>" . _('Manage subscribe') . "</h2>\n\t\t\t<h3>" . _('Message detail') . "</h3>\n\t\t\t<form action=index.php?app=main&inc=feature_sms_subscribe&op=msg_send method=post>\n\t\t\t" . _CSRF_FORM_ . "\n\t\t\t<input type=hidden value={$message} name=msg>\n\t\t\t<input type=hidden value={$subscribe_id} name=subscribe_id>\n\t\t\t<input type=hidden value={$msg_id} name=msg_id>\n\t\t\t<table class=playsms-table>\n\t\t\t<tr><td class=label-sizer>" . _('SMS subscribe keyword') . "</td><td>{$subscribe_name}</td></tr>\n\t\t\t<tr><td>" . _('Message ID') . "</td><td>" . $msg_id . "</td></tr>\n\t\t\t<tr><td>" . _('Message') . "</td><td>" . $message . "</td></tr>\n\t\t\t<tr><td>" . _('Sent') . "</td><td>" . $counter . "</td></tr>\n\t\t\t</table>\n\t\t\t<br />\n\t\t\t<p>" . _('Send this message to all members') . "</p>\n\t\t\t<p><input type=submit value=\"" . _('Send') . "\" class=\"button\" />\n\t\t\t</form>\n\t\t\t<p>" . _back('index.php?app=main&inc=feature_sms_subscribe&op=msg_list&subscribe_id=' . $subscribe_id);
     _p($content);
     break;
 case "msg_send":
     $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureSubscribe WHERE subscribe_id='{$subscribe_id}'";
     $db_result = dba_query($db_query);
     $db_row = dba_fetch_array($db_result);
     $smsc = $db_row['smsc'];
     $c_uid = $db_row['uid'];
     $username = user_uid2username($c_uid);
     $msg_id = $_POST['msg_id'];
     $db_query = "SELECT msg FROM " . _DB_PREF_ . "_featureSubscribe_msg WHERE subscribe_id='{$subscribe_id}' AND msg_id='{$msg_id}'";
     $db_result = dba_query($db_query);
     $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;
             }
         }
Example #12
0
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);
}
Example #13
0
     unset($smsc_list);
     $list = gateway_getall_smsc();
     foreach ($list as $c_smsc) {
         $smsc_list[] = $c_smsc['name'];
     }
     foreach ($smsc_list as $smsc_name) {
         $select_smsc .= "<option>" . $smsc_name . "</option>";
     }
     $select_smsc .= "</select>";
     $content .= "\n\t\t\t<h2>" . _('Route outgoing SMS') . "</h2>\n\t\t\t<h3>" . _('Add route') . "</h3>\n\t\t\t<form action='index.php?app=main&inc=feature_outgoing&op=outgoing_add_yes' method='post'>\n\t\t\t" . _CSRF_FORM_ . "\n\t\t\t<table class=playsms-table>\n\t\t\t<tr>\n\t\t\t\t<td class=label-sizer>" . _('User') . "</td><td>" . $select_users . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class=label-sizer>" . _mandatory(_('Destination name')) . "</td><td><input type='text' maxlength='30' name='add_dst' value=\"{$add_dst}\" required></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class=label-sizer>" . _mandatory(_('Prefix')) . "</td><td><input type='text' maxlength=8 name='add_prefix' value=\"{$add_prefix}\" required> " . _hint(_('Maximum 8 digits numeric only')) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class=label-sizer>" . _('SMSC') . "</td><td>" . $select_smsc . "</td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<input type='submit' class='button' value='" . _('Save') . "'>\n\t\t\t</form>\n\t\t\t" . _back('index.php?app=main&inc=feature_outgoing&op=outgoing_list');
     _p($content);
     break;
 case "outgoing_add_yes":
     $add_uid = $_REQUEST['add_uid'];
     if ($add_uid) {
         $add_username = user_uid2username($add_uid);
         if (!$add_username) {
             $add_uid = 0;
         }
     }
     $add_dst = $_POST['add_dst'];
     $add_prefix = $_POST['add_prefix'];
     $add_prefix = core_sanitize_numeric($add_prefix);
     $add_prefix = (string) substr($add_prefix, 0, 8);
     $add_smsc = $_POST['add_smsc'] ? $_POST['add_smsc'] : 'blocked';
     if ($add_dst) {
         $db_query = "\n\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_featureOutgoing (uid,dst,prefix,smsc)\n\t\t\t\t\tVALUES ('{$add_uid}','{$add_dst}','{$add_prefix}','{$add_smsc}')";
         if ($new_uid = @dba_insert_id($db_query)) {
             $_SESSION['error_string'] = _('Route has been added') . " (" . _('destination') . ": {$add_dst}, " . _('prefix') . ": {$add_prefix})";
         }
     } else {
Example #14
0
$sms_sender = $r['from'];
$message = $r['message'];
$sms_receiver = $r['sent_to'];
$ok = FALSE;
if ($sms_sync_enable && $c_uid && $r['secret'] == $sms_sync_secret && $message_id && $sms_sender && $message) {
    $db_table = _DB_PREF_ . '_featureSmssysnc';
    $conditions = array('uid' => $c_uid, 'message_id' => $message_id);
    if (dba_isavail($db_table, $conditions, 'AND')) {
        _log("saving uid:" . $c_uid . " dt:" . $sms_datetime . " ts:" . $r['sent_timestamp'] . " message_id:" . $message_id . " s:" . $sms_sender . " m:" . $message . " r:" . $sms_receiver, 3, "sms_sync sync");
        // if keyword does not exists (checkavailablekeyword == TRUE)
        // then prefix the message with an @username so that it will be routed to $c_uid's inbox
        $m = explode(' ', $message);
        $c_m = str_replace('#', '', $m[0]);
        if (checkavailablekeyword($c_m)) {
            _log("forwarded to inbox uid:" . $c_uid . " message_id:" . $message_id, 3, "sms_sync sync");
            $message = "@" . user_uid2username($c_uid) . " " . $message;
        }
        // route it
        if ($recvsms_id = recvsms($sms_datetime, $sms_sender, $message, $sms_receiver)) {
            $items = array('uid' => $c_uid, 'message_id' => $message_id, 'recvsms_id' => $recvsms_id);
            dba_add($db_table, $items);
            _log("saved uid:" . $c_uid . " message_id:" . $message_id . " recvsms_id:" . $recvsms_id, 3, "sms_sync sync");
            $ret = array('payload' => array('success' => "true", 'error' => NULL));
            $ok = TRUE;
        } else {
            $error_string = "fail to save uid:" . $c_uid . " message_id:" . $message_id;
            _log($error_string, 3, "sms_sync sync");
        }
    } else {
        $error_string = "duplicate message uid:" . $c_uid . " message_id:" . $message_id;
        _log($error_string, 3, "sms_sync sync");
Example #15
0
 $count = queuelog_countall();
 if ($count) {
     $content .= "<p><a href=\"javascript: ConfirmURL('" . addslashes(_("Are you sure you want to delete ALL queues")) . " ?','" . _u('index.php?app=main&inc=feature_queuelog&op=queuelog_delete_all') . "')\">" . $icon_config['delete'] . _("Delete ALL queues") . " ({$count})</a></p>";
 }
 $content .= "<div align=center>" . $nav['form'] . "</div>\n\t\t\t<div class=table-responsive>\n\t\t\t<table class=playsms-table-list>\n\t\t\t<thead>\n\t\t\t<tr>\n\t\t";
 if (auth_isadmin()) {
     $content .= "\n\t\t\t\t<th width=20%>" . _('Queue Code') . "</th>\n\t\t\t\t<th width=15%>" . _('User') . "</th>\n\t\t\t";
 } else {
     $content .= "\n\t\t\t\t<th width=30%>" . _('Queue Code') . "</th>\n\t\t\t";
 }
 $content .= "\n\t\t\t\t<th width=15%>" . _('Scheduled') . "</th>\n\t\t\t\t<th width=10%>" . _('Count') . "</th>\n\t\t\t\t<th width=30%>" . _('Message') . "</th>\n\t\t\t\t<th width=10%>" . _('Action') . "</th>\n\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t<tbody>\n\t\t";
 $data = queuelog_get($nav['limit'], $nav['offset']);
 for ($c = count($data) - 1; $c >= 0; $c--) {
     $c_queue_code = $data[$c]['queue_code'];
     $c_datetime_scheduled = core_display_datetime($data[$c]['datetime_scheduled']);
     $c_username = user_uid2username($data[$c]['uid']);
     // total number of SMS in queue
     $c_count = $data[$c]['sms_count'];
     $c_message = stripslashes(core_display_text($data[$c]['message']));
     $c_action = "<a href=\"javascript: ConfirmURL('" . addslashes(_("Are you sure you want to delete queue")) . " " . $c_queue_code . " ?','" . _u('index.php?app=main&inc=feature_queuelog&op=queuelog_delete&queue=' . $c_queue_code) . "')\">" . $icon_config['delete'] . "</a>";
     $content .= "\n\t\t\t\t<tr>\n\t\t\t";
     if (auth_isadmin()) {
         $content .= "\n\t\t\t\t\t<td>" . $c_queue_code . "</td>\n\t\t\t\t\t<td>" . $c_username . "</td>\n\t\t\t\t";
     } else {
         $content .= "\n\t\t\t\t\t<td>" . $c_queue_code . "</td>\n\t\t\t\t";
     }
     $content .= "\n\t\t\t\t\t<td>" . $c_datetime_scheduled . "</td>\n\t\t\t\t\t<td>" . $c_count . "</td>\n\t\t\t\t\t<td>" . $c_message . "</td>\n\t\t\t\t\t<td>" . $c_action . "</td>\n\t\t\t\t</tr>\n\t\t\t";
 }
 $content .= "\n\t\t\t</tbody></table>\n\t\t\t</div>\n\t\t\t<div align=center>" . $nav['form'] . "</div>\n\t\t";
 _p($content);
 break;
Example #16
0
/**
 * Intercept on before-process stage for incoming SMS
 *
 * @param $sms_datetime incoming
 *        SMS date/time
 * @param $sms_sender incoming
 *        SMS sender
 * @param $message incoming
 *        SMS message before interepted
 * @param $sms_receiver receiver
 *        number that is receiving incoming SMS
 * @param $reference_id reference_id
 *        data
 * @return array $ret
 */
function incoming_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver, $reference_id)
{
    $ret = array();
    $found_bc = FALSE;
    $found_pv = FALSE;
    // continue only when keyword does not exists
    $m = explode(' ', $message);
    if (!keyword_isavail($m[0])) {
        return $ret;
    }
    // get settings
    $settings = incoming_settings_get();
    // get post rules
    $pre_rules = incoming_pre_rules_get();
    // scan for #<sender's phonebook group code> and @<username> according to pre rules
    $msg = explode(' ', $message);
    if (count($msg) > 0) {
        $bc = array();
        $pv = array();
        for ($i = 0; $i < count($msg); $i++) {
            $c_text = trim($msg[$i]);
            // scan message for @username
            if ($pre_rules['match_username']) {
                if (substr($c_text, 0, 1) === '@') {
                    $pv[] = strtolower(substr($c_text, 1));
                    $found_pv = TRUE;
                }
            }
            // scan message for #groupcode
            if ($pre_rules['match_groupcode']) {
                if (substr($c_text, 0, 1) === '#') {
                    $bc[] = strtoupper(substr($c_text, 1));
                    $found_bc = TRUE;
                }
            }
        }
    }
    if ($found_bc || $found_pv) {
        _log("recvsms_intercept dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
    }
    if ($found_bc) {
        $groups = array_unique($bc);
        foreach ($groups as $key => $c_group_code) {
            $c_uid = user_mobile2uid($sms_sender);
            $list = phonebook_search_group($c_uid, $c_group_code, '', TRUE);
            $c_gpid = $list[0]['gpid'];
            if ($c_uid && $c_gpid) {
                $c_username = user_uid2username($c_uid);
                _log("bc g:" . phonebook_code_clean($c_group_code) . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                sendsms_bc($c_username, $c_gpid, $message);
                _log("bc end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            }
        }
    }
    if ($found_pv) {
        $users = array_unique($pv);
        foreach ($users as $key => $c_username) {
            $c_username = core_sanitize_username($c_username);
            if ($c_uid = user_username2uid($c_username)) {
                _log("pv u:" . $c_username . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "] reference_id:" . $reference_id, 3, 'incoming recvsms_intercept');
                recvsms_inbox_add($sms_datetime, $sms_sender, $c_username, $message, $sms_receiver, $reference_id);
                _log("pv end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            }
        }
    }
    return $ret;
}
Example #17
0
/**
 * Send SMS
 *
 * @global array $core_config, $user_config
 * @param string $username        	
 * @param mixed $sms_to        	
 * @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, $counts)
 */
function sendsms($username, $sms_to, $message, $sms_type = 'text', $unicode = 0, $smsc = '', $nofooter = false, $sms_footer = '', $sms_sender = '', $sms_schedule = '')
{
    global $core_config, $user_config;
    // get user data
    $user = $user_config;
    if ($username && $user['username'] != $username) {
        $user = user_getdatabyusername($username);
    }
    if (!is_array($sms_to)) {
        $sms_to = explode(',', $sms_to);
    }
    $uid = $user['uid'];
    // discard if banned
    if (user_banned_get($uid)) {
        logger_print("user banned, exit immediately uid:" . $uid, 2, "sendsms");
        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_id:[" . $sms_sender . "] smsc:[" . $smsc . "]", 2, "sendsms");
    // 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");
    // create a queue
    $queue_code = sendsms_queue_create($sms_sender, $sms_footer, $sms_msg, $uid, 0, $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");
        return array(FALSE, '', '', '', '');
    }
    if (is_array($sms_to)) {
        $array_sms_to = $sms_to;
    } else {
        $array_sms_to = explode(',', $sms_to);
    }
    // get manipulated and valid destination numbers
    $all_sms_to = array();
    for ($i = 0; $i < count($array_sms_to); $i++) {
        if ($c_sms_to = sendsms_getvalidnumber(trim($array_sms_to[$i]))) {
            $c_sms_to = sendsms_manipulate_prefix(trim($c_sms_to), $user);
            $all_sms_to[] = $c_sms_to;
        }
    }
    // remove double entries
    $all_sms_to = array_unique($all_sms_to);
    // calculate total sms and charges
    $total_count = 0;
    $total_charges = 0;
    foreach ($all_sms_to as $c_sms_to) {
        list($count, $rate, $charge) = rate_getcharges(strlen($message . $c_sms_footer), $unicode, $c_sms_to);
        $total_count += $count;
        $total_charges += $charge;
    }
    _log('dst:' . count($all_sms_to) . ' sms_count:' . $total_count . ' total_charges:' . $total_charges, 2, 'sendsms');
    // sender's
    $credit = rate_getusercredit($user['username']);
    $balance = $credit - $total_charges;
    // parent's when sender is a subuser
    $parent_uid = user_getparentbyuid($user['uid']);
    if ($parent_uid) {
        $username_parent = user_uid2username($parent_uid);
        $credit_parent = rate_getusercredit($username_parent);
        $balance_parent = $credit_parent - $total_charges;
    }
    // default returns
    for ($i = 0; $i < count($all_sms_to); $i++) {
        $ok[$i] = FALSE;
        $to[$i] = $all_sms_to[$i];
        $smslog_id[$i] = 0;
        $queue[$i] = $queue_code;
        $counts[$i] = $count;
    }
    if ($parent_uid) {
        if (!($balance_parent >= 0)) {
            _log('failed parent do not have enough credit. credit:' . $credit_parent . ' dst:' . count($all_sms_to) . ' sms_count:' . $total_count . ' total_charges:' . $total_charges, 2, 'sendsms');
            return array($ok, $to, $smslog_id, $queue, $counts);
        }
    } else {
        if (!($balance >= 0)) {
            _log('failed user do not have enough credit. credit:' . $credit_parent . ' dst:' . count($all_sms_to) . ' sms_count:' . $total_count . ' total_charges:' . $total_charges, 2, 'sendsms');
            return array($ok, $to, $smslog_id, $queue, $counts);
        }
    }
    $queue_count = 0;
    $sms_count = 0;
    $failed_queue_count = 0;
    $failed_sms_count = 0;
    for ($i = 0; $i < count($all_sms_to); $i++) {
        $c_sms_to = $all_sms_to[$i];
        if ($smslog_id[$i] = sendsms_queue_push($queue_code, $c_sms_to)) {
            $ok[$i] = TRUE;
            $queue_count++;
            $sms_count = $sms_count + $count;
        } else {
            $ok[$i] = FALSE;
            $failed_queue_count++;
            $failed_sms_count++;
        }
        $to[$i] = $c_sms_to;
        $queue[$i] = $queue_code;
        $counts[$i] = $count;
    }
    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");
    } else {
        logger_print("fail to prepare queue, exit immediately queue_code:" . $queue_code, 2, "sendsms");
        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");
        list($ok, $to, $smslog_id, $queue, $counts) = sendsmsd($queue_code);
    }
    return array($ok, $to, $smslog_id, $queue, $counts);
}
Example #18
0
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;
}
Example #19
0
/**
 * List all banned users
 *
 * @return array banned users
 */
function user_banned_list()
{
    $ret = array();
    $list = registry_search(1, 'auth', 'banned_users');
    foreach ($list['auth']['banned_users'] as $key => $val) {
        $uid = (int) $key;
        $username = user_uid2username($uid);
        $bantime = $val;
        if ($uid && $username && $bantime) {
            $ret[] = array('uid' => $uid, 'username' => $username, 'bantime' => $bantime);
        }
    }
    return $ret;
}
Example #20
0
function webservices_parent_get($uid)
{
    if ($parent_uid = user_getparentbyuid($uid)) {
        $json['status'] = 'OK';
        $json['error'] = '0';
        $json['parent_uid'] = $parent_uid;
        $json['parent'] = user_uid2username($parent_uid);
    } else {
        $json['status'] = 'ERR';
        $json['error'] = '610';
    }
    return $json;
}
Example #21
0
     break;
 case "sender_id_edit":
     $nav = themes_nav_session();
     $search = themes_search_session();
     if ($nav['url']) {
         $ref = $nav['url'] . '&search_keyword=' . $search['keyword'] . '&page=' . $nav['page'] . '&nav=' . $nav['nav'];
     } else {
         $ref = 'index.php?app=main&inc=core_sender_id&op=sender_id_list';
     }
     $items['id'] = $_REQUEST['id'];
     $items['uid'] = $uid;
     $items['sender_id'] = $data_sender_id[0]['registry_key'];
     $items['description'] = sender_id_description($uid, $data_sender_id[0]['registry_key']);
     if (auth_isadmin()) {
         $select_approve = _yesno('approved', $data_sender_id[0]['registry_value']);
         $select_users = user_getfieldbyuid($uid, 'name') . ' (' . user_uid2username($uid) . ')';
     }
     $default_sender_id = sender_id_default_get($uid);
     $select_default = _yesno('default', strtoupper($data_sender_id[0]['registry_key']) == strtoupper($default_sender_id) ? 1 : 0);
     $tpl = array('name' => 'sender_id_add', 'vars' => array('DIALOG_DISPLAY' => _dialog(), 'FORM_TITLE' => _('Manage sender ID'), 'FORM_SUBTITLE' => _('Edit sender ID'), 'ACTION_URL' => _u('index.php?app=main&inc=core_sender_id&op=sender_id_edit_yes'), 'BUTTON_BACK' => _back($ref), 'HTTP_PATH_THEMES' => _HTTP_PATH_THEMES_, 'HINT_DEFAULT' => _hint(_('Only when the sender ID is approved')), 'input_tag' => 'readonly', 'Sender ID' => _mandatory(_('Sender ID')), 'Description' => _('Description'), 'User' => _('User'), 'Approve sender ID' => _('Approve sender ID'), 'Set as default' => _('Set as default')), 'ifs' => array('isadmin' => auth_isadmin()), 'injects' => array('select_default', 'select_approve', 'select_users', 'items', 'icon_config', 'core_config'));
     _p(tpl_apply($tpl));
     break;
 case "sender_id_edit_yes":
     if (sender_id_update($uid, $c_sender_id, $c_sender_id_description, $_REQUEST['default'], $_REQUEST['approved'])) {
         $_SESSION['dialog']['info'][] = _('Sender ID description has been updated') . ' (' . _('Sender ID') . ': ' . $c_sender_id . ')';
     } else {
         $_SESSION['dialog']['info'][] = _('Fail to update due to invalid sender ID') . ' (' . _('Sender ID') . ': ' . $c_sender_id . ')';
     }
     header("Location: " . _u('index.php?app=main&inc=core_sender_id&op=sender_id_edit&id=' . $_REQUEST['id']));
     exit;
     break;
Example #22
0
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;
}
Example #23
0
 $content .= _dialog() . "\n\t\t\t<h2>" . _('Manage custom') . "</h2>\n\t\t\t" . _button('index.php?app=main&inc=feature_sms_custom&op=sms_custom_add', _('Add SMS custom'));
 if (!auth_isadmin()) {
     $query_user_only = "WHERE uid='" . $user_config['uid'] . "'";
 }
 $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureCustom " . $query_user_only . " ORDER BY service_name, custom_keyword, sms_receiver";
 $db_result = dba_query($db_query);
 $content .= "\n\t\t\t<div class=table-responsive>\n\t\t\t<table class=playsms-table-list>";
 if (auth_isadmin()) {
     $content .= "\n\t\t\t\t<thead><tr>\n\t\t\t\t\t<th width=20%>" . _('Service name') . "</th>\n\t\t\t\t\t<th width=50%>" . _('Service data') . "</th>\n\t\t\t\t\t<th width=20%>" . _('User') . "</th>\n\t\t\t\t\t<th width=10%>" . _('Action') . "</th>\n\t\t\t\t</tr></thead>";
 } else {
     $content .= "\n\t\t\t\t<thead><tr>\n\t\t\t\t\t<th width=20%>" . _('Service name') . "</th>\n\t\t\t\t\t<th width=70%>" . _('Service data') . "</th>\n\t\t\t\t\t<th width=10%>" . _('Action') . "</th>\n\t\t\t\t</tr></thead>";
 }
 $content .= "<tbody>";
 $i = 0;
 while ($db_row = dba_fetch_array($db_result)) {
     if ($owner = user_uid2username($db_row['uid'])) {
         $action = "<a href=\"" . _u('index.php?app=main&inc=feature_sms_custom&op=sms_custom_edit&custom_id=' . $db_row['custom_id']) . "\">" . $icon_config['edit'] . "</a>&nbsp;";
         $action .= "<a href=\"javascript: ConfirmURL('" . _('Are you sure you want to delete SMS custom ?') . " (" . _('keyword') . ": " . $db_row['custom_keyword'] . ")','" . _u('index.php?app=main&inc=feature_sms_custom&op=sms_custom_del&custom_id=' . $db_row['custom_id']) . "')\">" . $icon_config['delete'] . "</a>";
         $sms_receiver = '';
         if ($db_row['sms_receiver']) {
             $sms_receiver = "<div name=sms_custom_sms_receiver><span class=\"playsms-icon glyphicon glyphicon-inbox\" alt=\"" . _('Receiver number') . "\" title=\"" . _('Receiver number') . "\"></span>" . $db_row['sms_receiver'] . "</div>";
         }
         $custom_url = $db_row['custom_url'];
         if (auth_isadmin()) {
             $show_owner = "<td>" . $owner . "</td>";
         }
         $i++;
         $content .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . $db_row['service_name'] . "</td>\n\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t<div name=sms_custom_keywords><span class=\"playsms-icon glyphicon glyphicon-search\" alt=\"" . _('Keywords') . "\" title=\"" . _('Keywords') . "\"></span>" . $db_row['custom_keyword'] . "</div>\n\t\t\t\t\t\t\t" . $sms_receiver . "\n\t\t\t\t\t\t\t<div name=sms_custom_url>" . $custom_url . "</div>\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t" . $show_owner . "\n\t\t\t\t\t\t<td>{$action}</td>\n\t\t\t\t\t</tr>";
     }
 }
 $content .= "\n\t\t\t</tbody>\n\t\t\t</table>\n\t\t\t</div>\n\t\t\t" . _button('index.php?app=main&inc=feature_sms_custom&op=sms_custom_add', _('Add SMS custom'));
Example #24
0
     $tpl['name'] = 'user_inbox';
     $content = tpl_apply($tpl);
     _p($content);
     break;
 case "actions":
     $nav = themes_nav_session();
     $search = themes_search_session();
     $go = $_REQUEST['go'];
     switch ($go) {
         case 'export':
             $conditions = array('in_uid' => $user_config['uid'], 'flag_deleted' => 0);
             $list = dba_search(_DB_PREF_ . '_tblUser_inbox', '*', $conditions, $search['dba_keywords']);
             $data[0] = array(_('User'), _('Time'), _('From'), _('Message'));
             for ($i = 0; $i < count($list); $i++) {
                 $j = $i + 1;
                 $data[$j] = array(user_uid2username($list[$i]['in_uid']), core_display_datetime($list[$i]['in_datetime']), $list[$i]['in_sender'], $list[$i]['in_msg']);
             }
             $content = core_csv_format($data);
             $fn = 'user_inbox-' . $core_config['datetime']['now_stamp'] . '.csv';
             core_download($content, $fn, 'text/csv');
             break;
         case 'delete':
             for ($i = 0; $i < $nav['limit']; $i++) {
                 $checkid = $_POST['checkid' . $i];
                 $itemid = $_POST['itemid' . $i];
                 if ($checkid == "on" && $itemid) {
                     $up = array('c_timestamp' => mktime(), 'flag_deleted' => '1');
                     dba_update(_DB_PREF_ . '_tblUser_inbox', $up, array('in_uid' => $user_config['uid'], 'in_id' => $itemid));
                 }
             }
             $ref = $nav['url'] . '&search_keyword=' . $search['keyword'] . '&page=' . $nav['page'] . '&nav=' . $nav['nav'];
Example #25
0
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');
}
Example #26
0
function kannel_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $core_config, $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "kannel_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['kannel']['module_sender']) {
        $sms_sender = $plugin_config['kannel']['module_sender'];
    }
    $sms_footer = stripslashes(htmlspecialchars_decode($sms_footer));
    $sms_msg = stripslashes(htmlspecialchars_decode($sms_msg));
    $ok = false;
    $account = user_uid2username($uid);
    $msg_type = 1;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_type == 'flash') {
        $msg_type = 0;
        // flash
    } else {
        $msg_type = 1;
        // text, default
    }
    // this doesn't work properly if kannel is not on the same server with playSMS
    // $dlr_url = $core_config['http_path']['base'] . "/plugin/gateway/kannel/dlr.php?type=%d&smslog_id=$smslog_id&uid=$uid";
    // prior to 0.9.5.1
    // $dlr_url = $plugin_config['kannel']['playsms_web'] . "/plugin/gateway/kannel/dlr.php?type=%d&smslog_id=".$smslog_id."&uid=".$uid;
    // since 0.9.5.1
    $dlr_url = $plugin_config['kannel']['playsms_web'] . "/index.php?app=call&cat=gateway&plugin=kannel&access=dlr&type=%d&smslog_id=" . $smslog_id . "&uid=" . $uid;
    $URL = "/cgi-bin/sendsms?username="******"&password="******"&from=" . urlencode($sms_sender) . "&to=" . urlencode($sms_to);
    // Handle DLR options config (emmanuel)
    // $URL .= "&dlr-mask=31&dlr-url=".urlencode($dlr_url);
    $URL .= "&dlr-mask=" . $plugin_config['kannel']['dlr'] . "&dlr-url=" . urlencode($dlr_url);
    // end of Handle DLR options config (emmanuel)
    if ($sms_type == 'flash') {
        $URL .= "&mclass=" . $msg_type;
    }
    // Automatically setting the unicode flag if necessary
    if (!$unicode) {
        $unicode = core_detect_unicode($sms_msg);
    }
    if ($unicode) {
        if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
            $URL .= "&charset=UTF-16BE";
        }
        $URL .= "&coding=2";
    }
    $URL .= "&account=" . $account;
    $URL .= "&text=" . urlencode($sms_msg);
    // fixme anton - patch 1.4.3, dlr requries smsc-id, you should add at least smsc=<your smsc-id in kannel.conf> from web
    if ($additional_param = htmlspecialchars_decode($plugin_config['kannel']['additional_param'])) {
        $additional_param = "&" . $additional_param;
    }
    $URL .= $additional_param;
    $URL = str_replace("&&", "&", $URL);
    logger_print("URL: http://" . $plugin_config['kannel']['sendsms_host'] . ":" . $plugin_config['kannel']['sendsms_port'] . $URL, 3, "kannel_hook_sendsms");
    // srosa 20100531: Due to improper http response from Kannel, file_get_contents cannot be used.
    // One issue is that Kannel responds with HTTP 202 whereas file_get_contents expect HTTP 200
    // The other is that a missing CRLF at the end of Kannel's message forces file_get_contents to wait forever.
    // reverting to previous way of doing things which works fine.
    /*
     * if ($rv = trim(file_get_contents("$URL"))) { // old kannel responsed with Sent. // new kannel with the other 2 if (($rv == "Sent.") || ($rv == "0: Accepted for delivery") || ($rv == "3: Queued for later delivery")) { $ok = true; // set pending $p_status = 0; dlr($smslog_id, $uid, $p_status); } }
     */
    // fixme anton - deprecated when using PHP5
    // $connection = fsockopen($plugin_config['kannel']['sendsms_host'],$plugin_config['kannel']['sendsms_port'],&$error_number,&$error_description,60);
    $connection = fsockopen($plugin_config['kannel']['sendsms_host'], $plugin_config['kannel']['sendsms_port'], $error_number, $error_description, 60);
    if ($connection) {
        socket_set_blocking($connection, false);
        fputs($connection, "GET " . $URL . " HTTP/1.0\r\n\r\n");
        while (!feof($connection)) {
            $rv = fgets($connection, 128);
            if ($rv == "Sent." || $rv == "0: Accepted for delivery" || $rv == "3: Queued for later delivery") {
                logger_print("smslog_id:" . $smslog_id . " response:" . $rv, 3, "kannel outgoing");
                // set pending
                $p_status = 0;
                $ok = true;
            }
        }
        fclose($connection);
    }
    if (!$ok) {
        // set failed
        $p_status = 2;
        $ok = true;
        // return true eventhough failed
    }
    dlr($smslog_id, $uid, $p_status);
    logger_print("end smslog_id:" . $smslog_id . " p_status:" . $p_status, 3, "kannel outgoing");
    // good or bad, print it on the log
    return $ok;
}
Example #27
0
function credit_hook_rate_addusercredit($uid, $amount)
{
    global $plugin_config;
    $db_table = $plugin_config['credit']['db_table'];
    $parent_uid = user_getparentbyuid($uid);
    $username = user_uid2username($uid);
    $status = user_getfieldbyuid($uid, 'status');
    $balance = (double) rate_getusercredit($username);
    $amount = (double) $amount;
    if (abs($amount) <= 0) {
        _log('amount cannot be zero. amount:[' . $amount . ']', 2, 'credit_hook_rate_addusercredit');
        return FALSE;
    }
    // add to balance
    $balance = $balance + $amount;
    // record it
    $id = dba_add($db_table, array('parent_uid' => $parent_uid, 'uid' => $uid, 'username' => $username, 'status' => $status, 'create_datetime' => core_get_datetime(), 'amount' => $amount, 'balance' => $balance, 'flag_deleted' => 0));
    // update user's credit
    if ($id) {
        _log('saved id:' . $id . ' parent_uid:' . $parent_uid . ' uid:' . $uid . ' username:'******' amount:' . $amount . ' balance:' . $balance, 3, 'credit_add');
        if (rate_setusercredit($uid, $balance)) {
            _log('updated uid:' . $uid . ' credit:' . $balance, 3, 'credit_add');
            return TRUE;
        } else {
            _log('fail to update uid:' . $uid . ' credit:' . $balance, 3, 'credit_add');
            dba_remove($db_table, array('id' => $id));
            return FALSE;
        }
    } else {
        _log('fail to save parent_uid:' . $parent_uid . ' uid:' . $uid . ' username:'******' amount:' . $amount . ' balance:' . $balance, 3, 'credit_add');
        return FALSE;
    }
}
Example #28
0
                 // ban
                 $action .= "<a href=\"javascript: ConfirmURL('" . addslashes(_("Are you sure you want to ban account")) . " " . $list[$i]['username'] . " ?','" . _u('index.php?app=main&inc=core_user&route=user_mgmnt&op=user_ban&uname=' . $list[$i]['username']) . "&view=" . $view . "')\">" . $icon_config['ban'] . "</a>";
                 $banned_icon = '';
             }
         }
         // remove user except those who still have subusers
         $subusers = user_getsubuserbyuid($list[$i]['uid']);
         if (count($subusers) > 0) {
             $action .= _hint(_('Please remove all subusers from this user to delete'));
         } else {
             $action .= "<a href=\"javascript: ConfirmURL('" . addslashes(_("Are you sure you want to delete user")) . " " . $list[$i]['username'] . " ?','" . _u('index.php?app=main&inc=core_user&route=user_mgmnt&op=user_del&uname=' . $list[$i]['username']) . "&view=" . $view . "')\">" . $icon_config['user_delete'] . "</a>";
         }
         // subuser shows parent column
         if ($list[$i]['status'] == 4) {
             $isadmin = user_getfieldbyuid($list[$i]['parent_uid'], 'status') == 2 ? $icon_config['admin'] : '';
             $parent_column_row = "<td>" . user_uid2username($list[$i]['parent_uid']) . " " . $isadmin . "</td>";
         }
         $j--;
         $content .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td>" . core_display_datetime($list[$i]['register_datetime']) . "</td>\n\t\t\t\t\t" . $parent_column_row . "\n\t\t\t\t\t<td>" . $banned_icon . "" . $list[$i]['username'] . " </td>\n\t\t\t\t\t<td>" . $list[$i]['name'] . "</td>\n\t\t\t\t\t<td>" . $list[$i]['mobile'] . "</td>\n\t\t\t\t\t<td>" . rate_getusercredit($list[$i]['username']) . "</td>\n\t\t\t\t\t<td>" . acl_getnamebyuid($list[$i]['uid']) . "</td>\n\t\t\t\t\t<td>" . $action . "</td>\n\t\t\t\t</tr>";
     }
     $content .= "\n\t\t\t</tbody></table>\n\t\t\t</div>\n\t\t\t<div class=pull-right>" . $nav['form'] . "</div>";
     _p($content);
     break;
 case "user_add":
     if ($err = TRUE) {
         $content = _dialog();
     }
     $add_datetime_timezone = $_REQUEST['add_datetime_timezone'];
     $add_datetime_timezone = $add_datetime_timezone ? $add_datetime_timezone : core_get_timezone();
     // get language options
     $lang_list = '';
Example #29
0
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;
}
Example #30
0
     case "reduce":
         $continue = FALSE;
         $uids = $_POST['uids'];
         if (is_array($uids)) {
             foreach ($uids as $uid) {
                 if ($user_config['status'] == 3) {
                     $parent_uid = user_getparentbyuid($uid);
                     if ($parent_uid == $user_config['uid']) {
                         $continue = TRUE;
                     }
                 }
                 if (auth_isadmin()) {
                     $continue = TRUE;
                 }
                 $amount = -1 * abs($_POST['amount']);
                 if ($continue && $amount < 0 && ($username = user_uid2username($uid))) {
                     if (credit_add($uid, $amount)) {
                         $current_balance = credit_getbalance($uid);
                         $_SESSION['dialog']['info'][] .= _('Credit has been reduced') . ' (' . _('user') . ':' . $username . ' ' . _('amount') . ':' . $amount . ' ' . _('balance') . ':' . $current_balance . ')';
                     } else {
                         $_SESSION['dialog']['info'][] .= _('Fail to reduce credit') . ' (' . _('user') . ':' . $username . ' ' . _('amount') . ':' . $amount . ')';
                     }
                 } else {
                     $_SESSION['dialog']['info'][] .= _('Wrong amount or user does not exist') . ' (' . _('User ID') . ':' . $uid . ')';
                 }
             }
         }
         header("Location: " . _u('index.php?app=main&inc=feature_credit&op=credit_reduce'));
         exit;
         break;
 }