Exemple #1
0
def detail(request, pkginfo_path):
    '''Return detail for a specific pkginfo'''
    if request.method == 'GET':
        LOGGER.debug("Got read request for %s", pkginfo_path)
        try:
            plist = Plist.read('pkgsinfo', pkginfo_path)
        except FileDoesNotExistError:
            raise Http404("%s does not exist" % pkginfo_path)
        default_items = {
            'display_name': '',
            'description': '',
            'category': '',
            'developer': '',
            'unattended_install': False,
            'unattended_uninstall': False
        }
        for item in default_items:
            if not item in plist:
                plist[item] = default_items[item]
        pkginfo_text = plistlib.writePlistToString(plist)
        installer_item_path = plist.get('installer_item_location', '')
        icon_url = get_icon_url(plist)
        context = {'plist_text': pkginfo_text,
                   'pathname': pkginfo_path,
                   'installer_item_path': installer_item_path,
                   'icon_url': icon_url}
        return render(request, 'pkgsinfo/detail.html', context=context)
    if request.method == 'POST':
        return HttpResponse(
            json.dumps({'result': 'failed',
                        'exception_type': 'MethodNotSupported',
                        'detail': 'POST/PUT/DELETE should use the API'}),
            content_type='application/json', status=404)
Exemple #2
0
def plist_api(request, kind, filepath=None):
    """Basic API calls for working with Munki plist files"""
    if kind not in ["manifests", "pkgsinfo"]:
        return HttpResponse(status=404)

    response_type = "json"
    if request.META.get("HTTP_ACCEPT") == "application/xml":
        response_type = "xml_plist"
    request_type = "json"
    if request.META.get("CONTENT_TYPE") == "application/xml":
        request_type = "xml_plist"

    if request.method == "GET":
        LOGGER.debug("Got API GET request for %s", kind)
        if filepath:
            try:
                response = Plist.read(kind, filepath)
            except FileDoesNotExistError, err:
                return HttpResponse(
                    json.dumps({"result": "failed", "exception_type": str(type(err)), "detail": str(err)}),
                    content_type="application/json",
                    status=404,
                )
            except FileReadError, err:
                return HttpResponse(
                    json.dumps({"result": "failed", "exception_type": str(type(err)), "detail": str(err)}),
                    content_type="application/json",
                    status=403,
                )
            if response_type == "json":
                response = convert_dates_to_strings(response)
Exemple #3
0
def index(request, manifest_path=None):
    '''Returns manifest list or detail'''
    if manifest_path and request.is_ajax():
        # return manifest detail
        if request.method == 'GET':
            LOGGER.debug("Got read request for %s", manifest_path)
            try:
                plist = Plist.read('manifests', manifest_path)
            except (FileDoesNotExistError, FileReadError), err:
                return HttpResponse(json.dumps({
                    'result': 'failed',
                    'exception_type': str(type(err)),
                    'detail': str(err)
                }),
                                    content_type='application/json',
                                    status=404)
            manifest_text = plistlib.writePlistToString(plist)
            context = {'plist_text': manifest_text, 'pathname': manifest_path}
            return render(request, 'manifests/detail.html', context=context)
        if request.method == 'POST':
            return HttpResponse(json.dumps({
                'result':
                'failed',
                'exception_type':
                'MethodNotSupported',
                'detail':
                'POST/PUT/DELETE should use the API'
            }),
                                content_type='application/json',
                                status=404)
Exemple #4
0
def plist_api(request, kind, filepath=None):
    '''Basic API calls for working with Munki plist files'''
    if kind not in ['manifests', 'pkgsinfo', 'catalogs']:
        return HttpResponse(status=404)

    response_type = 'json'
    if request.META.get('HTTP_ACCEPT') == 'application/xml':
        response_type = 'xml_plist'
    request_type = 'json'
    if request.META.get('CONTENT_TYPE') == 'application/xml':
        request_type = 'xml_plist'

    if request.method == 'GET':
        LOGGER.debug("Got API GET request for %s", kind)
        if filepath:
            try:
                response = Plist.read(kind, filepath)
            except FileDoesNotExistError, err:
                return HttpResponse(
                    json.dumps({'result': 'failed',
                                'exception_type': str(type(err)),
                                'detail': str(err)}),
                    content_type='application/json', status=404)
            except FileReadError, err:
                return HttpResponse(
                    json.dumps({'result': 'failed',
                                'exception_type': str(type(err)),
                                'detail': str(err)}),
                    content_type='application/json', status=403)
            if response_type == 'json':
                response = convert_dates_to_strings(response)
Exemple #5
0
def detail(request, pkginfo_path):
    '''Return detail for a specific pkginfo'''
    if request.method == 'GET':
        LOGGER.debug("Got read request for %s", pkginfo_path)
        try:
            plist = Plist.read('pkgsinfo', pkginfo_path)
        except FileDoesNotExistError:
            raise Http404("%s does not exist" % pkginfo_path)
        default_items = {
            'display_name': '',
            'description': '',
            'category': '',
            'developer': '',
            'unattended_install': False,
            'unattended_uninstall': False
        }
        for item in default_items:
            if not item in plist:
                plist[item] = default_items[item]
        pkginfo_text = plistlib.writePlistToString(plist)
        installer_item_path = plist.get('installer_item_location', '')
        icon_url = get_icon_url(plist)
        context = {
            'plist_text': pkginfo_text,
            'pathname': pkginfo_path,
            'installer_item_path': installer_item_path,
            'icon_url': icon_url
        }
        return render(request, 'pkgsinfo/detail.html', context=context)
    if request.method == 'POST':
        return HttpResponse(json.dumps({
            'result':
            'failed',
            'exception_type':
            'MethodNotSupported',
            'detail':
            'POST/PUT/DELETE should use the API'
        }),
                            content_type='application/json',
                            status=404)
Exemple #6
0
def index(request, manifest_path=None):
    '''Returns manifest list or detail'''
    if manifest_path and request.is_ajax():
        # return manifest detail
        if request.method == 'GET':
            LOGGER.debug("Got read request for %s", manifest_path)
            try:
                plist = Plist.read('manifests', manifest_path)
            except (FileDoesNotExistError, FileReadError), err:
                return HttpResponse(
                    json.dumps({'result': 'failed',
                                'exception_type': str(type(err)),
                                'detail': str(err)}),
                    content_type='application/json', status=404)
            manifest_text = plistlib.writePlistToString(plist)
            context = {'plist_text': manifest_text,
                       'pathname': manifest_path}
            return render(request, 'manifests/detail.html', context=context)
        if request.method == 'POST':
            return HttpResponse(
                json.dumps({'result': 'failed',
                            'exception_type': 'MethodNotSupported',
                            'detail': 'POST/PUT/DELETE should use the API'}),
                content_type='application/json', status=404)
Exemple #7
0
     api_fields = filter_terms["api_fields"].split(",")
     del filter_terms["api_fields"]
 else:
     api_fields = None
 item_list = Plist.list(kind)
 response = []
 for item_name in item_list:
     if api_fields == ["filename"] and filter_terms.keys() in ([], ["filename"]):
         # don't read each manifest if all we want is filenames
         plist = {"filename": item_name}
         if "filename" in filter_terms.keys():
             if filter_terms["filename"].lower() not in item_name:
                 continue
         response.append(plist)
     else:
         plist = Plist.read(kind, item_name)
         plist = convert_dates_to_strings(plist)
         plist["filename"] = item_name
         matches_filters = True
         for key, value in filter_terms.items():
             if key not in plist:
                 matches_filters = False
                 continue
             plist_value = normalize_value_for_filtering(plist[key])
             match = next((item for item in plist_value if value.lower() in item.lower()), None)
             if not match:
                 matches_filters = False
                 continue
         if matches_filters:
             if api_fields:
                 # filter to just the requested fields
Exemple #8
0
     del filter_terms['api_fields']
 else:
     api_fields = None
 item_list = Plist.list(kind)
 response = []
 for item_name in item_list:
     if (api_fields == ['filename']
             and filter_terms.keys() in ([], ['filename'])):
         # don't read each manifest if all we want is filenames
         plist = {'filename': item_name}
         if 'filename' in filter_terms.keys():
             if filter_terms['filename'].lower() not in item_name:
                 continue
         response.append(plist)
     else:
         plist = Plist.read(kind, item_name)
         if response_type == 'json':
             plist = convert_dates_to_strings(plist)
         if kind == 'catalogs':
             # catalogs are list objects, not dicts
             plist = {'contents': plist}
         plist['filename'] = item_name
         matches_filters = True
         for key, value in filter_terms.items():
             if key not in plist:
                 matches_filters = False
                 continue
             plist_value = normalize_value_for_filtering(plist[key])
             match = next(
                 (item for item in plist_value
                  if value.lower() in item.lower()), None)