Example #1
0
function sms_command_handle($sms_datetime, $sms_sender, $command_keyword, $command_param = '')
{
    global $datetime_now, $plugin_config;
    $ok = false;
    $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'];
    $sms_datetime = core_display_datetime($sms_datetime);
    $command_exec = str_replace("{SMSDATETIME}", "\"{$sms_datetime}\"", $command_exec);
    $command_exec = str_replace("{SMSSENDER}", "\"{$sms_sender}\"", $command_exec);
    $command_exec = str_replace("{COMMANDKEYWORD}", "\"{$command_keyword}\"", $command_exec);
    $command_exec = str_replace("{COMMANDPARAM}", "\"{$command_param}\"", $command_exec);
    $command_exec = $plugin_config['feature']['sms_command']['bin'] . "/" . $command_exec;
    $command_output = shell_exec(stripslashes($command_exec));
    $username = uid2username($db_row['uid']);
    if ($db_row['command_return_as_reply'] == 1) {
        sendsms_pv($username, $sms_sender, $command_output, 'text', 0);
    }
    $db_query = "\n\tINSERT INTO " . _DB_PREF_ . "_featureCommand_log\n\t(sms_sender,command_log_datetime,command_log_keyword,command_log_exec) \n\tVALUES\n\t('{$sms_sender}','{$datetime_now}','{$command_keyword}','{$command_exec}')\n    ";
    if ($new_id = @dba_insert_id($db_query)) {
        $ok = true;
    }
    return $ok;
}
Example #2
0
function sms_custom_handle($sms_datetime, $sms_sender, $custom_keyword, $custom_param = '')
{
    global $datetime_now;
    $ok = false;
    $db_query = "SELECT custom_url 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'];
    $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);
    $url = parse_url($custom_url);
    if (!$url['port']) {
        $url['port'] = 80;
    }
    // fixme anton -deprecated when using PHP5
    //$connection = fsockopen($url['host'],$url['port'],&$error_number,&$error_description,60);
    $connection = fsockopen($url['host'], $url['port'], $error_number, $error_description, 60);
    if ($connection) {
        socket_set_blocking($connection, false);
        fputs($connection, "GET {$custom_url} HTTP/1.0\r\n\r\n");
        $db_query = "\n\t    INSERT INTO " . _DB_PREF_ . "_featureCustom_log\n\t    (sms_sender,custom_log_datetime,custom_log_keyword,custom_log_url) \n\t    VALUES\n\t    ('{$sms_sender}','{$datetime_now}','{$custom_keyword}','{$custom_url}')\n\t";
        if ($new_id = @dba_insert_id($db_query)) {
            $ok = true;
        }
    }
    return $ok;
}
Example #3
0
function sms_board_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $board_keyword, $board_param = '')
{
    global $web_title, $email_service, $email_footer, $gateway_module, $datetime_now;
    $ok = false;
    if ($sms_sender && $board_keyword && $board_param) {
        // masked sender sets here
        $masked_sender = substr_replace($sms_sender, 'xxxx', -4);
        $db_query = "\n\t    INSERT INTO " . _DB_PREF_ . "_featureBoard_log \n\t    (in_gateway,in_sender,in_masked,in_keyword,in_msg,in_datetime) \n\t    VALUES ('{$gateway_module}','{$sms_sender}','{$masked_sender}','{$board_keyword}','{$board_param}','{$datetime_now}')\n\t";
        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 = uid2username($c_uid);
                $c_name = phonebook_number2name($sms_sender, $c_username);
                $sms_sender = $c_name ? $c_name . ' <' . $sms_sender . '>' : $sms_sender;
                $subject = "[SMSGW-" . $board_keyword . "] " . _('from') . " {$sms_sender}";
                $body = _('Forward WebSMS') . " ({$web_title})\n\n";
                $body .= _('Date and time') . ": {$sms_datetime}\n";
                $body .= _('Sender') . ": {$sms_sender}\n";
                $body .= _('Receiver') . ": {$sms_receiver}\n";
                $body .= _('Keyword') . ": {$board_keyword}\n\n";
                $body .= _('Message') . ":\n{$board_param}\n\n";
                $body .= $email_footer . "\n\n";
                sendmail($email_service, $email, $subject, $body);
            }
            $ok = true;
        }
    }
    return $ok;
}
Example #4
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;
}
Example #5
0
function nexmo_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "nexmo_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['nexmo']['module_sender']) {
        $sms_sender = $plugin_config['nexmo']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_sender && $sms_to && $sms_msg) {
        $unicode = "";
        if ($unicode) {
            if (function_exists('mb_convert_encoding')) {
                // $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
                $sms_msg = mb_convert_encoding($sms_msg, "UCS-2", "auto");
                $unicode = "&type=unicode";
                // added at the of query string if unicode
            }
        }
        $query_string = "api_key=" . $plugin_config['nexmo']['api_key'] . "&api_secret=" . $plugin_config['nexmo']['api_secret'] . "&to=" . urlencode($sms_to) . "&from=" . urlencode($sms_sender) . "&text=" . urlencode($sms_msg) . $unicode . "&status-report-req=1&client-ref=" . $smslog_id;
        $url = $plugin_config['nexmo']['url'] . "?" . $query_string;
        _log("url:[" . $url . "]", 3, "nexmo outgoing");
        // fixme anton
        // rate limit to 1 second per submit - nexmo rule
        sleep(1);
        $resp = json_decode(file_get_contents($url), true);
        if ($resp['message-count']) {
            $c_status = $resp['messages'][0]['status'];
            $c_message_id = $resp['messages'][0]['message-id'];
            $c_network = $resp['messages'][0]['network'];
            $c_error_text = $resp['messages'][0]['error-text'];
            _log("sent smslog_id:" . $smslog_id . " message_id:" . $c_message_id . " status:" . $c_status . " error:" . $c_error_text, 2, "nexmo outgoing");
            $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayNexmo (local_smslog_id,remote_smslog_id,status,network,error_text)\n\t\t\t\tVALUES ('{$smslog_id}','{$c_message_id}','{$c_status}','{$c_network}','{$c_error_text}')";
            $id = @dba_insert_id($db_query);
            if ($id && $c_status == 0) {
                $ok = true;
                $p_status = 1;
                dlr($smslog_id, $uid, $p_status);
            }
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $resp = str_replace("\n", " ", $resp);
            $resp = str_replace("\r", " ", $resp);
            _log("failed smslog_id:" . $smslog_id . " resp:" . $resp, 2, "nexmo outgoing");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Example #6
0
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;
}
Example #7
0
function simplebilling_hook_billing_post($smslog_id, $rate, $credit)
{
    global $datetime_now;
    $ok = false;
    logger_print("saving smslog_id:" . $smslog_id . " rate:" . $rate . " credit:" . $credit, 3, "simplebilling post");
    $db_query = "INSERT INTO " . _DB_PREF_ . "_tblBilling (post_datetime,smslog_id,rate,credit,status) VALUES ('{$datetime_now}','{$smslog_id}','{$rate}','{$credit}','0')";
    if ($db_result = @dba_insert_id($db_query)) {
        logger_print("saved smslog_id:" . $smslog_id, 3, "simplebilling post");
        $ok = true;
    }
    return $ok;
}
Example #8
0
function uplink_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; // global all variables needed, eg: varibles from config.php
    // ...
    // ...
    // return true or false
    // return $ok;
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "uplink_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['uplink']['module_sender']) {
        $sms_sender = $plugin_config['uplink']['module_sender'];
    }
    $sms_footer = $sms_footer ? $sms_footer : stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg) . $sms_footer;
    $ok = false;
    if ($sms_to && $sms_msg) {
        $unicode = trim($unicode) ? 1 : 0;
        $nofooter = $plugin_config['uplink']['try_disable_footer'] ? 1 : 0;
        $ws = new Playsms\Webservices();
        $ws->url = $plugin_config['uplink']['master'] . '/index.php?app=ws';
        $ws->username = $plugin_config['uplink']['username'];
        $ws->token = $plugin_config['uplink']['token'];
        $ws->to = $sms_to;
        $ws->from = $sms_sender;
        $ws->msg = $sms_msg;
        $ws->unicode = $unicode;
        $ws->nofooter = $nofooter;
        $ws->sendSms();
        // _log('url:'.$ws->getWebservicesUrl(), 3, 'uplink sendsms');
        if ($ws->getStatus()) {
            $response = $ws->getData();
            $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayUplink (up_local_smslog_id,up_remote_smslog_id,up_status,up_remote_queue_code,up_dst)\n\t\t\t\tVALUES ('{$smslog_id}','" . $response->smslog_id . "','0','" . $response->queue . "','{$sms_to}')";
            if ($up_id = @dba_insert_id($db_query)) {
                $ok = true;
            }
            _log('sendsms success. smslog_id:' . $smslog_id . ' remote_smslog_id:' . $response->smslog_id . ' remote_queue:' . $response->queue, 3, 'uplink sendsms');
        } else {
            _log('sendsms failed. error:' . $ws->getError() . ' error_string:' . $ws->getErrorString(), 3, 'uplink sendsms');
        }
    }
    if ($ok && ($response->smslog_id || $response->queue)) {
        $p_status = 0;
    } else {
        $p_status = 2;
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}
Example #9
0
function gw_send_sms($mobile_sender, $sms_sender, $sms_to, $sms_msg, $gp_code = "", $uid = "", $smslog_id = "", $flash = false)
{
    // global $uplink_param;   // global all variables needed, eg: varibles from config.php
    // ...
    // ...
    // return true or false
    // return $ok;
    global $uplink_param;
    global $gateway_number;
    $ok = false;
    if ($gateway_number) {
        $sms_from = $gateway_number;
    } else {
        $sms_from = $mobile_sender;
    }
    if ($sms_sender) {
        $sms_msg = $sms_msg . $sms_sender;
    }
    $sms_type = 2;
    // text
    if ($flash) {
        $sms_type = 1;
        // flash
    }
    if ($sms_to && $sms_msg) {
        $query_string = "ws.php?u=" . $uplink_param[username] . "&p=" . $uplink_param[password] . "&ta=pv&to=" . urlencode($sms_to) . "&from=" . urlencode($sms_from) . "&type={$sms_type}&msg=" . urlencode($sms_msg);
        $url = $uplink_param[master] . "/" . $query_string;
        $fd = @implode('', file($url));
        if ($fd) {
            $response = explode(" ", $fd);
            if ($response[0] == "OK") {
                $remote_slid = $response[1];
                if ($remote_slid) {
                    $db_query = "\n\t\t\tINSERT INTO phpgw_sms_gwmodUplink (up_local_slid,up_remote_slid,up_status)\n\t\t\tVALUES ('{$smslog_id}','{$remote_slid}','0')\n\t\t    ";
                    $up_id = @dba_insert_id($db_query);
                    if ($up_id) {
                        $ok = true;
                    }
                }
            }
        }
    }
    if (!$ok) {
        $p_status = 2;
        setsmsdeliverystatus($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Example #10
0
function sms_quiz_handle($c_uid, $sms_datetime, $sms_sender, $quiz_keyword, $quiz_param = '')
{
    global $core_config, $datetime_now;
    $ok = false;
    $username = uid2username($c_uid);
    $sms_to = $sms_sender;
    // we are replying to this sender
    $db_query = "SELECT * FROM " . _DB_PREF_ . "_featureQuiz WHERE quiz_keyword='{$quiz_keyword}'";
    $db_result = dba_query($db_query);
    $db_row = dba_fetch_array($db_result);
    if ($db_row['quiz_enable'] == 1) {
        if ($db_row['quiz_answer'] == strtoupper($quiz_param)) {
            $message = $db_row['quiz_msg_correct'];
        } else {
            $message = $db_row['quiz_msg_incorrect'];
        }
        $quiz_id = $db_row['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}','{$datetime_now}')";
        if ($logged = @dba_insert_id($db_query)) {
            //list($ok,$to,$smslog_id) = sendsms_pv($username, $sms_to, $message);
            $unicode = 0;
            if (function_exists('mb_detect_encoding')) {
                $encoding = mb_detect_encoding($message, 'auto');
                if ($encoding != 'ASCII') {
                    $unicode = 1;
                }
            }
            $ret = sendsms($core_config['main']['cfg_gateway_number'], '', $sms_to, $message, $c_uid, 0, 'text', $unicode);
            // $ok = $ok[0];
            $ok = $ret['status'];
        }
    } else {
        if ($db_row['quiz_keyword'] == $quiz_keyword) {
            // returns true even if its logged as correct/incorrect answer
            // this situation happens when user answers a disabled quiz
            // returning false will make this SMS as unhandled SMS
            $ok = true;
        }
    }
    return $ok;
}
Example #11
0
function sms_autoreply_handle($sms_datetime, $sms_sender, $c_uid, $autoreply_id, $autoreply_keyword, $autoreply_param = '')
{
    global $datetime_now;
    $ok = false;
    $autoreply_request = $autoreply_keyword . " " . $autoreply_param;
    $array_autoreply_request = explode(" ", $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\tSELECT autoreply_scenario_result FROM " . _DB_PREF_ . "_featureAutoreply_scenario \n\tWHERE autoreply_id='{$autoreply_id}' AND {$autoreply_scenario_param_list} 1=1\n    ";
    $db_result = dba_query($db_query);
    $db_row = dba_fetch_array($db_result);
    if ($autoreply_scenario_result = $db_row['autoreply_scenario_result']) {
        $db_query = "\n\t    INSERT INTO " . _DB_PREF_ . "_featureAutoreply_log\n\t    (sms_sender,autoreply_log_datetime,autoreply_log_keyword,autoreply_log_request) \n\t    VALUES\n\t    ('{$sms_sender}','{$datetime_now}','{$autoreply_keyword}','{$autoreply_request}')\n\t";
        if ($new_id = @dba_insert_id($db_query)) {
            $ok = true;
        }
    }
    if ($ok) {
        $ok = false;
        $c_username = uid2username($c_uid);
        //list($ok,$to,$smslog_id) = sendsms_pv($c_username,$sms_sender,$autoreply_scenario_result);
        //$ok = $ok[0];
        $unicode = 0;
        if (function_exists('mb_detect_encoding')) {
            $encoding = mb_detect_encoding($message, 'auto');
            if ($encoding != 'ASCII') {
                $unicode = 1;
            }
        }
        list($ok, $to, $smslog_id) = sendsms_pv($c_username, $sms_sender, $autoreply_scenario_result, 'text', $unicode);
        $ok = $ok[0];
    }
    return $ok;
}
Example #12
0
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;
}
Example #13
0
function sms_custom_handle($sms_datetime, $sms_sender, $custom_keyword, $custom_param = '')
{
    global $datetime_now;
    $ok = false;
    $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'];
    $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);
    $username = uid2username($db_row['uid']);
    $debug = dba_query("INSERT INTO " . _DB_PREF_ . "_toolsDebug (value)VALUES('{$username}')");
    $url = parse_url($custom_url);
    if (!$url['port']) {
        $url['port'] = 80;
    }
    // fixme anton -deprecated when using PHP5
    //$connection = fsockopen($url['host'],$url['port'],&$error_number,&$error_description,60);
    //fixme Edward, change to file_get_contents
    $returns = file_get_contents($custom_url);
    if ($returns) {
        //fixme Edward, change to file_get_contents
        //socket_set_blocking($connection, false);
        //fputs($connection, "GET $custom_url HTTP/1.0\r\n\r\n");
        $username = uid2username($db_row['uid']);
        if ($db_row['custom_return_as_reply'] == 1) {
            sendsms_pv($username, $sms_sender, $returns, 'text', 0);
        }
        $db_query = "\n\t    INSERT INTO " . _DB_PREF_ . "_featureCustom_log\n\t    (sms_sender,custom_log_datetime,custom_log_keyword,custom_log_url) \n\t    VALUES\n\t    ('{$sms_sender}','{$datetime_now}','{$custom_keyword}','{$custom_url}')\n\t";
        if ($new_id = @dba_insert_id($db_query)) {
            $ok = true;
        }
    }
    return $ok;
}
Example #14
0
function jasmin_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "jasmin_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['jasmin']['module_sender']) {
        $sms_sender = $plugin_config['jasmin']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_sender && $sms_to && $sms_msg) {
        $unicode_query_string = '';
        if ($unicode) {
            if (function_exists('mb_convert_encoding')) {
                // $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
                $sms_msg = mb_convert_encoding($sms_msg, "UCS-2", "auto");
                // $sms_msg = mb_convert_encoding($sms_msg, "UTF-8", "auto");
                $unicode_query_string = "&coding=8";
                // added at the of query string if unicode
            }
        }
        $query_string = "username="******"&password="******"&to=" . urlencode($sms_to) . "&from=" . urlencode($sms_sender) . "&content=" . urlencode($sms_msg) . $unicode_query_string;
        $query_string .= "&dlr=yes&dlr-level=2&dlr-url=" . urlencode($plugin_config['jasmin']['callback_url']);
        $url = $plugin_config['jasmin']['url'] . "?" . $query_string;
        _log("send url:[" . $url . "]", 3, "jasmin_hook_sendsms");
        // new way
        $opts = array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($query_string) . "\r\nConnection: close\r\n", 'content' => $query_string));
        $context = stream_context_create($opts);
        $response = file_get_contents($plugin_config['jasmin']['url'], FALSE, $context);
        // Success "07033084-5cfd-4812-90a4-e4d24ffb6e3d"
        // Error "No route found"
        $resp = explode(' ', $response, 2);
        if ($resp[0] == 'Success') {
            $c_message_id = $resp[1];
            $c_message_id = str_replace('"', '', $c_message_id);
            _log("sent smslog_id:" . $smslog_id . " message_id:" . $c_message_id . " smsc:" . $smsc, 2, "jasmin_hook_sendsms");
            $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayJasmin_log (local_smslog_id, remote_smslog_id)\n\t\t\t\tVALUES ('{$smslog_id}', '{$c_message_id}')";
            $id = @dba_insert_id($db_query);
            if ($id) {
                $ok = true;
                $p_status = 1;
                dlr($smslog_id, $uid, $p_status);
            }
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            if ($resp[0] == 'Error') {
                $resp = $resp[1];
            } else {
                $resp = $response;
            }
            _log("failed smslog_id:" . $smslog_id . " resp:[" . $resp . "] smsc:" . $smsc, 2, "jasmin_hook_sendsms");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Example #15
0
         $j++;
     }
     $content .= "</table>\n\t\t\t\t<p><input type=submit class=button value=" . _('Add') . ">\n\t\t\t\t</form>\n\t\t\t";
     echo $content;
     break;
 case "sms_autosend_add_yes":
     $add_autosend_message = $_POST['add_autosend_message'];
     $add_autosend_number = $_POST['add_autosend_number'];
     $add_autosend_time = $_POST['add_autosend_time'];
     if ($add_autosend_message && $add_autosend_number && $add_autosend_time) {
         $db_query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_featureAutosend (uid,autosend_message, autosend_number)\n\t\t\t\t\t\t\t\t\tVALUES ('{$uid}','{$add_autosend_message}','{$add_autosend_number}')\n\t\t\t\t\t\t\t\t\t";
         if ($new_uid = @dba_insert_id($db_query)) {
             foreach ($add_autosend_time as $value) {
                 $db_query = "\n\t\t\t\t\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_featureAutosend_time (autosend_id, autosend_time)\n\t\t\t\t\t\t\t\t\tVALUES ('{$new_uid}','{$value}')\n\t\t\t\t\t\t\t\t\t";
                 if ($value) {
                     $insert = dba_insert_id($db_query);
                 }
             }
             if ($insert) {
                 $error_string = _('SMS autosend has been added');
             } else {
                 $db_query = "DELETE FROM " . _DB_PREF_ . "_featureAutosend WHERE autosend_id = '" . $db_row['autosend_id'] . "'";
                 $delete = @dba_affected_rows($db_query);
             }
         } else {
             $error_string = _('Fail to add SMS autosend');
         }
     } else {
         $error_string = _('You must fill all fields');
     }
     header("Location: index.php?app=menu&inc=feature_sms_autosend&op=sms_autosend_add&err=" . urlencode($error_string));
