コード例 #1
0
ファイル: fn.php プロジェクト: 10corp/playSMS
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;
}
コード例 #2
0
ファイル: fn.php プロジェクト: 10corp/playSMS
function simplebilling_hook_billing_post($smslog_id, $rate, $credit, $count, $charge)
{
    $ok = false;
    logger_print("saving smslog_id:" . $smslog_id . " rate:" . $rate . " credit:" . $credit . " count:" . $count . " charge:" . $charge, 2, "simplebilling post");
    $db_query = "INSERT INTO " . _DB_PREF_ . "_tblBilling (post_datetime,smslog_id,rate,credit,count,charge,status) VALUES ('" . core_get_datetime() . "','{$smslog_id}','{$rate}','{$credit}','{$count}','{$charge}','0')";
    if ($id = @dba_insert_id($db_query)) {
        logger_print("saved smslog_id:" . $smslog_id . " id:" . $id, 2, "simplebilling post");
        $ok = true;
    }
    return $ok;
}
コード例 #3
0
ファイル: fn.php プロジェクト: yrahman/playSMS
/**
 * Add notification
 * @param integer $uid User ID
 * @param string $label Notification label
 * @param string $subject Notification subject
 * @param string $body Notification body
 * @param array $data Additional data, json encoded
 * @return boolean
 */
function notif_add($uid, $label, $subject, $body, $data = array())
{
    $ret = FALSE;
    $db_table = _DB_PREF_ . '_tblNotif';
    $items = array('uid' => $uid, 'last_update' => core_get_datetime(), 'label' => $label, 'subject' => $subject, 'body' => $body, 'flag_unread' => 1, 'data' => json_encode($data));
    if ($result = dba_add($db_table, $items)) {
        logger_print('uid:' . $uid . ' id:' . $result . ' label:' . $label . ' subject:' . $subject, 2, 'notif_add');
        $ret = TRUE;
    }
    return $ret;
}
コード例 #4
0
ファイル: fn.php プロジェクト: 10corp/playSMS
/**
 * Add notification
 *
 * @param integer $uid
 *        User ID
 * @param string $label
 *        Notification label
 * @param string $subject
 *        Notification subject
 * @param string $body
 *        Notification body
 * @param array $data
 *        Additional data, json encoded
 * @return boolean
 */
function notif_add($uid, $label, $subject, $body, $data = array())
{
    $ret = FALSE;
    if (!is_array($data)) {
        $data = array($data);
    }
    $db_table = _DB_PREF_ . '_tblNotif';
    $items = array('uid' => $uid, 'last_update' => core_get_datetime(), 'label' => $label, 'subject' => $subject, 'body' => $body, 'flag_unread' => 1, 'data' => json_encode($data));
    if ($result = dba_add($db_table, $items)) {
        foreach ($data as $key => $val) {
            $show_data .= $key . ':' . $val . ' ';
        }
        _log('uid:' . $uid . ' id:' . $result . ' label:' . $label . ' subject:' . $subject . ' data:[' . trim($show_data) . ']', 2, 'notif_add');
        $ret = TRUE;
    }
    return $ret;
}
コード例 #5
0
ファイル: fn.php プロジェクト: 10corp/playSMS
function registry_update($uid, $registry_group, $registry_family, $items)
{
    $ret = false;
    $db_table = _DB_PREF_ . '_tblRegistry';
    if (is_array($items)) {
        foreach ($items as $key => $val) {
            $conditions = array('uid' => $uid, 'registry_group' => $registry_group, 'registry_family' => $registry_family, 'registry_key' => $key);
            $values = array('c_timestamp' => strtotime(core_get_datetime()), 'registry_value' => $val);
            if (dba_count($db_table, $conditions)) {
                $ret[$key] = dba_update($db_table, $values, $conditions);
            } else {
                $ret[$key] = dba_add($db_table, array_merge($conditions, $values));
            }
            unset($conditions);
            unset($values);
        }
    }
    return $ret;
}
コード例 #6
0
ファイル: fn_dlr.php プロジェクト: RobinKarlsen/playSMS
function setsmsdeliverystatus($smslog_id, $uid, $p_status)
{
    global $core_config;
    // $p_status = 0 --> pending
    // $p_status = 1 --> sent
    // $p_status = 2 --> failed
    // $p_status = 3 --> delivered
    // logger_print("smslog_id:".$smslog_id." uid:".$uid." p_status:".$p_status, 2, "setsmsdeliverystatus");
    $ok = false;
    $db_query = "UPDATE " . _DB_PREF_ . "_tblSMSOutgoing SET c_timestamp='" . mktime() . "',p_update='" . core_get_datetime() . "',p_status='{$p_status}' WHERE smslog_id='{$smslog_id}' AND uid='{$uid}'";
    if ($aff_id = @dba_affected_rows($db_query)) {
        // logger_print("saved smslog_id:".$smslog_id, 2, "setsmsdeliverystatus");
        $ok = true;
        if ($p_status > 0) {
            for ($c = 0; $c < count($core_config['featurelist']); $c++) {
                core_hook($core_config['featurelist'][$c], 'setsmsdeliverystatus', array($smslog_id, $uid, $p_status));
            }
        }
    }
    return $ok;
}
コード例 #7
0
ファイル: fn.php プロジェクト: 10corp/playSMS
function sms_board_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $board_keyword, $board_param = '', $smsc = '', $raw_message = '')
{
    global $core_config;
    $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_name = phonebook_number2name($c_uid, $sms_sender);
                $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";
                // fixme anton - ran by playsmsd, no http address, disabled for now looking for solution
                // $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;
}
コード例 #8
0
ファイル: fn.php プロジェクト: playsms/plugin-playnet
/**
 * hook_sendsms called by sendsms_process()
 *
 * @param string $smsc
 *        SMSC name
 * @param unknown $sms_sender
 *        Sender ID
 * @param string $sms_footer
 *        Message footer
 * @param string $sms_to
 *        Destination number
 * @param string $sms_msg
 *        Message
 * @param integer $uid
 *        User ID
 * @param integer $gpid
 *        Group ID
 * @param integer $smslog_id
 *        SMS Log ID
 * @param integer $sms_type
 *        Type of SMS
 * @param integer $unicode
 *        Unicode flag
 * @return boolean
 */
