Пример #1
0
def terminal(request):

    sid = int(request.GET.get("s", 0))
    k = request.GET.get("k")
    w = int(request.GET.get("w", 80))
    h = int(request.GET.get("h", 24))

    multiplex = MyServer("/var/run/webshell.sock")
    alive = False
    for i in range(3):
        try:
            alive = multiplex.proc_keepalive(sid, w, h)
            break
        except:
            notifier().restart("webshell")
            time.sleep(0.5)

    try:
        if alive:
            if k:
                multiplex.proc_write(sid, xmlrpclib.Binary(bytearray(str(k))))
            time.sleep(0.002)
            content_data = '<?xml version="1.0" encoding="UTF-8"?>' + multiplex.proc_dump(sid)
            response = HttpResponse(content_data, content_type="text/xml")
            return response
        else:
            response = HttpResponse("Disconnected")
            response.status_code = 400
            return response
    except (KeyError, ValueError, IndexError):
        response = HttpResponse("Invalid parameters")
        response.status_code = 400
        return response
Пример #2
0
    def _delete(self, destroy=True, cascade=True):
        """
        Some places reference a path which will not cascade delete
        We need to manually find all paths within this volume mount point
        """
        from metanasUI.services.models import iSCSITargetExtent

        # TODO: This is ugly.
        svcs = ('cifs', 'afp', 'nfs', 'iscsitarget')
        reloads = (False, False, False,  False)

        n = notifier()
        if cascade:

            for mp in self.mountpoint_set.all():
                reloads = map(sum, zip(reloads, mp.delete_attachments()))

            zvols = n.list_zfs_vols(self.vol_name)
            for zvol in zvols:
                qs = iSCSITargetExtent.objects.filter(
                    iscsi_target_extent_path='zvol/' + zvol,
                    iscsi_target_extent_type='ZVOL')
                if qs.exists():
                    if destroy:
                        retval = notifier().destroy_zfs_vol(zvol)
                    qs.delete()
                reloads = map(sum, zip(reloads, (False, False, False, True)))

        else:

            for mp in self.mountpoint_set.all():
                attachments = mp.has_attachments()
                reloads = map(sum,
                              zip(reloads,
                                [len(attachments[svc]) for svc in svcs])
                             )

        for (svc, dirty) in zip(svcs, reloads):
            if dirty:
                n.stop(svc)

        n.detach_volume_swaps(self)

        # Ghosts volumes, does not exists anymore but is in database
        ghost = False
        try:
            status = n.get_volume_status(self.vol_name, self.vol_fstype)
            ghost = status == 'UNKNOWN'
        except:
            ghost = True

        if ghost:
            pass
        elif destroy:
            n.destroy("volume", self)
        else:
            n.volume_detach(self.vol_name, self.vol_fstype)

        return (svcs, reloads)
Пример #3
0
 def delete(self, using=None, reload=True):
     if self.bsdgrp_builtin == True:
         raise ValueError(_("Group %s is built-in and can not be "
             "deleted!") % (self.bsdgrp_group))
     notifier().user_deletegroup(self.bsdgrp_group.__str__())
     super(bsdGroups, self).delete(using)
     if reload:
         notifier().reload("user")
Пример #4
0
 def delete(self):
     try:
         if self.repl_lastsnapshot != "":
             zfsname = self.repl_lastsnapshot.split('@')[0]
             notifier().zfs_inherit_option(zfsname, 'metanas:state', True)
     except:
         pass
     super(Replication, self).delete()
Пример #5
0
 def save(self):
     user = models.bsdUsers.objects.get(id=self.userid)
     models.bsdGroupMembership.objects.filter(bsdgrpmember_user=user).delete()
     groupid_list = self.cleaned_data["bsduser_to_group"]
     for groupid in groupid_list:
         group = models.bsdGroups.objects.get(id=groupid)
         m = models.bsdGroupMembership(bsdgrpmember_group=group, bsdgrpmember_user=user)
         m.save()
     notifier().reload("user")
Пример #6
0
def config_restore(request):
    if request.method == "POST":
        request.session["allow_reboot"] = True
        notifier().config_restore()
        user = User.objects.all()[0]
        backend = get_backends()[0]
        user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__)
        login(request, user)
        return render(request, "system/config_ok2.html")
    return render(request, "system/config_restore.html")
