Exemplo n.º 1
0
/**
 * Get site configuration
 *
 * @param integer $uid
 *        User ID
 * @return array Site configuration
 */
function site_config_get($uid = 0)
{
    global $user_config, $plugin_config;
    $c_uid = (int) $uid ? (int) $uid : $user_config['uid'];
    $reg = registry_search($c_uid, 'core', 'site_config');
    $plugin_config['site']['site_config'] = $reg['core']['site_config'];
    return $plugin_config['site']['site_config'];
}
Exemplo n.º 2
0
/**
 * Get pre rules
 *
 * @return array Pre rules
 *         Available pre rules keys:
 *         - match_username
 *         - match_groupcode
 */
function incoming_pre_rules_get()
{
    // scan message for @username
    $data = registry_search(1, 'feature', 'incoming', 'incoming_match_username');
    $pre_rules['match_username'] = (int) $data['feature']['incoming']['incoming_match_username'];
    // scan message for #groupcode
    $data = registry_search(1, 'feature', 'incoming', 'incoming_match_groupcode');
    $pre_rules['match_groupcode'] = (int) $data['feature']['incoming']['incoming_match_groupcode'];
    return $pre_rules;
}
Exemplo n.º 3
0
/**
 * Check if IP address deserved to get listed in blacklist, if deserved then blacklist_addip()
 *
 * @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 checked (not necessarily added)
 */
function firewall_hook_blacklist_checkip($label, $ip)
{
    global $plugin_config;
    $ret = FALSE;
    $hash = md5($label . $ip);
    $data = registry_search(0, 'feature', 'firewall');
    $login_attempt = $data['feature']['firewall'][$hash];
    if ($login_attempt > $plugin_config['firewall']['login_attempt_limit']) {
        blacklist_addip($label, $ip);
    }
    $items[$hash] = $login_attempt ? $login_attempt + 1 : 1;
    if (registry_update(0, 'feature', 'firewall', $items)) {
        $ret = TRUE;
    }
    return $ret;
}
Exemplo n.º 4
0
/**
 * Validate username and password
 *
 * @param string $username
 *        Username
 * @param string $password
 *        Password
 * @return boolean TRUE when validated or boolean FALSE when validation failed
 */