function playnet_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    $ok = FALSE;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "playnet_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['playnet']['module_sender']) {
        $sms_sender = $plugin_config['playnet']['module_sender'];
    }
    $sms_footer = stripslashes(htmlspecialchars_decode($sms_footer));
    $sms_msg = stripslashes(htmlspecialchars_decode($sms_msg));
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    $unicode = trim($unicode) ? 1 : 0;
    if (!$unicode) {
        $unicode = core_detect_unicode($sms_msg);
    }
    if ($sms_to && $sms_msg) {
        $now = core_get_datetime();
        $items = array('created' => $now, 'last_update' => $now, 'flag' => 1, 'uid' => $uid, 'smsc' => $smsc, 'smslog_id' => $smslog_id, 'sender_id' => $sms_sender, 'sms_to' => $sms_to, 'message' => $sms_msg, 'sms_type' => $sms_type, 'unicode' => $unicode);
        if ($id = dba_add(_DB_PREF_ . '_gatewayPlaynet_outgoing', $items)) {
            $ok = TRUE;
        }
    }
    if ($ok) {
        $p_status = 0;
        // pending
    } else {
        $p_status = 2;
        // failed
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
コード例 #9
0
ファイル: gateway.php プロジェクト: yrahman/playSMS
 case 'edit_smsc_save':
     $c_id = (int) $_REQUEST['id'];
     $smsc = gateway_get_smscbyid($c_id);
     // do not edit dev and blocked
     $continue = FALSE;
     if (!($smsc['gateway'] == 'dev' || $smsc['gateway'] == 'blocked')) {
         $continue = TRUE;
     }
     $c_gateway = gateway_valid_name($_REQUEST['gateway']);
     if ($continue && $c_id && $c_gateway && $c_gateway == $smsc['gateway']) {
         $dv = $plugin_config[$c_gateway]['_smsc_config_'] ? $plugin_config[$c_gateway]['_smsc_config_'] : array();
         $dynamic_variables = array();
         foreach ($dv as $key => $val) {
             $dynamic_variables[$key] = $_REQUEST[$key];
         }
         $items = array('last_update' => core_get_datetime(), 'data' => json_encode($dynamic_variables));
         $condition = array('id' => $c_id);
         $db_table = _DB_PREF_ . '_tblGateway';
         if ($new_id = dba_update($db_table, $items, $condition)) {
             $_SESSION['error_string'] = _('SMSC has been edited');
         } else {
             $_SESSION['error_string'] = _('Fail to edit SMSC');
         }
     } else {
         $_SESSION['error_string'] = _('Unknown error');
         header('Location: ' . _u('index.php?app=main&inc=core_gateway&op=gateway_list'));
         exit;
     }
     header('Location: ' . _u('index.php?app=main&inc=core_gateway&op=edit_smsc&id=' . $c_id));
     exit;
     break;
コード例 #10
0
ファイル: simulate.php プロジェクト: 10corp/playSMS
defined('_SECURE_') or die('Forbidden');
if (!auth_isadmin()) {
    auth_block();
}
switch (_OP_) {
    case "simulate":
        $sender = '629876543210';
        $receiver = '1234';
        $datetime = core_get_datetime();
        $content .= _dialog() . "\n\t\t\t<h2>" . _('Simulate incoming SMS') . "</h2>\n\t\t\t<form action=\"index.php?app=main&inc=gateway_dev&route=simulate&op=simulate_yes\" method=post>\n\t\t\t" . _CSRF_FORM_ . "\n\t\t\t<table class=playsms-table>\n\t\t\t\t<tbody>\n\t\t\t\t<tr><td class=label-sizer>" . _('Message') . "</td><td><input type=text name=message value=\"{$message}\" maxlength=250></td></tr>\n\t\t\t\t<tr><td>" . _('Sender') . "</td><td><input type=text name=sender value=\"{$sender}\" maxlength=20></td></tr>\n\t\t\t\t<tr><td>" . _('Receiver') . "</td><td><input type=text name=receiver value=\"{$receiver}\" maxlength=20></td></tr>\n\t\t\t\t<tr><td>" . _('Date/Time') . "</td><td><input type=text name=datetime value=\"" . core_display_datetime($datetime) . "\" maxlength=20></td></tr>\n\t\t\t\t</tbody>\n\t\t\t</table>\n\t\t\t<p><input type=submit class=button value=\"" . _('Submit') . "\">\n\t\t\t</form>";
        _p($content);
        break;
    case "simulate_yes":
        $sms_sender = $_REQUEST['sender'] ? $_REQUEST['sender'] : '629876543210';
        $sms_receiver = $_REQUEST['receiver'] ? $_REQUEST['receiver'] : '1234';
        $sms_datetime = $_REQUEST['datetime'] ? $_REQUEST['datetime'] : core_get_datetime();
        $message = $_REQUEST['message'] ? $_REQUEST['message'] : _('This is a test incoming SMS message');
        $message = htmlspecialchars_decode($message);
        if (trim($sms_sender) && trim($sms_receiver) && trim($sms_datetime) && trim($message)) {
            recvsms($sms_datetime, $sms_sender, $message, $sms_receiver, 'dev');
            $err[] = "Sender ID: " . $sms_sender;
            $err[] = "Receiver number: " . $sms_receiver;
            $err[] = "Sent: " . $sms_datetime;
            $err[] = "Message: " . stripslashes($message);
            _log(print_r($err, TRUE), 3, "dev incoming");
            $_SESSION['dialog']['info'][] = $err;
        } else {
            $_SESSION['dialog']['info'][] = _('Fail to simulate incoming SMS');
        }
        header("Location: " . _u('index.php?app=main&inc=gateway_dev&route=simulate&op=simulate'));
        exit;
コード例 #11
0
ファイル: fn.php プロジェクト: 10corp/playSMS
/**
 * Add sender ID
 *
 * @param integer $uid
 *        User ID
 * @param string $sender_id
 *        Sender ID
 * @param string $sender_id_description
 *        Sender ID description
 * @param integer $isdefault
 *        Flag 1 for default sender ID
 * @param integer $isapproved
 *        Flag 1 for approved sender ID
 * @return boolean TRUE when new sender ID has been added
 */
function sender_id_add($uid, $sender_id, $sender_id_description = '', $isdefault = 1, $isapproved = 1)
{
    global $user_config;
    if (sender_id_check($uid, $sender_id)) {
        // not available
        return FALSE;
    } else {
        $default = auth_isadmin() ? (int) $isdefault : 0;
        $approved = auth_isadmin() ? (int) $isapproved : 0;
        $data_sender_id = array($sender_id => $approved);
        $sender_id_description = trim($sender_id_description) ? trim($sender_id_description) : $sender_id;
        $data_description = array($sender_id => $sender_id_description);
        $uid = auth_isadmin() && $uid ? $uid : $user_config['uid'];
        if ($uid) {
            registry_update($uid, 'features', 'sender_id', $data_sender_id);
            $ret = registry_update($uid, 'features', 'sender_id_desc', $data_description);
        } else {
            // unknown error
            return FALSE;
        }
        if ($ret[$sender_id]) {
            _log('sender ID has been added id:' . $sender_id . ' uid:' . $uid, 2, 'sender_id_add');
        } else {
            _log('fail to add sender ID id:' . $sender_id . ' uid:' . $uid, 2, 'sender_id_add');
            return FALSE;
        }
        // if default and approved
        if (auth_isadmin() && $default && $approved) {
            sender_id_default_set($uid, $sender_id);
        }
        // notify admins if user or subuser
        if ($user_config['status'] == 3 || $user_config['status'] == 4) {
            $admins = user_getallwithstatus(2);
            foreach ($admins as $admin) {
                $message_to_admins = sprintf(_('Username %s with account ID %d has requested approval for sender ID %s'), user_uid2username($uid), $uid, $sender_id);
                recvsms_inbox_add(core_get_datetime(), _SYSTEM_SENDER_ID_, $admin['username'], $message_to_admins);
            }
        }
        // added
        return TRUE;
    }
}
コード例 #12
0
ファイル: fn.php プロジェクト: yrahman/playSMS
/**
 * Remove login sessions older than 1 hour idle
 */
function report_hook_playsmsd()
{
    global $plugin_config;
    $plugin_config['report']['current_tick'] = (int) strtotime(core_get_datetime());
    $period = $plugin_config['report']['current_tick'] - $plugin_config['report']['last_tick'];
    // login session older than 1 hour will be removed
    if ($period >= 60 * 60) {
        $users = report_whoseonline(0, FALSE, TRUE);
        foreach ($users as $user) {
            foreach ($user as $hash) {
                user_session_remove('', '', $hash['hash']);
                _log('login session removed uid:' . $hash['uid'] . ' hash:' . $hash['hash'], 3, 'report_hook_playsmsd');
            }
        }
        $plugin_config['report']['last_tick'] = $plugin_config['report']['current_tick'];
    }
}
コード例 #13
0
ファイル: credit.php プロジェクト: kothsada/playSMS
     $list = dba_search($db_table, '*', $conditions, $search['dba_keywords']);
     $data[0] = array(_('User'), _('Transaction datetime'), _('Amount'));
     for ($i = 0; $i < count($list); $i++) {
         $j = $i + 1;
         $data[$j] = array($list[$i]['username'], core_display_datetime($list[$i]['create_datetime']), $list[$i]['amount']);
     }
     $content = core_csv_format($data);
     $fn = 'credit-' . $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(), 'delete_datetime' => core_get_datetime(), 'flag_deleted' => '1');
             // only if users
             if ($user_config['status'] == 3) {
                 $up['parent_uid'] = $user_config['uid'];
                 $up['status'] = 4;
             }
             dba_update($db_table, $up, array('id' => $itemid));
         }
     }
     $ref = $nav['url'] . '&search_keyword=' . $search['keyword'] . '&page=' . $nav['page'] . '&nav=' . $nav['nav'];
     $_SESSION['dialog']['info'][] = _('Selected transactions has been deleted');
     header("Location: " . _u($ref));
     exit;
     break;
 case "add":
     $continue = FALSE;
