1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
(function(){var a=angular.module("llngManager",["ui.tree","ui.bootstrap","llApp","ngCookies"]);a.controller("TreeCtrl",["$scope","$http","$location","$q","$uibModal","$translator","$cookies","$htmlParams",function(r,n,j,k,g,f,h,s){r.links=links;r.menu=s.menu;r.menulinks=menulinks;r.staticPrefix=staticPrefix;r.formPrefix=formPrefix;r.availableLanguages=availableLanguages;r.waiting=true;r.showM=false;r.showT=false;r.form="home";r.currentCfg={};r.confPrefix=confPrefix;r.message={};r.result="";r.helpUrl="start.html#configuration";r.setShowHelp=function(u){if(typeof u==="undefined"){u=!r.showH}r.showH=u;var c=new Date(Date.now());c.setFullYear(c.getFullYear()+1);h.put("showhelp",(u?"true":"false"),{expires:c})};r.showH=(h.get("showhelp")==="false"?false:true);if(typeof r.showH==="undefined"){r.setShowHelp(true)}var t=function(c){var v=c.status;var u=c.statusText;r.waiting=false;if(v==403){r.message={title:"forbidden",message:"",items:[]}}else{if(v==401){console.log("Authentication needed");r.message={title:"authenticationNeeded",message:"__waitOrF5__",items:[]}}else{if(v==400){r.message={title:"badRequest",message:u}}else{if(v>0){r.message={title:"badRequest",message:u}}else{r.message={title:"networkProblem",message:""}}}}}return r.showModal("message.html")};r.showModal=function(u,w){var c=g.open({templateUrl:u,controller:"ModalInstanceCtrl",size:"lg",resolve:{elem:function(){return function(x){return r[x]}},set:function(){return function(y,x){r[y]=x}},init:function(){return w}}});var v=k.defer();c.result.then(function(x){r.message={title:"",message:"",items:[]};v.resolve(x)},function(x){r.message={title:"",message:"",items:[]};v.reject(x)});return c.result};r.menuClick=function(c){if(c.popup){window.open(c.popup)}else{if(!c.action){c.action=c.title}switch(typeof c.action){case"function":c.action(r.currentNode,r);break;case"string":r[c.action]();break;default:console.log(typeof c.action)}}r.showM=false};r.home=function(){r.form="home";r.showM=false};var i=function(u){r.message={title:"",message:"",items:[]};if(u.message&&u.message=="__needConfirmation__"){r.confirmNeeded=true}if(u.message){r.message.message=u.message}if(u.details){for(var c in u.details){if(c!="__changes__"){r.message.items.push({message:c,items:u.details[c]})}}}r.waiting=false;if(u.result==1){j.path("/confs/");r.message.title="successfullySaved"}else{r.message.title="saveReport"}r.showModal("message.html")};r.save=function(){r.showModal("save.html").then(function(){r.waiting=true;r.data.push({id:"cfgLog",title:"cfgLog",data:r.result?r.result:""});n.post(confPrefix+"?cfgNum="+r.currentCfg.cfgNum+(r.forceSave?"&force=1":""),r.data).then(function(c){r.data.pop();i(c.data)},function(c){t(c);r.data.pop()})},function(){console.log("Saving canceled")});r.showM=false};r.saveRawConf=function(c){r.waiting=true;n.post(confPrefix+"/raw",c).then(function(u){i(u.data)},t)};r.restore=function(){r.currentNode=null;r.form="restore"};r.cancel=function(){r.currentNode.data=null;r.getKey(r.currentNode)};var d=1;r._findContainer=function(){return r._findScopeContainer().$modelValue};r._findScopeContainer=function(){var c=r.currentScope;while(!c.$modelValue.type.match(/Container$/)){c=c.$parentNodeScope}return c};r._findScopeByKey=function(c){var u=r.currentScope;while(!(u.$modelValue.title===c)){u=u.$parentNodeScope}return u};r.newGrantRule=function(){var u=r._findContainer();var c=u.nodes.length;var v=c>0?c-1:0;u.nodes.splice(v,0,{id:u.id+"/n"+(d++),title:"New rule",re:"1",comment:"New rule",data:"Message",type:"grant"})};r.newRule=function(){var u=r._findContainer();var c=u.nodes.length;var v=c>0?c-1:0;u.nodes.splice(v,0,{id:u.id+"/n"+(d++),title:"New rule",re:"^/new",comment:"New rule",data:"accept",type:"rule"})};r.newPost=function(){var c=r._findContainer();c.nodes.push({id:c.id+"/n"+(d++),title:"/absolute/path/to/form",data:{},type:"post"})};r.newPostVar=function(){if(typeof r.currentNode.data.vars==="undefined"){r.currentNode.data.vars=[]}r.currentNode.data.vars.push(["var1","$uid"])};r.newAuthChoice=function(){var c=r._findContainer();c.nodes.push({id:c.id+"/n"+(d++),title:"1_Key",data:["Null","Null","Null"],type:"authChoice"});r.execFilters(r._findScopeByKey("authParams"))};r.newHashEntry=function(){var c=r._findContainer();c.nodes.push({id:c.id+"/n"+(d++),title:"new",data:"",type:"keyText"})};r.newCat=function(){var c=r.currentScope;if(c.$modelValue.type=="menuApp"){c=c.$parentNodeScope}c.$modelValue.nodes.push({id:c.$modelValue.id+"/n"+(d++),title:"New category",type:"menuCat",nodes:[]})};r.newApp=function(){var c=r.currentScope;if(c.$modelValue.type=="menuApp"){c=c.$parentNodeScope}c.$modelValue.nodes.push({id:c.$modelValue.id+"/n"+(d++),title:"New application",type:"menuApp",data:{description:"New app description",uri:"https://test.example.com/",logo:"network.png",display:"auto"}})};r.addSamlAttribute=function(){var c=r._findContainer();c.nodes.push({id:c.id+"/n"+(d++),title:"new",type:"samlAttribute",data:[0,"New","",""]})};r.addVhost=function(){var c=r.domain?("."+r.domain.data):".example.com";r.message={title:"virtualHostName",field:"hostname"};r.showModal("prompt.html",c).then(function(){var u=r.result;if(u){var v=r.addTemplateNode(u,"virtualHost");delete v.nodes[0].cnodes;v.nodes[0].nodes=[{id:"virtualHosts/new__"+u+"/locationRules/default",type:"rule",title:"default",comment:"",re:"default",data:"deny"}]}})};r.duplicateVhost=function(){var c=r.domain?("."+r.domain.data):".example.com";r.message={title:"virtualHostName",field:"hostname"};r.showModal("prompt.html",c).then(function(){var u=r.result;return r.duplicateNode(u,"virtualHost",r.currentNode.title)})};r.addSamlIDP=function(){r.newTemplateNode("samlIDPMetaDataNode","samlPartnerName","idp-example")};r.addSamlSP=function(){r.newTemplateNode("samlSPMetaDataNode","samlPartnerName","sp-example")};r.addOidcOp=function(){r.newTemplateNode("oidcOPMetaDataNode","oidcOPName","op-example")};r.addOidcRp=function(){r.newTemplateNode("oidcRPMetaDataNode","oidcRPName","rp-example")};r.newTemplateNode=function(c,v,u){r.message={title:v,field:"name"};r.showModal("prompt.html",u).then(function(){var w=r.result;if(w){r.addTemplateNode(w,c)}})};r.addTemplateNode=function(c,w){var v=r.currentScope;while(v.$modelValue.title!=w+"s"){v=v.$parentNodeScope}var u={id:w+"s/new__"+c,title:c,type:w,nodes:templates(w,"new__"+c)};v.$modelValue.nodes.push(u);v.expand();return u};var q=function(u){var v=k.defer();var c=k.defer();if(u._nodes){p(u);v.resolve()}else{if(u.cnodes){b(u).then(function(){v.resolve()})}else{if(u.nodes||u.data){v.resolve()}else{r.getKey(u).then(function(){v.resolve()})}}}v.promise.then(function(){var w=[];if(u.nodes){u.nodes.forEach(function(x){w.push(q(x))})}k.all(w).then(function(){c.resolve()})});return c.promise};r.duplicateNode=function(c,w,u){var v=r.currentScope;q(r.currentNode).then(function(){while(v.$modelValue.title!=w+"s"){v=v.$parentNodeScope}var x=JSON.parse(JSON.stringify(r.currentNode).replace(new RegExp(u,"g"),"new__"+c));x.id=w+"s/new__"+c;x.title=c;v.$modelValue.nodes.push(x);return x})};r.del=function(c,u){c.splice(u,1)};r.deleteEntry=function(){var c=r.currentScope.$parentNodeScope;r.currentScope.remove();r.displayForm(c)};r.down=function(){var x=r.currentNode.id;var w=r.currentScope.$parentNodeScope.$modelValue;var v=w.nodes.length;for(var u=0;u<w.nodes.length;u++){if(w.nodes[u].id==x){v=u}}if(v<w.nodes.length-1){var c=w.nodes[v];w.nodes[v]=w.nodes[v+1];w.nodes[v+1]=c}};r.up=function(){var x=r.currentNode.id;var w=r.currentScope.$parentNodeScope.$modelValue;var v=-1;for(var u=0;u<w.nodes.length;u++){if(w.nodes[u].id==x){v=u}}if(v>0){var c=w.nodes[v];w.nodes[v]=w.nodes[v-1];w.nodes[v-1]=c}};r.translateTitle=function(c){return f.translateField(c,"title")};r.translateP=f.translateP;r.translate=f.translate;r.inSelect=function(u){for(var c=0;c<r.currentNode.select.length;c++){if(r.currentNode.select[c].k==u){return true}}return false};r.changeRuleTitle=function(c){if(c.comment.length>0){c.title=c.comment}else{c.title=c.re}};r.filters={};r.execFilters=function(u){u=u?u:r;for(var c in r.filters){if(r.filters.hasOwnProperty(c)){filterFunctions[c](u,k,r.filters[c])}}};r.stoggle=function(c){var u=c.$modelValue;p(u);c.toggle()};var p=function(c){["nodes","nodes_cond"].forEach(function(u){if(c["_"+u]){c[u]=[];c["_"+u].forEach(function(v){c[u].push(v)});delete c["_"+u]}});if(c._nodes_filter){if(c.nodes){c.nodes.forEach(function(u){u.onChange=r.execFilters})}r.filters[c._nodes_filter]=c;r.execFilters()}};r.toggle=function(c){c.toggle()};r.download=function(c){var u=c.$modelValue;return b(u)};var b=function(c){var u=k.defer();u.notify("Trying to get datas");r.waiting=true;n.get(confPrefix+r.currentCfg.cfgNum+"/"+c.cnodes).then(function(v){var w=v.data;if(!w){u.reject("Empty response from server")}else{if(w.error){if(w.error.match(/setDefault$/)){if(c["default"]){c.nodes=c["default"].slice(0)}else{c.nodes=[]}delete c.cnodes;u.resolve("Set data to default value")}else{u.reject("Server return an error: "+w.error)}}else{delete c.cnodes;if(!c.type){c.type="keyTextContainer"}c.nodes=[];w.forEach(function(x){if(x.template){x._nodes=templates(x.template,x.title)}c.nodes.push(x)});u.resolve("OK")}}r.waiting=false},function(v){t(v);u.reject("")});return u.promise};r.openCnode=function(c){r.download(c).then(function(){c.toggle()})};var o=function(c){while(!c.$modelValue.help&&c.$parentNodeScope){c=c.$parentNodeScope}r.helpUrl=c.$modelValue.help||"start.html#configuration"};r.displayForm=function(c){var u=c.$modelValue;if(u.cnodes){r.download(c)}if(u._nodes){r.stoggle(c)}r.currentNode=u;r.currentScope=c;var v;if(u.type){v=u.type}else{v="text"}if(u.nodes||u._nodes||u.cnodes){r.form=v!="text"?v:"mini"}else{r.form=v;r.getKey(u)}if(u.type&&u.type=="simpleInputContainer"){u.nodes.forEach(function(w){r.getKey(w)})}r.showT=false;o(c)};r.keyWritable=function(c){var u=c.$modelValue;return u.type&&u.type.match(/^(authChoice|keyText|virtualHost|rule|menuCat|menuApp|samlAttribute)$/)?true:false};r.newRSAKey=function(){r.showModal("password.html").then(function(){r.waiting=true;var u=r.currentNode;var c=r.result;n.post(confPrefix+"/newRSAKey",{password:c}).then(function(v){var w=v.data;u.data[0].data=w["private"];u.data[1].data=c;u.data[2].data=w["public"];r.waiting=false},t)},function(){console.log("New key cancelled")})};r.newRSAKeyNoPassword=function(){r.waiting=true;var c=r.currentNode;n.post(confPrefix+"/newRSAKey",{password:""}).then(function(u){var v=u.data;c.data[0].data=v["private"];c.data[1].data=v["public"];r.waiting=false},t)};r.getKey=function(v){var w=k.defer();if(!v.data){r.waiting=true;if(v.get&&typeof(v.get)=="object"){v.data=[];var u=[];for(var c=0;c<v.get.length;c++){v.data[c]=({title:v.get[c],id:v.get[c]});u.push(r.getKey(v.data[c]))}k.all(u).then(function(){w.resolve(v.data)},function(x){w.reject(e);r.waiting=false})}else{n.get(confPrefix+r.currentCfg.cfgNum+"/"+(v.get?v.get:v.title)).then(function(x){var y=x.data;if((y.value===null||(y.error&&y.error.match(/setDefault$/)))&&v["default"]!==null){v.data=v["default"]}else{v.data=y.value}if(v.type&&v.type.match(/^(int|bool|trool)$/)){v.data=parseInt(v.data)}else{if(v.type&&v.type.match(/^(saml(Service|Assertion)|blackWhiteList)$/)&&!(typeof v.data==="object")){v.data=v.data.split(";")}}r.waiting=false;w.resolve(v.data)},function(x){w.reject(e);t(x)})}}else{w.resolve(v.data)}return w.promise};var l=function(u,c,v){var w=c.match(new RegExp("#/confs/(latest|[0-9]+)"));if(w===null){j.path("/confs/latest")}else{console.log("Trying to get cfg number "+w[1]);r.getCfg(w[1])}};r.$on("$locationChangeSuccess",l);r.getCfg=function(c){if(r.currentCfg.cfgNum!=c){n.get(confPrefix+c).then(function(u){var v=u.data;r.currentCfg=v;var w=new Date(r.currentCfg.cfgDate*1000);r.currentCfg.date=w.toLocaleString();console.log("Metadatas of cfg "+c+" loaded");j.path("/confs/"+c);r.init()},function(u){t(u).then(function(){r.currentCfg.cfgNum=0;r.init()})})}else{r.waiting=false}};r.getLanguage=function(c){r.lang=c;r.form="white";r.init();r.showM=false};r.init=function(){var c;r.waiting=true;r.data=[];r.confirmNeeded=false;r.forceSave=false;k.all([f.init(r.lang),n.get(staticPrefix+"struct.json").then(function(u){c=u.data;console.log("Structure loaded")})]).then(function(){console.log("Starting structure binding");r.data=c;c=null;if(r.currentCfg.cfgNum!=0){setScopeVars(r)}else{r.message={title:"emptyConf",message:"__zeroConfExplanations__"};r.showModal("message.html")}r.form="home";r.waiting=false},t)};var m=j.path().match(new RegExp("^/confs/(latest|[0-9]+)"));if(!m){console.log("Redirecting to /confs/latest");j.path("/confs/latest")}r.replaceContentByUrl=function(u,c){r.waiting=true;n.post(scriptname+"prx",{url:c}).then(function(v){u.data=v.data.content;r.waiting=false},t)};r.replaceContent=function(u,c){u.data=c};r.saveAs=function(v,u,c){saveAs(new Blob([v],{type:u}),c)}}])})(); |