Exemplo n.º 1
0
function mailsms_hook_playsmsd()
{
    global $core_config;
    // fetch every 60 seconds
    if (!core_playsmsd_timer(60)) {
        return;
    }
    // _log('fetch now:'.$now, 2, 'mailsms_hook_playsmsd');
    // get global mailsms registry data
    $items_global = registry_search(0, 'features', 'mailsms');
    $enable_fetch = $items_global['features']['mailsms']['enable_fetch'];
    $protocol = $items_global['features']['mailsms']['protocol'];
    $port = $items_global['features']['mailsms']['port'];
    $server = $items_global['features']['mailsms']['server'];
    $username = $items_global['features']['mailsms']['username'];
    $password = $items_global['features']['mailsms']['password'];
    if (!($enable_fetch && $protocol && $port && $server && $username && $password)) {
        return;
    }
    // _log('fetch uid:' . $uid, 3, 'mailsms_hook_playsmsd');
    $param = 'mailsms_fetch';
    $is_fetching = playsmsd_pid_get($param) ? TRUE : FALSE;
    if (!$is_fetching) {
        $RUN_THIS = "nohup " . $core_config['daemon']['PLAYSMS_BIN'] . "/playsmsd playsmsd once " . $param . " >/dev/null 2>&1 &";
        // _log('execute:' . $RUN_THIS, 3, 'mailsms_hook_playsmsd');
        shell_exec($RUN_THIS);
    }
}
Exemplo n.º 2
0
function email2sms_hook_playsmsd()
{
    global $core_config;
    // fetch every 60 seconds
    if (!core_playsmsd_timer(60)) {
        return;
    }
    // _log('fetch now:'.$now, 2, 'email2sms_hook_playsmsd');
    // get all users
    $users = dba_search(_DB_PREF_ . '_tblUser', 'uid');
    foreach ($users as $user) {
        $uid = $user['uid'];
        // get email2sms registry data for $uid
        $items = registry_search($uid, 'features', 'email2sms');
        $enable = $items['features']['email2sms']['enable'];
        $protocol = $items['features']['email2sms']['protocol'];
        $port = $items['features']['email2sms']['port'];
        $server = $items['features']['email2sms']['server'];
        $username = $items['features']['email2sms']['username'];
        $password = $items['features']['email2sms']['password'];
        if (!($enable && $protocol && $port && $server && $username && $password)) {
            continue;
        }
        // _log('fetch uid:' . $uid, 3, 'email2sms_hook_playsmsd');
        $param = 'email2sms_uid_' . $uid;
        $is_fetching = playsmsd_pid_get($param) ? TRUE : FALSE;
        if (!$is_fetching) {
            $RUN_THIS = "nohup " . $core_config['daemon']['PLAYSMS_BIN'] . "/playsmsd playsmsd once " . $param . " >/dev/null 2>&1 &";
            // _log('execute:' . $RUN_THIS, 3, 'email2sms_hook_playsmsd');
            shell_exec($RUN_THIS);
        }
    }
}
Exemplo n.º 3
0
function clickatell_hook_playsmsd()
{
    // fetch every 60 seconds
    if (!core_playsmsd_timer(60)) {
        return;
    }
    // force to check p_status=1 (sent) as getsmsstatus only check for p_status=0 (pending)
    // $db_query = "SELECT * FROM "._DB_PREF_."_tblSMSOutgoing WHERE p_status=0 OR p_status=1";
    $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing WHERE p_status='1' AND p_gateway='clickatell'";
    $db_result = dba_query($db_query);
    while ($db_row = dba_fetch_array($db_result)) {
        $uid = $db_row['uid'];
        $smslog_id = $db_row['smslog_id'];
        $p_datetime = $db_row['p_datetime'];
        $p_update = $db_row['p_update'];
        $gpid = $db_row['p_gpid'];
        core_hook('clickatell', 'getsmsstatus', array($gpid, $uid, $smslog_id, $p_datetime, $p_update));
    }
}
Exemplo n.º 4
0
function infobip_hook_playsmsd()
{
    global $plugin_config;
    // fetch every 60 seconds
    if (!core_playsmsd_timer(60)) {
        return;
    }
    if ($plugin_config['infobip']['dlr_nopush'] == '1') {
        // force to check p_status=1 (sent) as getsmsstatus only check for p_status=0 (pending)
        // $db_query = "SELECT * FROM "._DB_PREF_."_tblSMSOutgoing WHERE p_status=0 OR p_status=1";
        $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing WHERE p_status='1' AND p_gateway='infobip'";
        $db_result = dba_query($db_query);
        while ($db_row = dba_fetch_array($db_result)) {
            $uid = $db_row['uid'];
            $smslog_id = $db_row['smslog_id'];
            $p_datetime = $db_row['p_datetime'];
            $p_update = $db_row['p_update'];
            $gpid = $db_row['p_gpid'];
            core_hook('infobip', 'getsmsstatus', array($gpid, $uid, $smslog_id, $p_datetime, $p_update));
        }
    }
}
Exemplo n.º 5
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');
}
Exemplo n.º 6
0
function playnet_hook_playsmsd()
{
    global $core_config, $plugin_config;
    if (!core_playsmsd_timer($plugin_config['playnet']['poll_interval'])) {
        return;
    }
    $smscs = gateway_getall_smsc_names('playnet');
    foreach ($smscs as $smsc) {
        $c_plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
        $is_master = (bool) ($c_plugin_config['playnet']['local_playnet_username'] && $c_plugin_config['playnet']['local_playnet_password']);
        if ((int) $c_plugin_config['playnet']['remote_on'] && !$is_master) {
            // fetch from remote
            $ws = $c_plugin_config['playnet']['remote_playsms_url'] . '/index.php?app=ws&op=playnet';
            $ws .= '&go=get_outgoing';
            $ws .= '&s=' . $c_plugin_config['playnet']['remote_playnet_smsc'];
            $ws .= '&u=' . $c_plugin_config['playnet']['remote_playnet_username'];
            $ws .= '&p=' . $c_plugin_config['playnet']['remote_playnet_password'];
            $response_raw = @file_get_contents($ws);
            $response = json_decode($response_raw, 1);
            // validate response
            if (strtoupper($response['status']) == 'OK') {
                if (is_array($response['data'])) {
                    foreach ($response['data'] as $data) {
                        $remote_smsc = $data['smsc'];
                        $remote_smslog_id = $data['smslog_id'];
                        $remote_uid = $data['uid'];
                        $username = $c_plugin_config['playnet']['sendsms_username'];
                        $sms_to = $data['sms_to'];
                        $message = $data['message'];
                        $unicode = core_detect_unicode($message);
                        $sms_type = $data['sms_type'];
                        $sms_sender = $data['sender_id'];
                        _log('sendsms remote_smsc:' . $remote_smsc . ' remote_smslog_id:' . $remote_smslog_id . ' remote_uid:' . $remote_uid . ' u:' . $username . ' sender_id:' . $sms_sender . ' to:' . $sms_to . ' m:[' . $message . '] unicode:' . $unicode, 3, 'playnet_hook_playsmsd');
                        sendsms_helper($username, $sms_to, $message, $sms_type, $unicode, '', 1, '', $sms_sender);
                    }
                }
            }
        }
    }
}
Exemplo n.º 7
0
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);
            }
        }
    }
}
Exemplo n.º 8
0
/**
 * Remove login sessions older than 1 hour idle
 */
function report_hook_playsmsd()
{
    global $plugin_config;
    // fetch hourly
    if (!core_playsmsd_timer(3600)) {
        return;
    }
    // login session older than 1 hour will be removed
    $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'];
}