コード例 #14
0
ファイル: fn.php プロジェクト: 10corp/playSMS
function sms_subscribe_hook_playsmsd()
{
    global $core_config;
    // fetch hourly
    if (!core_playsmsd_timer(3600)) {
        return;
    }
    $db_table = _DB_PREF_ . "_featureSubscribe";
    $conditions = array('subscribe_enable' => 1);
    $extras = array('AND duration' => '>0');
    $list_subscribe = dba_search($db_table, '*', $conditions, '', $extras);
    foreach ($list_subscribe as $subscribe) {
        $c_id = $subscribe['subscribe_id'];
        $c_duration = $subscribe['duration'];
        $date_now = new DateTime(core_get_datetime());
        $list_member = dba_search(_DB_PREF_ . '_featureSubscribe_member', '*', array('subscribe_id' => $c_id));
        foreach ($list_member as $member) {
            $is_expired = FALSE;
            $date_since = new DateTime($member['member_since']);
            $diff = $date_since->diff($date_now);
            $d = (int) $diff->format('%R%a');
            // _log('check duration:' . $d . ' day set duration:' . $c_duration . ' date_now:' . core_get_datetime() . ' date_since:' . $member['member_since'] . ' k:' . $subscribe['subscribe_keyword'] . ' member_id:' . $member['member_id'] . ' number:' . $member['member_number'], 3, 'sms_subscribe_hook_playsmsd');
            if ($c_duration > 1000) {
                // days
                $c_interval = $c_duration - 1000;
                if ($c_interval && $d && $d >= $c_interval) {
                    _log('expired duration:' . $d . ' day k:' . $subscribe['subscribe_keyword'] . ' member_id:' . $member['member_id'] . ' number:' . $member['member_number'], 3, 'sms_subscribe_hook_playsmsd');
                    $is_expired = TRUE;
                }
            } else {
                if ($c_duration > 100) {
                    // weeks
                    $c_interval = $c_duration - 100;
                    $w = floor($d / 7);
                    // _log('interval:' . $c_interval . ' d:' . $d . ' w:' . $w, 3, 'sms_subscribe_hook_playsmsd');
                    if ($c_interval && $w && $w >= $c_interval) {
                        _log('expired duration:' . $w . ' week k:' . $subscribe['subscribe_keyword'] . ' member_id:' . $member['member_id'] . ' number:' . $member['member_number'], 3, 'sms_subscribe_hook_playsmsd');
                        $is_expired = TRUE;
                    }
                } else {
                    if ($c_duration > 0) {
                        // months
                        $c_interval = $c_duration;
                        $m = floor($d / 30);
                        // _log('interval:' . $c_interval . ' d:' . $d . ' m:' . $m, 3, 'sms_subscribe_hook_playsmsd');
                        if ($c_interval && $m && $m >= $c_interval) {
                            _log('expired duration:' . $m . ' month k:' . $subscribe['subscribe_keyword'] . ' member_id:' . $member['member_id'] . ' number:' . $member['member_number'], 3, 'sms_subscribe_hook_playsmsd');
                            $is_expired = TRUE;
                        }
                    }
                }
            }
            if ($is_expired) {
                _sms_subscribe_member_expired($subscribe, $member);
            }
        }
    }
}
コード例 #15
0
ファイル: fn.php プロジェクト: yrahman/playSMS
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;
    }
}
コード例 #16
0
ファイル: sms_subscribe.php プロジェクト: yrahman/playSMS
     break;
 case "msg_add":
     if ($err = $_SESSION['error_string']) {
         $content = "<div class=error_string>{$err}</div>";
     }
     $db_query = "SELECT subscribe_keyword FROM " . _DB_PREF_ . "_featureSubscribe where subscribe_id='{$subscribe_id}'";
     $db_result = dba_query($db_query);
     $db_row = dba_fetch_array($db_result);
     $subscribe_name = $db_row['subscribe_keyword'];
     $content .= "\n\t\t\t<h2>" . _('Manage subscribe') . "</h2>\n\t\t\t<h3>" . _('Add message') . "</h3>\n\t\t\t<form action=index.php?app=main&inc=feature_sms_subscribe&op=msg_add_yes method=post>\n\t\t\t" . _CSRF_FORM_ . "\n\t\t\t<input type=hidden value={$subscribe_id} name=subscribe_id>\n\t\t\t<table class=playsms-table>\n\t\t\t<tr>\n\t\t\t\t<td class=label-sizer>" . _('SMS subscribe keyword') . "</td><td>{$subscribe_name}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan=2>\n\t\t\t\t\t" . _('Message body') . "<br />\n\t\t\t\t\t<textarea name=add_mbr_message rows=5 cols=60></textarea>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p><input type=submit class=button value=\"" . _('Save') . "\">\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_add_yes":
     $add_mbr_message = $_POST['add_mbr_message'];
     if ($subscribe_id && $add_mbr_message) {
         $dt = core_get_datetime();
         $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_featureSubscribe_msg (subscribe_id,msg,create_datetime,update_datetime)\n\t\t\t\tVALUES ('{$subscribe_id}','{$add_mbr_message}','{$dt}','{$dt}')";
         if ($new_uid = @dba_insert_id($db_query)) {
             $_SESSION['error_string'] = _('Message has been added');
         } else {
             $_SESSION['error_string'] = _('Fail to add message');
         }
     } else {
         $_SESSION['error_string'] = _('You must fill all fields');
     }
     header("Location: " . _u('index.php?app=main&inc=feature_sms_subscribe&op=msg_add&subscribe_id=' . $subscribe_id));
     exit;
     break;
 case "msg_del":
     $msg_id = $_REQUEST['msg_id'];
     if ($msg_id) {
コード例 #17
0
            if (@dba_affected_rows($db_query)) {
                $_SESSION['dialog']['info'][] = sprintf(_('SMS autorespond %s has been saved'), $edit_service_name);
                _lastpost_empty();
            } else {
                $_SESSION['dialog']['danger'][] = _('Fail to save SMS autorespond');
            }
        } else {
            $_SESSION['dialog']['danger'][] = _('All mandatory fields must be filled');
        }
        header("Location: " . _u('index.php?app=main&inc=feature_autorespond&op=autorespond_edit&id=' . $id));
        exit;
        break;
    case "autorespond_del":
        if (!auth_isadmin()) {
            auth_block();
        }
        $db_query = "SELECT service_name FROM " . _DB_PREF_ . "_featureAutorespond WHERE id='{$id}' AND flag_deleted='0'";
        $db_result = dba_query($db_query);
        $db_row = dba_fetch_array($db_result);
        if ($id && $db_row['service_name']) {
            $db_query = "UPDATE " . _DB_PREF_ . "_featureAutorespond SET last_update='" . core_get_datetime() . "',flag_deleted='1' WHERE id='{$id}'";
            if (@dba_affected_rows($db_query)) {
                $_SESSION['dialog']['info'][] = sprintf(_('SMS autorespond %s has been deleted'), $db_row['service_name']);
            } else {
                $_SESSION['dialog']['danger'][] = _('Fail to delete SMS autorespond');
            }
        }
        header("Location: " . _u('index.php?app=main&inc=feature_autorespond&op=autorespond_list'));
        exit;
        break;
}
コード例 #18
0
ファイル: fn.php プロジェクト: vasrush/playSMS
/**
 * Counter for throttle limit
 *
 * @param integer $uid
 *        User ID
 * @param integer $count
 *        (default is 1)
 *        Sent SMS
 * @return boolean TRUE of successful counter
 */
