Esempio n. 1
0
    def _gen_dataset(self, node, dataset):
        if dataset.name.startswith('.'):
            return

        nav = TreeNode(dataset.name)
        nav.name = dataset.mountpoint
        nav.icon = u'VolumesIcon'

        ds = TreeNode('Dataset')
        ds.name = _(u'Create ZFS Dataset')
        ds.view = 'storage_dataset'
        ds.icon = u'AddDatasetIcon'
        ds.type = 'object'
        ds.kwargs = {'fs': dataset.path}
        nav.append_child(ds)

        subnav = TreeNode('ChangePermissions')
        subnav.name = _(u'Change Permissions')
        subnav.type = 'editobject'
        subnav.view = 'storage_mp_permission'
        subnav.kwargs = {'path': dataset.mountpoint}
        subnav.model = 'Volumes'
        subnav.icon = u'ChangePasswordIcon'
        subnav.app_name = 'storage'

        zv = AddZVol()
        zv.kwargs = {'parent': dataset.path}

        node.append_child(nav)
        nav.append_child(subnav)
        nav.append_child(zv)
        for child in dataset.children:
            self._gen_dataset(nav, child)
Esempio n. 2
0
    def _gen_dataset(self, node, dataset):
        if dataset.name.startswith('.'):
            return

        nav = TreeNode(dataset.name)
        nav.name = dataset.mountpoint
        nav.icon = u'VolumesIcon'

        ds = TreeNode('Dataset')
        ds.name = _(u'Create Dataset')
        ds.view = 'storage_dataset'
        ds.icon = u'AddDatasetIcon'
        ds.type = 'object'
        ds.kwargs = {'fs': dataset.path}
        nav.append_child(ds)

        subnav = TreeNode('ChangePermissions')
        subnav.name = _(u'Change Permissions')
        subnav.type = 'editobject'
        subnav.view = 'storage_mp_permission'
        subnav.kwargs = {'path': dataset.mountpoint}
        subnav.model = 'Volumes'
        subnav.icon = u'ChangePasswordIcon'
        subnav.app_name = 'storage'

        zv = AddZVol()
        zv.kwargs = {'parent': dataset.path}

        node.append_child(nav)
        nav.append_child(subnav)
        nav.append_child(zv)
        for child in dataset.children:
            self._gen_dataset(nav, child)
Esempio n. 3
0
    def __init__(self, *args, **kwargs):

        super(Volumes, self).__init__(*args, **kwargs)
        self.append_children([
            AddVolume(),
            ImportVolume(),
            AutoImportVolume(),
            ViewVolumes(),
            ViewDisks(),
        ])

        en_dataset = models.MountPoint.objects.filter(
            mp_volume__vol_fstype__exact='ZFS').count() > 0

        has_multipath = models.Disk.objects.exclude(
            disk_multipath_name='').exists()
        if has_multipath:
            self.append_child(ViewMultipaths())

        mp = models.MountPoint.objects.select_related().order_by('-id')
        for i in mp:
            nav = TreeNode(i.mp_volume.id)
            nav.name = i.mp_path
            nav.order = -i.id
            nav.model = 'Volume'
            nav.kwargs = {'oid': i.mp_volume.id, 'model': 'Volume'}
            nav.icon = u'VolumesIcon'

            if i.mp_volume.vol_fstype == 'ZFS':
                ds = TreeNode('Dataset')
                ds.name = _(u'Create ZFS Dataset')
                ds.view = 'storage_dataset'
                ds.icon = u'AddDatasetIcon'
                ds.type = 'object'
                append_app = False
                ds.kwargs = {'fs': i.mp_volume.vol_name}
                nav.append_child(ds)

                zv = AddZVol()
                zv.kwargs = {'parent': i.mp_volume.vol_name}
                nav.append_child(zv)

            subnav = TreeNode('ChangePermissions')
            subnav.name = _('Change Permissions')
            subnav.type = 'editobject'
            subnav.view = 'storage_mp_permission'
            subnav.kwargs = {'path': i.mp_path}
            subnav.model = 'Volume'
            subnav.icon = u'ChangePasswordIcon'
            subnav.app_name = 'storage'

            datasets = i.mp_volume.get_datasets(hierarchical=True)
            if datasets:
                for name, d in datasets.items():
                    # TODO: non-recursive algo
                    self._gen_dataset(nav, d)

            nav.append_child(subnav)
            self.insert_child(0, nav)
Esempio n. 4
0
    def __init__(self, *args, **kwargs):

        super(Volumes, self).__init__(*args, **kwargs)
        self.append_children([
            AddVolume(),
            ImportVolume(),
            AutoImportVolume(),
            ViewVolumes(),
            ViewDisks(),
        ])

        if not appPool.hook_feature_disabled('ufs'):
            self.append_child(AddVolumeUFS())

        has_multipath = models.Disk.objects.exclude(
            disk_multipath_name=''
        ).exists()
        if has_multipath:
            self.append_child(ViewMultipaths())

        mp = models.MountPoint.objects.select_related().order_by('-id')
        for i in mp:
            nav = TreeNode(i.mp_volume.id)
            nav.name = i.mp_path
            nav.order = -i.id
            nav.model = 'Volume'
            nav.kwargs = {'oid': i.mp_volume.id, 'model': 'Volume'}
            nav.icon = u'VolumesIcon'

            if i.mp_volume.vol_fstype == 'ZFS':
                ds = TreeNode('Dataset')
                ds.name = _(u'Create ZFS Dataset')
                ds.view = 'storage_dataset'
                ds.icon = u'AddDatasetIcon'
                ds.type = 'object'
                ds.kwargs = {'fs': i.mp_volume.vol_name}
                nav.append_child(ds)

                zv = AddZVol()
                zv.kwargs = {'parent': i.mp_volume.vol_name}
                nav.append_child(zv)

            subnav = TreeNode('ChangePermissions')
            subnav.name = _('Change Permissions')
            subnav.type = 'editobject'
            subnav.view = 'storage_mp_permission'
            subnav.kwargs = {'path': i.mp_path}
            subnav.model = 'Volume'
            subnav.icon = u'ChangePasswordIcon'
            subnav.app_name = 'storage'

            datasets = i.mp_volume.get_datasets(hierarchical=True)
            if datasets:
                for name, d in datasets.items():
                    # TODO: non-recursive algo
                    self._gen_dataset(nav, d)

            nav.append_child(subnav)
            self.insert_child(0, nav)
