Exemplo n.º 1
0
def updateDomainRecord(client, rr, domain, ip, type):
    records = getRecords(client, rr, domain)
    record_id = None
    for record in records:
        if record['RR'] == rr and record['DomainName'] == domain and record[
                'Type'] == type:
            record_id = record['RecordId']
            avail_ip = record['Value']
            avail_record = record
            break
    if record_id is None:
        print("不存在记录,正在添加记录")
        addDomainRecord(client, rr, domain, ip, type)
    else:
        print("存在记录:" + str(avail_record))
        if avail_ip == ip:
            print("ip未改变,不更改记录,原ip=" + avail_ip + ",现ip=" + ip)
        else:
            print("ip已改变,准备更改记录,原ip=" + avail_ip + ",现ip=" + ip)
            request = UpdateDomainRecordRequest()
            request.set_action_name("UpdateDomainRecord")
            request.set_RR(rr)
            request.set_RecordId(record_id)
            request.set_Type(type)
            request.set_Value(ip)
            request.set_TTL(600)
            request.set_accept_format('json')
            response = client.do_action_with_exception(request)
            print(str(response, encoding='utf-8'))
            return json.loads(response)['RecordId']
def UpdateDomainRecord(accessKeyId,accessSecret,NewIP):
    client = AcsClient(accessKeyId,accessSecret, 'default')

    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('alidns.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https') # https | http
    request.set_version('2015-01-09')
    request.set_action_name('UpdateDomainRecord')

    request.add_query_param('RR', 'WWW')
    request.add_query_param('Value', NewIP)
    request.add_query_param('Type', 'A')
    request.add_query_param('RecordId', '')

    response = str(client.do_action(request), encoding = 'utf-8')
    msg=json.loads(response)
    if 'Message' in msg:
        msg = msg['Message']
        content = stamp_to_time() + '  '  + msg + '\n'
        WriteContent('log.conf', content)
    else :
        content = stamp_to_time() + '  ' + 'the ip of demain liuyaoze.cn has change to :'+NewIP + '\n'
        WriteContent('log.conf', content)
Exemplo n.º 3
0
    def get_all_regions(self):
        '''get all available reigins for current region
        :return: a list, which is mapping for regions
        '''
        client = AcsClient(self.secret_key, self.secret_id, "default")
        request = self.__common_request_settings
        request.set_action_name('DescribeRegions')
        request.set_domain('ecs.aliyuncs.com')
        response = client.do_action_with_exception(request)
        str_response = (str(response, encoding='utf-8'))
        regions = json.loads(str_response).get('Regions').get('Region')

        return regions
Exemplo n.º 4
0
 def getAliyunDnsRecord(self):
     try:
         request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest(
         )
         request.set_PageSize(99)
         request.set_PageNumber(1)
         request.set_action_name("DescribeDomainRecords")
         request.set_DomainName(self.domain_name)
         # request.set_RRKeyWord(self.rr_keyword)
         request.set_TypeKeyWord(self.record_type)
         r = self.client.do_action_with_exception(request)
         return json.loads(r.decode('utf-8'))
     except Exception as e:
         print(e)
         return None
Exemplo n.º 5
0
 def getRecordId(domain):
     client = AcsClientSing.getInstance()
     request = CommonRequestSing.getInstance()
     request.set_domain('alidns.aliyuncs.com')
     request.set_version('2015-01-09')
     request.set_action_name('DescribeDomainRecords')
     request.add_query_param(
         'DomainName',
         Utils.getConfigJson().get('First-level-domain'))
     response = client.do_action_with_exception(request)
     jsonObj = json.loads(response.decode("UTF-8"))
     records = jsonObj["DomainRecords"]["Record"]
     for each in records:
         if each["RR"] == domain:
             return each["RecordId"]
Exemplo n.º 6
0
 def get_all_regions(self):
     '''get all available reigins for current region
     :return: a list, which is mapping for regions
     '''
     try:
         client = AcsClient(self.secret_id, self.secret_key, "default")
         request = self.__common_request_settings
         request.set_action_name('DescribeRegions')
         request.set_domain('ecs.aliyuncs.com')
         response = client.do_action_with_exception(request)
         str_response = (str(response, encoding='utf-8'))
         regions = json.loads(str_response).get('Regions').get('Region')
         return regions
     except ServerException:
         return {"msg":_("InvalidAccessKeyId.NotFound Specified access key is not found")}
Exemplo n.º 7
0
def alarm(message):
    print('开始发送信息:' + message)
    client = AcsClient(ACCESS_KEY_ID, ACCESS_SECRET, 'cn-hangzhou')
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')
    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', PHONE_NUMBER)
    request.add_query_param('SignName', "KisPig网")
    request.add_query_param('TemplateCode', "SMS_184215625")
    request.add_query_param('TemplateParam',
                            "{\"message\": \"" + message + "\"}")
    response = client.do_action_with_exception(request)
    print("通知短信%s已发送%s" % (message, response))
    quit()
Exemplo n.º 8
0
 def checkDomian():
     client = AcsClientSing.getInstance()
     request = CommonRequestSing.getInstance()
     request.set_domain('alidns.aliyuncs.com')
     request.set_version('2015-01-09')
     request.set_action_name('DescribeDomainRecords')
     request.add_query_param(
         'DomainName',
         Utils.getConfigJson().get('First-level-domain'))
     response = client.do_action_with_exception(request)
     jsonObj = json.loads(response.decode("UTF-8"))
     records = jsonObj["DomainRecords"]["Record"]
     dnsrecord = []
     for each in records:
         dnsrecord.append({
             "{_RR}.{_domain}".format(_RR=each["RR"],
                                      _domain=each["DomainName"]):
             each["Value"]
         })
     return dnsrecord
