Beispiel #1
0
echo '<div style="width:550px; border:1px solid #ccc; margin: 2em auto; padding:0 1em 1em 1em; background-color:#eee;">';
$nuser = trim(@$_REQUEST['uuser']);
$nfname = trim(@$_REQUEST['ufname']);
$nlname = trim(@$_REQUEST['ulname']);
$nexten = (int) trim(@$_REQUEST['uexten']);
$npin = (int) trim(@$_REQUEST['upin']);
$action = trim(@$_REQUEST['action']);
if (!$db) {
    return new GsError('Could not connect to database.');
}
if (!in_array($action, array('list', 'useradd'), true)) {
    $action = 'list';
}
$group_id = gs_group_id_get('admins');
if ($action === 'useradd') {
    $ulang = gs_get_lang_global(GS_LANG_OPT_AST, GS_LANG_FORMAT_AST);
    $ret = gs_user_add($nuser, $nexten, $npin, $nfname, $nlname, $ulang, '1', '');
    if (isGsError($ret)) {
        echo '<div class="errorbox">', $ret->getMsg(), '</div>', "\n";
    } else {
        $ret = gs_group_member_add($group_id, $nuser);
        if (isGsError($ret)) {
            echo '<div class="errorbox">', $ret->getMsg(), '</div>', "\n";
        }
    }
    $action = 'list';
}
if ($action === 'list') {
    echo '<h1>', __('Administratoren'), '</h1>';
    echo __('Sie m&uuml;ssen mindestens einen Benutzer mit Adminrechten anlegen. Mit diesem Benutzer k&ouml;nnem Sie sich am normalen Web-Interface anmelden. Pflichtfelder sind: Benutzername, Durchwahl und PIN.');
    echo '<p>';
Beispiel #2
0
        if ($params['port'] > 0) {
            echo 'port = ', $params['port'], "\n";
        }
        echo 'auth = ', $params['auth'], "\n";
        echo 'username = '******'user'], "\n";
        echo 'secret = ', $gw['pwd'], "\n";
        echo 'insecure = ', 'port,invite', "\n";
        echo 'jitterbuffer = ', $params['jitterbuffer'], "\n";
        echo 'trunk = ', $params['trunk'], "\n";
        echo 'setvar=__is_from_gateway=1', "\n";
        echo 'context = ', 'from-gg-' . $gw['gg_name'], "\n";
        echo 'qualify = ', $params['qualify'], "\n";
        echo 'encryption = ', $params['encryption'], "\n";
        echo 'disallow = ', 'all', "\n";
        echo 'requirecalltoken = ', 'no', "\n";
        if (strlen(trim(gs_get_conf('GS_INTL_ASTERISK_LANG'))) > 0) {
            echo 'language = ', gs_get_lang_global(GS_LANG_OPT_AST, GS_LANG_FORMAT_AST), "\n";
        }
        foreach ($codecs_allow as $codec => $allowed) {
            if ($allowed) {
                echo 'allow = ', $codec, "\n";
            }
        }
        if ($params['permit'] != null && 'x' . $params['permit'] != 'x' . '0.0.0.0/0') {
            echo 'deny = ', '0.0.0.0/0.0.0.0', "\n";
            # deny all
            echo 'permit = ', $params['permit'], "\n";
        }
        echo "\n";
    }
}
Beispiel #3
0
function gs_prov_add_phone_get_nobody_user_id($db, $mac_addr, $phone_type, $phone_ip)
{
    $add_nobody_locally_if_foreign_failed = false;
    # hack
    $mac_addr = preg_replace('/[^0-9A-F\\-]/', '', strToUpper($mac_addr));
    @gs_db_start_trans($db);
    # find host for the new nobody user
    #
    $boi_host_id = gs_prov_new_phone_find_boi_host_id($db, $phone_ip);
    if ($boi_host_id === false) {
        @gs_db_rollback_trans($db);
        return false;
    }
    if ($boi_host_id < 1) {
        # Gemeinschaft
        switch (gs_get_conf('GS_PROV_AUTO_ADD_PHONE_HOST')) {
            case 'last':
                $host_id_sql = 'SELECT MAX(`id`) FROM `hosts` WHERE `is_foreign`=0';
                break;
            case 'random':
                $host_id_sql = 'SELECT `id` FROM `hosts` WHERE `is_foreign`=0 ORDER BY RAND() LIMIT 1';
                break;
            case 'first':
            default:
                $host_id_sql = 'SELECT MIN(`id`) FROM `hosts` WHERE `is_foreign`=0';
                break;
        }
        $host_id = (int) $db->executeGetOne($host_id_sql);
        if ($host_id < 1) {
            gs_log(GS_LOG_WARNING, 'Could not find a host for adding a nobody user');
            @gs_db_rollback_trans($db);
            return false;
        }
    } else {
        # foreign host (BOI)
        $host_id = $boi_host_id;
    }
    # add a nobody user
    #
    $new_nobody_index = (int) ((int) $db->executeGetOne('SELECT MAX(`nobody_index`) FROM `users`') + 1);
    $new_nobody_num = 0;
    $hp_route_prefix = 0;
    $soap_user_ext = 0;
    if ($boi_host_id > 0) {
        $new_nobody_num = (int) $db->executeGetOne('SELECT COUNT(`user`) FROM `users` WHERE `nobody_index` IS NOT NULL AND `host_id`=' . $boi_host_id);
        $hp_route_prefix = (string) $db->executeGetOne('SELECT `value` FROM `host_params` ' . 'WHERE `host_id`=' . (int) $boi_host_id . ' AND `param`=\'route_prefix\'');
        $username = '******' . $hp_route_prefix . '-' . str_pad($new_nobody_num, 5, '0', STR_PAD_LEFT);
    } else {
        $username = '******' . str_pad($new_nobody_index, 5, '0', STR_PAD_LEFT);
    }
    $ok = $db->execute('INSERT INTO `users` ' . '(`id`, `user`, `pin`, `firstname`, `lastname`, `honorific`, `email`, `nobody_index`, `host_id`) ' . 'VALUES ' . '(NULL, \'' . $db->escape($username) . '\', \'\', \'\', \'\', \'\', \'\', ' . $new_nobody_index . ', ' . $host_id . ')');
    if (!$ok || !($user_id = (int) $db->getLastInsertId())) {
        gs_log(GS_LOG_WARNING, 'Failed to add nobody user ' . $username . ' to database');
        @gs_db_rollback_trans($db);
        return false;
    } else {
        //gs_log( GS_LOG_DEBUG, 'Nobody user '. $username .' added to database (pending)' );
    }
    # add a SIP account:
    #
    if ($boi_host_id > 0) {
        $user_ext = $hp_route_prefix . gs_nobody_index_to_extension($new_nobody_num, true);
        $soap_user_ext = gs_nobody_index_to_extension($new_nobody_num, true);
        //$user_ext = $hp_route_prefix . $soap_user_ext;
    } else {
        $user_ext = gs_nobody_index_to_extension($new_nobody_index, false);
    }
    $sip_pwd = gs_prov_gen_sip_pwd();
    $ok = $db->execute('INSERT INTO `ast_sipfriends` ' . '(`_user_id`, `name`, `secret`, `context`, `callerid`, `setvar`, `language`) ' . 'VALUES ' . '(' . $user_id . ', \'' . $db->escape($user_ext) . '\', \'' . $db->escape($sip_pwd) . '\', \'from-internal-nobody\', _utf8\'' . $db->escape(GS_NOBODY_CID_NAME . $new_nobody_index . ' <' . $user_ext . '>') . '\', \'' . $db->escape('__user_id=' . $user_id . ';__user_name=' . $user_ext) . '\', \'' . gs_get_lang_global(GS_LANG_OPT_GS, GS_LANG_FORMAT_AST) . '\')');
    if (!$ok) {
        gs_log(GS_LOG_WARNING, 'Failed to add a nobody user');
        @gs_db_rollback_trans($db);
        return false;
    }
    # add nobody user at foreign host?
    #
    if ($boi_host_id > 0) {
        gs_log(GS_LOG_DEBUG, "Adding a nobody user at foreign host ID {$boi_host_id}");
        if (!gs_get_conf('GS_BOI_ENABLED')) {
            gs_log(GS_LOG_WARNING, 'Failed to add nobody user on foreign host (BOI not enabled)');
            @gs_db_rollback_trans($db);
            return false;
        }
        include_once GS_DIR . 'inc/boi-soap/boi-api.php';
        $api = gs_host_get_api($boi_host_id);
        switch ($api) {
            case 'm01':
            case 'm02':
                if (!extension_loaded('soap')) {
                    gs_log(GS_LOG_WARNING, 'Failed to add nobody user on foreign host (SoapClient not available)');
                    @gs_db_rollback_trans($db);
                    return false;
                }
                include_once GS_DIR . 'inc/boi-soap/boi-soap.php';
                $boi_host = $db->executeGetOne('SELECT `host` FROM `hosts` WHERE `id`=' . $host_id);
                if (!$boi_host) {
                    gs_log(GS_LOG_WARNING, 'DB error: Failed to get host');
                    @gs_db_rollback_trans($db);
                    return false;
                }
                $soap_faultcode = null;
                $ok = gs_boi_update_extension($api, $boi_host, '', $soap_user_ext, $username, $sip_pwd, '', '', '', '', $soap_faultcode);
                if (!$ok) {
                    gs_log(GS_LOG_WARNING, "Failed to add nobody user {$username} on foreign host {$boi_host} (SOAP error)");
                    if (!$add_nobody_locally_if_foreign_failed) {
                        // normal behavior
                        @gs_db_rollback_trans($db);
                        return false;
                    } else {
                        //FIXME - remove me - ugly hack
                        $host_id = 1;
                        gs_log(GS_LOG_DEBUG, "Failed to add nobody user on foreign host. Updating user {$username}, id: {$user_id} to host id {$host_id}");
                        $ok = $db->execute('UPDATE `users` SET ' . '`host_id`=' . $host_id . ' ' . 'WHERE ' . '`id`=' . $user_id);
                        if (!$ok) {
                            gs_log(GS_LOG_WARNING, "Failed to update nobody user {$username} at host id {$host_id}");
                            @gs_db_rollback_trans($db);
                            return false;
                        }
                    }
                }
                break;
            case '':
                # host does not provide any API
                gs_log(GS_LOG_NOTICE, 'Adding user ' . $username . ' on foreign host ' . $boi_host_id . ' without any API');
                break;
            default:
                gs_log(GS_LOG_WARNING, 'Failed to add user ' . $username . ' on foreign host ' . $boi_host_id . ' - invalid API "' . $api . '"');
                @gs_db_rollback_trans($db);
                return false;
        }
    }
    # add the phone - but if it already exist only update the nobody-user
    #
    $old_id = $db->executeGetOne('SELECT `id` FROM `phones` WHERE `mac_addr`=\'' . $mac_addr . '\'');
    if ($old_id) {
        $ok = $db->execute('UPDATE `phones` SET `nobody_index`=' . $new_nobody_index . ' WHERE `id`=' . $old_id);
        if (!$ok) {
            gs_log(GS_LOG_WARNING, "Failed to update nobody_index {$new_nobody_index} of phone {$mac_addr}");
            @gs_db_rollback_trans($db);
            return false;
        }
    } else {
        $ok = $db->execute('INSERT INTO `phones` ' . '(`id`, `type`, `mac_addr`, `user_id`, `nobody_index`, `added`) ' . 'VALUES ' . '(NULL, \'' . $db->escape($phone_type) . '\', \'' . $db->escape($mac_addr) . '\', ' . $user_id . ', ' . $new_nobody_index . ', ' . time() . ')');
        if (!$ok) {
            gs_log(GS_LOG_WARNING, "Failed to add new phone {$mac_addr}");
            @gs_db_rollback_trans($db);
            return false;
        }
    }
    $ok = @gs_db_commit_trans($db);
    if (!$ok) {
        gs_log(GS_LOG_WARNING, 'DB error');
        return false;
    }
    return $user_id;
}