Esempio n. 5
0
    def __init__(self, *args, **kwargs):

        super(Volumes, self).__init__(*args, **kwargs)
        self.append_children([
            AddVolume(),
            ImportDisk(),
            ImportVolume(),
            ViewVolumes(),
            ViewDisks(),
        ])

        if not notifier().is_freenas():
            self.append_child(ViewEnclosure())

        has_multipath = models.Disk.objects.exclude(
            disk_multipath_name=''
        ).exists()
        if has_multipath:
            self.append_child(ViewMultipaths())

        for i in models.Volume.objects.order_by('-id'):
            nav = TreeNode(i.id)
            nav.name = i.vol_path
            nav.order = -i.id
            nav.model = 'Volume'
            nav.kwargs = {'oid': i.id, 'model': 'Volume'}
            nav.icon = 'VolumesIcon'

            ds = TreeNode('Dataset')
            ds.name = _('Create Dataset')
            ds.view = 'storage_dataset'
            ds.icon = 'AddDatasetIcon'
            ds.type = 'object'
            ds.kwargs = {'fs': i.vol_name}
            nav.append_child(ds)

            zv = AddZVol()
            zv.kwargs = {'parent': i.vol_name}
            nav.append_child(zv)

            subnav = TreeNode('ChangePermissions')
            subnav.name = _('Change Permissions')
            subnav.type = 'editobject'
            subnav.view = 'storage_mp_permission'
            subnav.kwargs = {'path': i.vol_path}
            subnav.model = 'Volume'
            subnav.icon = 'ChangePasswordIcon'
            subnav.app_name = 'storage'

            datasets = i.get_datasets(hierarchical=True)
            if datasets:
                for name, d in list(datasets.items()):
                    # TODO: non-recursive algo
                    self._gen_dataset(nav, d)

            nav.append_child(subnav)
            self.insert_child(0, nav)
Esempio n. 6
0
    def __init__(self, *args, **kwargs):

        super(Volumes, self).__init__(*args, **kwargs)
        self.append_children([
            AddVolume(),
            ImportDisk(),
            ImportVolume(),
            ViewVolumes(),
            ViewDisks(),
        ])

        if not notifier().is_freenas():
            self.append_child(ViewEnclosure())

        has_multipath = models.Disk.objects.exclude(
            disk_multipath_name='').exists()
        if has_multipath:
            self.append_child(ViewMultipaths())

        for i in models.Volume.objects.order_by('-id'):
            nav = TreeNode(i.id)
            nav.name = i.vol_path
            nav.order = -i.id
            nav.model = 'Volume'
            nav.kwargs = {'oid': i.id, 'model': 'Volume'}
            nav.icon = 'VolumesIcon'

            if i.vol_fstype == 'ZFS':
                ds = TreeNode('Dataset')
                ds.name = _('Create Dataset')
                ds.view = 'storage_dataset'
                ds.icon = 'AddDatasetIcon'
                ds.type = 'object'
                ds.kwargs = {'fs': i.vol_name}
                nav.append_child(ds)

                zv = AddZVol()
                zv.kwargs = {'parent': i.vol_name}
                nav.append_child(zv)

            subnav = TreeNode('ChangePermissions')
            subnav.name = _('Change Permissions')
            subnav.type = 'editobject'
            subnav.view = 'storage_mp_permission'
            subnav.kwargs = {'path': i.vol_path}
            subnav.model = 'Volume'
            subnav.icon = 'ChangePasswordIcon'
            subnav.app_name = 'storage'

            datasets = i.get_datasets(hierarchical=True)
            if datasets:
                for name, d in list(datasets.items()):
                    # TODO: non-recursive algo
                    self._gen_dataset(nav, d)

            nav.append_child(subnav)
            self.insert_child(0, nav)
Esempio n. 7
0
    def __init__(self, *args, **kwargs):

        super(Linkss, self).__init__(*args, **kwargs)

        laggadd = TreeNode('Add')
        laggadd.name = _('Create Link Aggregation')
        laggadd.view = 'freeadmin_network_lagginterface_add'
        laggadd.type = 'object'
        laggadd.icon = 'AddLAGGIcon'
        laggadd.model = 'LAGGInterface'
        laggadd.app_name = 'network'

        laggview = TreeNode('View')
        laggview.gname = 'View'
        laggview.name = _('View Link Aggregations')
        laggview.type = 'opennetwork'
        laggview.icon = 'ViewAllLAGGsIcon'
        laggview.model = 'LAGGInterface'
        laggview.app_name = 'network'
        self.append_children([laggadd, laggview])

        for value, name in LAGGType:

            laggs = models.LAGGInterface.objects.filter(
                lagg_protocol__exact=value)
            if laggs.count() > 0:
                nav = TreeNode()
                nav.name = name
                nav.icon = 'LAGGIcon'
                nav._children = []
                self.append_child(nav)

            for lagg in laggs:

                subnav = TreeNode()
                subnav.name = lagg.lagg_interface.int_name
                subnav.icon = 'LAGGIcon'
                subnav._children = []
                nav.append_child(subnav)

                laggm = models.LAGGInterfaceMembers.objects.filter(
                    lagg_interfacegroup__exact=lagg.id).order_by(
                        'lagg_ordernum')
                for member in laggm:
                    subsubnav = TreeNode()
                    subsubnav.name = member.lagg_physnic
                    subsubnav.type = 'editobject'
                    subsubnav.icon = 'LAGGIcon'
                    subsubnav.view = 'freeadmin_network_lagginterfacemembers_edit'
                    subsubnav.app_name = 'network'
                    subsubnav.model = 'LAGGInterfaceMembers' + lagg.lagg_interface.int_name
                    subsubnav.kwargs = {'oid': member.id}
                    subsubnav.append_url = '?deletable=false'
                    subsubnav._children = []
                    subnav.append_child(subsubnav)
Esempio n. 8
0
    def __init__(self, *args, **kwargs):

        super(Linkss, self).__init__(*args, **kwargs)

        laggadd = TreeNode("Add")
        laggadd.name = _(u"Create Link Aggregation")
        laggadd.view = "freeadmin_network_lagginterface_add"
        laggadd.type = "object"
        laggadd.icon = u"AddLAGGIcon"
        laggadd.model = "LAGGInterface"
        laggadd.app_name = "network"

        laggview = TreeNode("View")
        laggview.gname = "View"
        laggview.name = _(u"View Link Aggregations")
        laggview.type = "opennetwork"
        laggview.icon = u"ViewAllLAGGsIcon"
        laggview.model = "LAGGInterface"
        laggview.app_name = "network"
        self.append_children([laggadd, laggview])

        for value, name in LAGGType:

            laggs = models.LAGGInterface.objects.filter(lagg_protocol__exact=value)
            if laggs.count() > 0:
                nav = TreeNode()
                nav.name = name
                nav.icon = u"LAGGIcon"
                nav._children = []
                self.append_child(nav)

            for lagg in laggs:

                subnav = TreeNode()
                subnav.name = lagg.lagg_interface.int_name
                subnav.icon = u"LAGGIcon"
                subnav._children = []
                nav.append_child(subnav)

                laggm = models.LAGGInterfaceMembers.objects.filter(lagg_interfacegroup__exact=lagg.id).order_by(
                    "lagg_ordernum"
                )
                for member in laggm:
                    subsubnav = TreeNode()
                    subsubnav.name = member.lagg_physnic
                    subsubnav.type = "editobject"
                    subsubnav.icon = u"LAGGIcon"
                    subsubnav.view = "freeadmin_network_lagginterfacemembers_edit"
                    subsubnav.app_name = "network"
                    subsubnav.model = "LAGGInterfaceMembers" + lagg.lagg_interface.int_name
                    subsubnav.kwargs = {"oid": member.id}
                    subsubnav.append_url = "?deletable=false"
                    subsubnav._children = []
                    subnav.append_child(subsubnav)
Esempio n. 9
0
    def __init__(self, *args, **kwargs):

        super(Linkss, self).__init__(*args, **kwargs)

        laggadd = TreeNode('Add')
        laggadd.name = _(u'Create Link Aggregation')
        laggadd.view = 'freeadmin_network_lagginterface_add'
        laggadd.type = 'object'
        laggadd.icon = u'AddLAGGIcon'
        laggadd.model = 'LAGGInterface'
        laggadd.app_name = 'network'

        laggview = TreeNode('View')
        laggview.gname = 'View'
        laggview.name = _(u'View Link Aggregations')
        laggview.type = 'opennetwork'
        laggview.icon = u'ViewAllLAGGsIcon'
        laggview.model = 'LAGGInterface'
        laggview.app_name = 'network'
        self.append_children([laggadd, laggview])

        for value, name in LAGGType:

            laggs = models.LAGGInterface.objects.filter(lagg_protocol__exact=value)
            if laggs.count() > 0:
                nav = TreeNode()
                nav.name = name
                nav.icon = u'LAGGIcon'
                nav._children = []
                self.append_child(nav)

            for lagg in laggs:

                subnav = TreeNode()
                subnav.name = lagg.lagg_interface.int_name
                subnav.icon = u'LAGGIcon'
                subnav._children = []
                nav.append_child(subnav)

                laggm = models.LAGGInterfaceMembers.objects.filter(
                    lagg_interfacegroup__exact=lagg.id
                ).order_by('lagg_ordernum')
                for member in laggm:
                    subsubnav = TreeNode()
                    subsubnav.name = member.lagg_physnic
                    subsubnav.type = 'editobject'
                    subsubnav.icon = u'LAGGIcon'
                    subsubnav.view = 'freeadmin_network_lagginterfacemembers_edit'
                    subsubnav.app_name = 'network'
                    subsubnav.model = 'LAGGInterfaceMembers' + lagg.lagg_interface.int_name
                    subsubnav.kwargs = {'oid': member.id}
                    subsubnav.append_url = '?deletable=false'
                    subsubnav._children = []
                    subnav.append_child(subsubnav)
Esempio n. 10
0
    def __init__(self, *args, **kwargs):
        super(AdminAccount, self).__init__(*args, **kwargs)

        chpw = TreeNode('ChangePass')
        chpw.name = _('Change Password')
        chpw.type = 'openaccount'
        chpw.icon = u'ChangePasswordIcon'

        chad = TreeNode('ChangeAdmin')
        chad.name = _('Change Admin User')
        chad.type = 'openaccount'
        chad.icon = u'ChangeAdminIcon'
        self.append_children([chpw, chad])
Esempio n. 11
0
    def __init__(self, *args, **kwargs):
        super(AdminAccount, self).__init__(*args, **kwargs)

        chpw = TreeNode('ChangePass')
        chpw.name = _('Change Password')
        chpw.type = 'openaccount'
        chpw.icon = u'ChangePasswordIcon'

        chad = TreeNode('ChangeAdmin')
        chad.name = _('Change Admin User')
        chad.type = 'openaccount'
        chad.icon = u'ChangeAdminIcon'
        self.append_children([chpw, chad])
