예제 #1
0
 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))
예제 #2
0
 def urlPost(self, u, **kw):
     result = [bool(), str()]
     uApi = u
     self.uData.update(**kw)
     body = urllib.urlencode(self.uData)
     #print u
     #print self.uData
     httpclient = AsyncHTTPClient()
     uPost = yield httpclient.fetch(uApi,
                                    method='POST',
                                    body=body,
                                    headers=self.uHeaders)
     #print uPost.body
     print u
     print body
     try:
         jPost = jsonLoads(uPost.body)
         #print jPost
         if jPost.get("status", {}).get("code") == "1":
             result[0] = True
             result[1] = jPost
         else:
             result[0] = False
             result[1] = jPost
             #raise Exception(jPost['status'])
     except:
         result[0] = False
         result[1] = uPost.body
     raise Return(result)
예제 #3
0
파일: log.py 프로젝트: badpasta/dnsquicky
 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))
예제 #4
0
파일: aqb.py 프로젝트: badpasta/dnsquicky
 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)))
예제 #5
0
파일: aqb.py 프로젝트: badpasta/dnsquicky
 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))
예제 #6
0
 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)))
예제 #7
0
 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)) 
예제 #8
0
 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))
예제 #9
0
파일: aqb.py 프로젝트: badpasta/dnsquicky
    def on_message(self, message):
        data = jsonLoads(message)
        record = data['sub_domain'] + '.' + data[
            'zone_name'] if '@' not in data['sub_domain'] else data['zone_name']
        if 'aqb' in data['param']:
            tmp_mess = '记录: ' + record + '初始化..'
            self.write_message(tmp_mess)
            print tmp_mess

            #status = yield self.goCurl(record, **data)
            #print status

            status = yield self.goCurl(record, **data)
            print status
            try:
                status = yield self.goCurl(record, **data)
                assert status
            except:
                raise HTTPError(4001)
            yield self.switchDNS(record, **data)
            me = '域名切换成功.'
            self.write_message(me)
            print me