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