function sendsms_throttle_count($uid, $count = 1, $limit = 0, $period = 60)
{
    global $core_config;
    $limit = (int) $limit ? (int) $limit : $core_config['main']['sms_limit_per_hour'];
    $period = (int) $period ? (int) $period * 60 : 3600;
    if (!$limit) {
        // no limit no over limit
        return FALSE;
    }
    // get start time, UTC
    $reg = registry_search($uid, 'core', 'sendsms', 'throttle_start');
    $start = $reg['core']['sendsms']['throttle_start'];
    if ($start) {
        // get sum of sent SMS over the hour
        $reg = registry_search($uid, 'core', 'sendsms', 'throttle_sum');
        $sum = $reg['core']['sendsms']['throttle_sum'];
        _log('throttle bucket exists start:' . core_display_datetime($start) . ' sum:' . $sum . ' limit:' . $limit, 3, 'sendsms_throttle_count');
    } else {
        $start = core_get_datetime();
        $sum = 0;
        if (registry_update($uid, 'core', 'sendsms', array('throttle_start' => $start, 'throttle_sum' => $sum))) {
            _log('throttle bucket started start:' . core_display_datetime($start) . ' limit:' . $limit, 3, 'sendsms_throttle_count');
        } else {
            _log('fail to start throttle bucket', 3, 'sendsms_throttle_count');
            return FALSE;
        }
    }
    // check bucket expired
    if (strtotime($start) + $period < strtotime(core_get_datetime())) {
        // expired, create new
        $start = core_get_datetime();
        $sum = 0;
        _log('expired start:' . core_display_datetime($start), 3, 'sendsms_throttle_count');
    } else {
        //_log('not expired', 3, 'sendsms_throttle_count');
        // not expired
        if ((int) $sum <= $limit) {
            // add to bucket
            $sum += $count;
            //_log('add to bucket sum:' . $sum, 3, 'sendsms_throttle_count');
        } else {
            _log('overlimit sum:' . $sum . ' limit:' . $limit, 3, 'sendsms_throttle_count');
            return FALSE;
        }
    }
    // save in registry
    if (registry_update($uid, 'core', 'sendsms', array('throttle_start' => $start, 'throttle_sum' => $sum))) {
        return TRUE;
    }
    return FALSE;
}
コード例 #19
0
ファイル: fn.php プロジェクト: 10corp/playSMS
/**
 * Add account to banned account list
 *
 * @param integer $uid
 *        User ID
 * @return boolean TRUE if user successfully added to banned user list
 */
