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