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",function(n,l,h,i,e,d,f){n.links=links;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(p){if(typeof p==="undefined"){p=!n.showH}n.showH=p;var c=new Date(Date.now());c.setFullYear(c.getFullYear()+1);f.put("showhelp",(p?"true":"false"),{expires:c})};n.showH=(f.get("showhelp")==="false"?false:true);if(typeof n.showH==="undefined"){n.setShowHelp(true)}var o=function(c,p){n.waiting=false;if(p==403){n.message={title:"forbidden",message:"",items:[]}}else{if(p==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(p==400){n.message={title:"badRequest",message:(c.error?c.error:c)}}else{if(p>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(p,r){var c=e.open({templateUrl:p,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 r}}});var q=i.defer();c.result.then(function(s){n.message={title:"",message:"",items:[]};q.resolve(s)},function(s){n.message={title:"",message:"",items:[]};q.reject(s)});return c.result};n.setButtons=function(){n.buttons=buttons};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(p){n.message={title:"",message:"",items:[],};if(p.message&&p.message=="__needConfirmation__"){n.confirmNeeded=true}if(p.message){n.message.message=p.message}if(p.details){for(var c in p.details){if(c!="__changes__"){n.message.items.push({message:c,items:p.details[c]})}}}n.waiting=false;if(p.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});l.post(confPrefix+"?cfgNum="+n.currentCfg.cfgNum+(n.forceSave?"&force=1":""),n.data).success(function(c){n.data.pop();g(c)}).error(function(c,p){o(c,p);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(p){g(p)}).error(o)};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 p=n.currentScope;while(!(p.$modelValue.title===c)){p=p.$parentNodeScope}return p};n.newGrantRule=function(){var p=n._findContainer();var c=p.nodes.length;var q=c>0?c-1:0;p.nodes.splice(q,0,{id:p.id+"/n"+(b++),title:"New rule",re:"1",comment:"New rule",data:"Message",type:"grant"})};n.newRule=function(){var p=n._findContainer();var c=p.nodes.length;var q=c>0?c-1:0;p.nodes.splice(q,0,{id:p.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 p=n.result;if(p){var q=n.addTemplateNode(p,"virtualHost");delete q.nodes[0].cnodes;q.nodes[0].nodes=[{id:"virtualHosts/new__"+p+"/locationRules/default",type:"rule",title:"default",comment:"",re:"default",data:"deny"}]}})};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,q,p){n.message={title:q,field:"name"};n.showModal("prompt.html",p).then(function(){var r=n.result;if(r){n.addTemplateNode(r,c)}})};n.addTemplateNode=function(c,r){var q=n.currentScope;while(q.$modelValue.title!=r+"s"){q=q.$parentNodeScope}var p={id:r+"s/new__"+c,title:c,type:r,nodes:templates(r,"new__"+c)};q.$modelValue.nodes.push(p);q.expand();return p};n.del=function(c,p){c.splice(p,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(p){for(var c=0;c<n.currentNode.select.length;c++){if(n.currentNode.select[c].k==p){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(p){p=p?p:n;for(var c in n.filters){if(n.filters.hasOwnProperty(c)){filterFunctions[c](p,i,n.filters[c])}}};n.stoggle=function(c){var p=c.$modelValue;["nodes","nodes_cond"].forEach(function(q){if(p["_"+q]){p[q]=[];p["_"+q].forEach(function(r){p[q].push(r)});delete p["_"+q]}});if(p._nodes_filter){if(p.nodes){p.nodes.forEach(function(q){q.onChange=n.execFilters})}n.filters[p._nodes_filter]=p;n.execFilters()}c.toggle()};n.toggle=function(c){c.toggle()};n.download=function(c){var p=c.$modelValue;var q=i.defer();q.notify("Trying to get datas");n.waiting=true;l.get(confPrefix+n.currentCfg.cfgNum+"/"+p.cnodes).success(function(r){if(!r){q.reject("Empty response from server")}else{if(r.error){if(r.error.match(/setDefault$/)){if(p["default"]){p.nodes=p["default"].slice(0)}else{p.nodes=[]}delete p.cnodes;q.resolve("Set data to default value")}else{q.reject("Server return an error: "+r.error)}}else{delete p.cnodes;if(!p.type){p.type="keyTextContainer"}p.nodes=[];r.forEach(function(s){if(s.template){s._nodes=templates(s.template,s.title)}p.nodes.push(s)});q.resolve("OK")}}n.waiting=false}).error(function(r,s){o(r,s);q.reject("")});return q.promise};n.openCnode=function(c){n.download(c).then(function(){c.toggle()},function(p){if(typeof p=="string"){alert(p)}})};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 p=c.$modelValue;if(p.cnodes){n.download(c)}if(p._nodes){n.stoggle(c)}n.currentNode=p;n.currentScope=c;var q;if(p.type){q=p.type}else{q="text"}if(p.nodes||p._nodes||p.cnodes){n.form=q!="text"?q:"mini"}else{n.form=q;n.getKey(p)}if(p.type&&p.type=="simpleInputContainer"){p.nodes.forEach(function(r){n.getKey(r)})}n.showT=false;m(c)};n.keyWritable=function(c){var p=c.$modelValue;return p.type&&p.type.match(/^(authChoice|keyText|virtualHost|rule|menuCat|menuApp|samlAttribute)$/)?true:false};n.newRSAKey=function(){n.showModal("password.html").then(function(){n.waiting=true;var p=n.currentNode;var c=n.result;l.post(confPrefix+"/newRSAKey",{password:c}).success(function(q){p.data[0].data=q["private"];p.data[1].data=c;p.data[2].data=q["public"];n.waiting=false}).error(o)},function(){console.log("New key cancelled")})};n.newRSAKeyNoPassword=function(){n.waiting=true;var p=n.currentNode;var c=n.result;l.post(confPrefix+"/newRSAKey",{password:""}).success(function(q){p.data[0].data=q["private"];p.data[1].data=q["public"];n.waiting=false}).error(o)};n.getKey=function(q){var r=i.defer();if(!q.data){n.waiting=true;if(q.get&&typeof(q.get)=="object"){q.data=[];var p=[];for(var c=0;c<q.get.length;c++){q.data[c]=({title:q.get[c],id:q.get[c]});p.push(n.getKey(q.data[c]))}i.all(p).then(function(){r.resolve(q.data)},function(s,t){r.reject(t);n.waiting=false})}else{l.get(confPrefix+n.currentCfg.cfgNum+"/"+(q.get?q.get:q.title)).success(function(s){if((s.value===null||(s.error&&s.error.match(/setDefault$/)))&&q["default"]!==null){q.data=q["default"]}else{q.data=s.value}if(q.type&&q.type.match(/^(int|bool|trool)$/)){q.data=parseInt(q.data)}else{if(q.type&&q.type.match(/^(saml(Service|Assertion)|blackWhiteList)$/)&&!(typeof q.data==="object")){q.data=q.data.split(";")}}n.waiting=false;r.resolve(q.data)}).error(function(s,t){r.reject(t);o(s,t)})}}else{r.resolve(q.data)}return r.promise};var j=function(p,c,q){var r=c.match(new RegExp("#/confs/(latest|[0-9]+)"));if(r===null){h.path("/confs/latest")}else{console.log("Trying to get cfg number "+r[1]);n.getCfg(r[1])}};n.$on("$locationChangeSuccess",j);n.getCfg=function(c){if(n.currentCfg.cfgNum!=c){l.get(confPrefix+c).success(function(p){n.currentCfg=p;var q=new Date(n.currentCfg.cfgDate*1000);n.currentCfg.date=q.toLocaleString();console.log("Metadatas of cfg "+c+" loaded");h.path("/confs/"+c);n.init()}).error(function(p,q){o(p,q).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(p){c=p;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},o)};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(p,c){n.waiting=true;l.post(scriptname+"prx",{url:c}).success(function(q){p.data=q.content;n.waiting=false}).error(o)};n.replaceContent=function(p,c){p.data=c};n.saveAs=function(q,p,c){saveAs(new Blob([q],{type:p}),c)}}])})(); |