function user_banned_add($uid)
{
    global $user_config;
    // account admin and currently logged in user/admin cannot be ban
    if ($uid && ($uid == 1 || $uid == $user_config['uid'])) {
        _log('unable to ban uid:' . $uid, 2, 'user_banned_add');
        return FALSE;
    }
    $bantime = core_get_datetime();
    if (user_session_get($uid)) {
        if (!user_session_remove($uid)) {
            return FALSE;
        }
    }
    $item = array($uid => $bantime);
    if (registry_update(1, 'auth', 'banned_users', $item)) {
        _log('banned uid:' . $uid . ' bantime:' . $bantime, 2, 'user_banned_add');
        return TRUE;
    } else {
        return FALSE;
    }
}
コード例 #20
0
ファイル: fn.php プロジェクト: yrahman/playSMS
function sms_poll_check_option_vote($list, $sms_sender, $poll_keyword, $choice_keyword)
{
    $poll_id = $list['poll_id'];
    $poll_option_vote = $list['poll_option_vote'];
    $c_sms_sender = substr($sms_sender, 3);
    // check already vote
    $db_query = "SELECT in_datetime FROM " . _DB_PREF_ . "_featurePoll_log WHERE poll_sender LIKE '%{$c_sms_sender}' AND poll_id='{$poll_id}' AND status!=0 ORDER BY log_id DESC LIMIT 1";
    $db_result = dba_query($db_query);
    if ($db_row = dba_fetch_array($db_result)) {
        // yup, voted
        if ($poll_option_vote == 4) {
            logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' vote multiple', 2, 'sms_poll');
            return TRUE;
        }
        $in_datetime = $db_row['in_datetime'];
        $votes = (int) @dba_num_rows($db_query);
    } else {
        // nope, go ahead save it in the log
        logger_print('vote s:' . $sms_sender . ' k:' . $poll_keyword . ' c:' . $choice_keyword . ' continue', 2, 'sms_poll');
        return TRUE;
    }
    $continue = TRUE;
    switch ($poll_option_vote) {
        case 0:
            // one time
            if ($votes) {
                logger_print('vote s:' . $sms_sender . 'k:' . $poll_keyword . ' c:' . $choice_keyword . ' option_vote:' . $poll_option_vote . ' vote_count:' . $votes . ' already vote one time', 2, 'sms_poll');
                $continue = FALSE;
            }
            break;
        case 1:
            // one time every 24 hours
            if ($votes) {
                $d = new DateTime($in_datetime);
                $day_in = $d->format("Ymd");
                $d = new DateTime(core_get_datetime());
                $day_current = $d->format("Ymd");
                if ($day_in && $day_current && $day_in == $day_current) {
                    logger_print('vote s:' . $sms_sender . 'k:' . $poll_keyword . ' c:' . $choice_keyword . ' option_vote:' . $poll_option_vote . ' vote_count:' . $votes . ' already vote today', 2, 'sms_poll');
                    $continue = FALSE;
                }
            }
            break;
        case 2:
            // one time every week
            if ($votes) {
                $d = new DateTime($in_datetime);
                $week_in = $d->format("YmW");
                $d = new DateTime(core_get_datetime());
                $week_current = $d->format("YmW");
                if ($week_in && $week_current && $week_in == $week_current) {
                    logger_print('vote s:' . $sms_sender . 'k:' . $poll_keyword . ' c:' . $choice_keyword . ' option_vote:' . $poll_option_vote . ' vote_count:' . $votes . ' already vote this week', 2, 'sms_poll');
                    $continue = FALSE;
                }
            }
            break;
        case 3:
            // one time every month
            if ($votes) {
                $d = new DateTime($in_datetime);
                $month_in = $d->format("Ym");
                $d = new DateTime(core_get_datetime());
                $month_current = $d->format("Ym");
                if ($month_in && $month_current && $month_in == $month_current) {
                    logger_print('vote s:' . $sms_sender . 'k:' . $poll_keyword . ' c:' . $choice_keyword . ' option_vote:' . $poll_option_vote . ' vote_count:' . $votes . ' already vote this month', 2, 'sms_poll');
                    $continue = FALSE;
                }
            }
            break;
    }
    return $continue;
}
コード例 #21
0
ファイル: callback.php プロジェクト: kothsada/playSMS
                $p_status = 3;
                break;
                // delivered
            // delivered
            default:
                $p_status = 2;
                break;
                // failed
        }
        _log("dlr uid:" . $uid . " smslog_id:" . $smslog_id . " message_id:" . $remote_smslog_id . " status:" . $status, 2, "jasmin callback");
        dlr($smslog_id, $uid, $p_status);
        ob_end_clean();
        echo "ACK/Jasmin";
        exit;
    }
}
// incoming message
$sms_datetime = core_get_datetime();
$sms_sender = $requests['from'];
$message = htmlspecialchars_decode(urldecode($requests['content']));
$sms_receiver = $requests['to'];
$smsc = $requests['origin-connector'];
if ($remote_smslog_id && $message) {
    _log("incoming smsc:" . $smsc . " message_id:" . $remote_smslog_id . " from:" . $sms_sender . " to:" . $sms_receiver . " content:[" . $message . "]", 2, "jasmin callback");
    $sms_sender = addslashes($sms_sender);
    $message = addslashes($message);
    recvsms($sms_datetime, $sms_sender, $message, $sms_receiver, $smsc);
    ob_end_clean();
    echo "ACK/Jasmin";
    exit;
}
コード例 #22
0
ファイル: fn_core.php プロジェクト: RobinKarlsen/playSMS
/**
 * Get current server time in GMT+0
 *
 * @return current time
 */
