def receive(self, text=None, bytes=None, **kwargs): """ Called when a message is received with either text or bytes filled out. """ #self.close() return_info = {} return_info['permission'] = True data = json.loads(self.message['text']) self.clientip = '127.0.0.1' self.username = self.message.user.username try: self.role = self.message.user.userprofile.role except: self.role = 'none' #判断是否有权限 if not HasDnsPermission(self.message, "cf", data['product'], "add"): return_info['permission'] = False return_info['result'] = False self.message.reply_channel.send({'text': json.dumps(return_info)}) self.close() return False step = 0 for sub_domain in data['sub_domain']: step += 1 return_info['domain'] = sub_domain + '.' + data[ 'zone'] if sub_domain != "@" else data['zone'] return_info['step'] = step cf_acc = cf_account.objects.get(name=data['product']) try: cfapi = CfApi(CF_URL, cf_acc.email, cf_acc.key) except Exception as e: logger.error("新增 %s 域名失败!" % return_info['domain']) return_info['result'] = False else: result = cfapi.CreateZoneRecord( zone_id=data['zone_id'], record_name=return_info['domain'], record_type=data['type'], record_content=data['content'], proxied=True if data['proxied'].lower() == 'true' else False, ) return_info['result'] = result['success'] if return_info['result']: insert_ah( self.clientip, self.username, "null", "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], sub_domain + '.' + data['zone'], data['content'], '1'), return_info['result'], 'add') self.message.reply_channel.send({'text': json.dumps(return_info)})
def DeleteDnspodRecords(request): if request.method == 'GET': return HttpResponse('You get nothing!') elif request.method == 'POST': clientip = getIp(request) username = request.user.username manage = request.user.userprofile.manage try: role = request.user.userprofile.role except: role = 'none' if not username: logger.info('user: 用户名未知 | [POST]%s is requesting. %s' % (clientip, request.get_full_path())) return HttpResponseServerError("用户名未知,请登陆有效账号!") #if username != 'phexus_sa': # return HttpResponseServerError("抱歉,暂时不放开删除权限,请联系管理员!") #return HttpResponseServerError("抱歉,暂时不放开删除权限,请联系管理员!") logger.info('[POST]%s is requesting. %s' % (clientip, request.get_full_path())) data = json.loads(request.body) record_list = [] for zone in data: if not HasDnsPermission(request, "dnspod", zone['product'], "delete"): return HttpResponseServerError("抱歉,您没有删除账号[%s]解析的权限!" % zone['product']) dp_acc = dnspod_account.objects.get(name=zone['product']) try: dpapi = DpApi(DnsPod_URL, dp_acc.key) except Exception as e: logger.error("删除 %s 域名失败!%s" % (zone['name'], str(e))) return HttpResponseServerError("删除 %s 域名失败!" % zone['name']) else: result, status = dpapi.DeleteZoneRecord( zone['zone'], zone['record_id'], zone['name']) if not status: logger.error("删除 %s 域名失败!%s" % (zone['name'], str(result))) return HttpResponseServerError("删除 %s 域名失败!" % zone['name']) else: logger.info("删除 %s 域名成功!%s" % (zone['name'], str(result))) insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (zone['type'], zone['name'], zone['value'], zone['enabled']), "null", status, 'delete') return HttpResponse("删除 %s 域名成功!" % zone['name']) else: return HttpResponse('nothing!')
def DeleteRecords(request): if request.method == 'GET': return HttpResponse('You get nothing!') elif request.method == 'POST': clientip = getIp(request) username = request.user.username manage = request.user.userprofile.manage try: role = request.user.userprofile.role except: role = 'none' if not username: logger.info('user: 用户名未知 | [POST]%s is requesting. %s' % (clientip, request.get_full_path())) return HttpResponseServerError("用户名未知,请登陆有效账号!") logger.info('[POST]%s is requesting. %s' % (clientip, request.get_full_path())) data = json.loads(request.body) record_list = [] for zone in data: if not HasDnsPermission(request, "cf", zone['product'], "delete"): return HttpResponseServerError("抱歉,您没有删除账号[%s]解析的权限!" % zone['product']) cf_acc = cf_account.objects.get(name=zone['product']) try: cfapi = CfApi(CF_URL, cf_acc.email, cf_acc.key) except Exception as e: logger.error("删除 %s 域名失败!%s" % (zone['name'], str(e))) return HttpResponseServerError("删除 %s 域名失败!" % zone['name']) else: result = cfapi.DeleteZoneRecord(zone['zone_id'], zone['record_id']) if not result['success']: logger.error("删除 %s 域名失败!%s" % (zone['name'], str(result))) return HttpResponseServerError("删除 %s 域名失败!" % zone['name']) else: logger.info("删除 %s 域名成功!%s" % (zone['name'], str(result))) insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (zone['type'], zone['name'], zone['content'], zone['proxied']), "null", result['success'], 'delete') return HttpResponse("删除 %s 域名成功!" % zone['name']) else: return HttpResponse('nothing!')
def receive(self, text=None, bytes=None, **kwargs): """ Called when a message is received with either text or bytes filled out. """ #self.close() self.clientip = '127.0.0.1' self.username = self.message.user.username try: self.role = self.message.user.userprofile.role except: self.role = 'none' data = json.loads(self.message['text']) step = 0 for record in data['records']: step += 1 return_info = {} return_info['record'] = record return_info['step'] = step return_info['permission'] = True #判断是否有权限 if not HasDnsPermission(self.message, "cf", record['product'], "change"): return_info['permission'] = False return_info['result'] = False self.message.reply_channel.send({'text': json.dumps(return_info)}) continue cf_acc = cf_account.objects.filter(name=record['product']).first() cfapi = CfApi(CF_URL, cf_acc.email, cf_acc.key) if data['proxied'] == 'true': proxied = True else: proxied = False result = cfapi.UpdateZoneRecord(record['zone_id'], data['type'], record['name'], data['content'], proxied=proxied, record_id=record['record_id']) if not result['success']: return_info['result'] = False else: return_info['result'] = True logger.info("req_ip: %s | user: %s | updaterecord: { 'type':%s, 'name': %s, 'content': %s, 'proxied':%s } ---> { 'type':%s, 'name': %s, 'content': %s, 'proxied':%s }" %(self.clientip, self.username, record['type'], record['name'], record['content'], record['proxied'], data['type'], record['name'], data['content'], proxied)) insert_ah(self.clientip, self.username, "'type':%s, 'name': %s, 'content': %s, 'proxied':%s" %(record['type'], record['name'], record['content'], record['proxied']), "'type':%s, 'name': %s, 'content': %s, 'proxied':%s" %(data['type'], record['name'], data['content'], proxied), return_info['result']) self.message.reply_channel.send({'text': json.dumps(return_info)})
def receive(self, text=None, bytes=None, **kwargs): """ Called when a message is received with either text or bytes filled out. """ #self.close() return_info = {} return_info['permission'] = True data = json.loads(self.message['text']) self.clientip = '127.0.0.1' self.username = self.message.user.username try: self.role = self.message.user.userprofile.role except: self.role = 'none' #判断是否有权限 if not HasDnsPermission(self.message, "dnspod", data['product'], "add"): return_info['permission'] = False return_info['result'] = False self.message.reply_channel.send({'text': json.dumps(return_info)}) self.close() return False step = 0 for sub_domain in data['sub_domain']: step += 1 return_info['domain'] = sub_domain + '.' + data[ 'zone'] if sub_domain != "@" else data['zone'] return_info['step'] = step dp_acc = dnspod_account.objects.get(name=data['product']) try: dpapi = DpApi(DnsPod_URL, dp_acc.key) except Exception as e: logger.error("新增 %s 域名失败!" % return_info['domain']) return_info['result'] = False else: result, status = dpapi.CreateZoneRecord( domain=data['zone'], sub_domain=sub_domain, record_type=data['type'], value=data['value'], record_line=data['record_line'], #status = 'enable' if data['enabled'] == '1' else 'disable', ) if not status: return_info['result'] = False else: return_info['result'] = True insert_ah( self.clientip, self.username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], return_info['domain'], data['value'], '1'), status, 'add') self.message.reply_channel.send({'text': json.dumps(return_info)})
def UpdateDnspodRecords(request): if request.method == 'POST': clientip = getIp(request) username = request.user.username try: role = request.user.userprofile.role except: role = 'none' if not username: logger.info('user: 用户名未知 | [POST]%s is requesting. %s' % (clientip, request.get_full_path())) return HttpResponseServerError("用户名未知!") logger.info('user:%s | [POST]%s is requesting. %s' % (username, clientip, request.get_full_path())) data = json.loads(request.body) logger.info(data) for record in data: dp_acc = dnspod_account.objects.get(name=record['product']) #判断是否有权限 if not HasDnsPermission(request, "dnspod", record['product'], "change"): return HttpResponseServerError("抱歉,您没有修改账号[%s]解析的权限!" % record['product']) try: dpapi = DpApi(DnsPod_URL, dp_acc.key) except Exception as e: logger.error("修改 %s 域名失败!" % record['name']) insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (record['type'], record['name'], record['value'], record['enabled']), False) return HttpResponseServerError("修改 %s 域名失败!" % record['name']) else: result, status = dpapi.UpdateZoneRecord( domain=record['zone'], record_id=record['record_id'], sub_domain=record['sub_domain'], record_type=record['type'], value=record['value'], record_line_id=record['record_line_id'], status='enable' if record['enabled'] == '1' else 'disable', ) if not status: insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (record['type'], record['name'], record['value'], record['enabled']), status) return HttpResponseServerError('error!') return HttpResponse(result) insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (record['type'], record['name'], record['value'], record['enabled']), status) elif request.is_websocket(): clientip = getIp(request) username = request.user.username try: role = request.user.userprofile.role except: role = 'none' if not username: request.websocket.send('userNone') logger.info('user: 用户名未知 | [WS]%s is requesting. %s' % (clientip, request.get_full_path())) ### close websocket ### request.websocket.close() logger.info('user:%s | [WS]%s is requesting. %s' % (username, clientip, request.get_full_path())) for postdata in request.websocket: #logger.info(request.websocket.read()) if not postdata: request.websocket.send("nothing") break data = json.loads(postdata) step = 0 for record in data['records']: step += 1 return_info = {} return_info['record'] = record return_info['step'] = step return_info['permission'] = True #判断是否有权限 if not HasDnsPermission(request, "dnspod", record['product'], "change"): return_info['permission'] = False return_info['result'] = False request.websocket.send(json.dumps(return_info)) continue dp_acc = dnspod_account.objects.get(name=record['product']) try: dpapi = DpApi(DnsPod_URL, dp_acc.key) except Exception as e: logger.error("修改 %s 域名失败!" % record['name']) return_info['result'] = False else: result, status = dpapi.UpdateZoneRecord( domain=record['zone'], record_id=record['record_id'], sub_domain=record['sub_domain'], record_type=data['type'], value=data['value'], record_line_id=record['record_line_id'], status='enable' if data['enabled'] == '1' else 'disable', ) if not status: return_info['result'] = False else: return_info['result'] = True insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (record['type'], record['name'], record['value'], record['enabled']), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], record['name'], data['value'], data['enabled']), return_info['result']) request.websocket.send(json.dumps(return_info)) #### close websocket ### #request.websocket.close() elif request.method == 'GET': return HttpResponse('You get nothing!') else: return HttpResponse('nothing!')
def CreateDnspodRecords(request): if request.method == 'POST': clientip = getIp(request) username = request.user.username try: role = request.user.userprofile.role except: role = 'none' if not username: logger.info('user: 用户名未知 | [POST]%s is requesting. %s' % (clientip, request.get_full_path())) return HttpResponseServerError("用户名未知!") logger.info('user:%s | [POST]%s is requesting. %s' % (username, clientip, request.get_full_path())) data = json.loads(request.body) #判断是否有权限 if not HasDnsPermission(request, "dnspod", data['product'], "add"): return HttpResponseServerError("抱歉,您没有新增账号[%s]解析的权限!" % data['product']) for sub_domain in data['sub_domain']: dp_acc = dnspod_account.objects.get(name=data['product']) record_name = data[ 'zone'] if sub_domain == '@' else sub_domain + "." + data[ 'zone'] try: dpapi = DpApi(DnsPod_URL, dp_acc.key) except Exception as e: info = "新增 %s 域名失败!" % record_name logger.error(info) insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], record_name, data['value'], '1'), False, 'add') return HttpResponseServerError(info) else: result, status = dpapi.CreateZoneRecord( domain=data['zone'], sub_domain=sub_domain, record_type=data['type'], value=data['value'], record_line=data['record_line'], #status = 'enable' if data['enabled'] == '1' else 'disable', ) if not status: insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], sub_domain + '.' + data['zone'], data['value'], '1'), status, 'add') return HttpResponseServerError('error!') insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], sub_domain + '.' + data['zone'], data['value'], '1'), status, 'add') return HttpResponse(json.dumps(result)) elif request.is_websocket(): clientip = getIp(request) username = request.user.username try: role = request.user.userprofile.role except: role = 'none' if not username: request.websocket.send('userNone') logger.info('user: 用户名未知 | [WS]%s is requesting. %s' % (clientip, request.get_full_path())) ### close websocket ### request.websocket.close() logger.info('user:%s | [WS]%s is requesting. %s' % (username, clientip, request.get_full_path())) for postdata in request.websocket: if not postdata: request.websocket.send("nothing") break data = json.loads(postdata) #判断是否有权限 if not HasDnsPermission(request, "dnspod", data['product'], "add"): request.websocket.send('noPermission') ### close websocket ### request.websocket.close() break step = 0 for sub_domain in data['sub_domain']: step += 1 return_info = {} return_info['domain'] = sub_domain + '.' + data[ 'zone'] if sub_domain != "@" else data['zone'] return_info['step'] = step dp_acc = dnspod_account.objects.get(name=data['product']) try: dpapi = DpApi(DnsPod_URL, dp_acc.key) except Exception as e: logger.error("新增 %s 域名失败!" % return_info['domain']) return_info['result'] = False else: result, status = dpapi.CreateZoneRecord( domain=data['zone'], sub_domain=sub_domain, record_type=data['type'], value=data['value'], record_line=data['record_line'], #status = 'enable' if data['enabled'] == '1' else 'disable', ) if not status: return_info['result'] = False else: return_info['result'] = True insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], return_info['domain'], data['value'], '1'), status, 'add') request.websocket.send(json.dumps(return_info)) ### close websocket ### #request.websocket.close() elif request.method == 'GET': return HttpResponse('You get nothing!') else: return HttpResponse('nothing!')
def UpdateRecords(request): if request.is_websocket(): global username, role, clientip if request.META.has_key('HTTP_X_FORWARDED_FOR'): clientip = request.META['HTTP_X_FORWARDED_FOR'] else: clientip = request.META['REMOTE_ADDR'] username = request.user.username try: role = request.user.userprofile.role except: role = 'none' if not username: request.websocket.send('userNone') logger.info('user: 用户名未知 | [POST]%s is requesting. %s' % (clientip, request.get_full_path())) ### close websocket ### request.websocket.close() logger.info('user:%s | [POST]%s is requesting. %s' % (username, clientip, request.get_full_path())) for postdata in request.websocket: #logger.info(type(postdata)) if not postdata: logger.info('this is test!') break data = json.loads(postdata) step = 0 for record in data['records']: step += 1 return_info = {} return_info['record'] = record return_info['step'] = step return_info['permission'] = True #判断是否有权限 if not HasDnsPermission(request, "cf", record['product'], "change"): return_info['permission'] = False return_info['result'] = False request.websocket.send(json.dumps(return_info)) continue cf_acc = cf_account.objects.filter( name=record['product']).first() cfapi = CfApi(CF_URL, cf_acc.email, cf_acc.key) if data['proxied'] == 'true': proxied = True else: proxied = False result = cfapi.UpdateZoneRecord(record['zone_id'], data['type'], record['name'], data['content'], proxied=proxied, record_id=record['record_id']) if not result['success']: return_info['result'] = False else: return_info['result'] = True logger.info( "req_ip: %s | user: %s | updaterecord: { 'type':%s, 'name': %s, 'content': %s, 'proxied':%s } ---> { 'type':%s, 'name': %s, 'content': %s, 'proxied':%s }" % (clientip, username, record['type'], record['name'], record['content'], record['proxied'], data['type'], record['name'], data['content'], proxied)) insert_h = alter_history( time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), req_ip=clientip, user=username, pre_rec="'type':%s, 'name': %s, 'content': %s, 'proxied':%s" % (record['type'], record['name'], record['content'], record['proxied']), now_rec="'type':%s, 'name': %s, 'content': %s, 'proxied':%s" % (data['type'], record['name'], data['content'], proxied)) insert_h.save() request.websocket.send(json.dumps(return_info)) ### close websocket ### request.websocket.close()
def CreateRecords(request): if request.method == 'POST': clientip = getIp(request) username = request.user.username try: role = request.user.userprofile.role except: role = 'none' #if not username: # logger.info('user: 用户名未知 | [POST]%s is requesting. %s' %(clientip, request.get_full_path())) # return HttpResponseServerError("用户名未知!") logger.info('user:%s | [POST]%s is requesting. %s' % (username, clientip, request.get_full_path())) data = json.loads(request.body) #判断是否有权限 #if not HasDnsPermission(request, "cf", data['product'], "add"): # return HttpResponseServerError("抱歉,您没有新增账号[%s]解析的权限!" %data['product']) result_list = [] for sub_domain in data['sub_domain']: cf_acc = cf_account.objects.get(name=data['product']) record_name = sub_domain + '.' + data[ 'zone'] if sub_domain != '@' else data['zone'] try: cfapi = CfApi(CF_URL, cf_acc.email, cf_acc.key) except Exception as e: info = "新增 %s 域名失败: %s" % (record_name, str(e)) logger.error(info) result = {'result': None, 'errors': str(e), 'success': False} else: result = cfapi.CreateZoneRecord( zone_id=data['zone_id'], record_name=record_name, record_type=data['type'], record_content=data['content'], proxied=True if data['proxied'].lower() == 'true' else False, ) result_list.append(result) insert_ah( clientip, username, "null", "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], record_name, data['content'], '1'), result['success'], 'add') if not result['success']: return HttpResponseServerError(result_list) return HttpResponse(json.dumps(result_list)) elif request.is_websocket(): clientip = getIp(request) username = request.user.username try: role = request.user.userprofile.role except: role = 'none' if not username: request.websocket.send('userNone') logger.info('user: 用户名未知 | [WS]%s is requesting. %s' % (clientip, request.get_full_path())) ### close websocket ### request.websocket.close() logger.info('user:%s | [WS]%s is requesting. %s' % (username, clientip, request.get_full_path())) for postdata in request.websocket: if not postdata: ### close websocket ### request.websocket.close() break data = json.loads(postdata) #判断是否有权限 if not HasDnsPermission(request, "cf", data['product'], "add"): request.websocket.send('noPermission') ### close websocket ### request.websocket.close() break step = 0 for sub_domain in data['sub_domain']: step += 1 return_info = {} return_info['domain'] = sub_domain + '.' + data[ 'zone'] if sub_domain != "@" else data['zone'] return_info['step'] = step cf_acc = cf_account.objects.get(name=data['product']) try: cfapi = CfApi(CF_URL, cf_acc.email, cf_acc.key) except Exception as e: logger.error("新增 %s 域名失败!" % return_info['domain']) return_info['result'] = False else: result = cfapi.CreateZoneRecord( zone_id=data['zone_id'], record_name=return_info['domain'], record_type=data['type'], record_content=data['content'], proxied=True if data['proxied'].lower() == 'true' else False, ) return_info['result'] = result['success'] insert_ah( clientip, username, "null", "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], sub_domain + '.' + data['zone'], data['content'], '1'), return_info['result'], 'add') request.websocket.send(json.dumps(return_info)) ### close websocket ### request.websocket.close() elif request.method == 'GET': return HttpResponse('You get nothing!') else: return HttpResponse('nothing!')
def UpdateDnspodRecords(request): if request.method == 'POST': clientip = getIp(request) username = request.user.username try: role = request.user.userprofile.role except: role = 'none' if not username: logger.info('user: 用户名未知 | [POST]%s is requesting. %s' % (clientip, request.get_full_path())) return HttpResponseServerError("用户名未知!") logger.info('user:%s | [POST]%s is requesting. %s' % (username, clientip, request.get_full_path())) data = json.loads(request.body) logger.info(data) for record in data: dp_acc = dnspod_account.objects.get(name=record['product']) #判断是否有权限 if not HasDnsPermission(request, "dnspod", record['product'], "change"): return HttpResponseServerError("抱歉,您没有修改账号[%s]解析的权限!" % record['product']) try: dpapi = DpApi(DnsPod_URL, dp_acc.key) except Exception, e: logger.error("修改 %s 域名失败!" % record['name']) insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (record['type'], record['name'], record['value'], record['enabled']), False) return HttpResponseServerError("修改 %s 域名失败!" % record['name']) else: result, status = dpapi.UpdateZoneRecord( domain=record['zone'], record_id=record['record_id'], sub_domain=record['sub_domain'], record_type=record['type'], value=record['value'], record_line_id=record['record_line_id'], status='enable' if record['enabled'] == '1' else 'disable', ) if not status: insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (record['type'], record['name'], record['value'], record['enabled']), status) return HttpResponseServerError('error!') return HttpResponse(result) insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (record['type'], record['name'], record['value'], record['enabled']), status)
def CreateDnspodRecords(request): if request.method == 'POST': clientip = getIp(request) username = request.user.username try: role = request.user.userprofile.role except: role = 'none' if not username: logger.info('user: 用户名未知 | [POST]%s is requesting. %s' % (clientip, request.get_full_path())) return HttpResponseServerError("用户名未知!") logger.info('user:%s | [POST]%s is requesting. %s' % (username, clientip, request.get_full_path())) data = json.loads(request.body) #判断是否有权限 if not HasDnsPermission(request, "dnspod", data['product'], "add"): return HttpResponseServerError("抱歉,您没有新增账号[%s]解析的权限!" % data['product']) for sub_domain in data['sub_domain']: dp_acc = dnspod_account.objects.get(name=data['product']) record_name = data[ 'zone'] if sub_domain == '@' else sub_domain + "." + data[ 'zone'] try: dpapi = DpApi(DnsPod_URL, dp_acc.key) except Exception, e: info = "新增 %s 域名失败!" % record_name logger.error(info) insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], record_name, data['value'], '1'), False, 'add') return HttpResponseServerError(info) else: result, status = dpapi.CreateZoneRecord( domain=data['zone'], sub_domain=sub_domain, record_type=data['type'], value=data['value'], record_line=data['record_line'], #status = 'enable' if data['enabled'] == '1' else 'disable', ) if not status: insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], sub_domain + '.' + data['zone'], data['value'], '1'), status, 'add') return HttpResponseServerError('error!') insert_ah( clientip, username, "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % ('null', 'null', 'null', 'null'), "'type':%s, 'name': %s, 'content': %s, 'enabled':%s" % (data['type'], sub_domain + '.' + data['zone'], data['value'], '1'), status, 'add') return HttpResponse(json.dumps(result))
request.websocket.send('userNone') logger.info('user: 用户名未知 | [WS]%s is requesting. %s' % (clientip, request.get_full_path())) ### close websocket ### request.websocket.close() logger.info('user:%s | [WS]%s is requesting. %s' % (username, clientip, request.get_full_path())) for postdata in request.websocket: if not postdata: request.websocket.send("nothing") break data = json.loads(postdata) #判断是否有权限 if not HasDnsPermission(request, "dnspod", data['product'], "add"): request.websocket.send('noPermission') ### close websocket ### request.websocket.close() break step = 0 for sub_domain in data['sub_domain']: step += 1 return_info = {} return_info['domain'] = sub_domain + '.' + data[ 'zone'] if sub_domain != "@" else data['zone'] return_info['step'] = step dp_acc = dnspod_account.objects.get(name=data['product']) try:
logger.info('user: 用户名未知 | [WS]%s is requesting. %s' % (clientip, request.get_full_path())) ### close websocket ### request.websocket.close() logger.info('user:%s | [WS]%s is requesting. %s' % (username, clientip, request.get_full_path())) for postdata in request.websocket: if not postdata: ### close websocket ### request.websocket.close() break data = json.loads(postdata) #判断是否有权限 if not HasDnsPermission(request, "cf", data['product'], "add"): request.websocket.send('noPermission') ### close websocket ### request.websocket.close() break step = 0 for sub_domain in data['sub_domain']: step += 1 return_info = {} return_info['domain'] = sub_domain + '.' + data[ 'zone'] if sub_domain != "@" else data['zone'] return_info['step'] = step cf_acc = cf_account.objects.get(name=data['product']) try: