Example #1
0
def process(serial, items):
    """Process receives a list of items, checks if they need updating
    and updates them if necessary"""

    # Sanitize serial
    serial = ''.join([c for c in serial if c.isalnum()])

    # Get prefs
    baseurl = pref('BaseUrl') or \
              munkicommon.pref('SoftwareRepoURL') + '/report/'

    hashurl = baseurl + "index.php?/report/hash_check"
    checkurl = baseurl + "index.php?/report/check_in"

    # Get passphrase
    passphrase = pref('Passphrase')

    # Get hashes for all scripts
    for key, i in items.items():
        if i.get('path'):
            i['hash'] = munkicommon.getmd5hash(i.get('path'))

    # Check dict
    check = {}
    for key, i in items.items():
        if i.get('hash'):
            check[key] = {'hash': i.get('hash')}

    # Send hashes to server
    values = {'serial': serial,\
             'items': serialize(check),\
             'passphrase' : passphrase}
    response = curl(hashurl, values)
    server_data = response.read()

    # Decode response
    try:
        result = unserialize(server_data)
    except:
        display_error('Illegal response from the server: %s' % server_data)
        return -1

    if result.get('error') != '':
        display_error('Server error: %s' % result['error'])
        return -1

    # Retrieve hashes that need updating
    for i in items.keys():
        if i in result:
            display_detail('Need to update %s' % i)
            if items[i].get('path'):
                try:
                    f = open(items[i]['path'], "r")
                    items[i]['data'] = f.read()
                except:
                    display_warning("Can't open %s" % items[i]['path'])

        else:  # delete items that don't have to be uploaded
            del items[i]

    # Send new files with hashes
    if len(items):
        display_detail('Sending items')
        response = curl(checkurl, {'serial': serial,\
             'items': serialize(items),\
             'passphrase': passphrase})
        display_detail(response.read())
    else:
        display_detail('No changes')
Example #2
0
def process(serial, items):
    """Process receives a list of items, checks if they need updating
    and updates them if necessary"""

    # Sanitize serial
    serial = ''.join([c for c in serial if c.isalnum()])

    # Get prefs
    baseurl = pref('BaseUrl') or \
              munkicommon.pref('SoftwareRepoURL') + '/report/'

    hashurl = baseurl + "index.php?/report/hash_check"
    checkurl = baseurl + "index.php?/report/check_in"

    # Get passphrase
    passphrase = pref('Passphrase')

    # Get hashes for all scripts
    for key, i in items.items():
        if i.get('path'):
            i['hash'] = munkicommon.getmd5hash(i.get('path'))

    # Check dict
    check = {}
    for key, i in items.items():
        if i.get('hash'):
            check[key] = {'hash': i.get('hash')}

    # Send hashes to server
    values = {'serial': serial,\
             'items': serialize(check),\
             'passphrase' : passphrase}
    response = curl(hashurl, values)
    server_data = response.read()

    # Decode response
    try:
        result = unserialize(server_data)
    except:
        display_error('Illegal response from the server: %s' % server_data)
        return -1

    if result.get('error') != '':
        display_error('Server error: %s' % result['error'])
        return -1

    # Retrieve hashes that need updating
    for i in items.keys():
        if i in result:
            display_detail('Need to update %s' % i)
            if items[i].get('path'):
                try:
                    f = open(items[i]['path'], "r")
                    items[i]['data'] = f.read()
                except:
                    display_warning("Can't open %s" % items[i]['path'])

        else: # delete items that don't have to be uploaded
            del items[i]

    # Send new files with hashes
    if len(items):
        display_detail('Sending items')
        response = curl(checkurl, {'serial': serial,\
             'items': serialize(items),\
             'passphrase': passphrase})
        display_detail(response.read())
    else:
        display_detail('No changes')
Example #3
0
def getiteminfo(itempath):
    """
    Gets info for filesystem items passed to makecatalog item, to be used for
    the "installs" key.
    Determines if the item is an application, bundle, Info.plist, or a file or
    directory and gets additional metadata for later comparison.
    """
    infodict = {}
    if munkicommon.isApplication(itempath):
        infodict['type'] = 'application'
        infodict['path'] = itempath
        plist = getBundleInfo(itempath)
        for key in ['CFBundleName', 'CFBundleIdentifier',
                    'CFBundleShortVersionString', 'CFBundleVersion']:
            if key in plist:
                infodict[key] = plist[key]
        if 'LSMinimumSystemVersion' in plist:
            infodict['minosversion'] = plist['LSMinimumSystemVersion']
        elif 'SystemVersionCheck:MinimumSystemVersion' in plist:
            infodict['minosversion'] = \
                plist['SystemVersionCheck:MinimumSystemVersion']
        else:
            infodict['minosversion'] = '10.6'

    elif os.path.exists(os.path.join(itempath, 'Contents', 'Info.plist')) or \
         os.path.exists(os.path.join(itempath, 'Resources', 'Info.plist')):
        infodict['type'] = 'bundle'
        infodict['path'] = itempath
        plist = getBundleInfo(itempath)
        for key in ['CFBundleShortVersionString', 'CFBundleVersion']:
            if key in plist:
                infodict[key] = plist[key]

    elif itempath.endswith("Info.plist") or \
         itempath.endswith("version.plist"):
        infodict['type'] = 'plist'
        infodict['path'] = itempath
        try:
            plist = FoundationPlist.readPlist(itempath)
            for key in ['CFBundleShortVersionString', 'CFBundleVersion']:
                if key in plist:
                    infodict[key] = plist[key]
        except FoundationPlist.NSPropertyListSerializationException:
            pass

    # let's help the admin -- if CFBundleShortVersionString is empty
    # or doesn't start with a digit, and CFBundleVersion is there
    # use CFBundleVersion as the version_comparison_key
    if (not infodict.get('CFBundleShortVersionString') or
        infodict['CFBundleShortVersionString'][0]
        not in '0123456789'):
        if infodict.get('CFBundleVersion'):
            infodict['version_comparison_key'] = 'CFBundleVersion'
    elif 'CFBundleShortVersionString' in infodict:
        infodict['version_comparison_key'] = 'CFBundleShortVersionString'

    if not 'CFBundleShortVersionString' in infodict and \
       not 'CFBundleVersion' in infodict:
        infodict['type'] = 'file'
        infodict['path'] = itempath
        if os.path.isfile(itempath):
            infodict['md5checksum'] = munkicommon.getmd5hash(itempath)
    return infodict