Example #16
0
function msgtoolbox_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; // global all variables needed, eg: varibles from config.php
    // ...
    // ...
    // return true or false
    // return $ok;
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "msgtoolbox_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['msgtoolbox']['module_sender']) {
        $sms_sender = $plugin_config['msgtoolbox']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_to && $sms_msg) {
        if ($unicode) {
            if (function_exists('mb_convert_encoding')) {
                // $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
                $sms_msg = mb_convert_encoding($sms_msg, "UCS-2", "auto");
                $unicode = "&coding=unicode";
                // added at the of query string if unicode
            }
        }
        // fixme anton - from playSMS v0.9.5.1 references to input.php replaced with index.php?app=webservices
        // I should add autodetect, if its below v0.9.5.1 should use input.php
        $query_string = "username="******"&password="******"&to=" . urlencode($sms_to) . "&from=" . urlencode($sms_sender) . "&message=" . urlencode($sms_msg) . $unicode . "&route=" . $plugin_config['msgtoolbox']['route'];
        $url = $plugin_config['msgtoolbox']['url'] . "?" . $query_string;
        /*
         * not used if ($additional_param = $plugin_config['msgtoolbox']['additional_param']) { $additional_param = "&".$additional_param; } $url .= $additional_param; $url = str_replace("&&", "&", $url);
         */
        logger_print($url, 3, "msgtoolbox outgoing");
        $fd = @implode('', file($url));
        if ($fd) {
            $response = explode(",", $fd);
            if (trim($response[0]) == "1") {
                $remote_smslog_id = trim($response[1]);
                if ($remote_smslog_id) {
                    // this is for callback, if callback not used then the status would be sent or failed only
                    // local_smslog_id is local SMS log id (local smslog_id)
                    // remote_smslog_id is remote SMS log id (in API doc its referred to smsid or messageid)
                    // status=10 delivered to gateway
                    $db_query = "\n\t\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayMsgtoolbox (local_smslog_id,remote_smslog_id,status)\n\t\t\t\t\t\tVALUES ('{$smslog_id}','{$remote_smslog_id}','10')\n\t\t\t\t\t    ";
                    $id = @dba_insert_id($db_query);
                    if ($id) {
                        $ok = true;
                        $p_status = 1;
                        // sms sent
                        dlr($smslog_id, $uid, $p_status);
                    }
                }
            }
            logger_print("sent smslog_id:" . $smslog_id . " response:" . $fd, 2, "msgtoolbox outgoing");
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $fd = str_replace("\n", " ", $fd);
            $fd = str_replace("\r", " ", $fd);
            logger_print("failed smslog_id:" . $smslog_id . " response:" . $fd, 2, "msgtoolbox outgoing");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    return $ok;
}
Example #17
0
function sendsms_process($smslog_id, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid = 0, $sms_type = 'text', $unicode = 0, $queue_code = '', $smsc = '')
{
    global $user_config;
    $ok = false;
    $user = $user_config;
    if ($uid && $user['uid'] != $uid) {
        $user = user_getdatabyuid($uid);
    }
    $username = $user['username'];
    $sms_to = sendsms_getvalidnumber($sms_to);
    // now on sendsms()
    // $sms_to = sendsms_manipulate_prefix($sms_to, $user);
    $sms_datetime = core_get_datetime();
    // sent sms will be handled by plugins first
    $ret_intercept = sendsms_intercept($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $sms_type, $unicode, $smsc);
    if ($ret_intercept['modified']) {
        $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender;
        $sms_footer = $ret_intercept['param']['sms_footer'] ? $ret_intercept['param']['sms_footer'] : $sms_footer;
        $sms_to = $ret_intercept['param']['sms_to'] ? $ret_intercept['param']['sms_to'] : $sms_to;
        $sms_msg = $ret_intercept['param']['sms_msg'] ? $ret_intercept['param']['sms_msg'] : $sms_msg;
        $uid = $ret_intercept['param']['uid'] ? $ret_intercept['param']['uid'] : $uid;
        $gpid = $ret_intercept['param']['gpid'] ? $ret_intercept['param']['gpid'] : $gpid;
        $sms_type = $ret_intercept['param']['sms_type'] ? $ret_intercept['param']['sms_type'] : $sms_type;
        $unicode = $ret_intercept['param']['unicode'] ? $ret_intercept['param']['unicode'] : $unicode;
        $smsc = $ret_intercept['param']['smsc'] ? $ret_intercept['param']['smsc'] : $smsc;
    }
    // if hooked function returns cancel=true then stop the sending, return false
    if ($ret_intercept['cancel']) {
        logger_print("end with cancelled smslog_id:" . $smslog_id . " uid:" . $uid . " gpid:" . $gpid . " smsc:" . $smsc . " s:" . $sms_sender . " to:" . $sms_to . " type:" . $sms_type . " unicode:" . $unicode, 2, "sendsms_process");
        $ret['status'] = false;
        return $ret;
    }
    // get active gateway module as default gateway
    if (!$smsc) {
        $smsc = core_smsc_get();
    }
    // set no gateway if no default gateway selected
    if (!$smsc) {
        $smsc = 'blocked';
    }
    // 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
    $sms_msg = str_replace("\r\n", "\n", $sms_msg);
    // just to make sure its length, we need to stripslashes message before enter other procedures
    $sms_sender = stripslashes($sms_sender);
    $sms_msg = stripslashes($sms_msg);
    $sms_footer = stripslashes($sms_footer);
    // fixme anton - mobile number can be anything, screened by gateway
    // $sms_sender = sendsms_getvalidnumber($sms_sender);
    // fixme anton - add a space in front of $sms_footer
    if (trim($sms_footer)) {
        $sms_footer = ' ' . trim($sms_footer);
    }
    logger_print("start", 2, "sendsms_process");
    if (rate_cansend($username, strlen($sms_msg . $sms_footer), $unicode, $sms_to)) {
        $p_status = 0;
    } else {
        logger_print("end with fail not enough credit smslog_id:" . $smslog_id, 2, "sendsms_process");
        $ret['status'] = true;
        // set TRUE to stop queue
        $ret['to'] = $sms_to;
        $ret['smslog_id'] = $smslog_id;
        $ret['p_status'] = 2;
        // set failed
        return $ret;
    }
    // message entering this proc already stripslashed, we need to addslashes it before saving to db
    $sms_sender = addslashes($sms_sender);
    $sms_msg = addslashes($sms_msg);
    $sms_footer = addslashes($sms_footer);
    // we save all info first and then process with gateway module
    // the thing about this is that message saved may not be the same since gateway may not be able to process
    // message with that length or certain characters in the message are not supported by the gateway
    $db_query = "\n\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSOutgoing \n\t\t(smslog_id,uid,p_gpid,p_gateway,p_src,p_dst,p_footer,p_msg,p_datetime,p_status,p_sms_type,unicode,queue_code) \n\t\tVALUES ('{$smslog_id}','{$uid}','{$gpid}','{$smsc}','{$sms_sender}','{$sms_to}','{$sms_footer}','{$sms_msg}','{$sms_datetime}','{$p_status}','{$sms_type}','{$unicode}','{$queue_code}')";
    logger_print("saving smslog_id:" . $smslog_id . " u:" . $uid . " g:" . $gpid . " smsc:" . $smsc . " s:" . $sms_sender . " d:" . $sms_to . " type:" . $sms_type . " unicode:" . $unicode . " status:" . $p_status, 2, "sendsms");
    // continue to gateway only when save to db is true
    if ($id = @dba_insert_id($db_query)) {
        logger_print("saved smslog_id:" . $smslog_id . " id:" . $id, 2, "sendsms_process");
        if ($p_status == 0) {
            $smsc = gateway_get_smscbyname($smsc);
            logger_print("final smslog_id:" . $smslog_id . " gw:" . $smsc['gateway'] . " smsc:" . $smsc['name'] . " message:" . $sms_msg . $sms_footer . " len:" . strlen($sms_msg . $sms_footer), 3, "sendsms");
            if (core_hook($smsc['gateway'], 'sendsms', array($smsc['name'], $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $smslog_id, $sms_type, $unicode))) {
                // fixme anton - deduct user's credit as soon as gateway returns true
                rate_deduct($smslog_id);
                $ok = true;
            } else {
                logger_print("fail no hook for sendsms", 2, "sendsms_process");
            }
        }
    } else {
        logger_print("fail to save in db table smslog_id:" . $smslog_id, 2, "sendsms_process");
    }
    logger_print("end", 2, "sendsms_process");
    $ret['status'] = $ok;
    $ret['to'] = $sms_to;
    $ret['smslog_id'] = $smslog_id;
    $ret['p_status'] = $p_status;
    return $ret;
}
Example #18
0
function sendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid = 0, $sms_type = 'text', $unicode = 0)
{
    global $core_config, $gateway_module;
    $user = user_getdatabyuid($uid);
    $username = $user['username'];
    $sms_to = sendsms_getvalidnumber($sms_to);
    $sms_to = sendsms_manipulate_prefix($sms_to, $user);
    // make sure sms_datetime is in supported format and in GMT+0
    // timezone used for outgoing message is not module timezone, but default timezone
    // module gateway may have set already to +0000 (such kannel and clickatell)
    $sms_datetime = core_adjust_datetime($core_config['datetime']['now'], $core_config['main']['cfg_datetime_timezone']);
    // sent sms will be handled by plugin/tools/* first
    $ret_intercept = interceptsendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $sms_type, $unicode);
    if ($ret_intercept['modified']) {
        $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender;
        $sms_footer = $ret_intercept['param']['sms_footer'] ? $ret_intercept['param']['sms_footer'] : $sms_footer;
        $sms_to = $ret_intercept['param']['sms_to'] ? $ret_intercept['param']['sms_to'] : $sms_to;
        $sms_msg = $ret_intercept['param']['sms_msg'] ? $ret_intercept['param']['sms_msg'] : $sms_msg;
        $uid = $ret_intercept['param']['uid'] ? $ret_intercept['param']['uid'] : $uid;
        $gpid = $ret_intercept['param']['gpid'] ? $ret_intercept['param']['gpid'] : $gpid;
        $sms_type = $ret_intercept['param']['sms_type'] ? $ret_intercept['param']['sms_type'] : $sms_type;
        $unicode = $ret_intercept['param']['unicode'] ? $ret_intercept['param']['unicode'] : $unicode;
    }
    // if hooked function returns cancel=true then stop the sending, return false
    if ($ret_intercept['cancel']) {
        logger_print("cancelled:{$uid},{$gpid},{$gateway_module},{$sms_sender},{$sms_to},{$sms_type},{$unicode}", 3, "sendsms");
        $ret['status'] = false;
        return $ret;
    }
    // fixme anton - mobile number can be anything, screened by gateway
    // $sms_sender = sendsms_getvalidnumber($sms_sender);
    $ok = false;
    logger_print("start", 3, "sendsms");
    if (rate_cansend($username, $sms_to)) {
        // fixme anton - its a total mess ! need another DBA - we dont need this anymore
        //$sms_footer = addslashes(trim($sms_footer));
        //$sms_msg = addslashes($sms_msg);
        // we save all info first and then process with gateway module
        // the thing about this is that message saved may not be the same since gateway may not be able to process
        // message with that length or certain characters in the message are not supported by the gateway
        $db_query = "\n\t\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSOutgoing \n\t\t\t(uid,p_gpid,p_gateway,p_src,p_dst,p_footer,p_msg,p_datetime,p_sms_type,unicode) \n\t\t\tVALUES ('{$uid}','{$gpid}','{$gateway_module}','{$sms_sender}','{$sms_to}','{$sms_footer}','{$sms_msg}','{$sms_datetime}','{$sms_type}','{$unicode}')\n\t\t";
        logger_print("saving:{$uid},{$gpid},{$gateway_module},{$sms_sender},{$sms_to},{$sms_type},{$unicode}", 3, "sendsms");
        // continue to gateway only when save to db is true
        if ($smslog_id = @dba_insert_id($db_query)) {
            logger_print("smslog_id:" . $smslog_id . " saved", 3, "sendsms");
            // fixme anton - another mess with slashes! also trim $sms_footer and prefix it with a space
            $sms_footer = ' ' . stripslashes(trim($sms_footer));
            $sms_msg = stripslashes($sms_msg);
            if (x_hook($gateway_module, 'sendsms', array($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $smslog_id, $sms_type, $unicode))) {
                // fixme anton - deduct user's credit as soon as gateway returns true
                rate_deduct($smslog_id);
                $ok = true;
            }
        }
    }
    logger_print("end", 3, "sendsms");
    $ret['status'] = $ok;
    $ret['smslog_id'] = $smslog_id;
    return $ret;
}
Example #19
0
        break;
    case "user_add_yes":
        $add_email = $_POST['add_email'];
        $add_username = $_POST['add_username'];
        $add_name = $_POST['add_name'];
        $add_mobile = $_POST['add_mobile'];
        $add_sender = $_POST['add_sender'];
        $add_footer = $_POST['add_footer'];
        $add_password = $_POST['add_password'];
        $add_credit = $_POST['add_credit'];
        $add_status = $_POST['add_status'];
        $add_timezone = $_POST['add_timezone'];
        $add_language_module = $_POST['add_language_module'];
        if (ereg("^(.+)(.+)\\.(.+)\$", $add_email, $arr) && $add_email && $add_username && $add_name && $add_password) {
            $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblUser WHERE username='******'";
            $db_result = dba_query($db_query);
            if ($db_row = dba_fetch_array($db_result)) {
                $error_string = _('User is already exists') . " (" . _('username') . ": `" . $db_row['username'] . "`)";
            } else {
                $db_query = "\n\t\t    INSERT INTO " . _DB_PREF_ . "_tblUser (status,username,password,name,mobile,email,sender,footer,credit,datetime_timezone,language_module)\n\t\t    VALUES ('{$add_status}','{$add_username}','{$add_password}','{$add_name}','{$add_mobile}','{$add_email}','{$add_sender}','{$add_footer}','{$add_credit}','{$add_timezone}','{$add_language_module}')\n\t\t";
                if ($new_uid = @dba_insert_id($db_query)) {
                    rate_setusercredit($new_uid, $add_credit);
                    $error_string = _('User has been added') . " (" . _('username') . ": `{$add_username}`)";
                }
            }
        } else {
            $error_string = _('You must fill all fields');
        }
        header("Location: index.php?app=menu&inc=user_mgmnt&op=user_add&err=" . urlencode($error_string));
        break;
}
Example #20
0
function dba_add($db_table, $items)
{
    $ret = false;
    if (is_array($items)) {
        foreach ($items as $key => $val) {
            $sets .= $key . ",";
            $vals .= "'" . $val . "',";
        }
        if ($sets && $vals) {
            $sets = substr($sets, 0, -1);
            $vals = substr($vals, 0, -1);
            $db_query = "INSERT INTO " . $db_table . " (" . $sets . ") VALUES (" . $vals . ")";
            if ($c_id = dba_insert_id($db_query)) {
                $ret = $c_id;
            }
        }
    }
    return $ret;
}
Example #21
0
/**
 * Add IP address to blacklist
 *
 * @param string $label
 *        single label, can be $username or $uid, its up to the implementator
 * @param string $ip
 *        single IP address
 * @return boolean TRUE on added
 */
