lemonldap-ng/lemonldap-ng-manager/site/htdocs/static/js/manager.min.js

1 line
16 KiB
JavaScript

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