Skip to content

Commit

Permalink
IMAPD Configuration on Admin Console
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Tran committed Jan 16, 2018
1 parent 8576189 commit a494afd
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,42 @@ function () {
mods[ZaGlobalConfig.A_zimbraMtaBlockedExtension] = "";
}
}

//Check validation of reverse proxy upstream imap server: host name or IP address format
var invalidValues = [];
var isValidValue = true;
if(ZaItem.hasWritePermission(ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers,tmpObj)) {
if (!AjxUtil.isEmpty(tmpObj.attrs[ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers])) {
var proxies = tmpObj.attrs[ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers];

if(proxies.length == 1 && proxies[0] == "") {
this.runValidationStack(params);
return;
}

for(var i = 0; i < proxies.length; i++) {
if(!ZaServerController.isValidHostName(proxies[i])) {
isValidValue = false;
}
if(!isValidValue) {
try {
var exIPData = ZaIPUtil.isValidIP(proxies[i]);
isValidValue = true;
} catch (ex) {
isValidValue = false;
}
}
if(!isValidValue) {
invalidValues.push(proxies[i]);
}
}
}

if(invalidValues.length > 0) {
throw new AjxException(AjxMessageFormat.format(ZaMsg.ERROR_INVALID_IP_OR_HOSTNAME,invalidValues.join(",")),AjxException.INVALID_PARAM,"ZaServerController.prototype.validateReverseProxyUpstreamImapServers");
}
}

//save the model
if (this._currentObject[ZaModel.currentTab]!= tmpObj[ZaModel.currentTab])
this._currentObject[ZaModel.currentTab] = tmpObj[ZaModel.currentTab];
Expand Down
22 changes: 20 additions & 2 deletions WebRoot/js/zimbraAdmin/globalconfig/model/ZaGlobalConfig.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ ZaGlobalConfig.A2_retentionPoliciesPurge_Selection = "retentionPoliciesPurge_Sel
ZaGlobalConfig.A_zimbraHelpAdminURL = "zimbraHelpAdminURL";
ZaGlobalConfig.A_zimbraHelpDelegatedURL = "zimbraHelpDelegatedURL";

//IMAPD
ZaGlobalConfig.A_zimbraRemoteImapServerEnabled = "zimbraRemoteImapServerEnabled";
ZaGlobalConfig.A_zimbraRemoteImapSSLServerEnabled = "zimbraRemoteImapSSLServerEnabled";
ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers = "zimbraReverseProxyUpstreamImapServers";
ZaGlobalConfig.A_zimbraRemoteImapBindPort = "zimbraRemoteImapBindPort";
ZaGlobalConfig.A_zimbraRemoteImapSSLBindPort = "zimbraRemoteImapSSLBindPort";

ZaGlobalConfig.__configInstance = null;
ZaGlobalConfig.isDirty = true;

