Add OpenVPN policy

revert-dabc3590
Charitha Goonetilleke 6 years ago committed by Inosh Perara
parent 0b1deff245
commit 68a0979bce

@ -379,6 +379,8 @@ public class AndroidDeviceUtils {
deviceInfo.getDeviceDetailsMap().put("mac", prop.getValue());
} else if (prop.getName().equalsIgnoreCase("SERIAL")) {
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"];
payload = {
"operation": {
"serverAddress": operationData["serverAddress"],
"serverPort": operationData["serverPort"],
"sharedSecret": operationData["sharedSecret"],
"dnsServer": operationData["dnsServer"]
"type": operationData["type"],
"openvpn_config": operationData["openvpn_config"]
}
};
break;

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

@ -150,6 +150,28 @@ var inputIsValidAgainstRange = function (numberInput, min, 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.
*
@ -389,48 +411,20 @@ var validatePolicyProfile = function () {
}
if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) {
// if WIFI is configured
operation = androidOperationConstants["VPN_OPERATION"];
// initializing continueToCheckNextInputs to true
continueToCheckNextInputs = true;
var serverAddress = $("input#vpn-server-address").val();
if (!serverAddress) {
var openvpnConfig = $("#openvpn-config").val();
if (!openvpnConfig || openvpnConfig === '') {
validationStatus = {
"error": true,
"subErrorMsg": "Server address is required. You cannot proceed.",
"subErrorMsg": "ovpn config required. You cannot proceed.",
"erroneousFeature": operation
};
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
// this means that no error is found
if (continueToCheckNextInputs) {

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

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

@ -90,6 +90,28 @@ var inputIsValidAgainstRange = function (numberInput, min, 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.
*
@ -311,48 +333,20 @@ var validatePolicyProfile = function () {
}
if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) {
// if WIFI is configured
operation = androidOperationConstants["VPN_OPERATION"];
// initializing continueToCheckNextInputs to true
continueToCheckNextInputs = true;
var serverAddress = $("input#vpn-server-address").val();
if (!serverAddress) {
var openvpnConfig = $("input#openvpn-config").val();
if (!openvpnConfig || openvpnConfig === '') {
validationStatus = {
"error": true,
"subErrorMsg": "Server address is required. You cannot proceed.",
"subErrorMsg": "ovpn config file is required. You cannot proceed.",
"erroneousFeature": operation
};
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
// this means that no error is found
if (continueToCheckNextInputs) {

@ -1475,59 +1475,29 @@
</label>
</h2>
<div class="panel-title-description">
Configure the VPN settings on Android devices.
Once this profile is applied, the device owners won't be able to modify the configured settings
on their devices.
Configure the OpenVPN settings on Android devices.
In order to enable this, device needs to have "OpenVPN for Android" application installed.
</div>
</div>
<div id="vpn-body" class="panel-collapse panel-body collapse" role="tabpanel"
aria-labelledby="vpn-body">
<hr/>
Please note that * sign represents required fields of data.
<br>
<br>
<div id="vpn-feature-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div class="wr-input-control">
<label class="wr-input-label" for="vpn-server-address">
VPN Server Address*
<span class="helper" title="Address of the VPN server to be configured.">
<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.">
<label class="wr-input-label" for="ovpn-file">
OpenVPN Server Config*
<span class="helper" title="OpenVPN configurations from ovpn file">
<span class="wr-help-tip glyphicon glyphicon-question-sign"></span>
</span>
</label>
<input id="vpn-dns" type="text" class="form-control operationDataKeys" data-key="dnsServer"
maxlength="100" placeholder="[ Optional field ]"/>
<input id="ovpn-file" type="file" class="form-control operationDataKeys"
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>

Loading…
Cancel
Save