@carboncollins/mobileconfig
Version:
Create and sign iOS mobileconfig configuration files
234 lines (197 loc) • 10.2 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _uuid = require('uuid');
var _uuid2 = _interopRequireDefault(_uuid);
var _safe = require('../safe.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var requiredValues = ['PayloadType', 'PayloadVersion', 'PayloadIdentifier', 'PayloadUUID'];
/**
* @class MobileConfigProfile
* @description Structured model data for the mobileconfig profile
* @author CarbonCollins <toastyghost@carboncollins.uk>
* @memberof module:@carboncollins/mobileconfig
*/
var MobileConfigProfile = function () {
/**
* @constructor
* @description creates an instance of MobileConfigProfile
* @param {Object|MobileConfigProfile} [options={}] An object of options and structure data
*/
function MobileConfigProfile() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, MobileConfigProfile);
/**
* @member {String} [type=Configuration]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description Can only be `Configuration` currently
*/
this.type = options.type || 'Configuration';
/**
* @member {Number} [version=1]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description The version number of the profile format. This describes the version of the
* configuration profile as a whole, not of the individual payloads within it. This should
* start at 1
*/
this.version = options.version || 1;
/**
* @member {String} [scope=User]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description Determines if the profile should be installed for the system or for the user.
* In many cases, it determines the location of the certificate items, such as keychains.
* Though it is not possible to declare different payload scopes, payloads, like VPN, may
* automaticaly install their items in both scopes if needed. Values can be: `System`
* or `User`.
*/
this.scope = options.scope || 'User';
/**
* @member {module:@carboncollins/mobileconfig.MobileConfigPayload[]} [content=[]]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description An array of payload objects.
*/
this.content = options.content || [];
/**
* @member {String} [description=null]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description A description of the profile, shown on the detail screen for the profile. This
* should be descriptive enough to help the user decide whether to install the profile.
*/
this.description = options.description || null;
/**
* @member {String} [displayName=null]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description A human-readable name for the profile. This value is displayed on the detail
* screen. It does not have to be unique.
*/
this.displayName = options.displayName || null;
/**
* @member {Date} [expirationDate=null]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description A date in which a profile is considered to have expired and can be updated over
* the air. This key is only used if the profile is delivered via over-the-air profile
* delivery
*/
this.expirationDate = options.expirationDate || null;
/**
* @member {String} [identifier=com.example.myprofile]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description A reverse-DNS style identifier (com.example.myprofile, for example) that
* identifies the profile. The string is used to determine whether a new profile should
* replace an existing one or should be added.
*/
this.identifier = options.identifier || 'com.example.myprofile';
/**
* @member {String} [organization=null]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description A human-readable string containing the name of the organisation that provided
* the profile
*/
this.organization = options.organization || null;
/**
* @member {String} [uuid=new UUIDv4()]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description A globaly unique identifier for the profile. The actual content is
* unimportant, but it must be globaly unique. If left blank a new uuid will be generated.
* If in macOS you can use uuidgen to generate reasonable UUIDs.
*/
this.uuid = options.uuid || _uuid2.default.v4();
/**
* @member {Boolean} [removeDisallowed=false]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description Supervised only. If present and set to true, the user cannot delete the profile
* (unless the profile has a removal password and the user provides it)
*/
this.removeDisallowed = options.removeDisallowed || false;
/**
* @member {Date} [removalDate=null]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description The date on which the profile will automaticaly be removed. If
* `durationUntilRemoval` is also defined, whichever field yeilds the earliest date will be
* used.
*/
this.removalDate = options.removalDate || null;
/**
* @member {Number} [durationUntilRemoval=null]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description Number of seconds untill the profile is automaticaly removed. If `removalDate`
* is also defined, whichever field yeilds the earliest date will be used.
*/
this.durationUntilRemoval = options.durationUntilRemoval || null;
/**
* @member {Object} [consentText={}}]
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @description An object consiting of a key in IETF BCP 47 language identifier (e.g. `en`,
* `jp`) and a stirng value consisting of a lisence agreement the user must agree to before
* installing the profile. The system will choose which language to use based on the users
* current lanuage setting. If the language is not found then the default localisation is
* used. If the default is not found then `en` localisation is used. If there is no `en`
* localisation then the first available localisation is used.\n You should provide a default
* value if possible. No warning shall be displayed if the users locale does not match any
* localisation in the consentTest object.
*/
this.consentText = options.consentText || {}; // i18n dictionary files { en: 'some lisence agreement' }
}
/**
* @description generates a plist safe js object with all the required information for generating
* a mobileconfig profile
* @readonly
* @memberof module:@carboncollins/mobileconfig.MobileConfigProfile
* @author CarbonCollins <toastyghost@carboncollins.uk>
* @returns {Object} a plist object encoded into a js object
*/
_createClass(MobileConfigProfile, [{
key: 'addPayload',
/**
* @method module:@carboncollins/mobileconfig.MobileConfigProfile~addPayload
* @description Adds a payload to the profile (allows multiple settings to be added to a profile)
* @param {Payload} any of the various payloads
* @author CarbonCollins <toastyghost@carboncollins.uk>
*/
value: function addPayload() {
var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
// if (payload && payload.ancestors && payload.ancestors.include('MobileConfigPayload')) { // need to verify that it is a payload type
this.content.push(payload);
// }
}
/**
* @method module:@carboncollins/mobileconfig.MobileConfigProfile~clearPayloads
* @description Removes any previously added payloads from the profile
* @author CarbonCollins <toastyghost@carboncollins.uk>
*/
}, {
key: 'clearPayloads',
value: function clearPayloads() {
this.content = [];
}
}, {
key: 'plistSafeObject',
get: function get() {
var plistObj = {
PayloadContent: this.content.slice(0).map(function (content) {
return content.plistSafeObject;
}),
PayloadDescription: (0, _safe.toSafeString)(this.description),
PayloadDisplayName: (0, _safe.toSafeString)(this.displayName),
PayloadExpirationDate: (0, _safe.toSafeDate)(this.expirationDate),
PayloadIdentifier: (0, _safe.toSafeString)(this.identifier),
PayloadOrganization: (0, _safe.toSafeString)(this.organization),
PayloadUUID: (0, _safe.toSafeString)(this.uuid),
PayloadRemoveDisallowed: (0, _safe.toSafeBoolean)(this.removeDisallowed),
PayloadType: (0, _safe.toSafeString)(this.type),
PayloadVersion: (0, _safe.toSafeInteger)(this.version),
PayloadScope: (0, _safe.toSafeString)(this.scope),
RemovalDate: (0, _safe.toSafeDate)(this.removalDate),
DurationUntilRemoval: (0, _safe.toSafeFloat)(this.durationUntilRemoval),
ConsentText: this.consentText
};
(0, _safe.deleteEmptyKeys)(plistObj);
return (0, _safe.hasRequiredValues)(requiredValues, plistObj, 'profile') ? plistObj : null;
}
}]);
return MobileConfigProfile;
}();
exports.default = MobileConfigProfile;