Example #1
0
function _get_user()
{
    $db = gs_db_slave_connect();
    $remote_addr = @$_SERVER['REMOTE_ADDR'];
    $user_name = (string) $db->executeGetOne('SELECT `user`, `nobody_index` FROM `users` WHERE `current_ip`=\'' . $db->escape($remote_addr) . '\'');
    return gs_user_get($user_name);
}
Example #2
0
function InitRecordCall($filename, $index, $comment)
{
    //FIXME
    $user = gs_user_get($_SESSION['sudo_user']['name']);
    $call = "Channel: SIP/" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "MaxRetries: 0\n" . "WaitTime: 15\n" . "Context: vm-rec-multiple\n" . "Extension: webdialrecord\n" . "Callerid: {$comment} <Aufnahme>\n" . "Setvar: __user_id=" . $_SESSION['sudo_user']['info']['id'] . "\n" . "Setvar: __user_name=" . $_SESSION['sudo_user']['info']['ext'] . "\n" . "Setvar: CHANNEL(language)=" . gs_get_conf('GS_INTL_ASTERISK_LANG', 'de') . "\n" . "Setvar: __is_callfile_origin=1\n" . "Setvar: __callfile_from_user="******"\n" . "Setvar: __record_file=" . $filename . "\n";
    $filename = '/tmp/gs-' . $_SESSION['sudo_user']['info']['id'] . '-' . _pack_int(time()) . rand(100, 999) . '.call';
    $cf = @fOpen($filename, 'wb');
    if (!$cf) {
        gs_log(GS_LOG_WARNING, 'Failed to write call file "' . $filename . '"');
        echo 'Failed to write call file.';
        die;
    }
    @fWrite($cf, $call, strLen($call));
    @fClose($cf);
    @chmod($filename, 0666);
    $spoolfile = '/var/spool/asterisk/outgoing/' . baseName($filename);
    if (!gs_get_conf('GS_INSTALLATION_TYPE_SINGLE')) {
        $our_host_ids = @gs_get_listen_to_ids();
        if (!is_array($our_host_ids)) {
            $our_host_ids = array();
        }
        $user_is_on_this_host = in_array($_SESSION['sudo_user']['info']['host_id'], $our_host_ids);
    } else {
        $user_is_on_this_host = true;
    }
    if ($user_is_on_this_host) {
        # the Asterisk of this user and the web server both run on this host
        $err = 0;
        $out = array();
        @exec('sudo mv ' . qsa($filename) . ' ' . qsa($spoolfile) . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        if ($err != 0) {
            @unlink($filename);
            gs_log(GS_LOG_WARNING, 'Failed to move call file "' . $filename . '" to "' . '/var/spool/asterisk/outgoing/' . baseName($filename) . '"');
            echo 'Failed to move call file.';
            die;
        }
    } else {
        $cmd = 'sudo scp -o StrictHostKeyChecking=no -o BatchMode=yes ' . qsa($filename) . ' ' . qsa('root@' . $user['host'] . ':' . $filename);
        //echo $cmd, "\n";
        @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        @unlink($filename);
        if ($err != 0) {
            gs_log(GS_LOG_WARNING, 'Failed to scp call file "' . $filename . '" to ' . $user['host']);
            echo 'Failed to scp call file.';
            die;
        }
        //remote_exec( $user['host'], $cmd, 10, $out, $err ); // <-- does not use sudo!
        $cmd = 'sudo ssh -o StrictHostKeyChecking=no -o BatchMode=yes -l root ' . qsa($user['host']) . ' ' . qsa('mv ' . qsa($filename) . ' ' . qsa($spoolfile));
        //echo $cmd, "\n";
        @exec($cmd . ' 1>>/dev/null 2>>/dev/null', $out, $err);
        if ($err != 0) {
            gs_log(GS_LOG_WARNING, 'Failed to mv call file "' . $filename . '" on ' . $user['host'] . ' to "' . $spoolfile . '"');
            echo 'Failed to mv call file on remote host.';
            die;
        }
    }
}
function gs_prov_phone_checkcfg_by_user($usercode, $reboot = true)
{
    if (!preg_match('/^[a-z0-9\\-_.]+$/', $usercode)) {
        return new GsError('User must be alphanumeric.');
    }
    $ip = gs_user_ip_by_user($usercode);
    if (isGsError($ip)) {
        return new GsError($ip->getMsg());
    }
    $userArr = gs_user_get($usercode);
    if (isGsError($userArr)) {
        return new GsError($userArr->getMsg());
    }
    if (!is_array($userArr)) {
        return new GsError('Failed to get user from DB.');
    }
    $ext = $userArr['ext'];
    gs_log(GS_LOG_DEBUG, "phone_checkcfg by user \"{$usercode}\", ip \"{$ip}\", ext \"{$ext}\"");
    //echo "       IP: $ip\n";
    $ok1 = _gs_prov_phone_checkcfg_by_ip_do($ip, $reboot);
    //echo "Extension: $ext\n";
    $ok2 = _gs_prov_phone_checkcfg_by_ext_do($ext, $reboot);
    return $ok1 || $ok2;
}
Example #4
0
$methods = explode(',', GS_GUI_AUTH_METHOD);
array_walk($methods, 'gs_trim_value');
foreach ($methods as &$method) {
    $PAM = new PAMAL($method);
    $user = $PAM->getUser();
    if ($user) {
        break;
    }
}
unset($method);
if (!$user) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    die('Unauthorized');
}
$userinfo = gs_user_get($user);
$DB = gs_db_slave_connect();
$GS_INSTALLATION_TYPE_SINGLE = gs_get_conf('GS_INSTALLATION_TYPE_SINGLE');
if (!$GS_INSTALLATION_TYPE_SINGLE) {
    # find host
    #
    $rs = $DB->execute('SELECT `u`.`host_id` `id`, `h`.`host`
FROM
	`users` `u` LEFT JOIN
	`hosts` `h` ON (`h`.`id`=`u`.`host_id`)
WHERE
	`u`.`id`=' . (int) @$userinfo['id']);
    $host = $rs->fetchRow();
    if (!$host) {
        die('Failed to get host.');
    }
Example #5
0
# user
#####################################################################
if (!isset($_REQUEST['user'])) {
    gs_log(GS_LOG_NOTICE, 'No user code specified. Use user='******'No user code specified. Use user='******'user']);
if (gs_get_conf('GS_LVM_USER_6_DIGIT_INT')) {
    # hack to compare user names as if they were integers
    # padded to 6 digits
    $user_code = lTrim($user_code, '0');
    if (strLen($user_code) < 6) {
        $user_code = str_pad($user_code, 6, '0', STR_PAD_LEFT);
    }
}
$user = @gs_user_get($user_code);
if (isGsError($user)) {
    gs_log(GS_LOG_NOTICE, $user->getMsg());
    die_invalid($user->getMsg());
}
if ($user['nobody_index'] > 0) {
    gs_log(GS_LOG_NOTICE, 'Nobody user. Not allowed to init a call.');
    die_not_allowed('Nobody user. Not allowed to init a call.');
}
$db = gs_db_master_connect();
if (!$db) {
    gs_log(GS_LOG_NOTICE, 'Could not connect to database.');
    die_error('Could not connect to database.');
}
$is_foreign = (bool) (int) $db->executeGetOne('SELECT `is_foreign` FROM `hosts` WHERE `id`=' . $user['host_id']);
$user_ext_obj = new CanonicalPhoneNumber(gs_get_conf('GS_CANONIZE_LOCAL_BRANCH') . $user['ext']);
Example #6
0
function gs_user_language_changed_ui($username, $lang)
{
    include_once GS_DIR . 'inc/gs-fns/gs_user_get.php';
    $user = gs_user_get($username);
    if (isGsError($username)) {
        gs_log(GS_LOG_WARNING, $user_name->getMsg());
        return;
    }
    $data = _get_ui_head('UserLanguageChangedUI');
    $data[] = array('parm' => 'user', 'value' => $user['ext']);
    $data[] = array('parm' => 'language', 'value' => $lang);
    _gs_send_event($data);
}
Example #7
0
             if (isGsError($ret)) {
                 echo '<div class="errorbox">', $ret->getMsg(), '</div>', "\n";
             }
         }
     }
     if (GS_BUTTONDAEMON_USE == true) {
         $user = gs_user_get($edit_user);
         gs_pickupgroup_update_ui($user['ext']);
     }
 }
 if ($u_prv_grp_ed) {
     $query = 'UPDATE `users` SET ' . '`group_id`=' . ($u_prv_grp_id > 0 ? $u_prv_grp_id : 'NULL') . ' ' . 'WHERE `user`=\'' . $DB->escape($edit_user) . '\'';
     $ok = $DB->execute($query);
     if (GS_BUTTONDAEMON_USE == true) {
         if (!isset($user['ext'])) {
             $user = gs_user_get($edit_user);
         }
         gs_usergroup_update_ui($user['ext']);
     }
 }
 if ($bp_add_h > 0) {
     $user_id = (int) $DB->executeGetOne('SELECT `id` FROM `users` WHERE `user`=\'' . $DB->escape($edit_user) . '\'');
     if ($user_id > 0) {
         $host_exists = $DB->executeGetOne('SELECT 1 FROM `hosts` WHERE `id`=' . $bp_add_h);
         if ($host_exists) {
             $query = 'REPLACE INTO `boi_perms` (`user_id`, `host_id` , `roles`) VALUES (' . $user_id . ', ' . $bp_add_h . ', \'l\')';
             $ok = $DB->execute($query);
         }
     }
 }
 $action = 'list';
