lemonldap-ng/lemonldap-ng-manager/site/static/js/manager.min.js
2016-01-20 16:48:05 +00:00

1 line
12 KiB
JavaScript

(function(){var a=angular.module("llngManager",["ui.tree","ui.bootstrap","llApp","ngCookies"]);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","$cookies",function(n,k,g,h,l,d,e){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(c){if(typeof c==="undefined"){c=!n.showH}n.showH=c;e.put("showhelp",(c?"true":"false"))};n.showH=(e.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){console.log("Authentication needed")}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=l.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=h.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 f=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){g.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});k.post(confPrefix+"?cfgNum="+n.currentCfg.cfgNum+(n.forceSave?"&force=1":""),n.data).success(function(c){n.data.pop();f(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;k.post(confPrefix+"/raw",c).success(function(p){f(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:"https://my/form",data:[],type:"post"})};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,h,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=h.defer();q.notify("Trying to get datas");n.waiting=true;k.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){if(!n.showH){return}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:"home"}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;k.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;k.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=h.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]))}h.all(p).then(function(){r.resolve(q.data)},function(s,t){r.reject(t);n.waiting=false})}else{k.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 i=function(p,c,q){var r=c.match(new RegExp("#/confs/(latest|[0-9]+)"));if(r===null){g.path("/confs/latest")}else{console.log("Trying to get cfg number "+r[1]);n.getCfg(r[1])}};n.$on("$locationChangeSuccess",i);n.getCfg=function(c){if(n.currentCfg.cfgNum!=c){k.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");g.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;h.all([d.init(n.lang),k.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 j=g.path().match(new RegExp("^/confs/(latest|[0-9]+)"));if(!j){console.log("Redirecting to /confs/latest");g.path("/confs/latest")}n.replaceContentByUrl=function(p,c){n.waiting=true;k.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.localDownload=function(){var c=new Blob([n.currentNode.data],{type:"text/plain"});window.open(URL.createObjectURL(c))}}])})();