增加域名绑定功能

dependabot/npm_and_yarn/fir_admin/dns-packet-1.3.4
youngS 4 years ago
parent 250c07c1a6
commit 4a8de02afa
  1. 218
      fir_client/src/components/FirBase.vue
  2. 18
      fir_client/src/components/apps/FirAppInfossecurity.vue
  3. 252
      fir_client/src/components/base/BindDomain.vue
  4. 19
      fir_ser/api/migrations/0050_userdomaininfo_app_id.py
  5. 3
      fir_ser/api/models.py
  6. 4
      fir_ser/api/utils/app/apputils.py
  7. 5
      fir_ser/api/utils/app/supersignutils.py
  8. 16
      fir_ser/api/utils/baseutils.py
  9. 10
      fir_ser/api/utils/serializer.py
  10. 4
      fir_ser/api/utils/storage/caches.py
  11. 7
      fir_ser/api/utils/utils.py
  12. 66
      fir_ser/api/views/apps.py
  13. 59
      fir_ser/api/views/domain.py
  14. 3
      fir_ser/fir_ser/settings.py

@ -6,134 +6,8 @@
:close-on-press-escape="false"
:visible.sync="bind_domain_sure"
width="666px">
<div style="margin: 5px 20px">
<el-steps :active="active" finish-status="success">
<el-step title="步骤 1">
</el-step>
<el-step title="步骤 2">
</el-step>
<el-step title="步骤 3"></el-step>
</el-steps>
<div style="margin-top: 20px">
<div v-if="active===1">
<h2>你的二级域名</h2>
<el-input clearable autofocus v-model="domain_name"></el-input>
</div>
<div v-else-if="active===2">
<div style="text-align: center;margin: 20px 0">
<h3>还差一步绑定成功</h3>
</div>
请联系域名管理员前往 <strong>{{ domain_name }}</strong> 域名 DNS 管理后台添加如下 CNAME 记录
<el-table
:data="domain_tData"
border
stripe
style="width: 100%;margin-top: 20px">
<el-table-column
prop="type"
label="记录类型"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="host"
align="center"
label="主机记录"
>
</el-table-column>
<el-table-column
prop="dns"
align="center"
label="记录值"
width="300">
</el-table-column>
</el-table>
<el-alert title="请在域名DNS配置成功后,点击“下一步”按钮"
style="margin-top: 30px"
type="warning"
:closable="false"
show-icon/>
</div>
<div v-else-if="active===3">
<div v-if="!bind_status">
<div style="text-align: center;margin: 20px 0">
<el-link :underline="false" type="danger"
style="font-size: x-large">绑定失败
</el-link>
</div>
<p style="margin: 10px 0">您的账户正在绑定域名<strong>{{ domain_name }}</strong></p>
<el-row>
<el-col :span="16"><p>系统未检出到您的CNAME记录请检查您的配置</p></el-col>
<el-col :span="6">
<el-button type="danger" size="small" plain style="margin-top: 8px"
@click="remove_domain">
解除绑定
</el-button>
</el-col>
</el-row>
</div>
<div v-else>
<div style="text-align: center;margin: 20px 0">
<el-link :underline="false" type="success"
style="font-size: x-large">绑定成功
</el-link>
</div>
<el-row>
<el-col :span="16"><p>您的账户已绑定域名<strong>{{ domain_name }}</strong></p></el-col>
<el-col :span="6">
<el-button type="danger" size="small" plain style="margin-top: 8px"
@click="remove_domain">
解除绑定
</el-button>
</el-col>
</el-row>
</div>
<el-table
:data="domain_tData"
border
stripe
style="width: 100%;margin-top: 20px">
<el-table-column
prop="type"
label="记录类型"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="host"
align="center"
label="主机记录"
>
</el-table-column>
<el-table-column
prop="dns"
align="center"
label="记录值"
width="300">
</el-table-column>
</el-table>
<div v-if="!bind_status" style="text-align: center;margin: 30px 0">
<el-button @click="check_cname" type="success" plain>已经修改配置再次检查绑定</el-button>
</div>
</div>
</div>
</div>
<span slot="footer" class="dialog-footer" v-if="active!==3">
<el-button style="margin-top: 12px;" @click="last"
:disabled="bind_status|| active===1 ">上一步</el-button>
<el-button style="margin-top: 12px;" @click="next">下一步</el-button>
</span>
<bind-domain transitionName="bind-user-domain" />
</el-dialog>
<canvas ref="canvas" class="canvas" @mousemove="canvas_move" @mouseleave="canvas_leave"/>
<el-container>
<div style="margin: -5px 20px" v-if="$store.state.show_domain_msg">
@ -144,7 +18,7 @@
effect="dark">
<div slot="title">
<span :underline="false" class="domian-tip-bar">应用分发请绑定您自己的域名平台分发域名可能因不可违因素更换将导致您的应用无法访问</span>
<el-button size="medium" @click="bind_click">立即绑定</el-button>
<el-button size="medium" @click="bind_domain_sure=true">立即绑定</el-button>
</div>
</el-alert>
</div>
@ -171,12 +45,12 @@
import FirHeader from "@/components/FirHeader";
import FirFooter from "@/components/FirFooter";
import BackToTop from "@/components/base/BackToTop";
import BindDomain from "@/components/base/BindDomain";
import {show_beautpic,} from "@/utils";
import {domainFun} from "@/restful";
export default {
name: "FirBase",
components: {FirFooter, FirHeader, BackToTop},
components: {FirFooter, FirHeader, BackToTop, BindDomain},
data() {
return {
mousePosition: {},
@ -210,93 +84,11 @@
'$store.state.domain_action': function () {
if (this.$store.state.domain_action) {
this.$store.dispatch("dodomainaction", false);
this.bind_click()
this.bind_domain_sure=true;
}
},
}
, methods: {
check_cname() {
domainFun(data => {
if (data.code === 1000) {
if (this.active++ > 2) this.active = 3;
this.bind_status = true;
this.$store.dispatch("dodomainshow", false);
} else {
if (data.code === 1004) {
this.active = 1;
this.domain_name = '';
} else {
if (this.active++ > 2) this.active = 3;
}
this.bind_status = false;
this.$message.error("绑定失败 " + data.msg)
}
}, {methods: 'PUT', data: {}})
},
remove_domain() {
domainFun(data => {
if (data.code === 1000) {
this.bind_status = false;
this.active = 1;
this.$message.success("解除绑定成功 ");
this.$store.dispatch("dodomainshow", true);
} else {
this.$message.error("解除绑定失败 " + data.msg)
}
}, {methods: 'DELETE', data: {}});
},
bind_click() {
domainFun(data => {
if (data.code === 1000) {
if (data.data) {
if (data.data.domain_name) {
this.domain_name = data.data.domain_name;
}
if (data.data.domain_record) {
this.format_domain_tData(data.data.domain_record);
if (this.active++ > 2) this.active = 3;
}
if (data.data.is_enable) {
this.bind_status = true;
if (this.active++ > 2) this.active = 3;
}
this.bind_domain_sure = true;
}
} else {
this.$message.error("绑定失败 " + data.msg)
}
}, {methods: 'GET', data: {}});
},
format_domain_tData(cname_domain) {
let domain_name_list = this.domain_name.split('.');
const d_len = domain_name_list.length;
if (d_len === 2) {
this.domain_tData[0].host = '@'
} else if (d_len > 2) {
domain_name_list.splice(domain_name_list.length - 2, 2);
this.domain_tData[0].host = domain_name_list.join(".")
}
this.domain_tData[0].dns = cname_domain;
},
next() {
if (this.active === 1) {
domainFun(data => {
if (data.code === 1000) {
if (data.data && data.data.cname_domain) {
this.format_domain_tData(data.data.cname_domain);
if (this.active++ > 2) this.active = 3;
}
} else {
this.$message.error("绑定失败 " + data.msg)
}
}, {methods: 'POST', data: {domain_name: this.domain_name}})
} else if (this.active === 2) {
this.check_cname()
}
},
last() {
if (this.active-- < 2) this.active = 1;
},
canvas_move(e) {
this.mousePosition.x = e.pageX;
this.mousePosition.y = e.pageY;

@ -1,7 +1,13 @@
<template>
<div style="margin-top: 20px;width: 66%;margin-left: 8%">
<el-dialog
title="绑定应用专属下载页域名"
:close-on-click-modal="false"
:close-on-press-escape="false"
:visible.sync="bind_domain_sure"
width="666px">
<bind-domain transitionName="bind-user-domain" :app_id="this.currentapp.app_id"/>
</el-dialog>
<el-form label-width="80px">
<el-form-item label-width="200px" label="访问密码">
@ -46,7 +52,7 @@
<el-input v-model="currentapp.domain_name" clearable
style="width: 60%;margin-right: 10px" prefix-icon="el-icon-download"
:placeholder="defualt_dtitle"/>
<el-button @click="save_app_domain()">保存</el-button>
<el-button @click="bind_domain_sure=true">保存</el-button>
</el-form-item>
<el-form-item label-width="200px" label="微信内访问简易模式">
@ -82,18 +88,17 @@
</el-form>
</div>
</template>
<script>
import {apputils,} from "@/restful"
import {deepCopy} from "@/utils";
import BindDomain from "@/components/base/BindDomain";
export default {
name: "FirAppInfossecurity",
components: {BindDomain},
data() {
return {
currentapp: {},
@ -108,6 +113,7 @@
wxredirectflag: false,
wxeasy_disable: false,
defualt_dtitle: '专属下载页域名',
bind_domain_sure: false,
}
},
methods: {

@ -0,0 +1,252 @@
<template>
<transition :name="transitionName">
<div >
<div style="margin: 5px 20px">
<el-steps :active="active" finish-status="success">
<el-step title="步骤 1">
</el-step>
<el-step title="步骤 2">
</el-step>
<el-step title="步骤 3"/>
</el-steps>
<div style="margin-top: 20px">
<div v-if="active===1">
<h2>你的二级域名</h2>
<el-input clearable autofocus v-model="domain_name"/>
</div>
<div v-else-if="active===2">
<div style="text-align: center;margin: 20px 0">
<h3>还差一步绑定成功</h3>
</div>
请联系域名管理员前往 <strong>{{ domain_name }}</strong> 域名 DNS 管理后台添加如下 CNAME 记录
<el-table
:data="domain_tData"
border
stripe
style="width: 100%;margin-top: 20px">
<el-table-column
prop="type"
label="记录类型"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="host"
align="center"
label="主机记录"
>
</el-table-column>
<el-table-column
prop="dns"
align="center"
label="记录值"
width="300">
</el-table-column>
</el-table>
<el-alert title="请在域名DNS配置成功后,点击“下一步”按钮"
style="margin-top: 30px"
type="warning"
:closable="false"
show-icon/>
</div>
<div v-else-if="active===3">
<div v-if="!bind_status">
<div style="text-align: center;margin: 20px 0">
<el-link :underline="false" type="danger"
style="font-size: x-large">绑定失败
</el-link>
</div>
<p style="margin: 10px 0">您的账户正在绑定域名<strong>{{ domain_name }}</strong></p>
<el-row>
<el-col :span="16"><p>系统未检出到您的CNAME记录请检查您的配置</p></el-col>
<el-col :span="6">
<el-button type="danger" size="small" plain style="margin-top: 8px"
@click="remove_domain">
解除绑定
</el-button>
</el-col>
</el-row>
</div>
<div v-else>
<div style="text-align: center;margin: 20px 0">
<el-link :underline="false" type="success"
style="font-size: x-large">绑定成功
</el-link>
</div>
<el-row>
<el-col :span="16"><p>您的账户已绑定域名<strong>{{ domain_name }}</strong></p></el-col>
<el-col :span="6">
<el-button type="danger" size="small" plain style="margin-top: 8px"
@click="remove_domain">
解除绑定
</el-button>
</el-col>
</el-row>
</div>
<el-table
:data="domain_tData"
border
stripe
style="width: 100%;margin-top: 20px">
<el-table-column
prop="type"
label="记录类型"
align="center"
width="100">
</el-table-column>
<el-table-column
prop="host"
align="center"
label="主机记录"
>
</el-table-column>
<el-table-column
prop="dns"
align="center"
label="记录值"
width="300">
</el-table-column>
</el-table>
<div v-if="!bind_status" style="text-align: center;margin: 30px 0">
<el-button @click="check_cname" type="success" plain>已经修改配置再次检查绑定</el-button>
</div>
</div>
</div>
</div>
<div v-if="active!==3" style="margin:40px 20px 0;text-align: right">
<el-button @click="last"
:disabled="bind_status|| active===1 ">上一步</el-button>
<el-button @click="next">下一步</el-button>
</div>
</div>
</transition>
</template>
<script>
import {domainFun} from "@/restful";
export default {
name: 'BindDomain',
props: {
transitionName: {
type: String,
default: 'bind-domian'
},
app_id: {
type: String,
default: undefined
},
},
data() {
return {
active: 1,
bind_status: false,
bind_domain_sure:true,
domain_name:'',
domain_tData: [{'type': 'CNAME', 'host': 'xxx', 'dns': 'demo.xxx.cn'}],
}
},
mounted() {
this.bind_click()
},
beforeDestroy() {
this.bind_domain_sure=false;
},
methods: {
check_cname() {
domainFun(data => {
if (data.code === 1000) {
if (this.active++ > 2) this.active = 3;
this.bind_status = true;
this.$store.dispatch("dodomainshow", false);
} else {
if (data.code === 1004) {
this.active = 1;
this.domain_name = '';
} else {
if (this.active++ > 2) this.active = 3;
}
this.bind_status = false;
this.$message.error("绑定失败 " + data.msg)
}
}, {methods: 'PUT', data: {app_id:this.app_id}})
},
remove_domain() {
domainFun(data => {
if (data.code === 1000) {
this.bind_status = false;
this.active = 1;
this.$message.success("解除绑定成功 ");
this.$store.dispatch("dodomainshow", true);
} else {
this.$message.error("解除绑定失败 " + data.msg)
}
}, {methods: 'DELETE', data: {app_id:this.app_id}});
},
bind_click() {
domainFun(data => {
if (data.code === 1000) {
if (data.data) {
if (data.data.domain_name) {
this.domain_name = data.data.domain_name;
}
if (data.data.domain_record) {
this.format_domain_tData(data.data.domain_record);
if (this.active++ > 2) this.active = 3;
}
if (data.data.is_enable) {
this.bind_status = true;
if (this.active++ > 2) this.active = 3;
}
this.bind_domain_sure = true;
}
} else {
this.$message.error("绑定失败 " + data.msg)
}
}, {methods: 'GET', data: {app_id:this.app_id}});
},
format_domain_tData(cname_domain) {
let domain_name_list = this.domain_name.split('.');
const d_len = domain_name_list.length;
if (d_len === 2) {
this.domain_tData[0].host = '@'
} else if (d_len > 2) {
domain_name_list.splice(domain_name_list.length - 2, 2);
this.domain_tData[0].host = domain_name_list.join(".")
}
this.domain_tData[0].dns = cname_domain;
},
next() {
if (this.active === 1) {
domainFun(data => {
if (data.code === 1000) {
if (data.data && data.data.cname_domain) {
this.format_domain_tData(data.data.cname_domain);
if (this.active++ > 2) this.active = 3;
}
} else {
this.$message.error("绑定失败 " + data.msg)
}
}, {methods: 'POST', data: {domain_name: this.domain_name,app_id:this.app_id}})
} else if (this.active === 2) {
this.check_cname()
}
},
last() {
if (this.active-- < 2) this.active = 1;
},
}
}
</script>
<style scoped>
.dialog-footer{
}
</style>

@ -0,0 +1,19 @@
# Generated by Django 3.0.3 on 2021-05-19 18:15
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0049_remove_userinfo_domain_name'),
]
operations = [
migrations.AddField(
model_name='userdomaininfo',
name='app_id',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Apps',
verbose_name='APP专属域名'),
),
]

@ -122,7 +122,7 @@ class Apps(models.Model):
supersign_limit_number = models.IntegerField(verbose_name="签名使用限额", default=0)
wxredirect = models.BooleanField(verbose_name="微信内第三方链接自动跳转", default=True)
wxeasytype = models.BooleanField(verbose_name="微信内简易模式,避免微信封停", default=True)
domain_name = models.CharField(verbose_name="专属访问域名", blank=True, null=True, max_length=64)
# domain_name = models.CharField(verbose_name="专属访问域名", blank=True, null=True, max_length=64)
description = models.TextField('描述', blank=True, null=True, default=None, )
updated_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
@ -465,6 +465,7 @@ class DomainCnameInfo(models.Model):
class UserDomainInfo(models.Model):
user_id = models.ForeignKey(to="UserInfo", verbose_name="用户ID", on_delete=models.CASCADE)
app_id = models.ForeignKey(to="Apps", on_delete=models.CASCADE, verbose_name="APP专属域名", null=True, blank=True)
cname_id = models.ForeignKey(to="DomainCnameInfo", verbose_name="cname解析ID", on_delete=models.CASCADE)
domain_name = models.CharField(verbose_name="下载页面域名", db_index=True, max_length=64, null=False, blank=False)
is_enable = models.BooleanField(default=False, verbose_name="绑定成功")

@ -6,6 +6,8 @@
from api.utils.app.randomstrings import make_app_uuid
from api.models import AppReleaseInfo, Apps
import random
from api.utils.baseutils import get_user_domain_name
from api.utils.storage.storage import Storage
from api.utils.storage.caches import del_cache_response_by_short
import logging
@ -127,7 +129,7 @@ def SaveAppInfos(app_file_name, user_obj, appinfo, bundle_id, app_img, short, si
"short": short,
"bundle_id": bundle_id,
"count_hits": 0,
"wxeasytype": False if user_obj.domain_name else True
"wxeasytype": False if get_user_domain_name(user_obj) else True
}
try:
appmobj = Apps.objects.create(**appdata)

@ -12,9 +12,8 @@ from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppRe
from api.utils.app.randomstrings import make_app_uuid, make_from_user_uuid
from api.utils.storage.caches import del_cache_response_by_short, send_msg_over_limit
from api.utils.utils import delete_app_to_dev_and_file, send_ios_developer_active_status, delete_local_files, \
download_files_form_oss, \
get_developer_udided, get_user_domain_name
from api.utils.baseutils import file_format_path, delete_app_profile_file, get_profile_full_path
download_files_form_oss, get_developer_udided
from api.utils.baseutils import file_format_path, delete_app_profile_file, get_profile_full_path, get_user_domain_name
from api.utils.storage.storage import Storage
from django.core.cache import cache

@ -6,7 +6,7 @@
import os, re
from fir_ser.settings import SUPER_SIGN_ROOT
from api.models import AppReleaseInfo
from api.models import AppReleaseInfo, UserDomainInfo
from api.utils.app.randomstrings import make_app_uuid
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
@ -113,3 +113,17 @@ def get_cname_from_domain(domain):
return dns_resolver.query(domain, 'CNAME')[0].to_text()
except Exception:
return str(None)
def get_user_domain_name(obj):
domain_obj = UserDomainInfo.objects.filter(user_id=obj, is_enable=True).first()
if domain_obj:
return domain_obj.domain_name
return ''
def get_app_domain_name(obj):
domain_obj = UserDomainInfo.objects.filter(app_id=obj, is_enable=True).first()
if domain_obj:
return domain_obj.domain_name
return ''

@ -3,8 +3,9 @@ from api import models
from api.utils.app.apputils import bytes2human
from api.utils.TokenManager import DownloadToken
from api.utils.app.supersignutils import get_redirect_server_domain
from api.utils.baseutils import get_user_domain_name, get_app_domain_name
from api.utils.storage.storage import Storage
from api.utils.utils import get_developer_udided, get_choices_dict, get_choices_name_from_key, get_user_domain_name
from api.utils.utils import get_developer_udided, get_choices_dict, get_choices_name_from_key
from api.utils.storage.caches import get_user_free_download_times, get_user_cert_auth_status
import os, json, logging
@ -134,7 +135,7 @@ class AppsSerializer(serializers.ModelSerializer):
preview_url = serializers.SerializerMethodField()
def get_preview_url(self, obj):
return get_redirect_server_domain(None, obj.user_id, obj.domain_name)
return get_redirect_server_domain(None, obj.user_id, get_app_domain_name(obj))
sign_type_choice = serializers.SerializerMethodField()
@ -228,6 +229,11 @@ class AppsShortSerializer(serializers.ModelSerializer):
def get_screenshots(self, obj):
return get_screenshots_from_self(self, obj, True)
domain_name = serializers.SerializerMethodField()
def get_domain_name(self, obj):
return get_app_domain_name(obj)
need_password = serializers.SerializerMethodField()
def get_need_password(self, obj):

@ -12,7 +12,7 @@ from django.utils import timezone
from fir_ser.settings import CACHE_KEY_TEMPLATE, SERVER_DOMAIN, SYNC_CACHE_TO_DATABASE, DEFAULT_MOBILEPROVISION, \
USER_FREE_DOWNLOAD_TIMES, AUTH_USER_FREE_DOWNLOAD_TIMES
from api.utils.storage.storage import Storage, LocalStorage
from api.utils.baseutils import get_app_d_count_by_app_id, file_format_path
from api.utils.baseutils import get_app_d_count_by_app_id, file_format_path, get_app_domain_name
import logging
from django.db.models import F
@ -293,7 +293,7 @@ def set_default_app_wx_easy(user_obj, only_clean_cache=False):
if only_clean_cache:
del_cache_response_by_short(app_obj.app_id)
else:
if not app_obj.domain_name:
if not get_app_domain_name(app_obj):
app_obj.wxeasytype = True
app_obj.save()
del_cache_response_by_short(app_obj.app_id)

@ -306,10 +306,3 @@ def get_choices_name_from_key(choices, key):
if choice[0] == key:
return choice[1]
return ''
def get_user_domain_name(obj):
domain_obj = UserDomainInfo.objects.filter(user_id=obj, is_enable=True).first()
if domain_obj:
return domain_obj.domain_name
return ''

@ -17,8 +17,8 @@ from api.utils.serializer import AppsSerializer, AppReleaseSerializer
from rest_framework.pagination import PageNumberPagination
import logging
from fir_ser.settings import SERVER_DOMAIN
from api.utils.utils import delete_local_files, delete_app_screenshots_files, get_user_domain_name
from api.utils.baseutils import is_valid_domain
from api.utils.utils import delete_local_files, delete_app_screenshots_files
from api.utils.baseutils import is_valid_domain, get_user_domain_name
from api.base_views import app_delete
logger = logging.getLogger(__name__)
@ -142,7 +142,7 @@ class AppInfoView(APIView):
return Response(res.dict)
has_combo = data.get("has_combo", None)
domain_name = data.get("domain_name", None)
# domain_name = data.get("domain_name", None)
if has_combo:
actions = has_combo.get("action", None)
hcombo_id = has_combo.get("hcombo_id", None)
@ -168,36 +168,36 @@ class AppInfoView(APIView):
logger.error("app_id:%s actions:%s hcombo_id:%s Exception:%s" % (app_id, actions, hcombo_id, e))
res.code = 1004
res.msg = "该应用已经关联"
elif domain_name:
apps_obj = Apps.objects.filter(user_id=request.user, app_id=app_id).first()
logger.info("app_id:%s update old data:%s" % (app_id, apps_obj.__dict__))
domain_name_list = domain_name.strip(' ').replace("http://", "").replace("https://", "").split("/")
if len(domain_name_list) > 0:
domain_name = domain_name_list[0]
if len(domain_name) > 3 and is_valid_domain(domain_name):
if domain_name == SERVER_DOMAIN.get("REDIRECT_UDID_DOMAIN").split("//")[1]:
user_admin_obj = UserInfo.objects.filter(is_superuser=True, uid=request.user.uid).order_by(
'pk').first()
if user_admin_obj:
apps_obj.domain_name = domain_name
else:
res.code = 1004
res.msg = "域名设置失败,请更换其他域名"
return Response(res.dict)
else:
apps_obj.domain_name = domain_name
else:
res.code = 1004
res.msg = "域名校验失败"
return Response(res.dict)
if domain_name == '':
apps_obj.domain_name = None
if not get_user_domain_name(request.user):
apps_obj.wxeasytype = True
apps_obj.save()
del_cache_response_by_short(apps_obj.app_id)
return Response(res.dict)
# elif domain_name:
# apps_obj = Apps.objects.filter(user_id=request.user, app_id=app_id).first()
# logger.info("app_id:%s update old data:%s" % (app_id, apps_obj.__dict__))
# domain_name_list = domain_name.strip(' ').replace("http://", "").replace("https://", "").split("/")
# if len(domain_name_list) > 0:
# domain_name = domain_name_list[0]
# if len(domain_name) > 3 and is_valid_domain(domain_name):
# if domain_name == SERVER_DOMAIN.get("REDIRECT_UDID_DOMAIN").split("//")[1]:
# user_admin_obj = UserInfo.objects.filter(is_superuser=True, uid=request.user.uid).order_by(
# 'pk').first()
# if user_admin_obj:
# apps_obj.domain_name = domain_name
# else:
# res.code = 1004
# res.msg = "域名设置失败,请更换其他域名"
# return Response(res.dict)
# else:
# apps_obj.domain_name = domain_name
# else:
# res.code = 1004
# res.msg = "域名校验失败"
# return Response(res.dict)
#
# if domain_name == '':
# apps_obj.domain_name = None
# if not get_user_domain_name(request.user):
# apps_obj.wxeasytype = True
# apps_obj.save()
# del_cache_response_by_short(apps_obj.app_id)
# return Response(res.dict)
else:
try:
do_sign_flag = 0

@ -6,26 +6,34 @@
from rest_framework.views import APIView
from api.utils.baseutils import is_valid_domain, get_cname_from_domain
from api.utils.baseutils import is_valid_domain, get_cname_from_domain, get_user_domain_name
from api.utils.response import BaseResponse
from api.utils.auth import ExpiringTokenAuthentication
from rest_framework.response import Response
from api.models import UserDomainInfo, DomainCnameInfo
from api.models import UserDomainInfo, DomainCnameInfo, Apps
from django.db.models import Count
import logging
from api.utils.storage.caches import set_default_app_wx_easy
from api.utils.storage.caches import set_default_app_wx_easy, del_cache_response_by_short
logger = logging.getLogger(__name__)
def get_domain_filter(request):
filter_dict = {'user_id': request.user, 'app_id__app_id': None}
app_id = request.query_params.get("app_id", request.data.get("app_id", None))
if app_id:
filter_dict['app_id__app_id'] = app_id
return filter_dict
class DomainCnameView(APIView):
authentication_classes = [ExpiringTokenAuthentication, ]
def get(self, request):
res = BaseResponse()
res.data = {'domain_name': '', 'domain_record': '', 'is_enable': False}
user_domain_obj = UserDomainInfo.objects.filter(user_id=request.user).first()
user_domain_obj = UserDomainInfo.objects.filter(**get_domain_filter(request)).first()
if user_domain_obj:
res.data['domain_name'] = user_domain_obj.domain_name
res.data['is_enable'] = user_domain_obj.is_enable
@ -43,18 +51,29 @@ class DomainCnameView(APIView):
res.code = 1001
res.msg = "该域名已经被绑定,请更换其他域名"
else:
user_domian_obj = UserDomainInfo.objects.filter(user_id=request.user, domain_name=domain_name).first()
user_domian_obj = UserDomainInfo.objects.filter(**get_domain_filter(request),
domain_name=domain_name).first()
if user_domian_obj:
res.data = {'cname_domain': user_domian_obj.cname_id.domain_record}
else:
UserDomainInfo.objects.filter(user_id=request.user, is_enable=False).delete()
UserDomainInfo.objects.filter(**get_domain_filter(request), is_enable=False).delete()
min_domian_cname_info_obj = min(
DomainCnameInfo.objects.annotate(Count('userdomaininfo')).filter(is_enable=True),
key=lambda x: x.userdomaininfo__count)
if min_domian_cname_info_obj:
res.data = {'cname_domain': min_domian_cname_info_obj.domain_record}
UserDomainInfo.objects.create(user_id=request.user, cname_id=min_domian_cname_info_obj,
domain_name=domain_name)
data_dict = {
'user_id': request.user,
'cname_id': min_domian_cname_info_obj,
'domain_name': domain_name,
'app_id': None,
}
app_id = request.data.get("app_id", None)
if app_id:
app_obj = Apps.objects.filter(app_id=app_id).first()
if app_obj:
data_dict['app_id'] = app_obj
UserDomainInfo.objects.create(**data_dict)
else:
res.code = 1002
res.msg = "该域名校验失败,请检查"
@ -62,14 +81,22 @@ class DomainCnameView(APIView):
def put(self, request):
res = BaseResponse()
user_domian_obj = UserDomainInfo.objects.filter(user_id=request.user).first()
user_domian_obj = UserDomainInfo.objects.filter(**get_domain_filter(request)).first()
if user_domian_obj:
cname = get_cname_from_domain(user_domian_obj.domain_name)
if cname == user_domian_obj.cname_id.domain_record + '.':
user_domian_obj.is_enable = True
user_domian_obj.save()
UserDomainInfo.objects.filter(domain_name=user_domian_obj.domain_name, is_enable=False).delete()
set_default_app_wx_easy(request.user, True)
app_id = request.data.get("app_id", None)
if app_id:
app_obj = Apps.objects.filter(app_id=app_id).first()
if app_obj:
app_obj.wxeasytype = False
app_obj.save()
del_cache_response_by_short(app_obj.app_id)
else:
set_default_app_wx_easy(request.user, True)
else:
res.code = 1003
res.msg = "系统未检出到您的CNAME记录"
@ -80,6 +107,14 @@ class DomainCnameView(APIView):
def delete(sele, request):
res = BaseResponse()
if UserDomainInfo.objects.filter(user_id=request.user).delete()[0]:
set_default_app_wx_easy(request.user)
if UserDomainInfo.objects.filter(**get_domain_filter(request)).delete()[0]:
app_id = request.query_params.get("app_id", None)
if app_id:
app_obj = Apps.objects.filter(app_id=app_id).first()
if app_obj and not get_user_domain_name(request.user):
app_obj.wxeasytype = True
app_obj.save()
del_cache_response_by_short(app_obj.app_id)
else:
set_default_app_wx_easy(request.user)
return Response(res.dict)

@ -24,7 +24,8 @@ SECRET_KEY = 'j!g@^bc(z(a3*i&kp$_@bgb)bug&^#3=amch!3lz&1x&s6ss6t'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1', 'synchrotron', '172.16.133.34','ali.cdn.flyapp.dvcloud.xin','api.src.flyapp.dvcloud.xin']
ALLOWED_HOSTS = ['127.0.0.1', 'synchrotron', '172.16.133.34', 'ali.cdn.flyapp.dvcloud.xin',
'api.src.flyapp.dvcloud.xin']
# Application definition

Loading…
Cancel
Save