function firewall_hook_blacklist_addip($label, $ip)
{
    $ret = FALSE;
    $uid = user_username2uid($label);
    $db_query = "\n\t\t\tINSERT INTO " . _DB_PREF_ . "_featureFirewall (uid, ip_address)\n\t\t\tVALUES ('{$uid}', '{$ip}')";
    if (!blacklist_ifipexists($label, $ip)) {
        $new_ip = @dba_insert_id($db_query);
        if ($new_ip) {
            _log('add IP to blacklist ip:' . $new_ip . ' uid:' . $uid, 2, 'firewall_hook_blacklist_addip');
            $ret = TRUE;
        }
    }
    return $ret;
}
Example #22
0
function insertsmstoinbox($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver = "")
{
    global $core_config, $web_title, $email_service, $email_footer;
    // sms to inbox will be handled by plugin/tools/* first
    $ret_intercept = interceptsmstoinbox($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver);
    if ($ret_intercept['param_modified']) {
        $sms_datetime = $ret_intercept['param']['sms_datetime'] ? $ret_intercept['param']['sms_datetime'] : $sms_datetime;
        $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender;
        $target_user = $ret_intercept['param']['target_user'] ? $ret_intercept['param']['target_user'] : $target_user;
        $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message;
        $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver;
    }
    $ok = false;
    if ($sms_sender && $target_user && $message) {
        $user = user_getdatabyusername($target_user);
        if ($uid = $user['uid']) {
            // forward to Inbox
            if ($fwd_to_inbox = $user['fwd_to_inbox']) {
                $db_query = "\n\t\t    INSERT INTO " . _DB_PREF_ . "_tblUserInbox\n\t\t    (in_sender,in_receiver,in_uid,in_msg,in_datetime) \n\t\t    VALUES ('{$sms_sender}','{$sms_receiver}','{$uid}','{$message}','{$sms_datetime}')\n\t\t";
                logger_print("saving sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user, 3, "insertsmstoinbox");
                if ($cek_ok = @dba_insert_id($db_query)) {
                    logger_print("saved sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user, 3, "insertsmstoinbox");
                }
            }
            // forward to email
            if ($fwd_to_email = $user['fwd_to_email']) {
                if ($email = $user['email']) {
                    // make sure sms_datetime is in supported format and in user's timezone
                    $sms_datetime = core_display_datetime($sms_datetime);
                    // get name from target_user's phonebook
                    $c_name = phonebook_number2name($sms_sender, $target_user);
                    $sender = $c_name ? $c_name . ' <' . $sms_sender . '>' : $sms_sender;
                    // fixme anton - slash maddess
                    $message = stripslashes($message);
                    $subject = "[SMSGW-PV] " . _('from') . " {$sms_sender}";
                    $body = _('Forward Private WebSMS') . " ({$web_title})\n\n";
                    $body .= _('Date time') . ": {$sms_datetime}\n";
                    $body .= _('Sender') . ": {$sender}\n";
                    $body .= _('Receiver') . ": {$sms_receiver}\n\n";
                    $body .= _('Message') . ":\n{$message}\n\n";
                    $body .= $email_footer . "\n\n";
                    logger_print("send email from:" . $email_service . " to:" . $email, 3, "insertsmstoinbox");
                    sendmail($email_service, $email, $subject, $body);
                    logger_print("sent email from:" . $email_service . " to:" . $email, 3, "insertsmstoinbox");
                }
                $ok = true;
            }
            // forward to mobile
            if ($fwd_to_mobile = $user['fwd_to_mobile']) {
                if ($mobile = $user['mobile']) {
                    $unicode = 0;
                    if (function_exists('mb_detect_encoding')) {
                        $encoding = mb_detect_encoding($message, 'auto');
                        if ($encoding != 'ASCII') {
                            $unicode = 1;
                        }
                    }
                    $message = $sender . ' ' . $message;
                    logger_print("send to mobile:" . $mobile . " from:" . $sender . " user:"******"insertsmstoinbox");
                    list($ok, $to, $smslog_id) = sendsms_pv($target_user, $mobile, $message, 'text', $unicode);
                    if ($ok[0]) {
                        logger_print("sent to mobile:" . $mobile . " from:" . $sender . " user:"******"insertsmstoinbox");
                    }
                }
            }
        }
    }
    return $ok;
}
Example #23
0
     $db_row = dba_fetch_array($db_result);
     if ($err = TRUE) {
         $content = _dialog();
     }
     $content .= "\n\t\t\t<h2>" . _('Message template') . "</h2>\n\t\t\t<h3>" . _('Edit message template') . "</h3>\n\t\t\t<form action='index.php?app=main&inc=feature_msgtemplate&op=actions&go=edit' method=POST>\n\t\t\t" . _CSRF_FORM_ . "\n\t\t\t<input type=hidden name=item_count value='" . $i . "'>\n\t\t\t<input type=hidden name=tid value='" . $tid . "'>\n\t\t\t<table class=playsms-table>\n\t\t\t<tr>\n\t\t\t\t<td class=label-sizer>" . _('Message template name') . "</td><td><input type=text maxlength=100 name=t_title value='" . $db_row['t_title'] . "'></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td>" . _('Message template content') . "</td><td><input type=text name=t_text value='" . $db_row['t_text'] . "'></td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<input type='hidden' name='item_count' value='{$i}'>\n\t\t\t<p><input type='submit' class='button' value='" . _('Save') . "'></p>\n\t\t\t</form>\n\t\t\t" . _back('index.php?app=main&inc=feature_msgtemplate&op=list');
     _p($content);
     break;
 case "actions":
     $go = $_REQUEST['go'];
     switch ($go) {
         case "add":
             $t_title = $_POST['t_title'];
             $t_text = $_POST['t_text'];
             if ($t_title && $t_text) {
                 $db_query = "INSERT INTO " . _DB_PREF_ . "_featureMsgtemplate (uid,t_title,t_text) VALUES ('" . $user_config['uid'] . "','{$t_title}','{$t_text}')";
                 $db_result = dba_insert_id($db_query);
                 if ($db_result > 0) {
                     $_SESSION['dialog']['info'][] = _('Message template has been saved');
                 } else {
                     $_SESSION['dialog']['info'][] = _('Fail to add message template');
                 }
             } else {
                 $_SESSION['dialog']['info'][] = _('You must fill all fields');
             }
             header("Location: " . _u('index.php?app=main&inc=feature_msgtemplate&op=add'));
             exit;
             break;
         case "edit":
             $t_title = $_POST['t_title'];
             $t_text = $_POST['t_text'];
             if ($t_title && $t_text) {
Example #24
0
function logger_set_error_string($error_string)
{
    $db_query = "INSERT INTO " . _DB_PREF_ . "_tblErrorString (error_string) VALUES ('{$error_string}')";
    $id = @dba_insert_id($db_query);
    return $id;
}
Example #25
0
function twilio_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "twilio_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['twilio']['module_sender']) {
        $sms_sender = $plugin_config['twilio']['module_sender'];
    }
    $sms_footer = stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg);
    $ok = false;
    logger_print("sendsms start", 3, "twilio_hook_sendsms");
    if ($sms_footer) {
        $sms_msg = $sms_msg . $sms_footer;
    }
    if ($sms_sender && $sms_to && $sms_msg) {
        $url = $plugin_config['twilio']['url'] . '/2010-04-01/Accounts/' . $plugin_config['twilio']['account_sid'] . '/SMS/Messages.json';
        $data = array('To' => $sms_to, 'From' => $sms_sender, 'Body' => $sms_msg);
        if (trim($plugin_config['twilio']['callback_url'])) {
            $data['StatusCallback'] = trim($plugin_config['twilio']['callback_url']);
        }
        if (function_exists('curl_init')) {
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_USERPWD, $plugin_config['twilio']['account_sid'] . ':' . $plugin_config['twilio']['auth_token']);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            $returns = curl_exec($ch);
            curl_close($ch);
            logger_print("url:" . $url . " callback:" . $plugin_config['twilio']['callback_url'], 3, "twilio outgoing");
            $resp = json_decode($returns);
            if ($resp->status) {
                $c_status = $resp->status;
                $c_message_id = $resp->sid;
                $c_error_text = $c_status . '|' . $resp->code . '|' . $resp->message;
                logger_print("sent smslog_id:" . $smslog_id . " message_id:" . $c_message_id . " status:" . $c_status . " error:" . $c_error_text, 2, "twilio outgoing");
                $db_query = "\n\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayTwilio (local_smslog_id,remote_smslog_id,status,error_text)\n\t\t\t\t\tVALUES ('{$smslog_id}','{$c_message_id}','{$c_status}','{$c_error_text}')";
                $id = @dba_insert_id($db_query);
                if ($id && $c_status == 'queued') {
                    $ok = true;
                    $p_status = 0;
                } else {
                    $p_status = 2;
                }
                dlr($smslog_id, $uid, $p_status);
            } else {
                // even when the response is not what we expected we still print it out for debug purposes
                $resp = str_replace("\n", " ", $resp);
                $resp = str_replace("\r", " ", $resp);
                logger_print("failed smslog_id:" . $smslog_id . " resp:" . $resp, 2, "twilio outgoing");
            }
        } else {
            logger_print("fail to sendsms due to missing PHP curl functions", 3, "twilio_hook_sendsms");
        }
    }
    if (!$ok) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
    logger_print("sendsms end", 3, "twilio_hook_sendsms");
    return $ok;
}
Example #26
0
File: fn.php Project: borkz/playSMS
function smstools_hook_getsmsstatus($gpid = 0, $uid = '', $smslog_id = '', $p_datetime = '', $p_update = '')
{
    global $plugin_config;
    $plugin_config['smstools']['backup'] = $plugin_config['smstools']['default_queue'] . '/backup';
    if (!is_dir($plugin_config['smstools']['backup'] . '/sent')) {
        mkdir($plugin_config['smstools']['backup'] . '/sent', 0777, TRUE);
    }
    if (!is_dir($plugin_config['smstools']['backup'] . '/failed')) {
        mkdir($plugin_config['smstools']['backup'] . '/failed', 0777, TRUE);
    }
    // outfile
    $gpid = (int) $gpid ? (int) $gpid : 0;
    $uid = (int) $uid ? (int) $uid : 0;
    $smslog_id = (int) $smslog_id ? (int) $smslog_id : 0;
    $sms_id = $gpid . '.' . $uid . '.' . $smslog_id;
    $outfile = 'out.' . $sms_id;
    $fn = $plugin_config['smstools']['default_queue'] . '/sent/' . $outfile;
    $efn = $plugin_config['smstools']['default_queue'] . '/failed/' . $outfile;
    // set if its sent
    if (file_exists($fn)) {
        $message_id = 0;
        $lines = @file($fn);
        for ($c = 0; $c < count($lines); $c++) {
            $c_line = $lines[$c];
            if (preg_match('/^Message_id: /', $c_line)) {
                $message_id = trim(str_replace('Message_id: ', '', trim($c_line)));
                if ($message_id) {
                    break;
                }
            }
        }
        if ($message_id) {
            if (!rename($fn, $plugin_config['smstools']['backup'] . '/sent/' . $outfile)) {
                if (file_exists($fn)) {
                    @unlink($fn);
                }
            }
            if (!file_exists($fn)) {
                if ($smslog_id && $message_id) {
                    $db_query = "\n\t\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewaySmstools_dlr \n\t\t\t\t\t\t(c_timestamp,uid,smslog_id,message_id,status) \n\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t('" . mktime() . "','" . $uid . "','" . $smslog_id . "','" . $message_id . "','1')";
                    $dlr_id = dba_insert_id($db_query);
                    if ($dlr_id) {
                        _log('DLR mapped fn:' . $fn . ' id:' . $dlr_id . ' uid:' . $uid . ' smslog_id:' . $smslog_id . ' message_id:' . $message_id, 2, 'smstools_hook_getsmsstatus');
                    } else {
                        _log('Fail to map DLR fn:' . $fn . ' id:' . $dlr_id . ' uid:' . $uid . ' smslog_id:' . $smslog_id . ' message_id:' . $message_id, 2, 'smstools_hook_getsmsstatus');
                    }
                } else {
                    _log('No valid DLR fn:' . $fn . ' uid:' . $uid . ' smslog_id:' . $smslog_id . ' message_id:' . $message_id, 2, 'smstools_hook_getsmsstatus');
                }
                if ($smslog_id) {
                    $p_status = 1;
                    dlr($smslog_id, $uid, $p_status);
                } else {
                    _log('Error no smslog_id fn:' . $fn . ' uid:' . $uid, 2, 'smstools_hook_getsmsstatus');
                }
            }
        }
    }
    // set if its failed
    if (file_exists($efn)) {
        if (!rename($efn, $plugin_config['smstools']['backup'] . '/failed/' . $outfile)) {
            if (file_exists($efn)) {
                @unlink($efn);
            }
        }
        if ($smslog_id) {
            $p_status = 2;
            dlr($smslog_id, $uid, $p_status);
        } else {
            _log('Error no smslog_id efn:' . $efn . ' uid:' . $uid, 2, 'smstools_hook_getsmsstatus');
        }
    }
    // set failed if its at least 2 days old
    $p_datetime_stamp = strtotime($p_datetime);
    $p_update_stamp = strtotime($p_update);
    $p_delay = floor(($p_update_stamp - $p_datetime_stamp) / 86400);
    if ($smslog_id && $p_delay >= 2) {
        $p_status = 2;
        dlr($smslog_id, $uid, $p_status);
    }
}
Example #27
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 #28
0
     break;
 case "sms_poll_add_yes":
     $add_poll_keyword = strtoupper($_POST['add_poll_keyword']);
     $add_poll_title = $_POST['add_poll_title'];
     $add_poll_access_code = $_POST['add_poll_access_code'];
     $add_poll_option_vote = (int) $_POST['add_poll_option_vote'];
     $add_poll_message_option = $_POST['add_poll_message_option'];
     $add_poll_message_valid = $_POST['add_poll_message_valid'];
     $add_poll_message_invalid = $_POST['add_poll_message_invalid'];
     if (auth_isadmin()) {
         $add_smsc = $_POST['add_smsc'];
     }
     if ($add_poll_title && $add_poll_keyword && $add_poll_message_valid && $add_poll_message_invalid) {
         if (checkavailablekeyword($add_poll_keyword)) {
             $db_query = "\n\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_featurePoll (uid,poll_keyword,poll_title,poll_access_code,poll_option_vote,poll_message_option,poll_message_valid,poll_message_invalid,smsc)\n\t\t\t\t\tVALUES ('" . $user_config['uid'] . "','{$add_poll_keyword}','{$add_poll_title}','{$add_poll_access_code}','{$add_poll_option_vote}','{$add_poll_message_option}','{$add_poll_message_valid}','{$add_poll_message_invalid}','{$add_smsc}')";
             if ($new_poll_id = @dba_insert_id($db_query)) {
                 $_SESSION['error_string'] = _('SMS poll has been added') . " (" . _('keyword') . ": {$add_poll_keyword})";
             } else {
                 $_SESSION['error_string'] = _('Fail to add SMS poll') . " (" . _('keyword') . ": {$add_poll_keyword})";
             }
         } else {
             $_SESSION['error_string'] = _('SMS poll already exists, reserved or use by other feature') . " (" . _('keyword') . ": {$add_poll_keyword})";
         }
     } else {
         $_SESSION['error_string'] = _('You must fill all fields');
     }
     if ($new_poll_id) {
         header("Location: " . _u('index.php?app=main&inc=feature_sms_poll&op=sms_poll_edit&poll_id=' . $new_poll_id));
     } else {
         header("Location: " . _u('index.php?app=main&inc=feature_sms_poll&op=sms_poll_add'));
     }
