def post(self): origin_json = jsonLoads(self.request.body) url_path = origin_json['url'] rid = origin_json['rid'] reponse = dict() sql = 'update aqb_urlinfo SET url_path = %(url_path)s where rid = %(rid)s;' try: yield Task(self.db.insert, sql, url_path=url_path, rid=rid) reponse['status'] = True reponse['message'] = 'URL update successful!' except: reponse['status'] = False reponse['message'] = 'URL update failed!' print convJson(reponse) self.write(convJson(reponse))
def post(self): origin_json = jsonLoads(self.request.body) sql_list = origin_json['values'] sql_branch = origin_json['param'] origin_sql = self.forms['zone_groups'][sql_branch] time_now = time.time() data_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time_now)) for sql_dict in sql_list: if sql_branch == 'update': zgid = sql_dict['zgid'] select_sql = self.forms['zone_groups']['select'] http_client = AsyncHTTPClient() older_data = yield http_client.fetch( 'http://127.0.0.1:8001/api/zone?id=%s' % zgid) if sql_branch == 'insert': sql_dict['time'] = int(time_now) try: result_data = yield Task(self.db.insert, origin_sql, sql_dict) message = [{ "status": True, "message": "sql execution successed." }] except: message = [{ "status": False, "message": "sql execution failed." }] self.write(convJson(message))
def post(self): ''' { status=, rid=, zone_name=, } ''' rid = int() domain_name = str() record_status = str() try: rid = self.get_argument('rid') domain_name = self.get_argument('zone_name') record_status = 'enable' if 'True' in self.get_argument('status') else 'disable' except: raise HTTPError('params is error!!') func = yield self.initRequest() domain_id = yield Task(self._Domainid, func, domain_name) request = yield func.urlPost(self.dnspod_api['record']['disable'], domain_id=domain_id, record_id=rid, status=record_status) print request[0] print request[1] if request[0]: self.write(convJson(request[1])) else: raise HTTPError(request[1])
def post(self): #print self.request.body ixfr_server = self.extend_config['ixfr']['server'] origin_json = jsonLoads(self.request.body) dns_list = origin_json['values'] domain_id = origin_json['zid'] sql_branch = origin_json['param'] domain_name, domain_group = yield self._CheckGroup(domain_id) to_func = None result = list() message = str() if 'DNSPOD' in domain_group: func = yield self.initRequest() domain_id = yield Task(self._Domainid, func, domain_name) a_func = PushDNS(func, domain_id, self.dnspod_api['record'][sql_branch]) to_func = partial(eval('self.' + '_toDNSPOD'), func=a_func) if 'LOCAL' in domain_group: ptr_list = yield Task(self.getPTRList, ptrid='%') a_func = IxfrRecord(domain_name, master_server=ixfr_server) to_func = partial(eval('self.' + '_toLOCALDNS'), func=a_func, ptr_list=ptr_list, origin=domain_name) struct = dict() for record_dict in dns_list: if 'insert' in sql_branch: older_data = yield Task(self.checkOlderRecord, record_dict) else: older_data = yield Task(self.checkOlderRecordByRid, record_dict) struct['src'] = older_data struct['dst'] = record_dict if len(older_data): # len(older_data) > 0 if 'insert' in sql_branch: message = 'record already exits.' result.append(dict(status=False,message=message)) continue struct['dst'].update(dict(rid=older_data['rid'])) elif 'insert' not in sql_branch: # len(older_data) = 0 and 'insert' not in sql_branch message = 'Do not option this record. The record not exits.' result.append(dict(status=False,message=message)) continue status, message = yield Task(to_func, branch=sql_branch, **struct) if status: message = yield Task(self._insertChangeLog, sql_branch, **struct) result.append(dict(status=status,message=message)) print convJson(result) self.write(convJson(result))
def post(self): origin_json = jsonLoads(self.request.body) sql = self.forms['changelog']['insert'] origin_json['detail'] = convSimpleJson(origin_json['detail']) message = str() try: result_data = yield Task(self.db.insert, sql, origin_json) message = [{"status": True, "message": "sql execution successed."}] except: message = [{"status": False, "message": "sql execution failed."}] self.write(convJson(message))
def get(self): origin_json = dict() try: origin_json['zid'] = self.get_argument('zid') or '%' origin_sql = self.forms['record_zones']['select'] origin_data = yield Task(self.db.select, origin_sql, origin_json) table_name = ['zid', 'domain_name', 'zgid', 'description'] data_list = sqlZip(table_name, origin_data) message = {"status": True, "message": data_list} except: message = {"status": False, "message": "params not found."} self.write(convJson(message))
def get(self): origin_json = dict() try: origin_json['change_id'] = self.get_argument('change_id') or '%' origin_sql = self.forms['changelog']['select'] origin_data = yield Task(self.db.select, origin_sql, origin_json) table_name = ['time', 'action', 'detail'] data_list = map(lambda x: dict(zip(table_name, x)), origin_data) message = [{"status": True, "message": data_list}] except: message = [{"status": False, "message": "params not found."}] self.write(convJson(message))
def get(self): origin_json = dict() origin_json['zgid'] = self.get_argument('zgid') or '%' origin_sql = self.forms['zone_groups']['select'] origin_data = yield Task(self.db.select, origin_sql, **origin_json) table_name = ['zgid', 'group_name', 'description'] data_list = sqlZip(table_name, origin_data) #data_list = map(lambda x: dict(zip(table_name, x)), origin_data) message = {"status": True, "message": data_list} #try: #except: # message = {"status": False, "message": "params not found."} self.write(convJson(message))
def post(self): origin_json = jsonLoads(self.request.body) url_path = origin_json['url_path'] select_zid_sql = "select zid from record_zones where zone_name = %(zone_name)s;" origin_zid = yield Task(self.db.select, select_zid_sql, zone_name=origin_json['zone_name']) origin_json['zid'] = int(origin_zid[0][0]) record_dict = self.initRecord(**origin_json) post_dict = { "param": "insert", "zid": origin_json['zid'], "values": [ record_dict, ] } result = yield Task(self.recordHttpPost, **post_dict) if result.code != 200: status = False else: getRid_sql = 'select rid from record_list where zid = %(zid)s and sub_domain = %(sub_domain)s and value = %(value)s and record_type = %(record_type)s;' insert_url_sql = 'insert into aqb_urlinfo values (%(rid)s, %(url_path)s);' try: get_rid = yield Task(self.db.select, getRid_sql, **record_dict) rid = get_rid[0][0] yield Task(self.db.insert, insert_url_sql, rid=rid, url_path=url_path) self.redisClient.push('rpush', rid, *tuple(origin_json['rids'])) status = True except: status = False message = jsonLoads(result.body)[0]['message'] print convJson(dict(message=message, status=status)) self.write(convJson(dict(message=message, status=status)))
def get(self): origin_json = dict() status = str() result = dict() try: origin_json['zgid'] = self.get_argument('zgid') or '%' origin_sql = self.forms['record_zones']['select_num_by_zgid'] origin_data = yield Task(self.db.select, origin_sql, **origin_json) status = True result['record_num'] = origin_data[0][0] except: status = False result['message'] = "params not found." result['status'] = status self.write(convJson(result))
def post(self): origin_json = jsonLoads(self.request.body) self.group_name = origin_json['group_name'] group_sql = self.forms['record_zones']['select_by_group'] flush_sql = self.forms['record_list']['delete_by_zone'] zone_list = yield Task(self.db.select, group_sql, group_name=self.group_name) func = str() if self.group_name == 'DNSPOD': func = self.__FromDNSPOD if self.group_name == 'LOCAL': func = self.__FromFilePath result = list() for zid, name, file_path in zone_list: delete_status = yield Task(self.db.insert, flush_sql, zid=zid) zone_stat = yield Task(func, name, zid, file_path) result.append(zone_stat) self.write(convJson(dict(result=result)))
def post(self): origin_json = jsonLoads(self.request.body) status = bool() result = dict() sql = self.forms['record_list']['select_get_rid'] try: if origin_json.has_key('zone_name'): sql_select_zid = "select zid from record_zones where zone_name = %(zone_name)s;" tuple_data =yield Task(self.db.select, sql_select_zid, zone_name=origin_json['zone_name']) origin_json['zid'] = str(tuple_data[0][0]) origin_data = yield Task(self.db.select, sql, **origin_json) status = True result['rid'] = origin_data[0][0] except: status = False result['message'] = 'params not found.' result['status'] = status self.write(convJson(result))
def get(self): origin_json = self.request.arguments data =dict() status = str() result = dict() try: if not origin_json.has_key('zid'): sql_select_zid = "select zid from record_zones where zone_name = %(zone_name)s;" tuple_data =yield Task(self.db.select, sql_select_zid, zone_name=origin_json['zone_name'][0]) data['zid'] = str(tuple_data[0][0]) else: data['zid'] = origin_json['zid'][0] or '%' origin_sql = self.forms['record_list']['select_by_zid'] table_name = ['rid','sub_domain','record_type','value','ttl','weight','mx','record_line','status','zid','rgid','description'] origin_data = yield Task(self.db.select, origin_sql, **data) data_list = sqlZip(table_name, origin_data) status = True result['records'] = data_list except: status = False result['message'] = "params not found." result['status'] = status self.write(convJson(result))
def get(self): sql = "select * from record_aqb_view;" aqb_table = [ "rid", "sub_domain", "value", "record_type", "zone_name", "status", "url" ] kw = dict() sql_tuple = yield Task(self.db.select, sql, **kw) to_redis = dict() to_web = list() tuple_que = list() for tup in range(len(sql_tuple)): s = bool() tu = list(sql_tuple[tup]) if to_redis.has_key(tu[0]): s = True if not to_redis.has_key(tu[0]): to_redis[tu[0]] = list() to_redis[tu[0]].append(tu[1]) if s: num = tuple_que.index(int(tu[0])) to_web[num][2] = str(to_web[num][2]) + ',' + str(tu[4]) continue #print tu[4] +" "+tu[6] if tu[8]: # 注意:list删除元素后长度缩短1 del tu[6] del tu[4] else: del tu[5] del tu[3] del tu[1] to_web.append(list(tu)) tuple_que.append(tu[0]) aqb_list = sqlZip(aqb_table, to_web) self.finish(convJson(dict(status=True, records=aqb_list))) for key, values in to_redis.items(): self.redisClient.push('rpush', key, *values)
def get(self): origin = self.request.arguments origin_json = dict() status = bool() result = dict() sql = self.forms['record_list']['select_get_rid'] try: if not origin.has_key('zid'): sql_select_zid = "select zid from record_zones where zone_name = %(zone_name)s;" tuple_data =yield Task(self.db.select, sql_select_zid, zone_name=origin['zone_name'][0]) origin_json['zid'] = str(tuple_data[0][0]) else: origin_json['zid'] = self.get_argument('zid') origin_json['sub_domain'] = self.get_argument('sub_domain') origin_json['record_type'] = self.get_argument('record_type') origin_json['value'] = self.get_argument('value') origin_data = yield Task(self.db.select, sql, **origin_json) status = True result['rid'] = origin_data[0][0] except: status = False result['message'] = 'params not found.' result['status'] = status self.write(convJson(result))