Esempio n. 12
0
    def new_jail_node(self, jail, icon='JailIcon'):
        jail_node = TreeNode()

        jail_node.gname = jail.jail_host
        jail_node.name = jail.jail_host
        jail_node.icon = icon

        return jail_node
Esempio n. 13
0
    def new_storage_node(self, jail):
        storage_node = TreeNode()

        storage_node.gname = 'Storage'
        storage_node.name = _('Storage')
        storage_node.icon = 'JailStorageIcon'

        return storage_node
Esempio n. 14
0
    def new_storage_node(self, jail):
        storage_node = TreeNode()

        storage_node.gname = 'Storage'
        storage_node.name = _(u'Storage')
        storage_node.icon = u'JailStorageIcon'

        return storage_node
Esempio n. 15
0
    def new_jail_node(self, jail, icon=u'JailIcon'):
        jail_node = TreeNode()

        jail_node.gname = jail.jail_host
        jail_node.name = jail.jail_host
        jail_node.icon = icon

        return jail_node
Esempio n. 16
0
    def new_storage_node_mkdir(self, jail):
        storage_node_add = TreeNode()

        storage_node_add.name = _('Make Directory')
        storage_node_add.type = 'editobject'
        storage_node_add.view = 'jail_mkdir'
        storage_node_add.kwargs = {'id': jail.id}
        storage_node_add.icon = u'JailMkdirIcon'
        storage_node_add.app_name = 'jails'

        return storage_node_add
Esempio n. 17
0
    def new_storage_node_mkdir(self, jail):
        storage_node_add = TreeNode()

        storage_node_add.name = _('Make Directory')
        storage_node_add.type = 'editobject'
        storage_node_add.view = 'jail_mkdir'
        storage_node_add.kwargs = { 'id': jail.id }
        storage_node_add.icon = u'JailMkdirIcon'
        storage_node_add.app_name = 'jails' 

        return storage_node_add 
Esempio n. 18
0
    def new_storage_node_add(self, jail):
        storage_node_add = TreeNode()

        storage_node_add.name = _('Add Storage')
        storage_node_add.type = 'editobject'
        storage_node_add.view = 'jail_storage_add'
        storage_node_add.kwargs = { 'jail_id': jail.id }
        storage_node_add.model = 'NullMountPoint'
        storage_node_add.icon = u'JailStorageIcon'
        storage_node_add.app_name = 'jails' 

        return storage_node_add 
Esempio n. 19
0
    def new_storage_node_view(self, nmp):
        storage_node_view = TreeNode()

        storage_node_view.name = _('%s' % nmp.destination)
        storage_node_view.type = 'editobject'
        storage_node_view.view = 'jail_storage_view'
        storage_node_view.kwargs = { 'id': nmp.id }
        storage_node_view.model = 'NullMountPoint'
        storage_node_view.icon = u'SettingsIcon'
        storage_node_view.app_name = 'jails' 

        return storage_node_view
Esempio n. 20
0
    def new_jail_node_view(self, jail):
        jail_node_view = TreeNode()

        jail_node_view.name = _('Edit')
        jail_node_view.type = 'editobject'
        jail_node_view.view = 'jail_edit'
        jail_node_view.kwargs = {'id': jail.id}
        jail_node_view.model = 'Jails'
        jail_node_view.icon = u'SettingsIcon'
        jail_node_view.app_name = 'jails'

        return jail_node_view
Esempio n. 21
0
    def new_storage_node_add(self, jail):
        storage_node_add = TreeNode()

        storage_node_add.name = _('Add Storage')
        storage_node_add.type = 'editobject'
        storage_node_add.view = 'jail_storage_add'
        storage_node_add.kwargs = {'jail_id': jail.id}
        storage_node_add.model = 'NullMountPoint'
        storage_node_add.icon = u'JailStorageIcon'
        storage_node_add.app_name = 'jails'

        return storage_node_add
Esempio n. 22
0
    def new_storage_node_view(self, nmp):
        storage_node_view = TreeNode()

        storage_node_view.name = _('%s' % nmp.destination)
        storage_node_view.type = 'editobject'
        storage_node_view.view = 'jail_storage_view'
        storage_node_view.kwargs = {'id': nmp.id}
        storage_node_view.model = 'NullMountPoint'
        storage_node_view.icon = u'SettingsIcon'
        storage_node_view.app_name = 'jails'

        return storage_node_view
Esempio n. 23
0
    def new_jail_node_view(self, jail):
        jail_node_view = TreeNode()

        jail_node_view.name = _('Edit')
        jail_node_view.type = 'editobject'
        jail_node_view.view = 'jail_edit'
        jail_node_view.kwargs = { 'id': jail.id }
        jail_node_view.model = 'Jails'
        jail_node_view.icon = u'SettingsIcon'
        jail_node_view.app_name = 'jails' 

        return jail_node_view
Esempio n. 24
0
    def new_storage_node_view(self, nmp):
        storage_node_view = TreeNode()

        storage_node_view.name = nmp.destination
        storage_node_view.gname = str(nmp.id)
        storage_node_view.type = 'editobject'
        storage_node_view.view = 'freeadmin_jails_jailmountpoint_edit'
        storage_node_view.kwargs = {'oid': nmp.id}
        storage_node_view.model = 'JailMountPoint'
        storage_node_view.icon = 'SettingsIcon'
        storage_node_view.app_name = 'jails'

        return storage_node_view
Esempio n. 25
0
    def new_storage_node_view(self, nmp):
        storage_node_view = TreeNode()

        storage_node_view.name = nmp.destination
        storage_node_view.gname = nmp.id
        storage_node_view.type = 'editobject'
        storage_node_view.view = 'freeadmin_jails_jailmountpoint_edit'
        storage_node_view.kwargs = {'oid': nmp.id}
        storage_node_view.model = 'JailMountPoint'
        storage_node_view.icon = u'SettingsIcon'
        storage_node_view.app_name = 'jails'

        return storage_node_view
