Exemple #1
0
 def _reroll(self):
     from freenasUI.account.forms import FilteredSelectJSON
     try:
         groups = FreeNAS_Groups(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_GROUP)
     except:
         groups = []
     if len(groups) > 500:
         if self.initial:
             self.choices = ((self.initial, self.initial),)
         self.widget = FilteredSelectJSON(
             attrs=self.widget.attrs,
             url=("account_bsdgroup_json",)
         )
     else:
         glist = []
         if not self.required:
             glist.append(('-----', 'N/A'))
         notbuiltin = [
             o[0]
             for o in bsdGroups.objects.filter(
                 bsdgrp_builtin=False
             ).values_list('bsdgrp_gid')
         ]
         glist.extend(
             [(x.gr_name, x.gr_name) for x in sorted(
                 groups,
                 key=lambda y: (y.gr_gid not in notbuiltin, y.gr_name)
             )]
         )
         #self.choices = glist
         self.widget = FilteredSelectJSON(
             attrs=self.widget.attrs,
             url=("account_bsdgroup_json",),
             choices=glist
         )
Exemple #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
    return HttpResponse(
        json.dumps(json_group, indent=3),
        content_type='application/json',
    )
Exemple #3
0
def cache_fill(**kwargs):
    uargs = {'flags': FLAGS_DBINIT | FLAGS_CACHE_WRITE_USER}
    gargs = {'flags': FLAGS_DBINIT | FLAGS_CACHE_WRITE_GROUP}

    for u in FreeNAS_Users(**uargs):
        pass
    for g in FreeNAS_Groups(**gargs):
        pass
Exemple #4
0
def cache_dump(**kwargs):
    print("FreeNAS_Users:")
    for u in FreeNAS_Users(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_USER):
        print("    ", u)

    print("\n\n")

    print("FreeNAS_Groups:")
    for g in FreeNAS_Groups(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_GROUP):
        print("    ", g)
Exemple #5
0
 def _reroll(self):
     from freenasUI.account.forms import FilteredSelectJSON
     groups = FreeNAS_Groups(flags=FLAGS_DBINIT | FLAGS_CACHE_READ_GROUP
                             | FLAGS_CACHE_WRITE_GROUP)
     if len(groups) > 500:
         if self.initial:
             self.choices = ((self.initial, self.initial), )
         self.widget = FilteredSelectJSON(url=("account_bsdgroup_json", ))
     else:
         glist = []
         if not self.required:
             glist.append(('-----', 'N/A'))
         glist.extend([(x.gr_name, x.gr_name) for x in groups])
         self.widget = widgets.FilteringSelect()
         self.choices = glist
Exemple #6
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',
    )