Exemplo n.º 9
0
    def get_region_instance_detail(self, region_id, region_endpoint):
        '''get instances from one special region
        :param region_id: a string,regionID,区域id ,egg:`cn-qingdao`
        :return: a list, all instances
        '''
        client = AcsClient(self.secret_key, self.secret_id, region_id)
        request = self.__common_request_settings
        request.set_domain(region_endpoint)
        request.set_action_name("DescribeInstances")
        request.add_query_param('RegionId', region_id)
        try:
            response = client.do_action_with_exception(request)
            str_response = str(response, encoding="utf-8")
            result = json.loads(str_response).get('Instances').get('Instance')

            if result:
                self.instances.append(result)
            else:
                return
        except Exception:
            pass
Exemplo n.º 10
0
    def update_record(self, RR, value):
        request = UpdateDomainRecordRequest.UpdateDomainRecordRequest()
        request.set_action_name("UpdateDomainRecord")
        request.set_accept_format('json')
        request.set_TTL('600')
        sRecordid = self.get_record_id(RR)

        if sRecordid != None and WordsCheck.RegexChecker.judgeLegalIpv4(value):
            request.set_RecordId(sRecordid)
            request.set_Type(self.record_type)
            request.set_RR(RR)
            request.set_Value(value)
        else:
            return False
        pass
        try:
            # jsonReturn = json.load(self.client.do_action_with_exception(request))
            # rc = self.client.do_action_with_exception(request)
            if None != json.loads(
                    self.client.do_action_with_exception(request).decode(
                        'utf-8')):
                return True
        except:
            return False
Exemplo n.º 11
0
def __test_msg(params):
    """测试短信接口

     :return: 无返回值,测试结果通过控制台退出码获得。0为成功,非0为失败
    """
    params_config = {
        'sms_interface_type': {
            'must': True,
            'data': True,
            'short': 'I',
            'long': 'interface'
        },
        'mobile': {
            'must': True,
            'data': True,
            'short': 'M',
            'long': 'mobile'
        },
        'ali_accesskeyid': {
            'must': True,
            'data': True,
            'short': 'K',
            'long': 'keyid'
        },
        'ali_accesssecret': {
            'must': True,
            'data': True,
            'short': 'S',
            'long': 'secret'
        },
        'ali_signname': {
            'must': True,
            'data': True,
            'short': 'N',
            'long': 'signname'
        },
        'ali_verify_templatecode': {
            'must': True,
            'data': True,
            'short': 'T',
            'long': 'template_id'
        },
    }
    ret_dict = get(params_config, params)
    errcode = ret_dict.get('errcode')
    if errcode and errcode < 0:
        sys.exit(131)
    try:
        sms_interface_type = ret_dict.get('data').get('sms_interface_type')
        mobile = ret_dict.get('data').get('mobile')
        ali_accesskeyid = ret_dict.get('data').get('ali_accesskeyid')
        ali_accesssecret = ret_dict.get('data').get('ali_accesssecret')
        ali_signname = ret_dict.get('data').get('ali_signname')
        ali_verify_templatecode = ret_dict.get('data').get(
            'ali_verify_templatecode')
        if sms_interface_type == "2":
            import urllib
            import urllib.request
            import hashlib
            statusStr = {
                '0': '短信发送成功',
                '-1': '参数不全',
                '-2': '服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间',
                '30': '密码错误',
                '40': '账号不存在',
                '41': '余额不足',
                '42': '账户已过期',
                '43': 'IP地址限制',
                '50': '内容含有敏感词'
            }
            smsapi = "http://api.smsbao.com/"
            data = urllib.parse.urlencode({
                'u': ali_accesskeyid,
                'p': ali_accesssecret,
                'm': mobile,
                'c': ali_signname
            })
            send_url = smsapi + 'sms?' + data
            response = urllib.request.urlopen(send_url)
            the_page = response.read().decode('utf-8')
            if the_page != "0":
                print("\033[1;31m\n短信接口测试失败\n\033[0m")
                print(statusStr[the_page])
                sys.exit(131)
        else:
            from aliyunsdkcore.client import AcsClient
            from aliyunsdkcore.request import CommonRequest
            client = AcsClient(ali_accesskeyid, ali_accesssecret,
                               'cn-hangzhou')
            request = CommonRequest()
            request.set_accept_format('json')
            request.set_domain('dysmsapi.aliyuncs.com')
            request.set_method('POST')
            request.set_protocol_type('https')  # https | http
            request.set_version('2017-05-25')
            request.set_action_name('SendSms')
            request.add_query_param('RegionId', "cn-hangzhou")
            request.add_query_param('PhoneNumbers', mobile)
            request.add_query_param('SignName', ali_signname)
            request.add_query_param('TemplateCode', ali_verify_templatecode)
            request.add_query_param('TemplateParam', "{\"code\":8888}")
            response = client.do_action(request)
            result = str(response, encoding='utf-8')
            if result.find('"OK"') == -1:
                print("\033[1;31m\n短信接口测试失败\n\033[0m")
                print(result)
                sys.exit(131)
        print("\033[1;32m\n短信接口测试成功\n\033[0m")
        sys.exit(0)
    except Exception as e:
        print("\033[1;31m\n短信接口测试失败!\n\033[0m")
        print(e)
        sys.exit(131)