Esempio n. 26
0
    def new_activedirectory_node(self):
        ad_node = TreeNode("Active Directory")

        ad_node.name = 'Active Directory'
        ad_node.app_name = 'activedirectory'
        ad_node.icon = u'ActiveDirectoryIcon'

        try:
            ad = ActiveDirectory.objects.order_by("-id")[0]
            ad_node.kwargs = {'oid': ad.id}
            ad_node.type = 'editobject'
            ad_node.view = 'freeadmin_services_activedirectory_edit'

        except IndexError:
            ad_node.type = 'object'
            ad_node.view = 'freeadmin_services_activedirectory_add'

        return ad_node
Esempio n. 27
0
    def new_domaincontroller_node(self):
        ad_node = TreeNode("Domain Controller")

        ad_node.name = 'Domain Controller'
        ad_node.app_name = 'domaincontroller'
        ad_node.icon = u'DomainControllerIcon'

        try:
            ad = DomainController.objects.order_by("-id")[0]
            ad_node.kwargs = {'oid': ad.id}
            ad_node.type = 'editobject'
            ad_node.view = 'freeadmin_services_domaincontroller_edit'

        except IndexError:
            ad_node.type = 'object'
            ad_node.view = 'freeadmin_services_domaincontroller_add'

        return ad_node
Esempio n. 28
0
    def new_nt4_node(self):
        nt4_node = TreeNode("NT4")

        nt4_node.name = 'NT4'
        nt4_node.app_name = 'nt4'
        nt4_node.icon = u'NT4Icon'

        try:
            nt4 = NT4.objects.order_by("-id")[0]
            nt4_node.kwargs = {'oid': nt4.id}
            nt4_node.type = 'editobject'
            nt4_node.view = 'freeadmin_services_nt4_edit'

        except IndexError:
            nt4_node.type = 'object'
            nt4_node.view = 'freeadmin_services_nt4_add'

        return nt4_node
Esempio n. 29
0
    def new_ldap_node(self):
        ldap_node = TreeNode("LDAP")

        ldap_node.name = 'LDAP'
        ldap_node.app_name = 'ldap'
        ldap_node.icon = u'LDAPIcon'

        try:
            ldap = LDAP.objects.order_by("-id")[0]
            ldap_node.kwargs = {'oid': ldap.id}
            ldap_node.type = 'editobject'
            ldap_node.view = 'freeadmin_services_ldap_edit'

        except IndexError:
            ldap_node.type = 'object'
            ldap_node.view = 'freeadmin_services_ldap_add'

        return ldap_node
Esempio n. 30
0
    def new_ldap_node(self):
        ldap_node = TreeNode("LDAP")

        ldap_node.name = 'LDAP'
        ldap_node.app_name = 'ldap'
        ldap_node.icon = u'LDAPIcon'

        try:
            ldap = LDAP.objects.order_by("-id")[0]
            ldap_node.kwargs = {'oid': ldap.id}
            ldap_node.type = 'editobject'
            ldap_node.view = 'freeadmin_services_ldap_edit'

        except IndexError:
            ldap_node.type = 'object'
            ldap_node.view = 'freeadmin_services_ldap_add'

        return ldap_node
Esempio n. 31
0
    def new_nt4_node(self):
        nt4_node = TreeNode("NT4")

        nt4_node.name = 'NT4'
        nt4_node.app_name = 'nt4'
        nt4_node.icon = u'NT4Icon'

        try:
            nt4 = NT4.objects.order_by("-id")[0]
            nt4_node.kwargs = {'oid': nt4.id}
            nt4_node.type = 'editobject'
            nt4_node.view = 'freeadmin_services_nt4_edit'

        except IndexError:
            nt4_node.type = 'object'
            nt4_node.view = 'freeadmin_services_nt4_add'

        return nt4_node
Esempio n. 32
0
    def new_nis_node(self):
        nis_node = TreeNode("NIS")

        nis_node.name = 'NIS'
        nis_node.app_name = 'nis'
        nis_node.icon = u'NISIcon'

        try:
            nis = NIS.objects.order_by("-id")[0]
            nis_node.kwargs = {'oid': nis.id}
            nis_node.type = 'editobject'
            nis_node.view = 'freeadmin_services_nis_edit'

        except IndexError:
            nis_node.type = 'object'
            nis_node.view = 'freeadmin_services_nis_add'

        return nis_node
Esempio n. 33
0
    def new_domaincontroller_node(self):
        ad_node = TreeNode("Domain Controller")

        ad_node.name = 'Domain Controller'
        ad_node.app_name = 'domaincontroller'
        ad_node.icon = u'DomainControllerIcon'

        try:
            ad = DomainController.objects.order_by("-id")[0]
            ad_node.kwargs = {'oid': ad.id}
            ad_node.type = 'editobject'
            ad_node.view = 'freeadmin_services_domaincontroller_edit'

        except IndexError:
            ad_node.type = 'object'
            ad_node.view = 'freeadmin_services_domaincontroller_add'

        return ad_node
Esempio n. 34
0
    def new_nis_node(self):
        nis_node = TreeNode("NIS")

        nis_node.name = 'NIS'
        nis_node.app_name = 'nis'
        nis_node.icon = u'NISIcon'

        try:
            nis = NIS.objects.order_by("-id")[0]
            nis_node.kwargs = {'oid': nis.id}
            nis_node.type = 'editobject'
            nis_node.view = 'freeadmin_services_nis_edit'

        except IndexError:
            nis_node.type = 'object'
            nis_node.view = 'freeadmin_services_nis_add'

        return nis_node
