Beispiel #1
0
def json_groups(request):

    query = request.GET.get("q", None)

    json_group = {"identifier": "id", "label": "name", "items": []}

    idx = 1
    for grp in FreeNAS_Groups(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_GROUP | FLAGS_CACHE_WRITE_GROUP):
        if idx > 50:
            break
        if query is None or grp.gr_name.startswith(query):
            json_group["items"].append({"id": grp.gr_name, "name": grp.gr_name, "label": grp.gr_name})
            idx += 1

    # Show groups for the directory service provided in the wizard
    wizard_ds = request.session.get("wizard_ds")
    if request.GET.get("wizard") == "1" and wizard_ds:
        if wizard_ds.get("ds_type") == "ad":
            groups = FreeNAS_ActiveDirectory_Groups(
                domainname=wizard_ds.get("ds_ad_domainname"),
                bindname=wizard_ds.get("ds_ad_bindname"),
                bindpw=wizard_ds.get("ds_ad_bindpw"),
                flags=FLAGS_DBINIT,
            )
        elif wizard_ds.get("ds_type") == "ldap":
            groups = FreeNAS_LDAP_Groups(
                host=wizard_ds.get("ds_ldap_hostname"),
                basedn=wizard_ds.get("ds_ldap_basedn"),
                binddn=wizard_ds.get("ds_ldap_binddn"),
                bindpw=wizard_ds.get("ds_ldap_bindpw"),
                flags=FLAGS_DBINIT,
            )
        elif wizard_ds.get("ds_type") == "nis":
            groups = FreeNAS_NIS_Groups(
                domain=wizard_ds.get("ds_nis_domain"),
                servers=wizard_ds.get("ds_nis_servers"),
                secure_mode=wizard_ds.get("ds_nis_secure_mode"),
                manycast=wizard_ds.get("ds_nis_manycast"),
                flags=FLAGS_DBINIT,
            )
        else:
            groups = None

        if groups is not None:
            idx = 1
            # FIXME: code duplication withe the block above
            for group in groups._get_uncached_groupnames():
                if idx > 50:
                    break
                if query is None or group.startswith(query):
                    json_group["items"].append(
                        {"id": "%s_%s" % (wizard_ds.get("ds_type"), group), "name": group, "label": group}
                    )
                    idx += 1

            del groups

    return HttpResponse(json.dumps(json_group, indent=3), content_type="application/json")
Beispiel #2
0
def json_groups(request):

    query = request.GET.get("q", None)

    json_group = {
        'identifier': 'id',
        'label': 'name',
        'items': [],
    }

    idx = 1
    for grp in FreeNAS_Groups(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_GROUP
                              | FLAGS_CACHE_WRITE_GROUP):
        if idx > 50:
            break
        if query is None or grp.gr_name.startswith(query):
            json_group['items'].append({
                'id': grp.gr_name,
                'name': grp.gr_name,
                'label': grp.gr_name,
            })
            idx += 1

    # Show groups for the directory service provided in the wizard
    wizard_ds = request.session.get('wizard_ds')
    if request.GET.get('wizard') == '1' and wizard_ds:
        if wizard_ds.get('ds_type') == 'ad':
            groups = FreeNAS_ActiveDirectory_Groups(
                domainname=wizard_ds.get('ds_ad_domainname'),
                bindname=wizard_ds.get('ds_ad_bindname'),
                bindpw=wizard_ds.get('ds_ad_bindpw'),
                flags=FLAGS_DBINIT,
            )
        elif wizard_ds.get('ds_type') == 'ldap':
            groups = FreeNAS_LDAP_Groups(
                host=wizard_ds.get('ds_ldap_hostname'),
                basedn=wizard_ds.get('ds_ldap_basedn'),
                binddn=wizard_ds.get('ds_ldap_binddn'),
                bindpw=wizard_ds.get('ds_ldap_bindpw'),
                flags=FLAGS_DBINIT,
            )
        elif wizard_ds.get('ds_type') == 'nis':
            groups = FreeNAS_NIS_Groups(
                domain=wizard_ds.get('ds_nis_domain'),
                servers=wizard_ds.get('ds_nis_servers'),
                secure_mode=wizard_ds.get('ds_nis_secure_mode'),
                manycast=wizard_ds.get('ds_nis_manycast'),
                flags=FLAGS_DBINIT,
            )
        else:
            groups = None

        if groups is not None:
            idx = 1
            # FIXME: code duplication withe the block above
            for group in groups._get_uncached_groupnames():
                if idx > 50:
                    break
                if query is None or group.startswith(query):
                    json_group['items'].append({
                        'id':
                        '%s_%s' % (
                            wizard_ds.get('ds_type'),
                            group,
                        ),
                        'name':
                        group,
                        'label':
                        group,
                    })
                    idx += 1

            del groups

    return HttpResponse(
        json.dumps(json_group, indent=3),
        content_type='application/json',
    )
Beispiel #3
0
def json_groups(request):

    query = request.GET.get("q", None)

    json_group = {
        'identifier': 'id',
        'label': 'name',
        'items': [],
    }

    idx = 1
    curr_groups = []
    for grp in FreeNAS_Groups(
        flags=FLAGS_DBINIT | FLAGS_CACHE_READ_GROUP | FLAGS_CACHE_WRITE_GROUP
    ):
        if idx > 50:
            break
        if ((query is None or grp.gr_name.startswith(query.encode('utf8'))) and
            grp.gr_name not in curr_groups):
            json_group['items'].append({
                'id': grp.gr_name,
                'name': grp.gr_name,
                'label': grp.gr_name,
            })
            idx += 1
            curr_groups.append(grp.gr_name)

    # Show groups for the directory service provided in the wizard
    wizard_ds = request.session.get('wizard_ds')
    if request.GET.get('wizard') == '1' and wizard_ds:
        if wizard_ds.get('ds_type') == 'ad':
            groups = FreeNAS_ActiveDirectory_Groups(
                domainname=wizard_ds.get('ds_ad_domainname'),
                bindname=wizard_ds.get('ds_ad_bindname'),
                bindpw=wizard_ds.get('ds_ad_bindpw'),
                flags=FLAGS_DBINIT,
            )
        elif wizard_ds.get('ds_type') == 'ldap':
            groups = FreeNAS_LDAP_Groups(
                host=wizard_ds.get('ds_ldap_hostname'),
                basedn=wizard_ds.get('ds_ldap_basedn'),
                binddn=wizard_ds.get('ds_ldap_binddn'),
                bindpw=wizard_ds.get('ds_ldap_bindpw'),
                flags=FLAGS_DBINIT,
            )
        elif wizard_ds.get('ds_type') == 'nis':
            groups = FreeNAS_NIS_Groups(
                domain=wizard_ds.get('ds_nis_domain'),
                servers=wizard_ds.get('ds_nis_servers'),
                secure_mode=wizard_ds.get('ds_nis_secure_mode'),
                manycast=wizard_ds.get('ds_nis_manycast'),
                flags=FLAGS_DBINIT,
            )
        else:
            groups = None

        if groups is not None:
            idx = 1
            # FIXME: code duplication withe the block above
            for group in groups._get_uncached_groupnames():
                if idx > 50:
                    break
                if query is None or group.startswith(query.encode('utf8')):
                    json_group['items'].append({
                        'id': '%s_%s' % (
                            wizard_ds.get('ds_type'),
                            group,
                        ),
                        'name': group,
                        'label': group,
                    })
                    idx += 1

            del groups

    return HttpResponse(
        json.dumps(json_group, indent=3),
        content_type='application/json',
    )