Пример #7
0
    def save(self, commit):
        m = super(AliasForm, self).save(commit)

        iface = models.Interfaces.objects.filter(
            id=self.instance.alias_interface_id
            )
        if not iface:
            return m

        change = False
        iface = str(iface[0].int_interface)
        kwargs = {'oldip': str(self.instance._original_alias_v4address)}
        if self.instance._original_alias_v4address != \
                self.instance.alias_v4address:
            kwargs['oldip'] = str(self.instance._original_alias_v4address)
            kwargs['newip'] = str(self.instance.alias_v4address)
            change = True

        if self.instance._original_alias_v4netmaskbit != \
                self.instance.alias_v4netmaskbit:
            kwargs['oldnetmask'] = str(
                self.instance._original_alias_v4netmaskbit
                )
            kwargs['newnetmask'] = str(self.instance.alias_v4netmaskbit)
            change = True

        if change:
            if not notifier().ifconfig_alias(iface, **kwargs):
                return m

        change = False
        kwargs = {'oldip': str(self.instance._original_alias_v6address)}
        if self.instance._original_alias_v6address != \
                self.instance.alias_v6address:
            kwargs['oldip'] = str(self.instance._original_alias_v6address)
            kwargs['newip'] = str(self.instance.alias_v6address)
            change = True

        if self.instance._original_alias_v6netmaskbit != \
                self.instance.alias_v6netmaskbit:
            kwargs['oldnetmask'] = str(
                self.instance._original_alias_v6netmaskbit
                )
            kwargs['newnetmask'] = str(self.instance.alias_v6netmaskbit)
            change = True

        if change:
            if not notifier().ifconfig_alias(iface, **kwargs):
                return m

        if commit:
            m.save()
        return m
Пример #8
0
def plugin_delete(request, plugin_id):
    plugin_id = int(plugin_id)
    plugin = models.Plugins.objects.get(id=plugin_id)

    if request.method == "POST":
        notifier()._stop_plugins(plugin.plugin_name)
        if notifier().delete_pbi(plugin):
            return JsonResp(request, message=_("Plugin successfully removed."), events=["reloadHttpd()"])
        else:
            return JsonResp(request, error=True, message=_("Unable to remove plugin."))
    else:
        return render(request, "plugins/plugin_confirm_delete.html", {"plugin": plugin})
Пример #9
0
 def save(self):
     vlan_pint = self.cleaned_data['vlan_pint']
     if len(models.Interfaces.objects.filter(int_interface=vlan_pint)) == 0:
         vlan_interface = models.Interfaces(int_interface=vlan_pint,
                             int_name=vlan_pint,
                             int_dhcp=False,
                             int_ipv6auto=False,
                             int_options='up',
                             )
         vlan_interface.save()
     retval = super(VLANForm, self).save()
     notifier().start("network")
     return retval
Пример #10
0
def zpool_disk_remove(request, vname, label):

    volume = models.Volume.objects.get(vol_name=vname)
    disk = notifier().label_to_disk(label)

    if request.method == "POST":
        notifier().zfs_remove_disk(volume, label)
        return JsonResponse(message=_("Disk has been removed."))

    return render(request, 'storage/disk_remove.html', {
        'vname': vname,
        'label': label,
        'disk': disk,
    })
Пример #11
0
def disk_detach(request, vname, label):

    volume = models.Volume.objects.get(vol_name=vname)

    if request.method == "POST":
        notifier().zfs_detach_disk(volume, label)
        return JsonResponse(
            message=_("Disk detach has been successfully done.")
            )

    return render(request, 'storage/disk_detach.html', {
        'vname': vname,
        'label': label,
    })
Пример #12
0
def snapshot_delete(request, dataset, snapname):
    snapshot = '%s@%s' % (dataset, snapname)
    if request.method == 'POST':
        retval = notifier().destroy_zfs_dataset(path=str(snapshot))
        if retval == '':
            notifier().restart("collectd")
            return JsonResponse(message=_("Snapshot successfully deleted."))
        else:
            return JsonResponse(error=True, message=retval)
    else:
        return render(request, 'storage/snapshot_confirm_delete.html', {
            'snapname': snapname,
            'dataset': dataset,
        })
Пример #13
0
def zpool_scrub(request, vid):
    volume = models.Volume.objects.get(pk=vid)
    pool = notifier().zpool_parse(volume.vol_name)
    if request.method == "POST":
        if request.POST.get("scrub") == 'IN_PROGRESS':
            notifier().zfs_scrub(str(volume.vol_name), stop=True)
        else:
            notifier().zfs_scrub(str(volume.vol_name))
        return JsonResponse(message=_("The scrub process has begun"))

    return render(request, 'storage/scrub_confirm.html', {
        'volume': volume,
        'scrub': pool.scrub,
    })
