コード例 #1
0
    def save(self):
        path = self.cleaned_data['path']
        data = self.cleaned_data['data']
        count = self.cleaned_data['count']
        ltype = self.cleaned_data['type']
        cycle = self.cleaned_data['cycle']

        week = self.cleaned_data['week']
        minute = self.cleaned_data['minute']
        hour = self.cleaned_data['hour']
        date = self.cleaned_data['date']
        month = self.cleaned_data['month']
        obj = CoreConfig.saveFuction(function="auto_backup",
                                     enabled=None,
                                     param=json.dumps({
                                         "path": path,
                                         "data": data,
                                         "count": count,
                                         "cycle": cycle,
                                         "type": ltype,
                                         "month": month,
                                         "date": date,
                                         "week": week,
                                         "hour": hour,
                                         "minute": minute,
                                     }),
                                     withenabled=False)
        clear_redis_cache()
        return obj
コード例 #2
0
ファイル: views.py プロジェクト: zhouli121018/nodejsgm
def backupSetView(request):
    form = BackupSetForm(CoreConfig.getInitBackupParam())
    if request.method == "POST":
        form = BackupSetForm(request.POST)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS, u'设置成功!')
            return redirect('backup_maintain')
    return render(request, "maintain/backupset.html", context={
        "form": form,
    })
コード例 #3
0
def backup_set_view(request):
    form = BackupSetForm(CoreConfig.getInitBackupParam())
    if request.method == "POST":
        form = BackupSetForm(request.POST)
        if form.is_valid():
            obj = form.save()
            messages.add_message(request, messages.SUCCESS, _(u'设置成功!'))
            api_create_admin_log(request, obj, 'coreconfig',
                                 _(u"备份参数设置:{}").format(json.loads(obj.param)))
            return redirect('backup_maintain')
    return render(request, "maintain/backupset.html", context={
        "form": form,
    })
コード例 #4
0
ファイル: views.py プロジェクト: zhouli121018/nodejsgm
def sslEnableView(request):
    if request.method == "POST":
        ssl = request.POST.get("ssl", "-1")
        if ssl in ("1", "-1"):
            obj = CoreConfig.getFuctionObj('ssl')
            obj.enabled = ssl
            obj.save()

            redis = get_redis_connection()
            redis.rpush("task_queue:apply_setting", "ssl")
            messages.add_message(request, messages.SUCCESS, u'应用设置成功')
        else:
            messages.add_message(request, messages.ERROR, u'未知错误,操作失败!')
        return HttpResponseRedirect(reverse("ssl_maintain"))
    raise Http404
コード例 #5
0
ファイル: views.py プロジェクト: zhouli121018/nodejsgm
def sslView(request):
    # ssl开关
    sslobj = CoreConfig.getFuctionObj('ssl')
    # 私钥数据
    keyobj = DomainAttr.getAttrObj(item="ssl_privatekey")
    value = keyobj.value or None
    # 签名请求数据
    sigobj = DomainAttr.getAttrObj(item="ssl_signrequest")
    # 证书
    certobj = DomainAttr.getAttrObj(item="ssl_certificate")
    if request.method == "POST":
        status = request.POST.get("status", "")
        if status == "generate":
            # 系统生成私钥
            if value:
                messages.add_message(request, messages.ERROR, u'私钥已存在,设置私钥失败!')
                return HttpResponseRedirect(reverse("ssl_maintain"))
            else:
                try:
                    privkey = sslopts.genPrivKey()
                    keyobj.value = privkey
                    keyobj.save()
                    messages.add_message(request, messages.SUCCESS, u'生成私钥成功')
                    return HttpResponseRedirect(reverse("ssl_maintain"))
                except:
                    messages.add_message(request, messages.ERROR,
                                         u'生成私钥失败,请重新生成')
                    return HttpResponseRedirect(reverse("ssl_maintain"))

        if status == "clear":
            # 清除私钥
            keyobj.value = ""
            keyobj.save()
            # 清空证书签名请求
            DomainAttr.emptyAttrObjValue(item="ssl_signrequest")
            # 清除证书
            DomainAttr.emptyAttrObjValue(item="ssl_certificate")
            messages.add_message(request, messages.SUCCESS, u'清除私钥成功')
            return HttpResponseRedirect(reverse("ssl_maintain"))

        if status == "export-signature":
            # 导出签名请求
            sigvalue = sigobj.value or None
            if not sigvalue:
                messages.add_message(request, messages.ERROR, u'签名请求 不存在')
                return HttpResponseRedirect(reverse("ssl_maintain"))
            else:
                try:
                    wrapper = FileWrapper(StringIO.StringIO(sigvalue))
                    response = HttpResponse(
                        wrapper, content_type='application/octet-stream')
                    response['Content-Length'] = len(value)
                    response[
                        'Content-Disposition'] = 'attachment; filename=%s' % "ssl_signrequest.csr"
                    return response
                except:
                    messages.add_message(request, messages.ERROR,
                                         u'导出签名请求失败,请重新导出')
                    return HttpResponseRedirect(reverse("ssl_maintain"))

        if status == "clear-signature":
            # 清除签名请求
            DomainAttr.emptyAttrObjValue(item="ssl_signrequest")
            messages.add_message(request, messages.SUCCESS, u'清除签名请求成功')
            return HttpResponseRedirect(reverse("ssl_maintain"))

        if status == "cert-export":
            # 导出证书
            certvalue = certobj.value or None
            if not certvalue:
                messages.add_message(request, messages.ERROR, u'证书 不存在')
                return HttpResponseRedirect(reverse("ssl_maintain"))
            else:
                try:
                    wrapper = FileWrapper(StringIO.StringIO(certvalue))
                    response = HttpResponse(
                        wrapper, content_type='application/octet-stream')
                    response['Content-Length'] = len(value)
                    response[
                        'Content-Disposition'] = 'attachment; filename=%s' % "ssl_certificate.crt"
                    return response
                except:
                    messages.add_message(request, messages.ERROR,
                                         u'导出证书失败,请重新导出')
                    return HttpResponseRedirect(reverse("ssl_maintain"))

        if status == "cert-clear":
            # 清除证书
            DomainAttr.emptyAttrObjValue(item="ssl_certificate")
            messages.add_message(request, messages.SUCCESS, u'清除证书成功成功')
            return HttpResponseRedirect(reverse("ssl_maintain"))

    is_verify = False
    signature = DomainAttr.getSignatureCache()
    if sigobj.value:
        is_verify, signature2 = sslopts.parseSignature(sigobj.value)
        if is_verify: signature = signature2

    is_ca = False
    cert_subject, sert_issuer = None, None
    if certobj.value:
        is_ca = True
        cert_subject, sert_issuer = sslopts.parseCert(certobj.value)

    return render(
        request,
        "maintain/ssl.html",
        context={
            "sslobj": sslobj,
            "keyValue":
            sslopts.getPrivateKeySize(bytes(value)) if value else None,
            "is_verify": is_verify,
            "signature": signature,
            "is_ca": is_ca,
            "cert_subject": cert_subject,
            "sert_issuer": sert_issuer,
        })