function core_get_time()
{
    $ret = core_get_datetime();
    $arr = explode(' ', $ret);
    $ret = $arr[1];
    return $ret;
}
コード例 #23
0
ファイル: fn_webservices.php プロジェクト: 10corp/playSMS
function webservices_inject($c_username, $from, $msg, $recvnum = '', $smsc = '')
{
    $ret = '';
    if ($from && $msg) {
        if ($c_username) {
            // inject message
            $sms_datetime = core_display_datetime(core_get_datetime());
            recvsms($sms_datetime, $from, $msg, $recvnum, $smsc);
            $json['status'] = 'OK';
            $json['error'] = '0';
        } else {
            $json['status'] = 'ERR';
            $json['error'] = '601';
        }
    } else {
        $json['status'] = 'ERR';
        $json['error'] = '602';
    }
    return $json;
}
コード例 #24
0
ファイル: fn.php プロジェクト: 10corp/playSMS
function inboxgroup_dataadd($in_receiver, $keywords, $description)
{
    global $user_config;
    $dt = core_get_datetime();
    $uid = $user_config['uid'];
    $keywords = str_replace(' ', '', $keywords);
    $keywords = trim(strtoupper($keywords));
    $keywords = explode(',', $keywords);
    $k = '';
    for ($i = 0; $i < count($keywords); $i++) {
        if (keyword_isavail($keywords[$i])) {
            $k .= $keywords[$i] . ',';
        }
    }
    if ($keywords = substr($k, 0, -1)) {
        $db_query = "INSERT INTO " . _DB_PREF_ . "_featureInboxgroup (uid,in_receiver,keywords,description,creation_datetime) ";
        $db_query .= "VALUES ('{$uid}','{$in_receiver}','{$keywords}','{$description}','{$dt}')";
        $id = dba_insert_id($db_query);
    }
    return $id;
}
コード例 #25
0
ファイル: fn.php プロジェクト: 10corp/playSMS
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');
}
コード例 #26
0
ファイル: fn.php プロジェクト: 10corp/playSMS
function playnet_hook_webservices_output($operation, $requests, $returns)
{
    global $plugin_config;
    $go = $requests['go'];
    $smsc = $requests['smsc'];
    $username = $requests['u'];
    $password = $requests['p'];
    if (!($operation == 'playnet' && $go && $smsc && $username && $password)) {
        return FALSE;
    }
    $c_plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    // auth remote
    if (!($c_plugin_config['playnet']['local_playnet_username'] && $c_plugin_config['playnet']['local_playnet_password'] && $c_plugin_config['playnet']['local_playnet_username'] == $username && $c_plugin_config['playnet']['local_playnet_password'] == $password)) {
        $content['status'] = 'ERROR';
        $content['error_string'] = 'Authentication failed';
        $returns['modified'] = TRUE;
        $returns['param']['content'] = json_encode($content);
        $returns['param']['content-type'] = 'text/json';
        return $returns;
    }
    switch ($go) {
        case 'get_outgoing':
            $conditions = array('flag' => 1, 'smsc' => $smsc);
            $extras = array('ORDER BY' => 'id', 'LIMIT' => $c_plugin_config['playnet']['poll_limit']);
            $list = dba_search(_DB_PREF_ . '_gatewayPlaynet_outgoing', '*', $conditions, '', $extras);
            foreach ($list as $data) {
                $rows[] = array('smsc' => $data['smsc'], 'smslog_id' => $data['smslog_id'], 'uid' => $data['uid'], 'sender_id' => $data['sender_id'], 'sms_to' => $data['sms_to'], 'message' => $data['message'], 'sms_type' => $data['sms_type'], 'unicode' => $data['unicode']);
                // update flag
                $items = array('flag' => 2);
                $condition = array('flag' => 1, 'id' => $data['id']);
                dba_update(_DB_PREF_ . '_gatewayPlaynet_outgoing', $items, $condition, 'AND');
                // update dlr
                $p_status = 1;
                dlr($data['smslog_id'], $data['uid'], $p_status);
            }
            if (count($rows)) {
                $content['status'] = 'OK';
                $content['data'] = $rows;
            } else {
                $content['status'] = 'ERROR';
                $content['error_string'] = 'No outgoing data';
            }
            break;
        case 'set_incoming':
            $payload = json_decode(stripslashes($requests['payload']), 1);
            if ($payload['message']) {
                $sms_sender = $payload['sms_sender'];
                $message = $payload['message'];
                $sms_receiver = $payload['sms_receiver'];
                if ($id = recvsms(core_get_datetime(), $sms_sender, $message, $sms_receiver, $smsc)) {
                    $content['status'] = 'OK';
                    $content['data'] = array('recvsms_id' => $id);
                } else {
                    $content['status'] = 'ERROR';
                    $content['error_string'] = 'Unable to save incoming data';
                }
            } else {
                $content['status'] = 'ERROR';
                $content['error_string'] = 'No incoming data';
            }
    }
    $returns['modified'] = TRUE;
    $returns['param']['content'] = json_encode($content);
    $returns['param']['content-type'] = 'text/json';
    if ($content['status'] == 'OK') {
        _log('accessed param_go:[' . $go . '] param_smsc:[' . $smsc . '] param_u:[' . $username . '] param_p:[' . $password . ']', 3, 'playnet_hook_webservices_output');
    }
    return $returns;
}
コード例 #27
0
ファイル: fn.php プロジェクト: yrahman/playSMS
/**
 * Send SMS helper
 *
 * @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        	
 * @param string $reference_id        	
 * @return array array($status, $sms_to, $smslog_id, $queue, $counts, $sms_count, $sms_failed)
 */