Example #8
0
    $clir_internal = @$_REQUEST['clir-internal'] == 'yes' ? 'yes' : 'no';
    $clir_external = @$_REQUEST['clir-external'] == 'yes' ? 'yes' : 'no';
    gs_clir_activate($_SESSION['sudo_user']['name'], 'internal', $clir_internal);
    gs_clir_activate($_SESSION['sudo_user']['name'], 'external', $clir_external);
    $cw = !!@$_REQUEST['callwaiting'];
    # setting this reboots phone, so check if it has really changed
    $cw_old = gs_callwaiting_get($_SESSION['sudo_user']['name']);
    if (!isGsError($cw_old)) {
        if ($cw != $cw_old) {
            gs_callwaiting_activate($_SESSION['sudo_user']['name'], $cw);
        }
    }
}
$user_groups = gs_group_members_groups_get(array(@$_SESSION['sudo_user']['info']['id']), 'user');
$queues_allowed = gs_group_members_get(gs_group_permissions_get($user_groups, 'login_queues', 'queue'));
$user = gs_user_get($_SESSION['sudo_user']['name']);
$queue_ids = @$_REQUEST['queue_id'];
if (@$_REQUEST['action'] == 'loginqueue' && !empty($queue_ids)) {
    $ami = new AMI();
    $ami->ami_login('gscc', 'gspass', '127.0.0.1', 5038);
    $agent = $DB->executeGetOne('SELECT `name` FROM `ast_sipfriends` WHERE `_user_id`=' . $user['id']);
    // Ich vertraue  gs_group_members_get
    // in dem array sind NUR int()
    $queue_ids = array_intersect($queue_ids, $queues_allowed);
    $rs = $DB->execute('SELECT `_id`, `name` FROM `ast_queues`  WHERE `_host_id`=' . $user['host_id'] . ' 
		AND `_id` IN (' . implode(",", $queue_ids) . ') 
		AND `_id` NOT IN 
		(SELECT `_queue_id` FROM `ast_queue_members` WHERE `_user_id`=' . $user['id'] . ')');
    while ($queue_map = $rs->fetchRow()) {
        $penalty = $DB->executeGetOne('SELECT `penalty` FROM `penalties` WHERE `_user_id`=' . $user['id'] . ' AND `_queue_id`=' . $queue_map['_id']);
        if (!$penalty) {
Example #9
0
File: index.php Project: rkania/GS3
 * wget "http://GS_PROV_HOST/gemeinschaft/prov/twinkle/?login_user=hans&login_pwd=123" -O ~/.twinkle/hans.cfg
 * twinkle -f hans
 * You should be online ;-)
 *
 */
define('GS_VALID', true);
require_once dirName(__FILE__) . '/../../../inc/conf.php';
require_once GS_DIR . 'inc/gs-lib.php';
require_once GS_DIR . 'inc/db_connect.php';
require_once GS_DIR . 'inc/gs-fns/gs_user_get.php';
require_once GS_DIR . 'lib/yadb/yadb.php';
require_once GS_DIR . 'htdocs/gui/inc/pamal/pamal.php';
$PAM = new PAMAL(GS_GUI_AUTH_METHOD);
$user = $PAM->getUser();
if ($user) {
    $puser = gs_user_get($user);
    header("Content-Type: text/plain");
    header("Content-Disposition: attachment; filename=" . $user . '-' . $puser['host'] . ".cfg");
    $DB = @gs_db_slave_connect();
    $secret = $DB->executeGetOne('SELECT `secret` FROM `ast_sipfriends` WHERE `_user_id`=' . $puser['id']);
    echo '#USER', "\n";
    echo 'user_name=', $puser['ext'], "\n";
    echo 'user_domain=', $puser['host'], "\n";
    echo 'user_display=', $puser['firstname'], ', ', $puser['lastname'], "\n";
    echo 'user_organization=', "\n";
    echo 'auth_realm=', "\n";
    echo 'auth_name=', $puser['ext'], "\n";
    echo 'auth_pass='******'# SIP SERVER', "\n";
    echo 'outbound_proxy=' . $puser['host'], "\n";
    echo 'all_requests_to_proxy=no', "\n";