function auth_validate_login($username, $password)
{
    $uid = user_username2uid($username);
    _log('login attempt u:' . $username . ' uid:' . $uid . ' p:' . md5($password) . ' ip:' . $_SERVER['REMOTE_ADDR'], 3, 'auth_validate_login');
    // check blacklist
    if (blacklist_ifipexists($username, $_SERVER['REMOTE_ADDR'])) {
        _log('IP blacklisted u:' . $username . ' uid:' . $uid . ' ip:' . $_SERVER['REMOTE_ADDR'], 2, 'auth_validate_login');
        return FALSE;
    }
    if (user_banned_get($uid)) {
        _log('user banned u:' . $username . ' uid:' . $uid . ' ip:' . $_SERVER['REMOTE_ADDR'], 2, 'auth_validate_login');
        return FALSE;
    }
    $db_query = "SELECT password FROM " . _DB_PREF_ . "_tblUser WHERE flag_deleted='0' AND username='******'";
    $db_result = dba_query($db_query);
    $db_row = dba_fetch_array($db_result);
    $res_password = trim($db_row['password']);
    $password = md5($password);
    if ($password && $res_password && $password == $res_password) {
        _log('valid login u:' . $username . ' uid:' . $uid . ' ip:' . $_SERVER['REMOTE_ADDR'], 2, 'auth_validate_login');
        // remove IP on successful login
        blacklist_clearip($username, $_SERVER['REMOTE_ADDR']);
        return true;
    } else {
        $ret = registry_search(1, 'auth', 'tmp_password', $username);
        $tmp_password = $ret['auth']['tmp_password'][$username];
        if ($password && $tmp_password && $password == $tmp_password) {
            _log('valid login u:' . $username . ' uid:' . $uid . ' ip:' . $_SERVER['REMOTE_ADDR'] . ' using temporary password', 2, 'auth_validate_login');
            if (!registry_remove(1, 'auth', 'tmp_password', $username)) {
                _log('WARNING: unable to remove temporary password after successful login', 3, 'login');
            }
            // remove IP on successful login
            blacklist_clearip($username, $_SERVER['REMOTE_ADDR']);
            return true;
        }
    }
    // check blacklist
    blacklist_checkip($username, $_SERVER['REMOTE_ADDR']);
    _log('invalid login u:' . $username . ' uid:' . $uid . ' ip:' . $_SERVER['REMOTE_ADDR'], 2, 'auth_validate_login');
    return false;
}
Exemplo n.º 5
0
             $json['status'] = 'ERR';
             $json['error'] = '100';
         }
     } else {
         $json['status'] = 'ERR';
         $json['error'] = '100';
     }
     $log_this = TRUE;
     break;
 case "WS_LOGIN":
     $user = user_getdatabyusername($u);
     if ($c_uid = $user['uid']) {
         // supplied login key
         $login_key = trim($_REQUEST['login_key']);
         // saved login key
         $reg = registry_search($c_uid, 'core', 'webservices', 'login_key');
         $c_login_key = trim($reg['core']['webservices']['login_key']);
         // immediately remove saved login key, only proceed upon successful removal
         if (registry_remove($c_uid, 'core', 'webservices', 'login_key')) {
             // auth by comparing login keys
             if ($login_key && $c_login_key && $login_key == $c_login_key) {
                 // setup login session
                 auth_session_setup($c_uid);
                 _log("webservices logged in u:" . $u . " ip:" . $_SERVER['REMOTE_ADDR'] . " op:" . _OP_, 3, "webservices");
             } else {
                 _log("webservices invalid login u:" . $u . " ip:" . $_SERVER['REMOTE_ADDR'] . " op:" . _OP_, 3, "webservices");
             }
         } else {
             _log("webservices error unable to remove registry u:" . $u . " ip:" . $_SERVER['REMOTE_ADDR'] . " op:" . _OP_, 3, "webservices");
         }
     } else {
Exemplo n.º 6
0
<?php

defined('_SECURE_') or die('Forbidden');
$callback_url = '';
if (!$core_config['daemon_process']) {
    $callback_url = $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/plugin/gateway/generic/callback.php";
    $callback_url = str_replace("//", "/", $callback_url);
    $callback_url = ($core_config['ishttps'] ? "https://" : "http://") . $callback_url;
}
$data = registry_search(0, 'gateway', 'generic');
$plugin_config['generic'] = $data['gateway']['generic'];
$plugin_config['generic']['name'] = 'generic';
$plugin_config['generic']['default_url'] = 'http://example.api.url/handler.php?user={GENERIC_API_USERNAME}&pwd={GENERIC_API_PASSWORD}&sender={GENERIC_SENDER}&msisdn={GENERIC_TO}&message={GENERIC_MESSAGE}';
$plugin_config['generic']['default_callback_url'] = $callback_url;
if (!trim($plugin_config['generic']['url'])) {
    $plugin_config['generic']['url'] = $plugin_config['generic']['default_url'];
}
if (!trim($plugin_config['generic']['callback_url'])) {
    $plugin_config['generic']['callback_url'] = $plugin_config['generic']['default_callback_url'];
}
if (!trim($plugin_config['generic']['callback_url_authcode'])) {
    $plugin_config['generic']['callback_url_authcode'] = sha1(_PID_);
}
// smsc configuration
$plugin_config['generic']['_smsc_config_'] = array('url' => _('Generic send SMS URL'), 'api_username' => _('API username'), 'api_password' => _('API password'), 'module_sender' => _('Module sender ID'), 'datetime_timezone' => _('Module timezone'));
Exemplo n.º 7
0
<?php

defined('_SECURE_') or die('Forbidden');
$callback_url = '';
if (!$core_config['daemon_process']) {
    $callback_url = $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/plugin/gateway/jasmin/callback.php";
    $callback_url = str_replace("//", "/", $callback_url);
    $callback_url = ($core_config['ishttps'] ? "https://" : "http://") . $callback_url;
}
$data = registry_search(0, 'gateway', 'jasmin');
$plugin_config['jasmin'] = $data['gateway']['jasmin'];
$plugin_config['jasmin']['name'] = 'jasmin';
$plugin_config['jasmin']['default_url'] = 'https://127.0.0.1:1401/send';
$plugin_config['jasmin']['default_callback_url'] = $callback_url;
if (!trim($plugin_config['jasmin']['url'])) {
    $plugin_config['jasmin']['url'] = $plugin_config['jasmin']['default_url'];
}
if (!trim($plugin_config['jasmin']['callback_url'])) {
    $plugin_config['jasmin']['callback_url'] = $plugin_config['jasmin']['default_callback_url'];
}
// smsc configuration
$plugin_config['jasmin']['_smsc_config_'] = array('url' => _('Jasmin send SMS URL'), 'callback_url' => _('Callback URL'), 'api_username' => _('API username'), 'api_password' => _('API password'), 'module_sender' => _('Module sender ID'), 'datetime_timezone' => _('Module timezone'));
Exemplo n.º 8
0
 *
 * You should have received a copy of the GNU General Public License
 * along with playSMS.  If not, see <http://www.gnu.org/licenses/>.
 */
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
Exemplo n.º 9
0
/**
 * Get playSMS version
 *
 * @return string
 */
function core_get_version()
{
    $version = registry_search(1, 'core', 'config', 'playsms_version');
    if ($version = $version['core']['config']['playsms_version']) {
        return $version;
    } else {
        return '';
    }
}
Exemplo n.º 10
0
<?php

defined('_SECURE_') or die('Forbidden');
// get kannel config from registry
$data = registry_search(1, 'gateway', 'kannel');
$plugin_config['kannel'] = $data['gateway']['kannel'];
$plugin_config['kannel']['name'] = 'kannel';
$plugin_config['kannel']['bearerbox_host'] = $plugin_config['kannel']['bearerbox_host'] ? $plugin_config['kannel']['bearerbox_host'] : 'localhost';
$plugin_config['kannel']['sendsms_host'] = $plugin_config['kannel']['sendsms_host'] ? $plugin_config['kannel']['sendsms_host'] : $plugin_config['kannel']['bearerbox_host'];
$plugin_config['kannel']['sendsms_port'] = (int) ($plugin_config['kannel']['sendsms_port'] ? $plugin_config['kannel']['sendsms_port'] : '13131');
$plugin_config['kannel']['dlr_mask'] = (int) ($plugin_config['kannel']['dlr_mask'] ? $plugin_config['kannel']['dlr_mask'] : '27');
$plugin_config['kannel']['playsms_web'] = $plugin_config['kannel']['playsms_web'] ? $plugin_config['kannel']['playsms_web'] : _HTTP_PATH_BASE_;
$plugin_config['kannel']['admin_host'] = $plugin_config['kannel']['admin_host'] ? $plugin_config['kannel']['admin_host'] : $plugin_config['kannel']['bearerbox_host'];
$plugin_config['kannel']['admin_port'] = (int) ($plugin_config['kannel']['admin_port'] ? $plugin_config['kannel']['admin_port'] : '13000');
$plugin_config['kannel']['local_time'] = (int) ($plugin_config['kannel']['local_time'] ? 1 : 0);
// smsc configuration
$plugin_config['kannel']['_smsc_config_'] = array('username' => _('Username'), 'password' => _('Password'), 'module_sender' => _('Module sender ID'), 'module_timezone' => _('Module timezone'), 'bearerbox_host' => _('Bearerbox hostname or IP'), 'sendsms_host' => _('Send SMS hostname or IP'), 'sendsms_port' => _('Send SMS port'), 'dlr_mask' => _('DLR mask'), 'additional_param' => _('Additional URL parameter'), 'playsms_web' => _('playSMS web URL'));
Exemplo n.º 11
0
if (auth_isvalid()) {
    // load user's data from user's DB table
    $user_config = user_getdatabyusername($_SESSION['username']);
    $user_config['opt']['sms_footer_length'] = strlen($footer) > 0 ? strlen($footer) + 1 : 0;
    $user_config['opt']['per_sms_length'] = $core_config['main']['per_sms_length'] - $user_config['opt']['sms_footer_length'];
    $user_config['opt']['per_sms_length_unicode'] = $core_config['main']['per_sms_length_unicode'] - $user_config['opt']['sms_footer_length'];
    $user_config['opt']['max_sms_length'] = $core_config['main']['max_sms_length'] - $user_config['opt']['sms_footer_length'];
    $user_config['opt']['max_sms_length_unicode'] = $core_config['main']['max_sms_length_unicode'] - $user_config['opt']['sms_footer_length'];
    $user_config['opt']['gravatar'] = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($user_config['email'])));
    if (!$core_config['daemon_process']) {
        // save login session information
        user_session_set();
    }
    // special setting to credit unicode SMS the same as normal SMS length
    // for example: 2 unicode SMS (140 chars length) will be deducted as 1 credit just like a normal SMS (160 chars length)
    $result = registry_search($user_config['uid'], 'core', 'user_config', 'enable_credit_unicode');
    $user_config['opt']['enable_credit_unicode'] = (int) $result['core']['user_config']['enable_credit_unicode'];
    if (!$user_config['opt']['enable_credit_unicode']) {
        // global config overriden by user config
        $user_config['opt']['enable_credit_unicode'] = (int) $core_config['main']['enable_credit_unicode'];
    }
}
// override main config with site config for branding purposes distinguished by domain name
$site_config = array();
if (!$core_config['daemon_process'] && $_SERVER['HTTP_HOST']) {
    $s = site_config_getbydomain($_SERVER['HTTP_HOST']);
    if ((int) $s[0]['uid']) {
        $c_site_config = site_config_get((int) $s[0]['uid']);
        if (strtolower($c_site_config['domain']) == strtoloweR($_SERVER['HTTP_HOST'])) {
            $site_config = array_merge($c_site_config, $s[0]);
        }
Exemplo n.º 12
0
 * playSMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with playSMS. If not, see <http://www.gnu.org/licenses/>.
 */
defined('_SECURE_') or die('Forbidden');
if (!auth_isadmin()) {
    auth_block();
}
switch (_OP_) {
    case "main_config":
        // get original main_config
        $data = registry_search(1, 'core', 'main_config');
        $main_config = $data['core']['main_config'];
        // enable register yes-no option
        $option_enable_register = _options(array(_('yes') => 1, _('no') => 0), $main_config['enable_register']);
        // enable forgot yes-no option
        $option_enable_forgot = _options(array(_('yes') => 1, _('no') => 0), $main_config['enable_forgot']);
        // disable login as subuser yes-no option
        $option_disable_login_as = _options(array(_('yes') => 1, _('no') => 0), $main_config['disable_login_as']);
        // enhance privacy for subusers
        $option_enhance_privacy_subuser = _options(array(_('yes') => 1, _('no') => 0), $main_config['enhance_privacy_subuser']);
        // enable logo yes-no option
        $option_enable_logo = _options(array(_('yes') => 1, _('no') => 0), $main_config['enable_logo']);
        // enable logo to replace main website title yes-no option
        $option_logo_replace_title = _options(array(_('yes') => 1, _('no') => 0), $main_config['logo_replace_title']);
        // option default account status on user registration
        $option_default_user_status = _options(array(_('User') => 3, _('Subuser') => 4), $main_config['default_user_status']);
Exemplo n.º 13
0
<?php

defined('_SECURE_') or die('Forbidden');
// get gammu config from registry
$data = registry_search(0, 'gateway', 'smstools');
$plugin_config['smstools']['name'] = 'smstools';
$plugin_config['smstools']['default_queue'] = trim(core_sanitize_path($data['gateway']['smstools']['default_queue']));
if (!$plugin_config['smstools']['default_queue']) {
    $plugin_config['smstools']['default_queue'] = "/var/spool/sms";
}
// smsc configuration
$plugin_config['smstools']['_smsc_config_'] = array('sms_receiver' => _('Receiver number'), 'queue' => _('Queue directory'));
// insert to left menu array
//if (isadmin()) {
//	$menutab_gateway = $core_config['menutab']['gateway'];
//	$menu_config[$menutab_gateway][] = array("index.php?app=main&inc=gateway_smstools&op=manage", _('Manage smstools'));
//}
Exemplo n.º 14
0
function email2sms_hook_playsmsd_once($param)
{
    $c_param = explode('_', $param);
    if ($c_param[0] == 'email2sms') {
        if ($c_param[1] == 'uid') {
            $uid = (int) $c_param[2];
        }
    }
    // get username
    $username = user_uid2username($uid);
    // _log('fetch uid:' . $uid . ' username:'******'email2sms_hook_playsmsd_once');
    if ($uid && $username) {
        $items = registry_search($uid, 'features', 'email2sms');
        $enable = $items['features']['email2sms']['enable'];
        if (!$enable) {
            return;
        }
        $ssl = $items['features']['email2sms']['ssl'] == 1 ? "/ssl" : "";
        $novalidate_cert = $items['features']['email2sms']['novalidate_cert'] == 1 ? "/novalidate-cert" : "";
        $email_hostname = '{' . $items['features']['email2sms']['server'] . ':' . $items['features']['email2sms']['port'] . '/' . $items['features']['email2sms']['protocol'] . $ssl . $novalidate_cert . '}INBOX';
        $email_username = $items['features']['email2sms']['username'];
        $email_password = $items['features']['email2sms']['password'];
        // _log('fetch ' . $email_username . ' at ' . $email_hostname, 3, 'email2sms_hook_playsmsd_once');
        // open mailbox
        $inbox = imap_open($email_hostname, $email_username, $email_password);
        if (!$inbox) {
            $errors = imap_errors();
            foreach ($errors as $error) {
                // _log('error:' . $error, 3, 'email2sms_hook_playsmsd_once');
            }
            return;
        }
        $emails = imap_search($inbox, 'UNSEEN');
        if (count($emails)) {
            rsort($emails);
            foreach ($emails as $email_number) {
                $overview = imap_fetch_overview($inbox, $email_number, 0);
                $email_subject = trim($overview[0]->subject);
                $email_sender = trim($overview[0]->from);
                $email_body = trim(imap_fetchbody($inbox, $email_number, 1));
                _log('email from:[' . $email_sender . '] subject:[' . $email_subject . '] body:[' . $email_body . ']', 3, 'email2sms_hook_playsmsd');
                // destination numbers is in array and retrieved from email body
                // remove email footer/signiture
                $sms_to = preg_replace('/--[\\r\\n]+.*/s', '', $email_body);
                $sms_to = explode(',', $sms_to);
                // Check "from" email before checking PIN if option "Check email sender" is TRUE
                if ($items['features']['email2sms']['check_sender']) {
                    preg_match('#\\<(.*?)\\>#', $email_sender, $match);
                    if (user_email2uid($match[1]) == "") {
                        continue;
                    }
                }
                // message is from email subject
                // $message = trim($email_subject);
                $message = trim(preg_replace('/' . $items['features']['email2sms']['pin'] . '/', '', $email_subject, -1, $count));
                if ($count <= 0) {
                    _log('PIN does not match. Subject: ' . $email_subject, 2, 'email2sms_hook_playsmsd');
                }
                // sendsms
                if ($username && count($sms_to) && $message && $count > 0) {
                    _log('email2sms username:'******'email2sms_hook_playsmsd_once');
                    list($ok, $to, $smslog_id, $queue, $counts, $sms_count, $sms_failed) = sendsms_helper($username, $sms_to, $message, '', '', '', '', '', '', $reference_id);
                }
            }
        }
        // close mailbox
        imap_close($inbox);
    }
}
Exemplo n.º 15
0
function simplerate_hook_rate_deduct($smslog_id)
{
    global $core_config;
    logger_print("enter smslog_id:" . $smslog_id, 2, "simplerate deduct");
    $db_query = "SELECT p_dst,p_footer,p_msg,uid,unicode FROM " . _DB_PREF_ . "_tblSMSOutgoing WHERE smslog_id='{$smslog_id}'";
    $db_result = dba_query($db_query);
    if ($db_row = dba_fetch_array($db_result)) {
        $p_dst = $db_row['p_dst'];
        $p_msg = $db_row['p_msg'];
        $p_footer = $db_row['p_footer'];
        $uid = $db_row['uid'];
        $unicode = $db_row['unicode'];
        if ($p_dst && $p_msg && $uid) {
            // get charge
            $p_msg_len = strlen($p_msg) + strlen($p_footer);
            list($count, $rate, $charge) = rate_getcharges($uid, $p_msg_len, $unicode, $p_dst);
            // sender's
            $username = user_uid2username($uid);
            $credit = rate_getusercredit($username);
            $balance = $credit - $charge;
            // parent's when sender is a subuser
            $parent_uid = user_getparentbyuid($uid);
            if ($parent_uid) {
                $username_parent = user_uid2username($parent_uid);
                $credit_parent = rate_getusercredit($username_parent);
                $balance_parent = $credit_parent - $charge;
            }
            // if sender have parent then deduct parent first
            if ($parent_uid) {
                if (!rate_setusercredit($parent_uid, $balance_parent)) {
                    return FALSE;
                }
                logger_print("parent uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id . " msglen:" . $p_msg_len . " count:" . $count . " rate:" . $rate . " charge:" . $charge . " credit_parent:" . $credit_parent . " balance_parent:" . $balance_parent, 2, "simplerate deduct");
            }
            if (rate_setusercredit($uid, $balance)) {
                logger_print("user uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id . " msglen:" . $p_msg_len . " count:" . $count . " rate:" . $rate . " charge:" . $charge . " credit:" . $credit . " balance:" . $balance, 2, "simplerate deduct");
                if (billing_post($smslog_id, $rate, $credit, $count, $charge)) {
                    logger_print("deduct successful uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
                    // if balance under credit lowest limit and never been notified then notify admins, parent_uid and uid
                    $credit_lowest_limit = (double) $core_config['main']['credit_lowest_limit'];
                    _log('credit_lowest_limit:' . $credit_lowest_limit . ' balance:' . $balance . ' charge:' . $charge, 3, 'simplerate deduct');
                    $reg = registry_search($uid, 'feature', 'credit', 'lowest_limit_notif');
                    $notified = $reg['feature']['credit']['lowest_limit_notif'] ? TRUE : FALSE;
                    if ($charge && $balance && $credit_lowest_limit && $balance <= $credit_lowest_limit && !$notified) {
                        // set notified
                        registry_update($uid, 'feature', 'credit', array('lowest_limit_notif' => TRUE));
                        // notif admins
                        $admins = user_getallwithstatus(2);
                        foreach ($admins as $admin) {
                            $credit_message_to_admins = sprintf(_('Username %s with account ID %d has reached lowest credit limit of %s'), $username, $uid, $credit_lowest_limit);
                            recvsms_inbox_add(core_get_datetime(), _SYSTEM_SENDER_ID_, $admin['username'], $credit_message_to_admins);
                        }
                        // notif parent_uid if exists
                        if ($parent_uid && $username_parent) {
                            $credit_message_to_parent = sprintf(_('Your subuser with username %s and account ID %d has reached lowest credit limit of %s'), $username, $uid, $credit_lowest_limit);
                            recvsms_inbox_add(core_get_datetime(), _SYSTEM_SENDER_ID_, $username_parent, $credit_message_to_parent);
                        }
                        // notif uid
                        $sender_username = $username_parent ? $username_parent : _SYSTEM_SENDER_ID_;
                        $credit_message_to_self = sprintf(_('You have reached lowest credit limit of %s'), $credit_lowest_limit);
                        recvsms_inbox_add(core_get_datetime(), $sender_username, $username, $credit_message_to_self);
                        _log('sent notification credit_lowest_limit:' . $credit_lowest_limit, 3, 'simplerate deduct');
                    }
                    return TRUE;
                } else {
                    logger_print("deduct failed uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
                    return FALSE;
                }
            } else {
                logger_print("rate deduct failed due to unable to save to db uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
            }
        } else {
            logger_print("rate deduct failed due to empty data uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
        }
    } else {
        logger_print("rate deduct failed due to missing data uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
    }
    return FALSE;
}
Exemplo n.º 16
0
<?php

defined('_SECURE_') or die('Forbidden');
// get kannel config from registry
$data = registry_search(1, 'gateway', 'openvox');
$plugin_config['openvox'] = $data['gateway']['openvox'];
$plugin_config['openvox']['name'] = 'openvox';
$plugin_config['openvox']['gateway_port'] = $plugin_config['openvox']['gateway_port'] ? $plugin_config['openvox']['gateway_port'] : '80';
// smsc configuration
$plugin_config['openvox']['_smsc_config_'] = array('gateway_host' => _('Gateway host'), 'gateway_port' => _('Gateway port'), 'username' => _('Username'), 'password' => _('Password'));
//$gateway_number = $plugin_config['openvox']['module_sender'];
// insert to left menu array
//if (isadmin()) {
//	$menutab_gateway = $core_config['menutab']['gateway'];
//	$menu_config[$menutab_gateway][] = array("index.php?app=main&inc=gateway_openvox&op=manage", _('Manage openvox'));
//}
Exemplo n.º 17
0
/**
 * List all banned users
 *
 * @return array banned users
 */
function user_banned_list()
{
    $ret = array();
    $list = registry_search(1, 'auth', 'banned_users');
    foreach ($list['auth']['banned_users'] as $key => $val) {
        $uid = (int) $key;
        $username = user_uid2username($uid);
        $bantime = $val;
        if ($uid && $username && $bantime) {
            $ret[] = array('uid' => $uid, 'username' => $username, 'bantime' => $bantime);
        }
    }
    return $ret;
}
Exemplo n.º 18
0
<?php

defined('_SECURE_') or die('Forbidden');
// get gammu config from registry
$data = registry_search(0, 'gateway', 'gammu');
$plugin_config['gammu']['name'] = 'gammu';
$plugin_config['gammu']['path'] = trim(core_sanitize_path($data['gateway']['gammu']['path']));
if (!$plugin_config['gammu']['path']) {
    $plugin_config['gammu']['path'] = '/var/spool/gammu';
}
$plugin_config['gammu']['dlr'] = TRUE;
// smsc configuration
$plugin_config['gammu']['_smsc_config_'] = array('path' => _('Spool folder'));
// insert to left menu array
//if (isadmin()) {
//	$menutab_gateway = $core_config['menutab']['gateway'];
//	$menu_config[$menutab_gateway][] = array("index.php?app=main&inc=gateway_gammu&op=manage", _('Manage gammu'));
//}
Exemplo n.º 19
0
 *
 * playSMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with playSMS. If not, see <http://www.gnu.org/licenses/>.
 */
defined('_SECURE_') or die('Forbidden');
if (!auth_isvalid()) {
    auth_block();
}
switch (_OP_) {
    case "email2sms":
        $items = registry_search($user_config['uid'], 'features', 'email2sms');
        // option enable
        $option_enable = _options(array(_('yes') => 1, _('no') => 0), $items['features']['email2sms']['enable']);
        // option check email sender
        $option_check_sender = _options(array(_('yes') => 1, _('no') => 0), $items['features']['email2sms']['check_sender']);
        // option protocol
        $option_protocol = _options(array('IMAP' => 'imap', 'POP3' => 'pop3'), $items['features']['email2sms']['protocol']);
        // option ssl
        $option_ssl = _options(array(_('yes') => 1, _('no') => 0), $items['features']['email2sms']['ssl']);
        // option cert
        $option_novalidate_cert = _options(array(_('yes') => 1, _('no') => 0), $items['features']['email2sms']['novalidate_cert']);
        $tpl = array('name' => 'email2sms', 'vars' => array('DIALOG_DISPLAY' => _dialog(), 'FORM_TITLE' => _('Manage email to SMS'), 'ACTION_URL' => _u('index.php?app=main&inc=feature_email2sms&op=email2sms_save'), 'HTTP_PATH_THEMES' => _HTTP_PATH_THEMES_, 'HINT_PASSWORD' => _hint(_('Fill the password field to change password')), 'PIN for email to SMS' => _mandatory(_('PIN for email to SMS')), 'Enable email to SMS' => _('Enable email to SMS'), 'Check email sender' => _('Check email sender'), 'Email protocol' => _('Email protocol'), 'Use SSL' => _('Use SSL'), 'No validate cert option' => _('No validate cert option'), 'Mail server address' => _('Mail server address'), 'Mail server port' => _('Mail server port'), 'Mailbox username' => _('Mailbox username'), 'Mailbox password' => _('Mailbox password'), 'PORT_DEFAULT' => '443', 'PORT_DEFAULT_SSL' => '993'), 'injects' => array('select_users', 'option_enable', 'option_check_sender', 'option_protocol', 'option_ssl', 'option_novalidate_cert', 'items'));
        _p(tpl_apply($tpl));
        break;
    case "email2sms_save":
        $continue = FALSE;
Exemplo n.º 20
0
 *
 * playSMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with playSMS. If not, see <http://www.gnu.org/licenses/>.
 */
defined('_SECURE_') or die('Forbidden');
if (!auth_isadmin()) {
    auth_block();
}
switch (_OP_) {
    case "mailsms":
        $items_global = registry_search(0, 'features', 'mailsms');
        // option enable fetch
        $option_enable_fetch = _options(array(_('yes') => 1, _('no') => 0), $items_global['features']['mailsms']['enable_fetch']);
        // option check email sender
        $option_check_sender = _options(array(_('yes') => 1, _('no') => 0), $items_global['features']['mailsms']['check_sender']);
        // option protocol
        $option_protocol = _options(array('IMAP' => 'imap', 'POP3' => 'pop3'), $items_global['features']['mailsms']['protocol']);
        // option ssl
        $option_ssl = _options(array(_('yes') => 1, _('no') => 0), $items_global['features']['mailsms']['ssl']);
        // option cert
        $option_novalidate_cert = _options(array(_('yes') => 1, _('no') => 0), $items_global['features']['mailsms']['novalidate_cert']);
        $tpl = array('name' => 'mailsms', 'vars' => array('ERROR' => _err_display(), 'FORM_TITLE' => _('Manage email to SMS'), 'ACTION_URL' => _u('index.php?app=main&inc=feature_mailsms&op=mailsms_save'), 'HTTP_PATH_THEMES' => _HTTP_PATH_THEMES_, 'HINT_PASSWORD' => _hint(_('Fill the password field to change password')), 'Email to SMS address' => _('Email to SMS address'), 'Enable fetch new emails' => _('Enable fetch new emails'), 'Check email sender' => _('Check email sender'), 'Email protocol' => _('Email protocol'), 'Use SSL' => _('Use SSL'), 'No validate cert option' => _('No validate cert option'), 'Mail server address' => _('Mail server address'), 'Mail server port' => _('Mail server port'), 'Mailbox username' => _('Mailbox username'), 'Mailbox password' => _('Mailbox password'), 'PORT_DEFAULT' => '443', 'PORT_DEFAULT_SSL' => '993'), 'injects' => array('option_enable_fetch', 'option_check_sender', 'option_protocol', 'option_ssl', 'option_novalidate_cert', 'items_global'));
        _p(tpl_apply($tpl));
        break;
    case "mailsms_save":
        $items_global = array('email' => $_REQUEST['email'], 'enable_fetch' => $_REQUEST['enable_fetch'], 'check_sender' => $_REQUEST['check_sender'], 'protocol' => $_REQUEST['protocol'], 'ssl' => $_REQUEST['ssl'], 'novalidate_cert' => $_REQUEST['novalidate_cert'], 'port' => $_REQUEST['port'], 'server' => $_REQUEST['server'], 'username' => $_REQUEST['username'], 'hash' => md5($_REQUEST['username'] . $_REQUEST['server'] . $_REQUEST['port']));
Exemplo n.º 21
0
/**
 * 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;
}
Exemplo n.º 22
0
     }
     // get access control list
     $c_option_acl = array_flip(acl_getall());
     $option_acl = _input('text', '', acl_getname($acl_id), array('readonly'));
     if (auth_isadmin()) {
         $option_acl = _select('up_acl_id', $c_option_acl, $acl_id);
     }
     if ($user_edited['status'] == 4) {
         $parent_id = user_getparentbyuid($user_edited['uid']);
         if ($parent_id == $user_config['uid']) {
             $c_option_acl = array_flip(acl_getallbyuid($user_config['uid']));
             $option_acl = _select('up_acl_id', $c_option_acl, $acl_id);
         }
     }
     // additional user's config available on registry
     $data = registry_search($c_uid, 'core', 'user_config');
     // credit unicodes messages as single message
     $option_enable_credit_unicode = _options(array(_('yes') => 1, _('no') => 0), $data['core']['user_config']['enable_credit_unicode']);
     if (auth_isadmin()) {
         $option_enable_credit_unicode = "<select name='edit_enable_credit_unicode'>" . $option_enable_credit_unicode . "</select>";
     } else {
         $option_enable_credit_unicode = $user_config['opt']['enable_credit_unicode'] ? _('yes') : _('no');
     }
     // error string
     if ($err = TRUE) {
         $error_content = _dialog();
     }
     $tpl = array('name' => 'user_config', 'vars' => array('Application options' => _('Application options'), 'Username' => _('Username'), 'Access Control List' => _('Access Control List'), 'Effective SMS sender ID' => _('Effective SMS sender ID'), 'Default sender ID' => _('Default sender ID'), 'Default message footer' => _('Default message footer'), 'Webservices username' => _('Webservices username'), 'Webservices token' => _('Webservices token'), 'Renew webservices token' => _('Renew webservices token'), 'Enable webservices' => _('Enable webservices'), 'Webservices IP range' => _('Webservices IP range'), 'Active language' => _('Active language'), 'Timezone' => _('Timezone'), 'Credit' => _('Credit'), 'Enable credit unicode SMS as normal SMS' => _('Enable credit unicode SMS as normal SMS'), 'Forward message to inbox' => _('Forward message to inbox'), 'Forward message to email' => _('Forward message to email'), 'Forward message to mobile' => _('Forward message to mobile'), 'Local number length' => _('Local number length'), 'Prefix or country code' => _('Prefix or country code'), 'Always choose to send as unicode' => _('Always choose to send as unicode'), 'Save' => _('Save'), 'DIALOG_DISPLAY' => $error_content, 'FORM_TITLE' => $form_title, 'BUTTON_DELETE' => $button_delete, 'BUTTON_BACK' => $button_back, 'URL_UNAME' => $url_uname, 'VIEW' => $view, 'HINT_MAX_CHARS' => _hint(_('Max. 16 numeric or 11 alphanumeric characters')), 'HINT_MAX_ALPHANUMERIC' => _hint(_('Max. 30 alphanumeric characters')), 'HINT_COMMA_SEPARATED' => _hint(_('Comma separated')), 'HINT_TIMEZONE' => _hint(_('Eg: +0700 for Jakarta/Bangkok timezone')), 'HINT_LOCAL_LENGTH' => _hint(_('Min length to detect missing country code')), 'HINT_REPLACE_ZERO' => _hint(_('Replace prefix 0 or padding local numbers')), 'HINT_MANAGE_CREDIT' => _hint(_('Add or reduce credit from manage credit menu')), 'HINT_ACL' => _hint(_('ACL DEFAULT will not restrict access to menus')), 'option_new_token' => $option_new_token, 'option_enable_webservices' => $option_enable_webservices, 'option_language_module' => $option_language_module, 'option_fwd_to_inbox' => $option_fwd_to_inbox, 'option_fwd_to_email' => $option_fwd_to_email, 'option_fwd_to_mobile' => $option_fwd_to_mobile, 'option_acl' => $option_acl, 'option_sender_id' => $option_sender_id, 'c_username' => $c_username, 'effective_sender_id' => sendsms_get_sender($c_username), 'sender' => $sender, 'footer' => $footer, 'token' => $token, 'webservices_ip' => $webservices_ip, 'datetime_timezone' => $datetime_timezone, 'local_length' => $local_length, 'replace_zero' => $replace_zero, 'credit' => $credit, 'option_enable_credit_unicode' => $option_enable_credit_unicode));
     _p(tpl_apply($tpl));
     break;
 case "user_config_save":
Exemplo n.º 23
0
function mailsms_hook_playsmsd_once($param)
{
    if ($param != 'mailsms_fetch') {
        return;
    }
    // get username
    $username = user_uid2username($uid);
    // _log('fetch uid:' . $uid . ' username:'******'mailsms_hook_playsmsd_once');
    $items_global = registry_search(0, 'features', 'mailsms');
    $enable_fetch = $items_global['features']['mailsms']['enable_fetch'];
    if (!$enable_fetch) {
        return;
    }
    $ssl = $items_global['features']['mailsms']['ssl'] == 1 ? "/ssl" : "";
    $novalidate_cert = $items_global['features']['mailsms']['novalidate_cert'] == 1 ? "/novalidate-cert" : "";
    $email_hostname = '{' . $items_global['features']['mailsms']['server'] . ':' . $items_global['features']['mailsms']['port'] . '/' . $items_global['features']['mailsms']['protocol'] . $ssl . $novalidate_cert . '}INBOX';
    $email_username = $items_global['features']['mailsms']['username'];
    $email_password = $items_global['features']['mailsms']['password'];
    // _log('fetch ' . $email_username . ' at ' . $email_hostname, 3, 'mailsms_hook_playsmsd_once');
    // open mailbox
    $inbox = imap_open($email_hostname, $email_username, $email_password);
    if (!$inbox) {
        $errors = imap_errors();
        foreach ($errors as $error) {
            // _log('error:' . $error, 3, 'mailsms_hook_playsmsd_once');
        }
        return;
    }
    $emails = imap_search($inbox, 'UNSEEN');
    if (count($emails)) {
        rsort($emails);
        foreach ($emails as $email_number) {
            $overview = imap_fetch_overview($inbox, $email_number, 0);
            $email_subject = trim($overview[0]->subject);
            $email_sender = trim($overview[0]->from);
            $email_body = trim(imap_fetchbody($inbox, $email_number, 1));
            _log('email from:[' . $email_sender . '] subject:[' . $email_subject . '] body:[' . $email_body . ']', 3, 'mailsms_hook_playsmsd');
            $e = preg_replace('/\\s+/', ' ', trim($email_subject));
            $f = preg_split('/ +/', $e);
            $sender_username = str_replace('@', '', $f[0]);
            // in case user use @username
            $sender_pin = $f[1];
            //$message = str_replace($sender_username . ' ' . $sender_pin . ' ', '', $email_subject);
            $c_message = preg_split("/[\\s]+/", $email_subject, 3);
            $message = $c_message[2];
            $sender = user_getdatabyusername($sender_username);
            if ($sender['uid']) {
                $items = registry_search($sender['uid'], 'features', 'mailsms_user');
                $pin = $items['features']['mailsms_user']['pin'];
                if ($sender_pin && $pin && $sender_pin == $pin) {
                    if ($items_global['features']['mailsms']['check_sender']) {
                        preg_match('#\\<(.*?)\\>#', $email_sender, $match);
                        $sender_email = $match[1];
                        if ($sender['email'] != $sender_email) {
                            _log('check_sender:1 unknown sender from:' . $sender_email . ' uid:' . $sender['uid'] . ' e:' . $sender['email'], 3, 'mailsms_hook_playsmsd_once');
                            continue;
                        }
                    }
                } else {
                    _log('invalid pin uid:' . $sender['uid'] . ' sender_pin:[' . $sender_pin . ']', 3, 'mailsms_hook_playsmsd_once');
                    continue;
                }
            } else {
                _log('invalid username sender_username:[' . $sender_username . ']', 3, 'mailsms_hook_playsmsd_once');
                continue;
            }
            // destination numbers is in array and retrieved from email body
            // remove email footer/signiture
            $sms_to = preg_replace('/--[\\r\\n]+.*/s', '', $email_body);
            $sms_to = explode(',', $sms_to);
            // sendsms
            if ($sender_username && count($sms_to) && $message) {
                _log('mailsms uid:' . $sender['uid'] . ' from:[' . $sender_email . '] username:[' . $sender_username . ']', 3, 'mailsms_hook_playsmsd_once');
                list($ok, $to, $smslog_id, $queue, $counts, $sms_count, $sms_failed) = sendsms_helper($sender_username, $sms_to, $message, '', '', '', '', '', '', $reference_id);
            }
        }
    }
    // close mailbox
    imap_close($inbox);
}
Exemplo n.º 24
0
 *
 * playSMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with playSMS.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_SECURE_') or die('Forbidden');
if (!auth_isvalid()) {
    auth_block();
}
switch (_OP_) {
    case "sms_sync_list":
        $list = registry_search($user_config['uid'], 'feature', 'sms_sync');
        $sms_sync_secret = $list['feature']['sms_sync']['secret'];
        if ($list['feature']['sms_sync']['enable']) {
            $option_enable = 'checked';
        }
        $sync_url = $core_config['http_path']['base'] . '/plugin/feature/sms_sync/sync.php?uid=' . $user_config['uid'];
        unset($tpl);
        $tpl = array('name' => 'sms_sync', 'vars' => array('DIALOG_DISPLAY' => _dialog(), 'HINT_SECRET' => _hint(_('Secret key is used in SMSSync app')), 'HINT_ENABLE' => _hint(_('Check to enable receiving push messages from SMSSync app')), 'SECRET' => $sms_sync_secret, 'CHECKED' => $option_enable, 'SYNC_URL' => $sync_url, 'Manage sync' => _('Manage sync'), 'Secret key' => _('Secret key'), 'Enable SMS Sync' => _('Enable SMS Sync'), 'Sync URL' => _('Sync URL'), 'Notes' => _('Notes'), 'Download SMSSync app for Android from' => _('Download SMSSync app for Android from'), 'Save' => _('Save')));
        _p(tpl_apply($tpl));
        break;
    case "sms_sync_save":
        $items['secret'] = $_POST['sms_sync_secret'];
        $items['enable'] = trim($_POST['sms_sync_enable']) ? 1 : 0;
        if (registry_update($user_config['uid'], 'feature', 'sms_sync', $items)) {
            $_SESSION['dialog']['info'][] = _('SMS Sync configuration has been saved');
        } else {
Exemplo n.º 25
0
<?php

defined('_SECURE_') or die('Forbidden');
// get playnet config from registry
$data = registry_search(0, 'gateway', 'playnet');
$plugin_config['playnet'] = $data['gateway']['playnet'];
$plugin_config['playnet']['name'] = 'playnet';
$plugin_config['playnet']['poll_interval'] = 2;
$plugin_config['playnet']['poll_limit'] = 400;
// smsc configuration
$plugin_config['playnet']['_smsc_config_'] = array('local_playnet_username' => _('Local playnet username'), 'local_playnet_password' => _('Local playnet password'), 'remote_on' => _('Remote is on'), 'remote_playsms_url' => _('Remote playSMS URL'), 'remote_playnet_smsc' => _('Remote playnet SMSC name'), 'remote_playnet_username' => _('Remote playnet username'), 'remote_playnet_password' => _('Remote playnet password'), 'sendsms_username' => _('Send SMS from remote using local username'), 'module_sender' => _('Module sender ID'), 'module_timezone' => _('Module timezone'));