function sendsms_helper($username, $sms_to, $message, $sms_type = 'text', $unicode = 0, $smsc = '', $nofooter = false, $sms_footer = '', $sms_sender = '', $sms_schedule = '', $reference_id = '')
{
    global $core_config, $user_config;
    // get user data
    if ($username && $user_config['username'] != $username) {
        $user_config = user_getdatabyusername($username);
    }
    if (!is_array($sms_to)) {
        $sms_to = explode(',', $sms_to);
    }
    // get destinations
    for ($i = 0; $i < count($sms_to); $i++) {
        if (substr(trim($sms_to[$i]), 0, 1) == '#') {
            if ($c_group_code = substr(trim($sms_to[$i]), 1)) {
                $c_gpid = phonebook_groupcode2id($user_config['uid'], $c_group_code);
                $members = phonebook_getdatabyid($c_gpid);
                foreach ($members as $member) {
                    if (trim($member['p_num'])) {
                        $array_sms_to[] = trim($member['p_num']);
                    }
                }
            }
        } else {
            if (substr(trim($sms_to[$i]), 0, 1) == '@') {
                if ($c_username = substr(trim($sms_to[$i]), 1)) {
                    // reference self will be ignored
                    if ($c_username != $user_config['username']) {
                        $array_username[] = $c_username;
                    }
                }
            } else {
                $array_sms_to[] = trim($sms_to[$i]);
            }
        }
    }
    // remove duplicates destinations
    array_unique($array_sms_to);
    $sms_queued = 0;
    $sms_failed = 0;
    // sendsms
    if (is_array($array_sms_to) && $array_sms_to[0]) {
        list($ok, $to, $smslog_id, $queue, $counts) = sendsms($user_config['username'], $array_sms_to, $message, $sms_type, $unicode, $smsc, $nofooter, $sms_footer, $sms_sender, $sms_schedule);
    }
    // fixme anton - IMs doesn't count
    // count SMSes only
    for ($i = 0; $i < count($ok); $i++) {
        if ($ok[$i]) {
            $sms_count += $counts[$i];
        } else {
            $sms_failed += $counts[$i];
        }
    }
    // sendsms_im
    if (is_array($array_username) && $array_username[0]) {
        $im_sender = '@' . $user_config['username'];
        foreach ($array_username as $target_user) {
            $im_sender = '@' . $user_config['username'];
            if (recvsms_inbox_add(core_get_datetime(), $im_sender, $target_user, $message, '', $reference_id)) {
                $ok[] = '1';
                $to[] = '@' . $target_user;
                $queue[] = md5($target_user . microtime());
                $sms_count++;
            }
        }
    }
    return array($ok, $to, $smslog_id, $queue, $counts, $sms_count, $sms_failed);
}
コード例 #28
0
ファイル: fn.php プロジェクト: 10corp/playSMS
/**
 * Intercept on after-process stage for incoming SMS and forward it to selected user's inbox
 *
 * @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 $feature feature
 *        managed to hook current incoming SMS
 * @param $status recvsms()
 *        status, 0 or FALSE for unhandled
 * @param $uid keyword
 *        owner
 * @return array $ret
 */
