lemonldap-ng/lemonldap-ng-manager/site/static/js/manager.min.js
2016-03-14 22:22:09 +00:00

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