Merge branch 'master' into 'master'

Add OpenVPN policy

See merge request entgra/carbon-device-mgt-plugins!17
revert-dabc3590
Inosh Perara 6 years ago
commit 140fd9af71

@ -379,6 +379,8 @@ public class AndroidDeviceUtils {
deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue()); deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue());
} else if (prop.getName().equalsIgnoreCase("SERIAL")) { } else if (prop.getName().equalsIgnoreCase("SERIAL")) {
deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue()); deviceInfo.getDeviceDetailsMap().put("serial", prop.getValue());
} else {
deviceInfo.getDeviceDetailsMap().put(prop.getName(), prop.getValue());
} }
} }

@ -417,10 +417,8 @@ var generatePayload = function (operationCode, operationData, deviceList) {
operationType = operationTypeConstants["PROFILE"]; operationType = operationTypeConstants["PROFILE"];
payload = { payload = {
"operation": { "operation": {
"serverAddress": operationData["serverAddress"], "type": operationData["type"],
"serverPort": operationData["serverPort"], "openvpn_config": operationData["openvpn_config"]
"sharedSecret": operationData["sharedSecret"],
"dnsServer": operationData["dnsServer"]
} }
}; };
break; break;

@ -166,10 +166,8 @@ var androidOperationModule = function () {
break; break;
case androidOperationConstants["VPN_OPERATION_CODE"]: case androidOperationConstants["VPN_OPERATION_CODE"]:
payload = { payload = {
"serverAddress": operationPayload["serverAddress"], "type": operationPayload["type"],
"serverPort": operationPayload["serverPort"], "openvpn_config": operationPayload["openvpn_config"]
"sharedSecret": operationPayload["sharedSecret"],
"dnsServer": operationPayload["dnsServer"]
}; };
break; break;
case androidOperationConstants["APPLICATION_OPERATION_CODE"]: case androidOperationConstants["APPLICATION_OPERATION_CODE"]:
@ -341,10 +339,8 @@ var androidOperationModule = function () {
operationType = operationTypeConstants["PROFILE"]; operationType = operationTypeConstants["PROFILE"];
payload = { payload = {
"operation": { "operation": {
"serverAddress": operationData["serverAddress"], "type": operationData["type"],
"serverPort": operationData["serverPort"], "openvpn_config": operationData["openvpn_config"]
"sharedSecret": operationData["sharedSecret"],
"dnsServer": operationData["dnsServer"]
} }
}; };
break; break;

@ -150,6 +150,28 @@ var inputIsValidAgainstRange = function (numberInput, min, max) {
return (numberInput == min || (numberInput > min && numberInput < max) || numberInput == max); return (numberInput == min || (numberInput > min && numberInput < max) || numberInput == max);
}; };
var ovpnConfigUploaded = function () {
var ovpnFileInput = document.getElementById("ovpn-file");
if ('files' in ovpnFileInput) {
if (ovpnFileInput.files.length === 1) {
var reader = new FileReader();
reader.onload = function(progressEvent){
var txt = "";
var lines = this.result.split('\n');
for(var line = 0; line < lines.length; line++){
console.log(lines[line]);
if (lines[line].charAt(0) !== '#') {
txt += lines[line] + '\n';
}
}
document.getElementById ("openvpn-config").value = txt;
console.log(txt);
};
reader.readAsText(ovpnFileInput.files[0]);
}
}
};
/** /**
* Validates policy profile operations for the windows platform. * Validates policy profile operations for the windows platform.
* *
@ -389,48 +411,20 @@ var validatePolicyProfile = function () {
} }
if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) { if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) {
// if WIFI is configured
operation = androidOperationConstants["VPN_OPERATION"]; operation = androidOperationConstants["VPN_OPERATION"];
// initializing continueToCheckNextInputs to true // initializing continueToCheckNextInputs to true
continueToCheckNextInputs = true; continueToCheckNextInputs = true;
var serverAddress = $("input#vpn-server-address").val(); var openvpnConfig = $("#openvpn-config").val();
if (!serverAddress) { if (!openvpnConfig || openvpnConfig === '') {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Server address is required. You cannot proceed.", "subErrorMsg": "ovpn config required. You cannot proceed.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
} }
if (continueToCheckNextInputs) {
var serverPort = $("input#vpn-server-port").val();
if (!serverPort) {
validationStatus = {
"error": true,
"subErrorMsg": "VPN server port is required. You cannot proceed.",
"erroneousFeature": operation
};
continueToCheckNextInputs = false;
} else if (!$.isNumeric(serverPort)) {
validationStatus = {
"error": true,
"subErrorMsg": "VPN server port requires a number input.",
"erroneousFeature": operation
};
continueToCheckNextInputs = false;
} else if (!inputIsValidAgainstRange(serverPort, 0, 65535)) {
validationStatus = {
"error": true,
"subErrorMsg": "VPN server port is not within the range " +
"of valid port numbers.",
"erroneousFeature": operation
};
continueToCheckNextInputs = false;
}
}
// at-last, if the value of continueToCheckNextInputs is still true // at-last, if the value of continueToCheckNextInputs is still true
// this means that no error is found // this means that no error is found
if (continueToCheckNextInputs) { if (continueToCheckNextInputs) {

@ -1213,59 +1213,37 @@
</label> </label>
</h2> </h2>
<div class="panel-title-description"> <div class="panel-title-description">
This configurations can be used to configure VPN settings on an Android device. Configure the OpenVPN settings on Android devices.
Once this configuration profile is installed on a device, corresponding users will not be able In order to enable this, device needs to have "OpenVPN for Android" application installed.
to modify these settings on their devices.
</div> </div>
</div> </div>
<div id="vpn-body" class="panel-collapse panel-body collapse" role="tabpanel" <div id="vpn-body" class="panel-collapse panel-body collapse" role="tabpanel"
aria-labelledby="vpn-body"> aria-labelledby="vpn-body">
<hr/> <hr/>
Please note that * sign represents required fields of data.
<br>
<br> <br>
<div id="vpn-feature-error-msg" class="alert alert-danger hidden" role="alert"> <div id="vpn-feature-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
</div> </div>
<div class="wr-input-control"> <div class="wr-input-control">
<label class="wr-input-label" for="vpn-server-address"> <label class="wr-input-label" for="ovpn-file">
VPN Server Address* OpenVPN Server Config file
<span class="helper" title="Address of the VPN server to be configured."> <span class="helper" title="OpenVPN configurations ovpn file">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-server-address" type="text" class="form-control operationDataKeys"
data-key="serverAddress" maxlength="200" placeholder="[ Should be a valid hostname ]"/>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-server-port">
VPN Server Port
<span class="helper" title="Port of the VPN server to be configured.">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-server-port" type="text" class="form-control operationDataKeys"
data-key="serverPort" maxlength="100" placeholder="[ Optional field ]"/>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-shared-secret">
Shared Secret
<span class="helper" title="Shared secret.">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span> <span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span> </span>
</label> </label>
<input id="vpn-shared-secret" type="password" class="form-control operationDataKeys" <input id="ovpn-file" type="file" class="form-control operationDataKeys"
data-key="sharedSecret" maxlength="100" placeholder="[ Optional field ]"/> maxlength="200" onchange="ovpnConfigUploaded()"/>
</div> </div>
<div class="wr-input-control"> <div class="wr-input-control">
<label class="wr-input-label" for="vpn-dns"> <label class="wr-input-label" for="openvpn-config">
DNS Server OpenVPN Server Config
<span class="helper" title="DNS Server."> <span class="helper" title="OpenVPN configurations from ovpn file">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span> <span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span> </span>
</label> </label>
<input id="vpn-dns" type="text" class="form-control operationDataKeys" data-key="dnsServer" <textarea id="openvpn-config" class="form-control operationDataKeys"
maxlength="100" placeholder="[ Optional field ]"/> data-key="openvpn_config" style="height: 400px;"></textarea>
<input id="vpn-type" class="form-control operationDataKeys" type="hidden" data-key="type" value="OpenVPN" />
</div> </div>
</div> </div>
</div> </div>

@ -1455,60 +1455,26 @@
</label> </label>
</h2> </h2>
<div class="panel-title-description"> <div class="panel-title-description">
This configurations can be used to configure VPN settings on an Android device. Configure the OpenVPN settings on Android devices.
Once this configuration profile is installed on a device, corresponding users will not be able In order to enable this, device needs to have "OpenVPN for Android" application installed.
to modify these settings on their devices.
</div> </div>
</div> </div>
<div id="vpn-body" class="panel-collapse panel-body collapse" role="tabpanel" <div id="vpn-body" class="panel-collapse panel-body collapse" role="tabpanel"
aria-labelledby="vpn-body"> aria-labelledby="vpn-body">
<hr/> <hr/>
Please note that * sign represents required fields of data.
<br>
<br> <br>
<div id="vpn-feature-error-msg" class="alert alert-danger hidden" role="alert"> <div id="vpn-feature-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
</div> </div>
<div class="wr-input-control"> <div class="wr-input-control">
<label class="wr-input-label" for="vpn-server-address"> <label class="wr-input-label" for="openvpn-config">
VPN Server Address* Open VPN Config
<span class="helper" title="Address of the VPN server to be configured."> <span class="helper" title="OpenVPN configurations from ovpn file">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-server-address" type="text" class="form-control operationDataKeys"
data-key="serverAddress" maxlength="200" placeholder="[ Should be a valid hostname ]"
disabled/>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-server-port">
VPN Server Port
<span class="helper" title="Port of the VPN server to be configured.">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-server-port" type="text" class="form-control operationDataKeys"
data-key="serverPort" maxlength="100" placeholder="[ Optional field ]" disabled/>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-shared-secret">
Shared Secret
<span class="helper" title="Shared secret.">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-shared-secret" type="password" class="form-control operationDataKeys"
data-key="sharedSecret" maxlength="100" placeholder="[ Optional field ]" disabled/>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-dns">
DNS Server
<span class="helper" title="DNS Server.">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span> <span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span> </span>
</label> </label>
<input id="vpn-dns" type="text" class="form-control operationDataKeys" data-key="dnsServer" <textarea id="openvpn-config" class="form-control operationDataKeys"
maxlength="100" placeholder="[ Optional field ]" disabled/> data-key="openvpn_config" style="height: 400px;" disabled></textarea>
</div> </div>
</div> </div>
</div> </div>

@ -90,6 +90,28 @@ var inputIsValidAgainstRange = function (numberInput, min, max) {
return (numberInput == min || (numberInput > min && numberInput < max) || numberInput == max); return (numberInput == min || (numberInput > min && numberInput < max) || numberInput == max);
}; };
var ovpnConfigUploaded = function () {
var ovpnFileInput = document.getElementById("ovpn-file");
if ('files' in ovpnFileInput) {
if (ovpnFileInput.files.length === 1) {
var reader = new FileReader();
reader.onload = function(progressEvent){
var txt = "";
var lines = this.result.split('\n');
for(var line = 0; line < lines.length; line++){
console.log(lines[line]);
if (lines[line].charAt(0) !== '#') {
txt += lines[line] + '\n';
}
}
document.getElementById ("openvpn-config").value = txt;
console.log(txt);
};
reader.readAsText(ovpnFileInput.files[0]);
}
}
};
/** /**
* Validates policy profile operations for the windows platform. * Validates policy profile operations for the windows platform.
* *
@ -311,48 +333,20 @@ var validatePolicyProfile = function () {
} }
if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) { if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) {
// if WIFI is configured
operation = androidOperationConstants["VPN_OPERATION"]; operation = androidOperationConstants["VPN_OPERATION"];
// initializing continueToCheckNextInputs to true // initializing continueToCheckNextInputs to true
continueToCheckNextInputs = true; continueToCheckNextInputs = true;
var serverAddress = $("input#vpn-server-address").val(); var openvpnConfig = $("input#openvpn-config").val();
if (!serverAddress) { if (!openvpnConfig || openvpnConfig === '') {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Server address is required. You cannot proceed.", "subErrorMsg": "ovpn config file is required. You cannot proceed.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
} }
if (continueToCheckNextInputs) {
var serverPort = $("input#vpn-server-port").val();
if (!serverPort) {
validationStatus = {
"error": true,
"subErrorMsg": "VPN server port is required. You cannot proceed.",
"erroneousFeature": operation
};
continueToCheckNextInputs = false;
} else if (!$.isNumeric(serverPort)) {
validationStatus = {
"error": true,
"subErrorMsg": "VPN server port requires a number input.",
"erroneousFeature": operation
};
continueToCheckNextInputs = false;
} else if (!inputIsValidAgainstRange(serverPort, 0, 65535)) {
validationStatus = {
"error": true,
"subErrorMsg": "VPN server port is not within the range " +
"of valid port numbers.",
"erroneousFeature": operation
};
continueToCheckNextInputs = false;
}
}
// at-last, if the value of continueToCheckNextInputs is still true // at-last, if the value of continueToCheckNextInputs is still true
// this means that no error is found // this means that no error is found
if (continueToCheckNextInputs) { if (continueToCheckNextInputs) {

@ -1475,59 +1475,29 @@
</label> </label>
</h2> </h2>
<div class="panel-title-description"> <div class="panel-title-description">
Configure the VPN settings on Android devices. Configure the OpenVPN settings on Android devices.
Once this profile is applied, the device owners won't be able to modify the configured settings In order to enable this, device needs to have "OpenVPN for Android" application installed.
on their devices.
</div> </div>
</div> </div>
<div id="vpn-body" class="panel-collapse panel-body collapse" role="tabpanel" <div id="vpn-body" class="panel-collapse panel-body collapse" role="tabpanel"
aria-labelledby="vpn-body"> aria-labelledby="vpn-body">
<hr/> <hr/>
Please note that * sign represents required fields of data.
<br>
<br> <br>
<div id="vpn-feature-error-msg" class="alert alert-danger hidden" role="alert"> <div id="vpn-feature-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
</div> </div>
<div class="wr-input-control"> <div class="wr-input-control">
<label class="wr-input-label" for="vpn-server-address"> <label class="wr-input-label" for="ovpn-file">
VPN Server Address* OpenVPN Server Config*
<span class="helper" title="Address of the VPN server to be configured."> <span class="helper" title="OpenVPN configurations from ovpn file">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-server-address" type="text" class="form-control operationDataKeys"
data-key="serverAddress" maxlength="200" placeholder="[ Should be a valid hostname ]"/>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-server-port">
VPN Server Port
<span class="helper" title="Port of the VPN server to be configured.">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-server-port" type="text" class="form-control operationDataKeys"
data-key="serverPort" maxlength="100" placeholder="[ Optional field ]"/>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-shared-secret">
Shared Secret
<span class="helper" title="Shared secret.">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-shared-secret" type="password" class="form-control operationDataKeys"
data-key="sharedSecret" maxlength="100" placeholder="[ Optional field ]"/>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-dns">
DNS Server
<span class="helper" title="DNS Server.">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span> <span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span> </span>
</label> </label>
<input id="vpn-dns" type="text" class="form-control operationDataKeys" data-key="dnsServer" <input id="ovpn-file" type="file" class="form-control operationDataKeys"
maxlength="100" placeholder="[ Optional field ]"/> maxlength="200" onchange="ovpnConfigUploaded()"/>
<input id="openvpn-config" class="form-control operationDataKeys" type="hidden" data-key="openvpn_config" />
<input id="vpn-type" class="form-control operationDataKeys" type="hidden" data-key="type" value="OpenVPN" />
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save