function incoming_hook_recvsms_intercept_after($sms_datetime, $sms_sender, $message, $sms_receiver, $feature, $status, $uid, $smsc)
{
    global $core_config;
    $ret = array();
    $users = array();
    $is_routed = FALSE;
    // continue only if its sandbox
    if ($status) {
        return $ret;
    }
    // get settings
    $settings = incoming_settings_get();
    // get post rules
    $post_rules = incoming_post_rules_get();
    // sandbox match receiver number and sender ID
    if (!$is_routed) {
        // route sandbox if receiver number matched with default sender ID of users
        if ($post_rules['match_sender_id']) {
            $s = array();
            if ($settings['match_all_sender_id']) {
                // get all approved sender ID
                $s = sender_id_getall();
            } else {
                $data = user_search($sms_receiver, 'sender');
                foreach ($data as $user) {
                    // get default sender ID
                    if ($user['sender']) {
                        $s[] = $user['sender'];
                        // in case an error occured where multiple users own the same sender ID
                        break;
                    }
                }
            }
            // start matching
            foreach ($s as $sender_id) {
                if ($sender_id && $sms_receiver && $sender_id == $sms_receiver) {
                    unset($usernames);
                    unset($username);
                    if ($settings['match_all_sender_id']) {
                        // get $username who owns $sender_id
                        $uids = sender_id_owner($sender_id);
                        foreach ($uids as $uid) {
                            $usernames[] = user_uid2username($uid);
                        }
                    } else {
                        $usernames[] = $user['username'];
                    }
                    $usernames = array_unique($usernames);
                    foreach ($usernames as $username) {
                        if ($username) {
                            _log("sandbox match sender start u:" . $username . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "]", 3, 'incoming recvsms_intercept_after');
                            recvsms_inbox_add($sms_datetime, $sms_sender, $username, $message, $sms_receiver);
                            _log("sandbox match sender end u:" . $username, 3, 'incoming recvsms_intercept_after');
                            $is_routed = TRUE;
                            // single match only
                            // break;
                        }
                    }
                }
            }
        }
        // sandbox prefix
        if (!$is_routed) {
            // route sandbox by adding a prefix to message and re-enter it to recvsms()
            //if ($post_rules['insert_prefix'] && trim($message)) {
            //	$message = $post_rules['insert_prefix'] . ' ' . trim($message);
            //	_log("sandbox add prefix start keyword:" . $post_rules['insert_prefix'] . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept_after');
            //	recvsms($sms_datetime, $sms_sender, $message, $sms_receiver, $smsc);
            //	_log("sandbox add prefix end keyword:" . $post_rules['insert_prefix'], 3, 'incoming recvsms_intercept_after');
            //	$is_routed = TRUE;
            //}
        }
        // sandbox forward to users
        if (!$is_routed) {
            foreach ($post_rules['forward_to'] as $uid) {
                $c_username = user_uid2username($uid);
                if ($c_username) {
                    $users[] = $c_username;
                }
            }
            // route sandbox to users inbox
            foreach ($users as $username) {
                _log("sandbox to user start u:" . $username . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "]", 3, 'incoming recvsms_intercept_after');
                recvsms_inbox_add($sms_datetime, $sms_sender, $username, $message, $sms_receiver);
                _log("sandbox to user end u:" . $username, 3, 'incoming recvsms_intercept_after');
                $is_routed = TRUE;
            }
        }
        // sandbox forward to URL
        if ($url = trim($post_rules['forward_to_url'])) {
            $payload = array('datetime' => core_get_datetime(), 'sms_datetime' => $sms_datetime, 'sms_sender' => $sms_sender, 'message' => $message, 'sms_receiver' => $sms_receiver, 'smsc' => $smsc);
            $json = json_encode($payload);
            $url = str_replace('{SANDBOX_PAYLOAD}', urlencode($json), $url);
            $url = str_replace('{SANDBOX_DATETIME}', urlencode($sms_datetime), $url);
            $url = str_replace('{SANDBOX_SENDER}', urlencode($sms_sender), $url);
            $url = str_replace('{SANDBOX_MESSAGE}', urlencode($message), $url);
            $url = str_replace('{SANDBOX_RECEIVER}', urlencode($sms_receiver), $url);
            $url = str_replace('{SANDBOX_SMSC}', urlencode($smsc), $url);
            _log("sandbox forward to URL start url:[" . $url . "]", 3, 'incoming recvsms_intercept_after');
            $response = @file_get_contents($url);
            _log("sandbox forward to URL end response:[" . $response . "]", 3, 'incoming recvsms_intercept_after');
        }
    }
    // flag the hook if is_routed
    if ($is_routed) {
        $ret['param']['feature'] = 'incoming';
        if ($settings['leave_copy_sandbox']) {
            $ret['param']['status'] = 0;
        } else {
            $ret['param']['status'] = 1;
        }
        $ret['param']['uid'] = 1;
        $ret['modified'] = TRUE;
    }
    return $ret;
}
コード例 #29
0
ファイル: sync.php プロジェクト: yrahman/playSMS
error_reporting(0);
if (!$called_from_hook_call) {
    chdir("../../../");
    // ignore CSRF
    $core_config['init']['ignore_csrf'] = TRUE;
    include "init.php";
    include $core_config['apps_path']['libs'] . "/function.php";
    chdir("plugin/feature/sms_sync/");
}
$r = $_REQUEST;
$c_uid = $r['uid'];
$list = registry_search($c_uid, 'feature', 'sms_sync');
$sms_sync_secret = $list['feature']['sms_sync']['secret'];
$sms_sync_enable = $list['feature']['sms_sync']['enable'];
$message_id = $r['message_id'];
$sms_datetime = core_display_datetime(core_get_datetime());
$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");
コード例 #30
0
ファイル: sendfromfile.php プロジェクト: RobinKarlsen/playSMS
         $data[2] = $sms_username;
     }
 } else {
     $sms_username = $user_config['username'];
     $uid = $user_config['uid'];
     $data[2] = $sms_username;
 }
 if ($nodups) {
     if (in_array($sms_to, $all_numbers)) {
         $dup = true;
     }
 }
 if ($sms_to && $sms_msg && $uid && !$dup) {
     $all_numbers[] = $sms_to;
     $db_query = "INSERT INTO " . _DB_PREF_ . "_featureSendfromfile (uid,sid,sms_datetime,sms_to,sms_msg,sms_username) ";
     $db_query .= "VALUES ('{$uid}','{$sid}','" . core_get_datetime() . "','{$sms_to}','" . addslashes($sms_msg) . "','{$sms_username}')";
     if ($db_result = dba_insert_id($db_query)) {
         $item_valid[$valid] = $data;
         $valid++;
     } else {
         $item_invalid[$invalid] = $data;
         $invalid++;
     }
 } else {
     if ($sms_to || $sms_msg) {
         $item_invalid[$invalid] = $data;
         $invalid++;
     }
 }
 $num_of_rows = $valid + $invalid;
 if ($num_of_rows >= $sendfromfile_row_limit) {