コード例 #6
0
ファイル: views.py プロジェクト: zhouli121018/nodejsgm
def backupView(request):
    backuppath = CoreConfig.getInitBackupParam()["path"]
    if request.method == 'POST':
        auto_status = request.POST.get('auto_status', "")
        if auto_status:
            auto_status = "1" if auto_status == "1" else "-1"
            instance = CoreConfig.getFuctionObj("auto_backup")
            CoreConfig.saveFuction("auto_backup", auto_status, instance.param)
        else:
            name = request.POST.get('name')
            status = request.POST.get('status')
            redis = get_redis_connection()
            if redis.exists("task_trigger:backup"):
                messages.add_message(request, messages.ERROR,
                                     u'正在执行备份操作,操作失败!')
                return redirect('backup_maintain')
            if redis.exists("task_trigger:restore"):
                messages.add_message(request, messages.ERROR,
                                     u'正在执行数据恢复操作,操作失败!')
                return redirect('backup_maintain')

            if status == "backup":
                redis.set("task_trigger:backup", 1)
                messages.add_message(request, messages.SUCCESS,
                                     u'正在备份数据,请耐心等待!')
            if status == "delete":
                path = os.path.join(backuppath, name)
                if os.path.exists(path):
                    cmd = "sudo /usr/local/u-mail/app/exec/backup delete {}".format(
                        name)
                    child = subprocess.Popen(cmd, shell=True)
                    # child.communicate()
                    messages.add_message(request, messages.SUCCESS,
                                         u'正在删除备份数据,请耐心等待!')
                else:
                    messages.add_message(request, messages.ERROR,
                                         u'备份数据文件不存在,操作失败!')
            if status == "restore":
                task_id = generateRedisTaskID()
                d = json.dumps({
                    "backup_name": name,
                })
                p = redis.pipeline()
                p.set("task_trigger:restore", 1)
                p.rpush("task_queue:restore", task_id)
                p.hset("task_data:restore", task_id, d)
                p.execute()
                messages.add_message(request, messages.SUCCESS,
                                     u'已提交数据恢复任务,请耐心等待数据恢复完成!')
        return redirect('backup_maintain')

    index = 0
    lists = []
    listsa = []
    if os.path.exists(backuppath):
        listsa = os.listdir(backuppath)
    listsa.sort()
    for f in listsa:
        if f.startswith("umail_"):
            size = 0
            times = ""
            names = []
            path = os.path.join(backuppath, f)
            for ff in os.listdir(path):
                filepath = os.path.join(path, ff)
                if ff.startswith("database"):
                    names.append(u"数据库")
                if ff.startswith("licence"):
                    timestamp = os.path.getmtime(filepath)
                    dt = datetime.datetime.fromtimestamp(
                        timestamp, pytz.timezone('Asia/Shanghai'))
                    times = dt.strftime("%Y:%m:%d %H:%M:%S")
                if os.path.isfile(filepath):
                    size += os.path.getsize(filepath)

            maildata = os.path.join(path, "maildata")
            if os.path.exists(maildata):
                names.append(u"邮件数据")
                for ff in os.listdir(maildata):
                    filepath = os.path.join(maildata, ff)
                    if os.path.isfile(filepath):
                        size += os.path.getsize(filepath)

            netdisk = os.path.join(path, "netdisk")
            if os.path.exists(netdisk):
                names.append(u"网盘数据")
                for ff in os.listdir(netdisk):
                    filepath = os.path.join(netdisk, ff)
                    if os.path.isfile(filepath):
                        size += os.path.getsize(filepath)
            if names:
                index += 1
                lists.append(
                    BackupFormat._make(
                        [index, f, u",".join(names), size, times]))

    backupstatus = None
    redis = get_redis_connection()
    if redis.exists("task_trigger:restore"):
        backupstatus = u"数据恢复"
    if redis.exists("task_trigger:backup"):
        backupstatus = u"数据备份"

    auto_backup = int(CoreConfig.getFuctionEnabled("auto_backup"))
    return render(request,
                  "maintain/backup.html",
                  context={
                      "lists": lists,
                      "backupstatus": backupstatus,
                      "auto_backup": auto_backup,
                  })