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