Пример #14
0
def zfsvolume_edit(request, object_id):

    mp = models.MountPoint.objects.get(pk=object_id)
    volume_form = forms.ZFSVolume_EditForm(mp=mp)

    if request.method == 'POST':
        volume_form = forms.ZFSVolume_EditForm(request.POST, mp=mp)
        if volume_form.is_valid():
            volume = mp.mp_volume
            volume_name = volume.vol_name
            volume_name = mp.mp_path.replace("/mnt/", "")

            if volume_form.cleaned_data["volume_refquota"] == "0":
                volume_form.cleaned_data["volume_refquota"] = "none"

            error, errors = False, {}
            for attr in ('compression',
                    'atime',
                    'refquota',
                    'refreservation',
                    ):
                formfield = 'volume_%s' % attr
                if volume_form.cleaned_data[formfield] == "inherit":
                    success, err = notifier().zfs_inherit_option(
                        volume_name,
                        attr,
                        )
                else:
                    success, err = notifier().zfs_set_option(
                        volume_name,
                        attr,
                        volume_form.cleaned_data[formfield],
                        )
                if not success:
                    error = True
                    errors[formfield] = err

            if not error:
                return JsonResponse(
                    message=_("Native dataset successfully edited.")
                    )
            else:
                for field, err in errors.items():
                    volume_form._errors[field] = volume_form.error_class([
                        err,
                        ])
    return render(request, 'storage/volume_edit.html', {
        'mp': mp,
        'form': volume_form
    })
Пример #15
0
def dataset_edit(request, dataset_name):
    if request.method == 'POST':
        dataset_form = forms.ZFSDataset_EditForm(request.POST, fs=dataset_name)
        if dataset_form.is_valid():
            if dataset_form.cleaned_data["dataset_quota"] == "0":
                dataset_form.cleaned_data["dataset_quota"] = "none"
            if dataset_form.cleaned_data["dataset_refquota"] == "0":
                dataset_form.cleaned_data["dataset_refquota"] = "none"

            error = False
            errors = {}

            for attr in ('compression',
                    'atime',
                    'reservation',
                    'refreservation',
                    'quota',
                    'refquota',
                    ):
                formfield = 'dataset_%s' % attr
                if dataset_form.cleaned_data[formfield] == "inherit":
                    success, err = notifier().zfs_inherit_option(
                        dataset_name,
                        attr,
                        )
                else:
                    success, err = notifier().zfs_set_option(
                        dataset_name,
                        attr,
                        dataset_form.cleaned_data[formfield],
                        )
                error |= not success
                if not success:
                    errors[formfield] = err

            if not error:
                return JsonResponse(message=_("Dataset successfully edited."))
            else:
                for field, err in errors.items():
                    dataset_form._errors[field] = dataset_form.error_class([
                        err,
                        ])
    else:
        dataset_form = forms.ZFSDataset_EditForm(fs=dataset_name)
    return render(request, 'storage/dataset_edit.html', {
        'dataset_name': dataset_name,
        'form': dataset_form
    })
Пример #16
0
def snapshot_delete_bulk(request):

    snaps = request.POST.get("snaps", None)
    delete = request.POST.get("delete", None)
    if snaps and delete == "true":
        snap_list = snaps.split('|')
        for snapshot in snap_list:
            retval = notifier().destroy_zfs_dataset(path=str(snapshot))
            if retval != '':
                return JsonResponse(error=True, message=retval)
        notifier().restart("collectd")
        return JsonResponse(message=_("Snapshots successfully deleted."))

    return render(request, 'storage/snapshot_confirm_delete_bulk.html', {
        'snaps': snaps,
    })
Пример #17
0
def zvol_create(request, volume_name):
    defaults = {'zvol_compression': 'inherit', }
    if request.method == 'POST':
        zvol_form = forms.ZVol_CreateForm(request.POST, vol_name=volume_name)
        if zvol_form.is_valid():
            props = {}
            cleaned_data = zvol_form.cleaned_data
            zvol_size = cleaned_data.get('zvol_size')
            zvol_name = "%s/%s" % (volume_name, cleaned_data.get('zvol_name'))
            zvol_compression = cleaned_data.get('zvol_compression')
            props['compression'] = str(zvol_compression)
            errno, errmsg = notifier().create_zfs_vol(name=str(zvol_name),
                size=str(zvol_size),
                props=props)
            if errno == 0:
                return JsonResponse(
                    message=_("ZFS Volume successfully added.")
                    )
            else:
                zvol_form.set_error(errmsg)
    else:
        zvol_form = forms.ZVol_CreateForm(initial=defaults,
            vol_name=volume_name)
    return render(request, 'storage/zvols.html', {
        'form': zvol_form,
        'volume_name': volume_name,
    })