Esempio n. 35
0
    def new_activedirectory_node(self):
        ad_node = TreeNode("Active Directory")

        ad_node.name = 'Active Directory'
        ad_node.app_name = 'activedirectory'
        ad_node.icon = u'ActiveDirectoryIcon'

        try:
            ad = ActiveDirectory.objects.order_by("-id")[0]
            ad_node.kwargs = {'oid': ad.id}
            ad_node.type = 'editobject'
            ad_node.view = 'freeadmin_services_activedirectory_edit'

        except IndexError:
            ad_node.type = 'object'
            ad_node.view = 'freeadmin_services_activedirectory_add'

        return ad_node
Esempio n. 36
0
    def __init__(self, *args, **kwargs):
        super(ViewPluginJails, self).__init__(*args, **kwargs)
        request = kwargs.get('request')

        host = get_base_url(request)
        jails = Jails.objects.filter(jail_type=WARDEN_TYPE_PLUGINJAIL)

        for jail in jails:
            jail_node = self.new_jail_node(jail, u'JailPluginIcon')
            self.append_child(jail_node)

            jail_node_view = self.new_jail_node_view(jail)
            jail_node_view.order = 1
            jail_node.append_child(jail_node_view)

            storage_node = self.new_storage_node(jail)
            storage_node.order = 2
            jail_node.append_child(storage_node)

            storage_order = 1
            nmps = NullMountPoint.objects.filter(jail=jail.jail_host)
            for nmp in nmps:
                storage_node_view = self.new_storage_node_view(nmp)
                storage_node_view.order = storage_order
                storage_node.append_child(storage_node_view)
                storage_order += 1

            storage_node_mkdir = self.new_storage_node_mkdir(jail)
            storage_node_mkdir.order = storage_order
            storage_node.append_child(storage_node_mkdir)
            storage_order += 1

            storage_node_add = self.new_storage_node_add(jail)
            storage_node_add.order = storage_order
            storage_node.append_child(storage_node_add)

            plugin_node = TreeNode()
            plugin_node.gname = 'Plugins'
            plugin_node.name = _(u'Plugins')
            plugin_node.icon = u'PluginIcon'
            plugin_node.order = 3

            args = map(
                lambda y: (y, host, request),
                Plugins.objects.filter(plugin_enabled=True,
                                       plugin_jail=jail.jail_host))

            plugin_order = 1
            pool = eventlet.GreenPool(20)
            for plugin, url, data in pool.imap(self.plugin_fetch, args):
                if not data:
                    continue

                try:
                    data = simplejson.loads(data)
                    nodes = unserialize_tree(data)
                    for node in nodes:
                        node.order = plugin_order
                        plugin_node.append_child(node)
                        plugin_order += 1

                except Exception, e:
                    log.warn(
                        _("An error occurred while unserializing from "
                          "%(url)s: %(error)s") % {
                              'url': url,
                              'error': e
                          })
                    log.debug(
                        _("Error unserializing %(url)s (%(error)s), data "
                          "retrieved:") % {
                              'url': url,
                              'error': e,
                          })
                    for line in data.splitlines():
                        log.debug(line)

                continue

            plugin_node_add = TreeNode()
            plugin_node_add.name = _('Install Plugin')
            plugin_node_add.type = 'editobject'
            plugin_node_add.view = 'plugin_install'
            plugin_node_add.kwargs = {'jail_id': jail.id}
            plugin_node_add.model = 'Plugins'
            plugin_node_add.icon = u'PluginInstallIcon'
            plugin_node_add.app_name = 'jails'
            plugin_node_add.order = plugin_order

            plugin_node.append_child(plugin_node_add)

            jail_node.append_child(plugin_node)
