lemonldap-ng/lemonldap-ng-manager/site/htdocs/static/js/manager.min.js
2018-04-28 22:02:07 +02:00

1 line
14 KiB
JavaScript

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