示例#1
0
def update_ip(request):
    myip = request.GET.get('myip', request.META['REMOTE_ADDR'])
    if func.validIP(myip) is False:
        myip = request.META['REMOTE_ADDR']

    hostname = request.GET.get('hostname')

    obj = op.Zone(request.user, request)

    if not hostname:
        return HttpResponse("nofqdn")

    try:
        hosts = [int(i) for i in hostname.split(',')]
    except:
        return HttpResponse("notfqdn")

    if len(hosts) > 20:
        return HttpResponse("numhost")

    records = DnsRecords.objects.filter(id__in=hosts, type="A")
    if records.count() == 0:
        return HttpResponse("nohost")

    zones = records.values_list('zone', flat=True).distinct()
    for i in zones:
        try:
            obj.check_valid_zone(i, strict_owner=False)
        except:
            return HttpResponse("nohost")

    records.update(data=str(myip))
    return HttpResponse("good")
示例#2
0
    def post(self, request, zone_slug=None, reg_slug=None, format=None):
        if request.DATA:
            data = request.DATA
        else:
            raise ValueError("No post data received")

        obj = op.Zone(request.user, request, rev_prefix='v1_0', format=format)
        obj.share(zone_slug, data)
        return Response({"detail": "success"}, status=201)
示例#3
0
 def __init__(self, user, request=None, rev_prefix=None, format=None):
     if isinstance(user, User) is False:
         raise Exception('Expected User object')
     self.account = user
     self.profile = user.get_profile()
     self.request = request
     self.z = op.Zone(self.account)
     self.rev_prefix = rev_prefix or 'v1_0'
     self.format = format or 'json'
示例#4
0
 def get(self, request, zone_slug=None, reg_slug=None, format=None):
     obj = op.Zone(request.user, request, rev_prefix='v1_0', format=format)
     if zone_slug is None:
         res = obj.listZones(strip_type=True)[2]
         return Response({"results": res}, status=200)
     if reg_slug is None:
         res = obj.zoneEntries_as_dict(zone_slug)
         return Response(res, status=200)
     res = obj.getRecord(zone=zone_slug, recordID=reg_slug)
     return Response(res, status=200)
示例#5
0
 def post(self, request, zone_slug=None, reg_slug=None, format=None):
     obj = op.Zone(request.user, request, rev_prefix='v1_0', format=format)
     if request.DATA:
         data = request.DATA
     else:
         raise ValueError("No post data received")
     if zone_slug is None:
         obj.createZone(data)
     else:
         obj.updateRecords(zone_slug, data)
     return Response({"detail": "success"}, status=201)
示例#6
0
 def delete(self, request, zone_slug=None, reg_slug=None, format=None):
     # reg_slug e userul
     obj = op.Zone(request.user, request, rev_prefix='v1_0', format=format)
     if reg_slug:
         obj.unshare(zone_slug, reg_slug)
     usrs = []
     if 'ids' in request.GET:
         usrs.extend(str(request.GET['ids']).split(','))
     if 'users' in request.GET:
         usrs.extend(str(request.GET['users']).split(','))
     obj.unshare(zone_slug, usrs)
     return Response({}, status=204)
示例#7
0
 def put(self, request, zone_slug, reg_slug=None, format=None):
     obj = op.Zone(request.user, request, rev_prefix='v1_0', format=format)
     if request.DATA:
         data = request.DATA
     else:
         raise ValueError("No post data received")
     if reg_slug:
         return Response(
             {
                 "detail":
                 "Please refer to %s for instructions on how to update individual records."
                 % s.DEV_HELP_URL
             }, 401)
     obj.updateRecords(zone_slug, data)
     return Response({"detail": "success"}, status=200)
示例#8
0
    def delete(self, request, zone_slug=None, reg_slug=None, format=None):
        obj = op.Zone(request.user, request, rev_prefix='v1_0', format=format)
        if zone_slug is None:
            if 'zones' in request.GET:
                zones_arr = request.GET['zones'].split(',')
                obj.deleteZone(zone=zones_arr)
                return Response({}, status=204)
            else:
                raise ValueError()

        if reg_slug is None:
            if 'ids' in request.GET:
                ids_arr = request.GET['ids'].split(',')
                obj.deleteRecord(recordID=ids_arr, zone=zone_slug)
                return Response({}, status=204)
            obj.deleteZone(zone_slug)
            return Response({}, status=204)
        obj.deleteRecord(recordID=reg_slug, zone=zone_slug)
        return Response({}, status=204)
示例#9
0
 def get(self, request, zone_slug=None, reg_slug=None, format=None):
     obj = op.Zone(request.user, request, rev_prefix='v1_0', format=format)
     shares = obj.list_shares(zone_slug, reg_slug)
     response = Response({"results": shares}, status=200)
     return response