Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #11797: Impossible to add authorized network for relay #1809

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class EditPolicyServerAllowedNetwork extends DispatchSnippet with Loggable {
// we need to store that out of the form, so that the changes are persisted at redraw
private[this] val allowedNetworksMap = scala.collection.mutable.Map[NodeId, Buffer[VH]]()


def dispatch = {
case "render" =>
policyServers match {
Expand All @@ -97,7 +96,6 @@ class EditPolicyServerAllowedNetwork extends DispatchSnippet with Loggable {
}
}


def errorMessage(htmlId: String, b:EmptyBox) = {
val error = b ?~! "Error when processing allowed network"
logger.debug(error.messageChain, b)
Expand Down Expand Up @@ -184,18 +182,14 @@ class EditPolicyServerAllowedNetwork extends DispatchSnippet with Loggable {
def delete(i:Long) : JsCmd = {
allowedNetworks -= VH(i)
allowedNetworksMap.put(policyServerId, allowedNetworks)
Replace(allowedNetworksFormId, outerXml.applyAgain) & JsRaw("""
initInputAddress();
""")
Replace(allowedNetworksFormId, outerXml.applyAgain)
}

def add() : JsCmd = {
allowedNetworks.append(VH(net = addNetworkField))
addNetworkField = ""
allowedNetworksMap.put(policyServerId, allowedNetworks)
Replace(allowedNetworksFormId, outerXml.applyAgain) & JsRaw("""
initInputAddress();
""")
Replace(allowedNetworksFormId, outerXml.applyAgain)
}

//process the list of networks
Expand All @@ -204,28 +198,30 @@ class EditPolicyServerAllowedNetwork extends DispatchSnippet with Loggable {
case _ =>
"#allowedNetworksForm [id]" #> allowedNetworksFormId andThen
"#policyServerDetails" #> <h3>{"Allowed networks for policy server "}{policyServerName} {s"(Rudder ID: ${policyServerId.value})"}</h3> &
"#allowNetworkFields [id]" #> s"allowNetworkFields${policyServerId.value}" &
"#allowNetworkFields *" #> { (xml:NodeSeq) =>
allowedNetworks.flatMap { case VH(i,net) =>
val id = "network_"+ i

(
".deleteNetwork" #> SHtml.ajaxButton(<span class="glyphicon glyphicon-minus"></span>, () => delete(i)) &
"#errorNetworkField" #> <div id="errorNetworkField"><span class={"lift:Msg?errorClass=bs-text-danger;id=errornetwork_"+i}>[error]</span></div> &
"#errorNetworkField" #> <div><span class={"lift:Msg?errorClass=bs-text-danger;id=errornetwork_"+i}>[error]</span></div> &
".networkField [name]" #> id andThen
".networkField" #> SHtml.text(net, {x =>
allowedNetworks.find { case VH(y,_) => y==i }.foreach{ v => v.net = x }
}, "id" -> id)
)(xml)
}
} &
"#addNetworkButton" #> SHtml.ajaxButton(<span class="glyphicon glyphicon-plus"></span>, add _) &
"#addaNetworkfield" #> SHtml.ajaxText(addNetworkField, addNetworkField = _) &
"#addNetworkButton" #> SHtml.ajaxButton(<span class="glyphicon glyphicon-plus"></span>, add _ , ("id", s"addNetworkButton${policyServerId.value}")) &
"#addaNetworkfield" #> SHtml.ajaxText(addNetworkField, addNetworkField = _, ("id", s"addaNetworkfield${policyServerId.value}")) &
"#submitAllowedNetwork" #> {
SHtml.ajaxSubmit("Save changes", process _,("id","submitAllowedNetwork"), ("class","btn btn-default")) ++ Script(
SHtml.ajaxSubmit("Save changes", process _,("id",s"submitAllowedNetwork${policyServerId.value}"), ("class","btn btn-default")) ++ Script(
OnLoad (
JsRaw("""
$(".networkField").keydown( function(event) {
processKey(event , 'submitAllowedNetwork')
JsRaw(s"""
initInputAddress("${policyServerId.value}")
$$(".networkField").keydown( function(event) {
processKey(event , 'submitAllowedNetwork${policyServerId.value}')
});
""")
)
Expand All @@ -234,7 +230,6 @@ class EditPolicyServerAllowedNetwork extends DispatchSnippet with Loggable {
}
}


///////////// success pop-up ///////////////
private[this] def successPopup : JsCmd = {
JsRaw(""" callPopupWithTimeout(200, "successConfirmationDialog")""")
Expand Down
84 changes: 84 additions & 0 deletions rudder-web/src/main/webapp/javascript/rudder/authorizedNetworks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
*************************************************************************************
* Copyright 2017 Normation SAS
*************************************************************************************
*
* This file is part of Rudder.
*
* Rudder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In accordance with the terms of section 7 (7. Additional Terms.) of
* the GNU General Public License version 3, the copyright holders add
* the following Additional permissions:
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
* Public License version 3, when you create a Related Module, this
* Related Module is not considered as a part of the work and may be
* distributed under the license agreement of your choice.
* A "Related Module" means a set of sources files including their
* documentation that, without modification of the Source Code, enables
* supplementary functions or services in addition to those offered by
* the Software.
*
* Rudder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Rudder. If not, see <http://www.gnu.org/licenses/>.

*
*************************************************************************************
*/

function checkError(input,error,find){
var input = $(input);
var val = input.val();
var warning = find ? input.parent().parent().find(error) : $(error);
if(checkIPaddress(val)){
warning.hide();
input.removeClass('error');
}else{
warning.show();
input.addClass('error');
}
}
function updateBtnStatus(input,btn){
var input = $(input);
var val = input.val();
var btn = $(btn);
var disabled = !checkIPaddress(val);
if(input.hasClass('error') && !disabled){
input.removeClass('error');
}
btn.attr('disabled',disabled);
}
function initInputAddress(relayId){
$('#addaNetworkfield'+relayId).on(
'change'
, function(e) {
checkError(e.currentTarget,'#warningNetworkField'+relayId)
}
).on(
'keyup'
, function(e){
updateBtnStatus(e.currentTarget,'#addNetworkButton'+relayId)
}
);

$('#allowNetworkFields'+relayId+' .networkField').on(
'keyup'
, function(e){
updateBtnStatus(e.currentTarget,'#submitAllowedNetwork'+relayId)
}
).on(
'change'
, function(e){
checkError(e.currentTarget,'#warningNetworkField'+relayId, true)
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,7 @@
}
</style>
<script type="text/javascript" data-lift="with-cached-resource" src="/javascript/rudder/angular/auditMode.js"></script>
<script>
function checkError(input,error,find){
var input = $(input);
var val = input.val();
var warning = find ? input.parent().parent().find(error) : $(error);
if(checkIPaddress(val)){
warning.hide();
input.removeClass('error');
}else{
warning.show();
input.addClass('error');
}
}
function updateBtnStatus(input,btn){
var input = $(input);
var val = input.val();
var btn = $(btn);
var disabled = !checkIPaddress(val);
if(input.hasClass('error') && !disabled){
input.removeClass('error');
}
btn.attr('disabled',disabled);
}
function initInputAddress(){
$('#addaNetworkfield').on('change',function(e){checkError(e.currentTarget,'#warningNetworkField')}).on('keyup',function(e){updateBtnStatus(e.currentTarget,'#addNetworkButton')});
$('#allowNetworkFields .networkField').on('keyup' ,function(e){updateBtnStatus(e.currentTarget,'#submitAllowedNetwork')}).on('change',function(e){checkError(e.currentTarget,'.warningNetworkField', true)});
}
$(document).ready(function(){
initInputAddress();
});
</script>
<script type="text/javascript" data-lift="with-cached-resource" src="/javascript/rudder/authorizedNetworks.js"></script>
</head>
<div class="portlet tw-bs">
<div class="inner-portlet">
Expand Down