Expand Down Expand Up @@ -297,6 +304,11 @@ ZaGlobalConfig.prototype.initFromJS = function(obj) {
if(AjxUtil.isString(this.attrs[ZaGlobalConfig.A_zimbraWebClientLogoutURLAllowedIP])) {
this.attrs[ZaGlobalConfig.A_zimbraWebClientLogoutURLAllowedIP] = [this.attrs[ZaGlobalConfig.A_zimbraWebClientLogoutURLAllowedIP]];
}

if(AjxUtil.isString(this.attrs[ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers])) {
this.attrs[ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers] = [this.attrs[ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers]];
}

// convert available components to hidden fields for xform binding
var components = this.attrs[ZaGlobalConfig.A_zimbraComponentAvailable];
if (components) {
Expand Down Expand Up @@ -635,7 +647,13 @@ ZaGlobalConfig.myXModel = {
{id:ZaGlobalConfig.A2_retentionPoliciesKeep, type:_LIST_},
{id:ZaGlobalConfig.A2_retentionPoliciesPurge, type:_LIST_},
{id:ZaGlobalConfig.A2_retentionPoliciesKeep_Selection, type:_LIST_},
{id:ZaGlobalConfig.A2_retentionPoliciesPurge_Selection, type:_LIST_}

{id:ZaGlobalConfig.A2_retentionPoliciesPurge_Selection, type:_LIST_},

//IMAPD
{ id:ZaGlobalConfig.A_zimbraRemoteImapServerEnabled, ref:"attrs/" + ZaGlobalConfig.A_zimbraRemoteImapServerEnabled, type:_ENUM_, choices:ZaModel.BOOLEAN_CHOICES},
{ id:ZaGlobalConfig.A_zimbraRemoteImapSSLServerEnabled, ref:"attrs/" + ZaGlobalConfig.A_zimbraRemoteImapSSLServerEnabled, type:_ENUM_, choices:ZaModel.BOOLEAN_CHOICES},
{ id:ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers, ref:"attrs/" + ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers, type:_LIST_, listItem:{ type:_STRING_, maxLength: 256} },
{ id:ZaGlobalConfig.A_zimbraRemoteImapBindPort, ref:"attrs/" + ZaGlobalConfig.A_zimbraRemoteImapBindPort, type:_PORT_ },
{ id:ZaGlobalConfig.A_zimbraRemoteImapSSLBindPort, ref:"attrs/" + ZaGlobalConfig.A_zimbraRemoteImapSSLBindPort, type:_PORT_ }
]
}
90 changes: 89 additions & 1 deletion WebRoot/js/zimbraAdmin/globalconfig/view/GlobalConfigXFormView.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ GlobalConfigXFormView.shouldEnableAddAllButton = function() {
return (!AjxUtil.isEmpty(this.getInstanceValue(ZaGlobalConfig.A_zimbraMtaCommonBlockedExtension)));
}

GlobalConfigXFormView.isImapdInstalledInAnyServer = function() {
var isImapdInstalled = false;

var servers = ZaServer.getAll().getArray();
for (var i = 0; i < servers.length; i++) {
var s = servers[i];
if (s.attrs[ZaServer.A_zimbraImapdServiceInstalled]) {
isImapdInstalled = true;
break;
}
}

return isImapdInstalled;
}

GlobalConfigXFormView.removeExt = function() {
var blockedExtArray = this.getInstanceValue(ZaGlobalConfig.A_zimbraMtaBlockedExtension);
var selectedExtArray = this.getInstanceValue(ZaGlobalConfig.A2_blocked_extension_selection);
Expand Down Expand Up @@ -385,6 +400,10 @@ GlobalConfigXFormView.AUTO_PROV_TAB_ATTRS = [ ZaGlobalConfig.A_zimbraAutoProvNot
ZaGlobalConfig.A_zimbraAutoProvNotificationSubject ];
GlobalConfigXFormView.AUTO_PROV_TAB_RIGHTS = [];

GlobalConfigXFormView.IMAPD_TAB_ATTRS = [ ZaGlobalConfig.A_zimbraRemoteImapServerEnabled,
ZaGlobalConfig.A_zimbraRemoteImapSSLServerEnabled, ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers];
GlobalConfigXFormView.IMAPD_TAB_RIGHTS = [];

GlobalConfigXFormView.RETENTION_POLICY_TAB_ATTRS = [];
GlobalConfigXFormView.RETENTION_POLICY_TAB_RIGHTS = [];

Expand Down Expand Up @@ -436,7 +455,7 @@ GlobalConfigXFormView.myXFormModifier = function(xFormObject, entry) {
"auto", null, null, true, true);

xFormObject.tableCssStyle = "width:100%;overflow:auto;";
var _tab1, _tab2, _tab3, _tab4, _tab5, _tab6, _tab7, _tab8, _tab9, _tab10, _tab11;
var _tab1, _tab2, _tab3, _tab4, _tab5, _tab6, _tab7, _tab8, _tab9, _tab10, _tab11, _tab12;

var tabBarChoices = [];
var switchItems = [];
Expand Down Expand Up @@ -1115,6 +1134,75 @@ GlobalConfigXFormView.myXFormModifier = function(xFormObject, entry) {
switchItems.push(case4);
}

if (GlobalConfigXFormView.isImapdInstalledInAnyServer()){
if (ZaTabView.isTAB_ENABLED(entry, GlobalConfigXFormView.IMAPD_TAB_ATTRS, GlobalConfigXFormView.IMAPD_TAB_RIGHTS)) {
_tab12 = ++this.TAB_INDEX;
//this.helpMap[_tab12] = [ location.pathname, ZaUtil.HELP_URL,
// "managing_global_settings/.htm", "?locid=", AjxEnv.DEFAULT_LOCALE ].join("");
tabBarChoices.push({
value : _tab12,
label : ZaMsg.NAD_Tab_IMAPD
});
var case12 = {
type : _ZATABCASE_,
caseKey : _tab12,
paddingStyle : "padding-left:15px;",
width : "98%",
cellpadding : 2,
colSizes : [ "auto" ],
numCols : 1,
id : "global_remote_imap_tab",
items : [{
type : _DWT_ALERT_,
containerCssStyle : "padding-bottom:0px",
style : DwtAlert.WARNING,
iconVisible : true,
content : ZaMsg.Alert_ServerRestart
}, {
type : _ZA_TOP_GROUPER_,
label : ZaMsg.Global_IMAPD_ServiceGrp,
items : [{
ref : ZaGlobalConfig.A_zimbraReverseProxyUpstreamImapServers,
type : _REPEAT_,
label : ZaMsg.Reverse_Proxy_Upstream_Imap,
labelLocation : _LEFT_,
align : _LEFT_,
repeatInstance : "",
showAddButton : true,
showRemoveButton : true,
showAddOnNextRow : true,
addButtonLabel : ZaMsg.Add_zimbraReverseProxyUpstreamImapServers,
removeButtonLabel : ZaMsg.Remove_zimbraReverseProxyUpstreamImapServers,
removeButtonCSSStyle : "margin-left: 50px",
visibilityChecks : [ ZaItem.hasReadPermission ],
items : [ {
ref : ".",
type : _TEXTFIELD_,
label : null,
labelLocation : _NONE_,
width : 200,
toolTipContent : ZaMsg.tt_zimbraReverseProxyUpstreamImapServers,
visibilityChecks : [ ZaItem.hasReadPermission ]
} ]
},{
ref : ZaGlobalConfig.A_zimbraRemoteImapServerEnabled,
type : _CHECKBOX_,
label : ZaMsg.Remote_IMAP_Server,
trueValue : "TRUE",
falseValue : "FALSE"
}, {
ref : ZaGlobalConfig.A_zimbraRemoteImapSSLServerEnabled,
type : _CHECKBOX_,
label : ZaMsg.Remote_IMAP_SSLServer,
trueValue : "TRUE",
falseValue : "FALSE"
}]
}]
};
switchItems.push(case12);
}
}

if (ZaTabView.isTAB_ENABLED(entry, GlobalConfigXFormView.POP_TAB_ATTRS, GlobalConfigXFormView.POP_TAB_RIGHTS)) {
_tab5 = ++this.TAB_INDEX;
this.helpMap[_tab5] = [ location.pathname, ZaUtil.HELP_URL, "managing_global_settings/configuring_pop.htm",
Expand Down
170 changes: 168 additions & 2 deletions WebRoot/js/zimbraAdmin/servers/controller/ZaServerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,46 @@ function () {
ZaServerController.prototype._saveChanges =
function () {
var obj = this._view.getObject();
if (this._currentObject[ZaModel.currentTab]!= obj[ZaModel.currentTab])
this._currentObject[ZaModel.currentTab] = obj[ZaModel.currentTab];
if (this._currentObject[ZaModel.currentTab]!= obj[ZaModel.currentTab]) {
this._currentObject[ZaModel.currentTab] = obj[ZaModel.currentTab];
}

//Check validation of reverse proxy upstream imap server: host name or IP address format
var invalidValues = [];
var isValidValue = true;

if (ZaItem.hasWritePermission(ZaServer.A_zimbraReverseProxyUpstreamImapServers,obj)) {
if (!AjxUtil.isEmpty(obj.attrs[ZaServer.A_zimbraReverseProxyUpstreamImapServers])) {
var proxies = obj.attrs[ZaServer.A_zimbraReverseProxyUpstreamImapServers];

if (proxies.length == 1 && proxies[0] == "") {
this.runValidationStack(params);
return;
}

for (var i = 0; i < proxies.length; i++) {
if (!ZaServerController.isValidHostName(proxies[i])) {
isValidValue = false;
}
if (!isValidValue) {
try {
var exIPData = ZaIPUtil.isValidIP(proxies[i]);
isValidValue = true;
} catch (ex) {
isValidValue = false;
}
}
if (!isValidValue) {
invalidValues.push(proxies[i]);
}
}
}

if (invalidValues.length > 0) {
throw new AjxException(AjxMessageFormat.format(ZaMsg.ERROR_INVALID_IP_OR_HOSTNAME,invalidValues.join(",")),AjxException.INVALID_PARAM,"ZaServerController.prototype.validateReverseProxyUpstreamImapServers");
}
}

this._currentObject.modify(obj);
this._view.setDirty(false);
ZaApp.getInstance().getAppCtxt().getAppController().setActionStatusMsg(AjxMessageFormat.format(ZaMsg.ServerModified,[this._currentObject.name]));
Expand Down Expand Up @@ -464,6 +502,61 @@ function (params) {
}
ZaXFormViewController.preSaveValidationMethods["ZaServerController"].push(ZaServerController.prototype.validateImapSSLBindPort);

ZaServerController.prototype.validateRemoteImapBindPort =
function (params) {
if(!ZaItem.hasWritePermission(ZaServer.A_zimbraRemoteImapBindPort,this._currentObject)) {
this.runValidationStack(params);
return;
}
var obj = this._view.getObject();
var tmpObj = {selectedChoice:0, choice1Label:"",choice2Label:"",choice3Label:"",warningMsg:"",fieldRef:""};

if( (obj.attrs[ZaServer.A_zimbraMailProxyServiceEnabled] != this._currentObject.attrs[ZaServer.A_zimbraMailProxyServiceEnabled] && obj.attrs[ZaServer.A_zimbraMailProxyServiceEnabled] == true)
) {
if ((obj.attrs[ZaServer.A_zimbraRemoteImapBindPort] != ZaServer.DEFAULT_REMOTE_IMAP_PORT_ZCS && (obj.attrs[ZaServer.A_zimbraRemoteImapBindPort] != null)) || (obj.attrs[ZaServer.A_zimbraRemoteImapBindPort] == null && (obj._defaultValues.attrs[ZaServer.A_zimbraRemoteImapBindPort] != ZaServer.DEFAULT_REMOTE_IMAP_PORT_ZCS))) {
tmpObj.defVal = ZaServer.DEFAULT_REMOTE_IMAP_PORT_ZCS;
tmpObj.warningMsg = AjxMessageFormat.format(ZaMsg.Server_WrongPortWarning,[ZaMsg.IMAP_Port,obj.attrs[ZaServer.A_zimbraRemoteImapBindPort]]);
tmpObj.choice1Label = AjxMessageFormat.format(ZaMsg.Server_WrongPortWarning_OP1,[ZaMsg.IMAP_Port,ZaServer.DEFAULT_REMOTE_IMAP_PORT_ZCS]);
tmpObj.choice2Label = AjxMessageFormat.format(ZaMsg.Server_WrongPortWarning_OP2,[ZaMsg.IMAP_Port,obj.attrs[ZaServer.A_zimbraRemoteImapBindPort]]);
tmpObj.choice3Label = ZaMsg.Server_WrongPortWarning_OP3;
tmpObj.fieldRef = ZaServer.A_zimbraRemoteImapBindPort;
ZaServerController.showPortWarning.call(this, params,tmpObj);
} else {
this.runValidationStack(params);
return;
}
} else {
this.runValidationStack(params);
return;
}
}
ZaXFormViewController.preSaveValidationMethods["ZaServerController"].push(ZaServerController.prototype.validateRemoteImapBindPort);

ZaServerController.prototype.validateRemoteImapSSLBindPort =
function (params) {
var obj = this._view.getObject();
var tmpObj = {selectedChoice:0, choice1Label:"",choice2Label:"",choice3Label:"",warningMsg:"",fieldRef:""};

if( (obj.attrs[ZaServer.A_zimbraMailProxyServiceEnabled] != this._currentObject.attrs[ZaServer.A_zimbraMailProxyServiceEnabled] && obj.attrs[ZaServer.A_zimbraMailProxyServiceEnabled] == true)) {
if ((obj.attrs[ZaServer.A_zimbraRemoteImapSSLBindPort] != ZaServer.DEFAULT_REMOTE_IMAP_SSL_PORT_ZCS && (obj.attrs[ZaServer.A_zimbraRemoteImapSSLBindPort] != null)) || (obj.attrs[ZaServer.A_zimbraRemoteImapSSLBindPort] == null && (obj._defaultValues.attrs[ZaServer.A_zimbraRemoteImapSSLBindPort] != ZaServer.DEFAULT_REMOTE_IMAP_SSL_PORT_ZCS))) {
tmpObj.defVal = ZaServer.DEFAULT_REMOTE_IMAP_SSL_PORT_ZCS;
tmpObj.warningMsg = AjxMessageFormat.format(ZaMsg.Server_WrongPortWarning,[ZaMsg.IMAP_Port,obj.attrs[ZaServer.A_zimbraRemoteImapSSLBindPort]]);
tmpObj.choice1Label = AjxMessageFormat.format(ZaMsg.Server_WrongPortWarning_OP1,[ZaMsg.IMAP_SSLPort,ZaServer.DEFAULT_REMOTE_IMAP_SSL_PORT_ZCS]);
tmpObj.choice2Label = AjxMessageFormat.format(ZaMsg.Server_WrongPortWarning_OP2,[ZaMsg.IMAP_SSLPort,obj.attrs[ZaServer.A_zimbraRemoteImapSSLBindPort]]);
tmpObj.choice3Label = ZaMsg.Server_WrongPortWarning_OP3;
tmpObj.fieldRef = ZaServer.A_zimbraRemoteImapSSLBindPort;
ZaServerController.showPortWarning.call(this, params,tmpObj);
} else {
this.runValidationStack(params);
return;
}
} else {
this.runValidationStack(params);
return;
}
}
ZaXFormViewController.preSaveValidationMethods["ZaServerController"].push(ZaServerController.prototype.validateRemoteImapSSLBindPort);

ZaServerController.prototype.validatePop3BindPort =
function (params) {
if(!ZaItem.hasWritePermission(ZaServer.A_zimbraPop3BindPort,this._currentObject)) {
Expand Down Expand Up @@ -681,6 +774,79 @@ function (params) {
}
ZaXFormViewController.preSaveValidationMethods["ZaServerController"].push(ZaServerController.prototype.validatePop3SSLProxyBindPort);

ZaServerController.prototype.validateReverseProxyUpstreamImapServers =
function (params) {
if(!ZaItem.hasWritePermission(ZaServer.A_zimbraReverseProxyUpstreamImapServers,this._currentObject)) {
this.runValidationStack(params);
return;
}
var obj = this._view.getObject();
var invalidValues = [];
var isValidValue = true;

if(obj.attrs[ZaServer.A_zimbraReverseProxyUpstreamImapServers]) {
var proxies = obj.attrs[ZaServer.A_zimbraReverseProxyUpstreamImapServers];

if (proxies.length == 1 && proxies[0] == "") {
this.runValidationStack(params);
return;
}

for(var i = 0; i < proxies.length; i++) {
if(!ZaServerController.isValidHostName(proxies[i])) {
isValidValue = false;
}
if(!isValidValue) {
try {
var exIPData = ZaIPUtil.isValidIP(proxies[i]);
isValidValue = true;
} catch (ex) {
isValidValue = false;
}
}
if(!isValidValue) {
invalidValues.push(proxies[i]);
}
}
}

if(invalidValues.length > 0) {
throw new AjxException(AjxMessageFormat.format(ZaMsg.ERROR_INVALID_IP_OR_HOSTNAME,invalidValues.join(",")),AjxException.INVALID_PARAM,"ZaServerController.prototype.validateReverseProxyUpstreamImapServers");
} else {
this.runValidationStack(params);
}
}
ZaXFormViewController.preSaveValidationMethods["ZaServerController"].push(ZaServerController.prototype.validateReverseProxyUpstreamImapServers);

ZaServerController.isValidHostName = function (isHostNameStr) {
if (!isHostNameStr) {
return false;
}

//Check isHostNameStr has '.' at index 0 (First dot in host name)
if (isHostNameStr[0] == ".") {
return false;
}

//Check isHostNameStr has '.' at the end of host name (Last dot in host name)
if (isHostNameStr[isHostNameStr.length -1] == ".") {
return false;
}

//Invalid host name that has two or more adjacent dot
for(var i = 0; i < isHostNameStr.length - 1; i++) {
if (isHostNameStr[i] == "." && isHostNameStr[i+1] == ".") {
return false;
}
}

if(AjxUtil.isHostName(isHostNameStr)) {
return true;
}

return false;
}


ZaServerController.showPortWarning = function (params, instanceObj) {
if(ZaApp.getInstance().dialogs["confirmMessageDialog"])
Expand Down
Loading

0 comments on commit a494afd

Please sign in to comment.