Example #29
0
/**
 * Process register an account
 *
 */
function auth_register()
{
    global $core_config;
    $ok = false;
    if ($core_config['main']['cfg_enable_register']) {
        $username = trim($_REQUEST['username']);
        $email = trim($_REQUEST['email']);
        $name = trim($_REQUEST['name']);
        $mobile = trim($_REQUEST['mobile']);
        $error_string = _('Fail to register an account');
        if ($username && $email && $name && $mobile) {
            $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblUser WHERE username='******'";
            $db_result = dba_query($db_query);
            if ($db_row = dba_fetch_array($db_result)) {
                $error_string = _('User is already exists') . " (" . _('username') . ": `" . $username . "`)";
            } else {
                $password = substr(md5(time()), 0, 6);
                $sender = ' - ' . $username;
                if (ereg("^(.+)(.+)\\.(.+)\$", $email, $arr)) {
                    // by default the status is 3 (normal user)
                    $db_query = "\n\t\t\tINSERT INTO " . _DB_PREF_ . "_tblUser (status,username,password,name,mobile,email,sender,credit)\n\t\t\tVALUES ('3','{$username}','{$password}','{$name}','{$mobile}','{$email}','{$sender}','" . $core_config['main']['cfg_default_credit'] . "')\n\t\t    ";
                    if ($new_uid = @dba_insert_id($db_query)) {
                        $ok = true;
                    }
                }
            }
            if ($ok) {
                logger_print("u:" . $username . " email:" . $email . " ip:" . $_SERVER['REMOTE_ADDR'], 3, "register");
                $subject = "[SMSGW] " . _('New account registration');
                $body = $core_config['main']['cfg_web_title'] . "\n";
                $body .= $core_config['http_path']['base'] . "\n\n";
                $body .= _('Username') . "\t: {$username}\n";
                $body .= _('Password') . "\t: {$password}\n\n";
                $body .= $core_config['main']['cfg_email_footer'] . "\n\n";
                $error_string = _('User has been added') . " (" . _('username') . ": `" . $username . "`)";
                $error_string .= "<br />";
                if (sendmail($core_config['main']['cfg_email_service'], $email, $subject, $body)) {
                    $error_string .= _('Password has been sent to your email');
                } else {
                    $error_string .= _('Fail to send email');
                }
            }
        }
    } else {
        $error_string = _('Public registration disabled');
    }
    $errid = logger_set_error_string($error_string);
    header("Location: " . $core_config['http_path']['base'] . "?errid=" . $errid);
    exit;
}
Example #30
0
function uplink_hook_sendsms($mobile_sender, $sms_sender, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    // global $uplink_param;   // global all variables needed, eg: varibles from config.php
    // ...
    // ...
    // return true or false
    // return $ok;
    global $uplink_param;
    global $gateway_number;
    $ok = false;
    if ($uplink_param['global_sender']) {
        $sms_from = $uplink_param['global_sender'];
    } else {
        if ($gateway_number) {
            $sms_from = $gateway_number;
        } else {
            $sms_from = $mobile_sender;
        }
    }
    if ($sms_sender) {
        $sms_msg = $sms_msg . $sms_sender;
    }
    $sms_type = 2;
    // text
    if ($msg_type == "flash") {
        $sms_type = 1;
        // flash
    }
    if ($sms_to && $sms_msg) {
        if ($unicode) {
            // fixme anton - this isn't right, encoding should be done in master, not locally
            /*
            if (function_exists('mb_convert_encoding')) {
            $sms_msg = mb_convert_encoding($sms_msg, "UCS-2BE", "auto");
            }
            */
            $unicode = 1;
        }
        // fixme anton - from playSMS v0.9.5.1 references to input.php replaced with index.php?app=webservices
        // I should add autodetect, if its below v0.9.5.1 should use input.php
        $query_string = "index.php?app=webservices&u=" . $uplink_param['username'] . "&p=" . $uplink_param['password'] . "&ta=pv&to=" . urlencode($sms_to) . "&from=" . urlencode($sms_from) . "&type={$sms_type}&msg=" . urlencode($sms_msg) . "&unicode=" . $unicode;
        $url = $uplink_param['master'] . "/" . $query_string;
        if ($additional_param = $uplink_param['additional_param']) {
            $additional_param = "&" . $additional_param;
        }
        $url .= $additional_param;
        $url = str_replace("&&", "&", $url);
        logger_print($url, 3, "uplink outgoing");
        $fd = @implode('', file($url));
        if ($fd) {
            $response = split(" ", $fd);
            if ($response[0] == "OK") {
                $remote_slid = $response[1];
                if ($remote_slid) {
                    $db_query = "\n\t\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayUplink (up_local_slid,up_remote_slid,up_status)\n\t\t\t\t\t\tVALUES ('{$smslog_id}','{$remote_slid}','0')\n\t\t\t\t\t    ";
                    $up_id = @dba_insert_id($db_query);
                    if ($up_id) {
                        $ok = true;
                    }
                }
            }
            logger_print("smslog_id:" . $smslog_id . " response:" . $response[0] . " " . $response[1], 3, "uplink outgoing");
        } else {
            // even when the response is not what we expected we still print it out for debug purposes
            $fd = str_replace("\n", " ", $fd);
            $fd = str_replace("\r", " ", $fd);
            logger_print("smslog_id:" . $smslog_id . " response:" . $fd, 3, "clickatell outgoing");
        }
    }
    if (!$ok) {
        $p_status = 2;
        setsmsdeliverystatus($smslog_id, $uid, $p_status);
    }
    return $ok;
}