Пример #18
0
def multipath_status_json(request):

    multipaths = notifier().multipath_all()
    _id = 1
    items = []
    for mp in multipaths:
        children = []
        for cn in mp.consumers:
            items.append({
                'id': str(_id),
                'name': cn.devname,
                'status': cn.status,
                'type': 'consumer',
            })
            children.append({'_reference': str(_id)})
            _id += 1
        data = {
            'id': str(_id),
            'name': mp.devname,
            'status': mp.status,
            'type': 'root',
            'children': children,
        }
        items.append(data)
        _id += 1
    return HttpResponse(simplejson.dumps({
        'identifier': 'id',
        'label': 'name',
        'items': items,
    }, indent=2), content_type='application/json')
Пример #19
0
def wizard(request):

    if request.method == "POST":

        form = forms.VolumeWizardForm(request.POST)
        if form.is_valid():
            form.done(request)
            return JsonResponse(message=_("Volume successfully added."))
        else:
            if 'volume_disks' in request.POST:
                disks = request.POST.getlist('volume_disks')
            else:
                disks = None
            zpoolfields = re.compile(r'zpool_(.+)')
            zfsextra = [(zpoolfields.search(i).group(1), i, request.POST.get(i)) \
                        for i in request.POST.keys() if zpoolfields.match(i)]

    else:
        form = forms.VolumeWizardForm()
        disks = []
        zfsextra = None
    return render(request, 'storage/wizard.html', {
        'form': form,
        'disks': disks,
        'zfsextra': zfsextra,
        'zfsversion': notifier().zfs_get_version(),
    })
Пример #20
0
def plugin_install(request):
    if request.method == "POST":
        pj = PluginsJail.objects.order_by("-id")[0]
        notifier().change_upload_location(pj.plugins_path)
        form = forms.PBIUploadForm(request.POST, request.FILES)
        if form.is_valid():
            form.done()
            return JsonResponse(message=_("Plugin successfully installed"), events=["reloadHttpd()"], enclosed=True)
        else:
            resp = render(request, "plugins/plugin_install.html", {"form": form})
            resp.content = "<html><body><textarea>" + resp.content + "</textarea></boby></html>"
            return resp
    else:
        form = forms.PBIUploadForm()

    return render(request, "plugins/plugin_install.html", {"form": form})
Пример #21
0
 def done(self, request, events):
     if self.instance._original_stg_guiprotocol != self.instance.stg_guiprotocol or \
         self.instance._original_stg_guiaddress != self.instance.stg_guiaddress or \
         self.instance._original_stg_guiport != self.instance.stg_guiport:
         if self.instance.stg_guiaddress == "0.0.0.0":
             address = request.META['HTTP_HOST'].split(':')[0]
         else:
             address = self.instance.stg_guiaddress
         newurl = "%s://%s" % (self.instance.stg_guiprotocol,
                                 address
                                 )
         if self.instance.stg_guiport != '':
             newurl += ":" + self.instance.stg_guiport
         if self.instance._original_stg_guiprotocol == 'http':
             notifier().start_ssl("nginx")
         events.append("restartHttpd('%s')" % newurl)
Пример #22
0
def config_upload(request):

    if request.method == "POST":
        form = forms.ConfigUploadForm(request.POST, request.FILES)

        variables = {"form": form}

        if form.is_valid():
            if not notifier().config_upload(request.FILES["config"]):
                form._errors["__all__"] = form.error_class([_("The uploaded file is not valid.")])
            else:
                request.session["allow_reboot"] = True
                return render(request, "system/config_ok.html", variables)

        if request.GET.has_key("iframe"):
            return HttpResponse(
                "<html><body><textarea>"
                + render_to_string("system/config_upload.html", variables)
                + "</textarea></boby></html>"
            )
        else:
            return render(request, "system/config_upload.html", variables)
    else:
        FIRMWARE_DIR = "/var/tmp/firmware"
        if os.path.exists(FIRMWARE_DIR):
            if os.path.islink(FIRMWARE_DIR):
                os.unlink(FIRMWARE_DIR)
            if os.path.isdir(FIRMWARE_DIR):
                shutil.rmtree(FIRMWARE_DIR + "/")
        os.mkdir(FIRMWARE_DIR)
        os.chmod(FIRMWARE_DIR, 01777)
        form = forms.ConfigUploadForm()

        return render(request, "system/config_upload.html", {"form": form})