Esempio n. 37
0
    def _generate_app(self, app, request, tree_roots, childs_of):

        # Thats the root node for the app tree menu
        nav = TreeRoot(app.split(".")[-1])

        modnav = self._get_module(app, 'nav')
        if hasattr(modnav, 'BLACKLIST'):
            BLACKLIST = modnav.BLACKLIST
        else:
            BLACKLIST = []

        if hasattr(modnav, 'ICON'):
            nav.icon = modnav.ICON

        if hasattr(modnav, 'NAME'):
            nav.name = modnav.NAME
        else:
            nav.name = self.titlecase(app)

        if modnav:
            modname = "%s.nav" % app
            for c in dir(modnav):
                navc = getattr(modnav, c)
                try:
                    subclass = issubclass(navc, TreeNode)
                except TypeError:
                    continue
                if navc.__module__ == modname and subclass:
                    obj = navc(request=request)

                    if obj.skip is True:
                        continue
                    if not obj.append_to:
                        self.register_option(obj, nav, replace=True)
                    else:
                        self._navs[obj.append_to + '.' + obj.gname] = obj

            tree_roots.register(nav)  # We register it to the tree root
            if hasattr(modnav, 'init'):
                modnav.init(tree_roots, nav)

        else:
            log.debug("App %s has no nav.py module, skipping", app)
            return

        modmodels = self._get_module(app, 'models')
        if modmodels:

            modname = '%s.models' % app
            for c in dir(modmodels):
                model = getattr(modmodels, c)
                try:
                    if (issubclass(model, models.Model)
                            and model._meta.app_label == app):
                        continue
                except TypeError, e:
                    continue

                if c in BLACKLIST:
                    log.debug(
                        "Model %s from app %s blacklisted, skipping",
                        c,
                        app,
                    )
                    continue

                if not (model.__module__ in (
                        modname,
                        'freenasUI.' + modname,
                ) and model in self._modelforms):
                    log.debug("Model %s does not have a ModelForm", model)
                    continue

                if model._admin.deletable is False:
                    navopt = TreeNode(str(model._meta.object_name),
                                      name=model._meta.verbose_name,
                                      model=c,
                                      app_name=app,
                                      type='dialog')
                    try:
                        navopt.kwargs = {
                            'oid': model.objects.order_by("-id")[0].id,
                        }
                        navopt.view = 'freeadmin_%s_%s_edit' % (
                            model._meta.app_label,
                            model._meta.module_name,
                        )
                    except:
                        navopt.view = 'freeadmin_%s_%s_add' % (
                            model._meta.app_label,
                            model._meta.module_name,
                        )

                else:
                    navopt = TreeNode(str(model._meta.object_name))
                    navopt.name = model._meta.verbose_name_plural
                    navopt.model = c
                    navopt.app_name = app
                    navopt.order_child = False

                for key in model._admin.nav_extra.keys():
                    navopt.__setattr__(key, model._admin.nav_extra.get(key))
                if model._admin.icon_model is not None:
                    navopt.icon = model._admin.icon_model

                if model._admin.menu_child_of is not None:
                    childs_of.append((navopt, model))
                    reg = True
                else:
                    reg = self.register_option(navopt, nav)

                if reg and not navopt.type:

                    qs = model.objects.filter(
                        **model._admin.object_filters).order_by('-id')
                    if qs.count() > 0:
                        if model._admin.object_num > 0:
                            qs = qs[:model._admin.object_num]
                        for e in qs:
                            subopt = TreeNode('Edit')
                            subopt.type = 'editobject'
                            subopt.view = 'freeadmin_%s_%s_edit' % (
                                model._meta.app_label,
                                model._meta.module_name,
                            )
                            if model._admin.icon_object is not None:
                                subopt.icon = model._admin.icon_object
                            subopt.model = c
                            subopt.app_name = app
                            subopt.kwargs = {
                                'oid': e.id,
                            }
                            try:
                                subopt.name = unicode(e)
                            except:
                                subopt.name = 'Object'
                            navopt.append_child(subopt)

                    # Node to add an instance of model
                    subopt = TreeNode('Add')
                    subopt.name = _(u'Add %s') % model._meta.verbose_name
                    subopt.view = 'freeadmin_%s_%s_add' % (
                        model._meta.app_label,
                        model._meta.module_name,
                    )
                    subopt.order = 500
                    subopt.type = 'dialog'
                    if model._admin.icon_add is not None:
                        subopt.icon = model._admin.icon_add
                    subopt.model = c
                    subopt.app_name = app
                    self.register_option(subopt, navopt)

                    # Node to view all instances of model
                    subopt = TreeNode('View')
                    subopt.name = _(u'View %s') % (
                        model._meta.verbose_name_plural, )
                    subopt.view = u'freeadmin_%s_%s_datagrid' % (
                        model._meta.app_label,
                        model._meta.module_name,
                    )
                    if model._admin.icon_view is not None:
                        subopt.icon = model._admin.icon_view
                    subopt.model = c
                    subopt.app_name = app
                    subopt.order = 501
                    subopt.type = 'viewmodel'
                    self.register_option(subopt, navopt)
Esempio n. 38
0
    def _generate_app(self, app, request, tree_roots, childs_of):

        # Thats the root node for the app tree menu
        nav = TreeRoot(app.split(".")[-1])

        modnav = self._get_module(app, 'nav')
        if hasattr(modnav, 'BLACKLIST'):
            BLACKLIST = modnav.BLACKLIST
        else:
            BLACKLIST = []

        if hasattr(modnav, 'ICON'):
            nav.icon = modnav.ICON

        if hasattr(modnav, 'NAME'):
            nav.name = modnav.NAME
        else:
            nav.name = self.titlecase(app)

        if hasattr(modnav, 'TYPE'):
            nav.type = modnav.TYPE

        if hasattr(modnav, 'HIDE'):
            nav.skip = modnav.HIDE

        if hasattr(modnav, 'URL'):
            nav.url = reverse(modnav.URL)

        if modnav:
            modname = "%s.nav" % app
            for c in dir(modnav):
                navc = getattr(modnav, c)
                try:
                    subclass = issubclass(navc, TreeNode)
                except TypeError:
                    continue
                if navc.__module__ == modname and subclass:
                    obj = navc(request=request)

                    if obj.skip is True:
                        continue
                    if not obj.append_to:
                        self.register_option(obj, nav, replace=True)
                    else:
                        self._navs[obj.append_to + '.' + obj.gname] = obj

            tree_roots.register(nav)  # We register it to the tree root
            if hasattr(modnav, 'init'):
                modnav.init(tree_roots, nav, request)
            appPool.hook_nav_init(nav.gname, tree_roots, nav, request)

        else:
            log.debug("App %s has no nav.py module, skipping", app)
            return

        modmodels = self._get_module(app, 'models')
        if modmodels:

            modname = '%s.models' % app
            for c in dir(modmodels):

                model = getattr(modmodels, c)
                try:
                    if issubclass(model, models.Model):
                        if model._meta.app_label == app:
                            continue
                    else:
                        continue
                except TypeError, e:
                    continue

                if c in BLACKLIST:
                    log.debug(
                        "Model %s from app %s blacklisted, skipping",
                        c,
                        app,
                    )
                    continue

                if not (
                    model.__module__ in (
                        modname,
                        'freenasUI.' + modname,
                    )
                    and
                    model in self._modelforms
                ):
                    log.debug("Model %s does not have a ModelForm", model)
                    continue

                if model._admin.deletable is False:
                    navopt = TreeNode(
                        str(model._meta.object_name),
                        name=model._meta.verbose_name,
                        model=c, app_name=app, type='dialog')
                    try:
                        navopt.kwargs = {
                            'oid': model.objects.order_by("-id")[0].id,
                        }
                        navopt.view = 'freeadmin_%s_%s_edit' % (
                            model._meta.app_label,
                            model._meta.module_name,
                        )
                    except:
                        navopt.view = 'freeadmin_%s_%s_add' % (
                            model._meta.app_label,
                            model._meta.module_name,
                        )

                else:
                    navopt = TreeNode(str(model._meta.object_name))
                    navopt.name = model._meta.verbose_name_plural
                    navopt.model = c
                    navopt.app_name = app
                    navopt.order_child = False

                for key in model._admin.nav_extra.keys():
                    navopt.__setattr__(
                        key,
                        model._admin.nav_extra.get(key))
                if model._admin.icon_model is not None:
                    navopt.icon = model._admin.icon_model

                if model._admin.menu_child_of is not None:
                    childs_of.append((navopt, model))
                    reg = True
                else:
                    reg = self.register_option(navopt, nav)

                if reg and not navopt.type:

                    qs = model.objects.filter(
                        **model._admin.object_filters).order_by('-id')
                    if qs.count() > 0:
                        if model._admin.object_num > 0:
                            qs = qs[:model._admin.object_num]
                        for e in qs:
                            subopt = TreeNode('Edit')
                            subopt.type = 'editobject'
                            subopt.view = 'freeadmin_%s_%s_edit' % (
                                model._meta.app_label,
                                model._meta.module_name,
                            )
                            if model._admin.icon_object is not None:
                                subopt.icon = model._admin.icon_object
                            subopt.model = c
                            subopt.app_name = app
                            subopt.kwargs = {
                                'oid': e.id,
                            }
                            if model._admin.edit_modelform:
                                subopt.kwargs['mf'] = (
                                    model._admin.edit_modelform
                                )
                            subopt.gname = e.id
                            try:
                                subopt.name = unicode(e)
                            except:
                                subopt.name = 'Object'
                            navopt.append_child(subopt)

                    # Node to add an instance of model
                    subopt = TreeNode('Add')
                    subopt.name = _(u'Add %s') % model._meta.verbose_name
                    subopt.view = 'freeadmin_%s_%s_add' % (
                        model._meta.app_label,
                        model._meta.module_name,
                    )
                    subopt.order = 500
                    subopt.type = 'dialog'
                    if model._admin.icon_add is not None:
                        subopt.icon = model._admin.icon_add
                    subopt.model = c
                    subopt.app_name = app
                    self.register_option(subopt, navopt)

                    # Node to view all instances of model
                    subopt = TreeNode('View')
                    subopt.name = _(u'View %s') % (
                        model._meta.verbose_name_plural,
                    )
                    subopt.view = u'freeadmin_%s_%s_datagrid' % (
                        model._meta.app_label,
                        model._meta.module_name,
                    )
                    if model._admin.icon_view is not None:
                        subopt.icon = model._admin.icon_view
                    subopt.model = c
                    subopt.app_name = app
                    subopt.order = 501
                    subopt.type = 'viewmodel'
                    self.register_option(subopt, navopt)