Пример #23
0
    def delete(self, do_reload=True):
        if do_reload:
            reloads = self.delete_attachments()

        if self.mp_volume.vol_fstype == 'ZFS':
            Task.objects.filter(task_filesystem=self.mp_path[5:]).delete()
            Replication.objects.filter(
                repl_filesystem=self.mp_path[5:]).delete()

        if do_reload:
            svcs = ('cifs', 'afp', 'nfs', 'iscsitarget')
            for (svc, dirty) in zip(svcs, reloads):
                if dirty:
                    notifier().restart(svc)

        super(MountPoint, self).delete()
Пример #24
0
    def pre_dehydrate(self):
        if notifier().plugins_jail_configured():
            return

        for nav in list(self.option_list):
            if nav.gname == 'NullMountPoint':
                self.option_list.remove(nav)
                break
Пример #25
0
 def __init__(self, *args, **kwargs):
     super(PluginsSettings, self).__init__(*args, **kwargs)
     if notifier().plugins_jail_configured():
         oid = models.PluginsJail.objects.order_by('-id')[0].id
         self.view = 'freeadmin_model_edit'
         self.kwargs = {'app': 'services', 'model': 'PluginsJail', 'oid': oid}
     else:
         self.view = 'plugins_jailpbi'
Пример #26
0
 def delete(self, using=None, reload=True):
     if self.bsdusr_builtin == True:
         raise ValueError(_("User %s is built-in and can not be "
             "deleted!") % (self.bsdusr_username))
     notifier().user_deleteuser(self.bsdusr_username.__str__())
     try:
         gobj = self.bsdusr_group
         count = bsdGroupMembership.objects.filter(
             bsdgrpmember_group=gobj).count()
         count2 = bsdUsers.objects.filter(bsdusr_group=gobj).exclude(
             id=self.id).count()
         if not gobj.bsdgrp_builtin and count == 0 and count2 == 0:
             gobj.delete(reload=False)
     except:
         pass
     super(bsdUsers, self).delete(using)
     if reload:
         notifier().reload("user")
Пример #27
0
 def _get_status(self):
     try:
         # Make sure do not compute it twice
         if not hasattr(self, '_status'):
             self._status = notifier().get_volume_status(self.vol_name,
                 self.vol_fstype)
         return self._status
     except Exception, e:
         return _(u"Error")
Пример #28
0
 def __init__(self, *args, **kwargs):
     super(bsdGroupsForm, self).__init__(*args, **kwargs)
     if self.instance.id:
         self.fields["bsdgrp_gid"].widget.attrs["readonly"] = True
         self.fields["bsdgrp_gid"].widget.attrs["class"] = (
             "dijitDisabled" " dijitTextBoxDisabled dijitValidationTextBoxDisabled"
         )
     else:
         self.initial["bsdgrp_gid"] = notifier().user_getnextgid()
         self.fields["allow"] = forms.BooleanField(label=_("Allow repeated GIDs"), initial=False, required=False)
Пример #29
0
def main():
    parser = argparse.ArgumentParser(description='Sync disks.')
    parser.add_argument('devs', metavar='N', type=str, nargs='*', help='device name(s)')
    args = parser.parse_args()
    _notifier = notifier()
    if args.devs:
        for dev in args.devs:
            dev = dev.replace("/dev/", "")
            _notifier.sync_disk(dev)
    else:
        _notifier.sync_disks()
Пример #30
0
def volume_status_json(request, vid):
    volume = models.Volume.objects.get(id=vid)
    if volume.vol_fstype == 'ZFS':
        pool = notifier().zpool_parse(volume.vol_name)
        items = pool.treedump()
    else:
        items = notifier().geom_disks_dump(volume)
        children = [{'_reference': item['id']} for item in items]
        items.append({
            'name': volume.vol_name,
            'id': len(items) + 1,
            'status': '',
            'type': 'root',
            'children': children,
        })
    return HttpResponse(simplejson.dumps({
        'identifier': 'id',
        'label': 'name',
        'items': items,
    }, indent=2), content_type='application/json')
Пример #31
0
 def commit(self):
     snapshot = self.cleaned_data['cs_snapshot'].__str__()
     retval = notifier().zfs_clonesnap(snapshot,
                                       str(self.cleaned_data['cs_name']))
     return retval
Пример #32
0
 def save(self):
     rv = super(ReplRemoteForm, self).save()
     notifier().reload("ssh")
     return rv