Esempio n. 39
0
    def __init__(self, *args, **kwargs):
        super(ViewPluginJails, self).__init__(*args, **kwargs)
        request = kwargs.get('request')

        host = get_base_url(request)
        jails = Jails.objects.filter(jail_type=WARDEN_TYPE_PLUGINJAIL)
        for jail in jails:
            jail_node = self.new_jail_node(jail, u'JailPluginIcon')
            self.append_child(jail_node)

            jail_node_view = self.new_jail_node_view(jail)
            jail_node_view.order = 1
            jail_node.append_child(jail_node_view)

            storage_node = self.new_storage_node(jail)
            storage_node.order = 2
            jail_node.append_child(storage_node)

            storage_order = 1
            nmps = NullMountPoint.objects.filter(jail=jail.jail_host)
            for nmp in nmps:
                storage_node_view = self.new_storage_node_view(nmp)
                storage_node_view.order = storage_order
                storage_node.append_child(storage_node_view)
                storage_order += 1

            storage_node_mkdir = self.new_storage_node_mkdir(jail)
            storage_node_mkdir.order = storage_order
            storage_node.append_child(storage_node_mkdir)
            storage_order += 1

            storage_node_add = self.new_storage_node_add(jail)
            storage_node_add.order = storage_order
            storage_node.append_child(storage_node_add)

            plugin_node = TreeNode()
            plugin_node.gname = 'Plugins'
            plugin_node.name = _(u'Plugins')
            plugin_node.icon = u'PluginIcon'
            plugin_node.order = 3

            args = map(
                lambda y: (y, host, request),
                Plugins.objects.filter(plugin_enabled=True, plugin_jail=jail.jail_host))

            plugin_order = 1
            pool = eventlet.GreenPool(20)
            for plugin, url, data in pool.imap(self.plugin_fetch, args):
                if not data:
                    continue

                try:
                    data = simplejson.loads(data)
                    nodes = unserialize_tree(data)
                    for node in nodes:
                        node.order = plugin_order 
                        plugin_node.append_child(node) 
                        plugin_order += 1

                except Exception, e:
                    log.warn(_(
                         "An error occurred while unserializing from "
                        "%(url)s: %(error)s") % {'url': url, 'error': e})
                    log.debug(_(
                        "Error unserializing %(url)s (%(error)s), data "
                        "retrieved:") % {
                            'url': url,
                            'error': e,
                        })
                    for line in data.splitlines():
                        log.debug(line)

                continue

            plugin_node_add = TreeNode()
            plugin_node_add.name = _('Install Plugin')
            plugin_node_add.type = 'editobject'
            plugin_node_add.view = 'plugin_install'
            plugin_node_add.kwargs = {'jail_id': jail.id }
            plugin_node_add.model = 'Plugins'
            plugin_node_add.icon = u'PluginInstallIcon'
            plugin_node_add.app_name = 'jails' 
            plugin_node_add.order = plugin_order

            plugin_node.append_child(plugin_node_add)

            jail_node.append_child(plugin_node)