diff --git a/webadmin/dist/js/index.js b/webadmin/dist/js/index.js index a09a84004..d085df667 100644 --- a/webadmin/dist/js/index.js +++ b/webadmin/dist/js/index.js @@ -1,2 +1,2 @@ -"use strict";var app=angular.module("Application",["ngRoute","ngAnimate","angular-md5"]);app.config(["$routeProvider",function(e){e.when("/",{redirectTo:"/apps"}).when("/dashboard",{controller:"DashboardController",templateUrl:"views/dashboard.html"}).when("/usercreate",{controller:"UserCreateController",templateUrl:"views/usercreate.html"}).when("/userpassword",{controller:"UserPasswordController",templateUrl:"views/userpassword.html"}).when("/userlist",{controller:"UserListController",templateUrl:"views/userlist.html"}).when("/appstore",{controller:"AppStoreController",templateUrl:"views/appstore.html"}).when("/apps",{controller:"AppListController",templateUrl:"views/applist.html"}).when("/app/:appStoreId/install",{controller:"AppInstallController",templateUrl:"views/appinstall.html"}).when("/app/:appId/configure",{controller:"AppConfigureController",templateUrl:"views/appconfigure.html"}).when("/app/:appId/details",{controller:"AppDetailsController",templateUrl:"views/appdetails.html"}).when("/settings",{controller:"SettingsController",templateUrl:"views/settings.html"}).when("/account",{controller:"AccountController",templateUrl:"views/account.html"}).when("/graphs",{controller:"GraphsController",templateUrl:"views/graphs.html"}).when("/security",{controller:"SecurityController",templateUrl:"views/security.html"}).otherwise({redirectTo:"/"})}]),app.filter("installationActive",function(){return function(e){return"error"===e?!1:"installed"===e?!1:!0}}),app.filter("installationStateLabel",function(){return function(e){return"error"===e?"Error":"subdomain_error"===e?"Error":"installed"===e?"Installed":"downloading_image"===e?"Downloading":"pending_install"===e?"Installing":"pending_uninstall"===e?"Uninstalling":"creating_container"===e?"Container":"downloading_manifest"===e?"Manifest":"creating_volume"===e?"Volume":"registering_subdomain"===e?"Subdomain":"allocated_oauth_credentials"===e?"OAuth":e}}),app.filter("accessRestrictionLabel",function(){return function(e){return""===e?"public":"roleUser"===e?"private":"roleAdmin"===e?"private (Admins only)":e}}),app.directive("laterName",function(){return{restrict:"A",require:["?ngModel","^?form"],link:function(e,t,n,o){n.$set("name",n.laterName);var r=o[0],i=o[1];r&&i&&(r.$name=n.name,i.$addControl(r),e.$on("$destroy",function(){i.$removeControl(r)}))}}}),angular.module("Application").service("Client",["$http","md5",function(e,t){function n(e,t){Error.call(this),this.name=this.constructor.name,this.statusCode=e,this.message="string"==typeof t?t:JSON.stringify(t)}function o(e){return function(t,o){return 401===o?i.logout():void e(new n(o,t))}}function r(){this._ready=!1,this._configListener=[],this._readyListener=[],this._userInfo={username:null,email:null,admin:!1},this._token=null,this._clientId="cid-webadmin",this._clientSecret="unused",this._config={apiServerOrigin:null,webServerOrigin:null,fqdn:null,ip:null,revision:null,update:null,isDev:!1,progress:{}},this._installedApps=[],this.setToken(localStorage.token)}var i=null;return r.prototype.setReady=function(){this._ready||(this._ready=!0,this._readyListener.forEach(function(e){e()}))},r.prototype.onReady=function(e){this._ready&&e(),this._readyListener.push(e)},r.prototype.onConfig=function(e){this._configListener.push(e),e(this._config)},r.prototype.setUserInfo=function(e){this._userInfo.username=e.username,this._userInfo.email=e.email,this._userInfo.admin=!!e.admin,this._userInfo.gravatar="https://www.gravatar.com/avatar/"+t.createHash(e.email.toLowerCase())+".jpg?s=24&d=mm"},r.prototype.setConfig=function(e){this._config.apiServerOrigin=e.apiServerOrigin,this._config.webServerOrigin=e.webServerOrigin,this._config.version=e.version,this._config.fqdn=e.fqdn,this._config.ip=e.ip,this._config.revision=e.revision,this._config.update=e.update,this._config.isDev=e.isDev,this._config.progress=e.progress;var t=this;this._configListener.forEach(function(e){e(t._config)})},r.prototype.getInstalledApps=function(){return this._installedApps},r.prototype.getUserInfo=function(){return this._userInfo},r.prototype.getConfig=function(){return this._config},r.prototype.setToken=function(t){e.defaults.headers.common.Authorization="Bearer "+t,t?localStorage.token=t:localStorage.removeItem("token"),this._token=t},r.prototype.config=function(t){e.get("/api/v1/cloudron/config").success(function(e,o){return 200!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e)}).error(o(t))},r.prototype.userInfo=function(t){e.get("/api/v1/profile").success(function(e,o){return 200!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e)}).error(o(t))},r.prototype.installApp=function(t,r,i,a,s,l){var p=this,c={appStoreId:t,version:r,password:i,location:s.location,portBindings:s.portBindings,accessRestriction:s.accessRestriction};e.post("/api/v1/apps/install",c).success(function(e,t){return 202!==t||"object"!=typeof e?l(new n(t,e)):(e.manifest={title:a},p._installedApps.push(e),void l(null,e.id))}).error(o(l))},r.prototype.uninstallApp=function(t,r,i){var a={password:r};e.post("/api/v1/apps/"+t+"/uninstall",a).success(function(e,t){return 202!==t?i(new n(t,e)):void i(null)}).error(o(i))},r.prototype.configureApp=function(t,r,i,a){var s={appId:t,password:r,location:i.location,portBindings:i.portBindings,accessRestriction:i.accessRestriction};e.post("/api/v1/apps/"+t+"/configure",s).success(function(e,t){return 202!==t?a(new n(t,e)):void a(null)}).error(o(a))},r.prototype.updateApp=function(t,r,i,a){e.post("/api/v1/apps/"+t+"/update",{version:r,password:i}).success(function(e,t){return 202!==t?a(new n(t,e)):void a(null)}).error(o(a))},r.prototype.startApp=function(t,r){var i={};e.post("/api/v1/apps/"+t+"/start",i).success(function(e,t){return 202!==t?r(new n(t,e)):void r(null)}).error(o(r))},r.prototype.stopApp=function(t,r){var i={};e.post("/api/v1/apps/"+t+"/stop",i).success(function(e,t){return 202!==t?r(new n(t,e)):void r(null)}).error(o(r))},r.prototype.version=function(t){e.get("/api/v1/cloudron/status").success(function(e,o){return 200!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e)}).error(o(t))},r.prototype.isServerFirstTime=function(t){e.get("/api/v1/cloudron/status").success(function(e,o){return 200!==o||"object"!=typeof e?t(new n(o,e)):void t(null,!e.activated)}).error(o(t))},r.prototype.getNakedDomain=function(t){e.get("/api/v1/settings/naked_domain").success(function(e,o){return 200!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e.appid)}).error(o(t))},r.prototype.setNakedDomain=function(t,r){e.post("/api/v1/settings/naked_domain",{appid:t}).success(function(e,t){return 204!==t?r(new n(t)):void r(null)}).error(o(r))},r.prototype.getApps=function(t){e.get("/api/v1/apps").success(function(e,o){return 200!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e.apps)}).error(o(t))},r.prototype.getApp=function(e,t){var n=null;return this._installedApps.some(function(t){return t.id===e?(n=t,!0):!1}),n?t(null,n):t(new Error("App not found"))},r.prototype.getAppLogStream=function(e){var t=new EventSource("/api/v1/apps/"+e+"/logstream");return t},r.prototype.getAppLogUrl=function(e){return"/api/v1/apps/"+e+"/logs?access_token="+this._token},r.prototype.setAdmin=function(t,r,i){var a={username:t,admin:r};e.post("/api/v1/users/"+t+"/admin",a).success(function(e,t){return 204!==t?i(new n(t,e)):void i(null)}).error(o(i))},r.prototype.createAdmin=function(t,r,i,a,s){var l={username:t,password:r,email:i},p=this;e.post("/api/v1/cloudron/activate?setupToken="+a,l).success(function(e,o){return 201!==o||"object"!=typeof e?s(new n(o,e)):(p.setToken(e.token),p.setUserInfo({username:t,email:i,admin:!0}),void s(null,e.activated))}).error(o(s))},r.prototype.listUsers=function(t){e.get("/api/v1/users").success(function(e,o){return 200!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e)}).error(o(t))},r.prototype.getOAuthClients=function(t){e.get("/api/v1/oauth/clients").success(function(e,o){return 200!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e.clients)}).error(o(t))},r.prototype.delTokensByClientId=function(t,r){e["delete"]("/api/v1/oauth/clients/"+t+"/tokens").success(function(e,t){return 204!==t?r(new n(t,e)):void r(null)}).error(o(r))},r.prototype.update=function(t){e.get("/api/v1/cloudron/update").success(function(e,o){return 202!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e)}).error(o(t))},r.prototype.reboot=function(t){e.get("/api/v1/cloudron/reboot").success(function(e,o){return 202!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e)}).error(o(t))},r.prototype.backup=function(t){e.post("/api/v1/cloudron/backups").success(function(e,o){return 202!==o||"object"!=typeof e?t(new n(o,e)):void t(null,e)}).error(o(t))},r.prototype.setCertificate=function(t,r,i){console.log("will set certificate");var a=new FormData;a.append("certificate",t),a.append("key",r),e.post("/api/v1/cloudron/certificate",a,{headers:{"Content-Type":void 0},transformRequest:angular.identity}).success(function(e,t){return 202!==t?i(new n(t,e)):void i(null)}).error(o(i))},r.prototype.graphs=function(t,r,i){var a={params:{target:t,format:"json",from:r}};e.get("/api/v1/cloudron/graphs",a).success(function(e,t){return 200!==t||"object"!=typeof e?i(new n(t,e)):void i(null,e)}).error(o(i))},r.prototype.createUser=function(t,r,i){var a={username:t,email:r};e.post("/api/v1/users",a).success(function(e,t){return 201!==t||"object"!=typeof e?i(new n(t,e)):void i(null,e)}).error(o(i))},r.prototype.removeUser=function(t,r,i){var a={username:t,password:r};e({method:"DELETE",url:"/api/v1/users/"+t,data:a,headers:{"Content-Type":"application/json"}}).success(function(e,t){return 204!==t?i(new n(t,e)):void i(null)}).error(o(i))},r.prototype.changePassword=function(t,r,i){var a={password:t,newPassword:r};e.post("/api/v1/users/"+this._userInfo.username+"/password",a).success(function(e,t){return 204!==t||"object"!=typeof e?i(new n(t,e)):void i(null,e)}).error(o(i))},r.prototype.refreshConfig=function(e){var t=this;e="function"==typeof e?e:function(){},this.config(function(n,o){return n?e(n):(t.setConfig(o),void e(null))})},r.prototype.refreshInstalledApps=function(e){var t=this;e="function"==typeof e?e:function(){},this.getApps(function(n,o){if(n)return e(n);o.forEach(function(e){for(var n=!1,o=0;o=0;--r)o.some(function(e){return e.id===t._installedApps[r].id})||t._installedApps.splice(r,1);e(null)})},r.prototype.logout=function(){this.setToken(null),this._userInfo={},window.location.href="/api/v1/session/logout"},r.prototype.exchangeCodeForToken=function(t,r){var i={grant_type:"authorization_code",code:t,redirect_uri:window.location.origin,client_id:this._clientId,client_secret:this._clientSecret};e.post("/api/v1/oauth/token?response_type=token&client_id="+this._clientId,i).success(function(e,t){return 200!==t||"object"!=typeof e?r(new n(t,e)):void r(null,e.access_token)}).error(o(r))},i=new r}]),angular.module("Application").service("AppStore",["$http","Client",function(e,t){function n(e,t){Error.call(this),this.name=this.constructor.name,this.statusCode=e,this.message="string"==typeof t?t:JSON.stringify(t)}function o(){this._appsCache={}}return o.prototype.getApps=function(o){if(null===t.getConfig().apiServerOrigin)return o(new n(420,"Enhance Your Calm"));var r=this;e.get(t.getConfig().apiServerOrigin+"/api/v1/appstore/apps",{params:{boxVersion:t.getConfig().version}}).success(function(e,t){return 200!==t?o(new n(t,e)):(e.apps.forEach(function(e){r._appsCache[e.id]||(r._appsCache[e.id]=e)}),o(null,r._appsCache))}).error(function(e,t){return o(new n(t,e))})},o.prototype.getAppById=function(e,t){if(e in this._appsCache)return t(null,this._appsCache[e]);var o=this;this.getApps(function(r){return r?t(r):e in o._appsCache?t(null,o._appsCache[e]):void t(new n(404,"Not found"))})},o.prototype.getManifest=function(o,r){if(null===t.getConfig().apiServerOrigin)return r(new n(420,"Enhance Your Calm"));var i=t.getConfig().apiServerOrigin+"/api/v1/appstore/apps/"+o+"/manifest";console.log("Getting the manifest of ",o,i),e.get(i).success(function(e,t){return 200!==t?r(new n(t,e)):r(null,e)}).error(function(e,t){return r(new n(t,e))})},new o}]),angular.module("Application").controller("MainController",["$scope","$route","$interval","Client",function(e,t,n,o){e.initialized=!1,e.userInfo=o.getUserInfo(),e.config={},e.isActive=function(e){return t.current?0===t.current.$$route.originalPath.indexOf(e):!1},e.logout=function(t){t.stopPropagation(),e.initialized=!1,o.logout()},e.login=function(){var e=window.location.origin+"/login_callback.html",t="root,profile,apps,roleAdmin";window.location.href="/api/v1/oauth/dialog/authorize?response_type=code&client_id="+o._clientId+"&redirect_uri="+e+"&scope="+t},e.setup=function(){window.location.href="/error.html?errorCode=1"},e.error=function(e){console.error(e),window.location.href="/error.html"},o.isServerFirstTime(function(t,r){return t?e.error(t):r?e.setup():void(localStorage.token?o.refreshConfig(function(t){return t&&401===t.statusCode?e.login():t?e.error(t):(o.getConfig().progress.update&&(window.location.href="/update.html"),void o.userInfo(function(t,r){return t?e.error(t):(o.setUserInfo(r),void o.refreshInstalledApps(function(t){if(t)return e.error(t);var r=n(o.refreshInstalledApps.bind(o),2e3),i=n(o.refreshConfig.bind(o),5e3);e.$on("$destroy",function(){n.cancel(r),n.cancel(i)}),o.setReady(),e.config=o.getConfig(),e.initialized=!0}))}))}):e.login())}),o.onConfig(function(e){e.progress.update&&(window.location.href="/update.html")})}]),angular.module("Application").controller("AccountController",["$scope","$location","Client",function(e,t,n){e.user=n.getUserInfo(),e.config=n.getConfig(),e.changePassword=function(){t.path("/userpassword")}}]),angular.module("Application").controller("AppConfigureController",["$scope","$routeParams","$location","Client",function(e,t,n,o){o.getUserInfo().admin||n.path("/"),e.app=null,e.password="",e.location="",e.accessRestriction="",e.disabled=!1,e.error={},e.domain="",e.portBindings={},e.configureApp=function(){e.error.name=null,e.error.password=null;var n={};for(var r in e.portBindings)n[r]=e.portBindings[r].hostPort;o.configureApp(t.appId,e.password,{location:e.location,portBindings:n,accessRestriction:e.accessRestriction},function(n){return n?(403===n.statusCode?(e.error.password="Wrong password provided.",e.password=""):e.error.name="App with the name "+e.app.name+" cannot be configured.",void(e.disabled=!1)):void window.location.replace("#/app/"+t.appId+"/details")})},e.cancel=function(){window.history.back()},o.onReady(function(){e.domain=o.getConfig().fqdn,o.getApp(t.appId,function(t,n){if(e.error=t||{},!t){e.app=n,e.location=n.location,e.portBindings=n.manifest.tcpPorts,e.accessRestriction=n.accessRestriction;for(var o in e.portBindings)e.portBindings[o].hostPort=n.portBindings[o]}})}),document.getElementById("inputLocation").focus()}]),angular.module("Application").controller("AppDetailsController",["$scope","$http","$routeParams","$location","Client",function(e,t,n,o,r){function i(e,t){var n=[];t&&t.datapoints&&(n=t.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var o=new Rickshaw.Graph({element:document.querySelector("#"+e+"CpuChart"),renderer:"area",width:580,height:250,min:0,max:100,series:[{color:"steelblue",data:n||[],name:"cpu"}]});new Rickshaw.Graph.Axis.Time({graph:o}),new Rickshaw.Graph.Axis.Y({graph:o,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"CpuYAxis")}),new Rickshaw.Graph.HoverDetail({graph:o,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n).toFixed(2)+"%
";return r}})}o.render()}function a(e,t){var n=[];t&&t.datapoints&&(n=t.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var o=new Rickshaw.Graph({element:document.querySelector("#"+e+"MemoryChart"),renderer:"area",width:580,height:250,min:0,max:2147483648,series:[{color:"steelblue",data:n||[],name:"memory"}]});new Rickshaw.Graph.Axis.Time({graph:o}),new Rickshaw.Graph.Axis.Y({graph:o,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"MemoryYAxis")}),new Rickshaw.Graph.HoverDetail({graph:o,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n/1048576).toFixed(2)+"MB
";return r}})}o.render()}function s(e,t){var n=[];t&&t.datapoints&&(n=t.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var o=new Rickshaw.Graph({element:document.querySelector("#"+e+"DiskChart"),renderer:"area",width:580,height:250,min:0,max:32212254720,series:[{color:"steelblue",data:n||[],name:"apps"}]});new Rickshaw.Graph.Axis.Time({graph:o}),new Rickshaw.Graph.Axis.Y({graph:o,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"DiskYAxis")}),new Rickshaw.Graph.HoverDetail({graph:o,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n/1048576).toFixed(2)+"MB
";return r}}),new Rickshaw.Graph.Legend({graph:o,element:document.getElementById(e+"DiskLegend")})}o.render()}r.getUserInfo().admin||o.path("/"),e.app={},e.initialized=!1,e.updateAvailable=!1,e.activeTab="day",e.updateVersion=null,e.password="",e.passwordWrong=!1,e.startApp=function(){r.startApp(n.appId,function(e){e&&console.error(e)})},e.stopApp=function(){r.stopApp(n.appId,function(e){e&&console.error(e)})},e.updateApp=function(){e.passwordWrong=!1,r.updateApp(n.appId,e.updateVersion,e.password,function(t){t&&403===t.statusCode?(e.password="",e.passwordWrong=!0,$("#inputPasswordUpdate").focus()):t?console.error(t):($("#updateAppModal").modal("hide"),e.updateAvailable=!1,e.updateVersion=null,e.password="")})},e.uninstallApp=function(){e.passwordWrong=!1,r.uninstallApp(n.appId,e.password,function(t){t&&403===t.statusCode?(e.password="",e.passwordWrong=!0,$("#inputPasswordUninstall").focus()):t?console.error(t):($("#uninstallAppModal").modal("hide"),e.password="",window.location.href="#/")})},e.updateGraphs=function(){var t="nonNegativeDerivative(sumSeries(collectd.localhost.table-"+e.app.id+"-cpu.gauge-user,collectd.localhost.table-"+e.app.id+"-cpu.gauge-system))",n="collectd.localhost.table-"+e.app.id+"-memory.gauge-max_usage_in_bytes",o="collectd.localhost.filecount-"+e.app.id+"-appdata.bytes",l=e.activeTab,p="-24hours";switch(l){case"day":p="-24hours";break;case"month":p="-1month";break;case"year":p="-1year";break;default:console.log("internal errror")}r.graphs([t,n,o],p,function(e,t){return e?console.log(e):(i(l,t[0]),a(l,t[1]),void s(l,t[2]))})},r.onReady(function(){r.getApp(n.appId,function(t,n){if(t)return console.error(t),void(window.location.href="#/");if(e.app=n,e.appLogUrl=r.getAppLogUrl(n.id),r.getConfig().update&&r.getConfig().update.apps)for(var o=r.getConfig().update.apps,i=0;i',r=o+e.name+": "+new Number(n).toFixed(2)+"%
";return r}})}o.render()}function r(e,t,n){var o=[],r=[];t&&t.datapoints&&(o=t.datapoints.map(function(e){return{y:e[0],x:e[1]}})),n&&n.datapoints&&(r=n.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var i=new Rickshaw.Graph({element:document.querySelector("#"+e+"NetworkChart"),renderer:"area",width:580,height:250,series:[{color:"steelblue",data:o,name:"tx"},{color:"green",data:r,name:"rx"}]});new Rickshaw.Graph.Axis.Time({graph:i}),new Rickshaw.Graph.Axis.Y({graph:i,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"NetworkYAxis")}),new Rickshaw.Graph.HoverDetail({graph:i,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n/1024).toFixed(2)+"KB
";return r}})}i.render()}function i(e,t,n){var o=[],r=[];t&&t.datapoints&&(o=t.datapoints.map(function(e){return{y:e[0],x:e[1]}})),n&&n.datapoints&&(r=n.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var i=new Rickshaw.Graph({element:document.querySelector("#"+e+"DiskChart"),renderer:"area",width:580,height:250,min:0,max:32212254720,series:[{color:"steelblue",data:o,name:"apps"},{color:"green",data:r,name:"data"}]});new Rickshaw.Graph.Axis.Time({graph:i}),new Rickshaw.Graph.Axis.Y({graph:i,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"DiskYAxis")}),new Rickshaw.Graph.HoverDetail({graph:i,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n/1073741824).toFixed(2)+"GB
";return r}}),new Rickshaw.Graph.Legend({graph:i,element:document.getElementById(e+"DiskLegend")})}i.render()}n.getUserInfo().admin||t.path("/"),e.activeTab="day";var a="transformNull(scale(divideSeries(sumSeries(collectd.localhost.cpu-0.cpu-system,collectd.localhost.cpu-0.cpu-nice,collectd.localhost.cpu-0.cpu-user),sumSeries(collectd.localhost.cpu-0.cpu-idle,collectd.localhost.cpu-0.cpu-system,collectd.localhost.cpu-0.cpu-nice,collectd.localhost.cpu-0.cpu-user,collectd.localhost.cpu-0.cpu-wait)), 100), 0)",s="transformNull(collectd.localhost.interface-eth0.if_octets.tx, 0)",l="transformNull(collectd.localhost.interface-eth0.if_octets.rx, 0)",p="transformNull(collectd.localhost.df-loop0.df_complex-used, 0)",c="transformNull(collectd.localhost.df-loop1.df_complex-used, 0)";e.updateGraphs=function(){var t=e.activeTab,u="-24hours";switch(t){case"day":u="-24hours";break;case"month":u="-1month";break;case"year":u="-1year";break;default:console.log("internal errror")}n.graphs([a,s,l,p,c],u,function(e,n){return e?console.log(e):(o(t,n[0]),r(t,n[1],n[2]),void i(t,n[3],n[4]))})},n.onReady(e.updateGraphs)}]),angular.module("Application").controller("SecurityController",["$scope","Client",function(e,t){e.activeClients=[],e.tokenInUse=null,e.removeAccessTokens=function(e,n){e._busy=!0,t.delTokensByClientId(e.id,function(t){return t?console.error(t):($(n.target).addClass("disabled"),void(e._busy=!1))})},t.onReady(function(){e.tokenInUse=t._token,t.getOAuthClients(function(t,n){return t?console.error(t):void(e.activeClients=n)})})}]),angular.module("Application").controller("SettingsController",["$scope","$location","Client",function(e,t,n){n.getUserInfo().admin||t.path("/"),e.user=n.getUserInfo(),e.config=n.getConfig(),e.nakedDomainApp=null,e.certificateFile=null,e.certificateFileName="",e.keyFile=null,e.keyFileName="",e.setNakedDomain=function(){var t=e.nakedDomainApp?e.nakedDomainApp.id:"admin";n.setNakedDomain(t,function(e){return e?console.error("Error setting naked domain",e):void 0})},e.backup=function(){$("#backupProgressModal").modal("show"),e.$parent.initialized=!1,n.backup(function(t){function o(){n.version(function(t){return t?window.setTimeout(o,1e3):($("#backupProgressModal").modal("hide"),void(e.$parent.initialized=!0))})}t&&console.error(t),window.setTimeout(o,5e3)})},e.update=function(){$("#updateModal").modal("hide"),e.$parent.initialized=!1,n.update(function(e){e&&console.error(e),window.location.href="/update.html"})},document.getElementById("idCertificate").onchange=function(t){e.$apply(function(){e.certificateFile=t.target.files[0],e.certificateFileName=t.target.files[0].name})},document.getElementById("idKey").onchange=function(t){e.$apply(function(){e.keyFile=t.target.files[0],e.keyFileName=t.target.files[0].name})},e.setCertificate=function(){return console.log("Will set the certificate"),e.certificateFile?e.keyFile?void n.setCertificate(e.certificateFile,e.keyFile,function(e){return e?console.log(e):void window.setTimeout(window.location.reload.bind(window.location,!0),3e3)}):console.log("Key not set"):console.log("Certificate not set")},n.onConfig(function(){e.tokenInUse=n._token,n.getApps(function(t,o){t&&console.error("Error loading app list"),e.apps=o,n.getNakedDomain(function(t,n){if(t)return console.error(t);e.nakedDomainApp=null;for(var o=0;o=0;--r)o.some(function(e){return e.id===t._installedApps[r].id})||t._installedApps.splice(r,1);e(null)})},r.prototype.logout=function(){this.setToken(null),this._userInfo={},window.location.href="/api/v1/session/logout"},r.prototype.exchangeCodeForToken=function(t,r){var i={grant_type:"authorization_code",code:t,redirect_uri:window.location.origin,client_id:this._clientId,client_secret:this._clientSecret};e.post("/api/v1/oauth/token?response_type=token&client_id="+this._clientId,i).success(function(e,t){return 200!==t||"object"!=typeof e?r(new n(t,e)):void r(null,e.access_token)}).error(o(r))},i=new r}]),angular.module("Application").service("AppStore",["$http","Client",function(e,t){function n(e,t){Error.call(this),this.name=this.constructor.name,this.statusCode=e,this.message="string"==typeof t?t:JSON.stringify(t)}function o(){this._appsCache={}}return o.prototype.getApps=function(o){if(null===t.getConfig().apiServerOrigin)return o(new n(420,"Enhance Your Calm"));var r=this;e.get(t.getConfig().apiServerOrigin+"/api/v1/appstore/apps",{params:{boxVersion:t.getConfig().version}}).success(function(e,t){return 200!==t?o(new n(t,e)):(e.apps.forEach(function(e){r._appsCache[e.id]||(r._appsCache[e.id]=e)}),o(null,r._appsCache))}).error(function(e,t){return o(new n(t,e))})},o.prototype.getAppById=function(e,t){if(e in this._appsCache)return t(null,this._appsCache[e]);var o=this;this.getApps(function(r){return r?t(r):e in o._appsCache?t(null,o._appsCache[e]):void t(new n(404,"Not found"))})},o.prototype.getManifest=function(o,r){if(null===t.getConfig().apiServerOrigin)return r(new n(420,"Enhance Your Calm"));var i=t.getConfig().apiServerOrigin+"/api/v1/appstore/apps/"+o+"/manifest";console.log("Getting the manifest of ",o,i),e.get(i).success(function(e,t){return 200!==t?r(new n(t,e)):r(null,e)}).error(function(e,t){return r(new n(t,e))})},new o}]),angular.module("Application").controller("MainController",["$scope","$route","$interval","Client",function(e,t,n,o){e.initialized=!1,e.userInfo=o.getUserInfo(),e.config={},e.isActive=function(e){return t.current?0===t.current.$$route.originalPath.indexOf(e):!1},e.logout=function(t){t.stopPropagation(),e.initialized=!1,o.logout()},e.login=function(){var e=window.location.origin+"/login_callback.html",t="root,profile,apps,roleAdmin";window.location.href="/api/v1/oauth/dialog/authorize?response_type=code&client_id="+o._clientId+"&redirect_uri="+e+"&scope="+t},e.setup=function(){window.location.href="/error.html?errorCode=1"},e.error=function(e){console.error(e),window.location.href="/error.html"},o.isServerFirstTime(function(t,r){return t?e.error(t):r?e.setup():void(localStorage.token?o.refreshConfig(function(t){return t&&401===t.statusCode?e.login():t?e.error(t):(o.getConfig().progress.update&&(window.location.href="/update.html"),void o.userInfo(function(t,r){return t?e.error(t):(o.setUserInfo(r),void o.refreshInstalledApps(function(t){if(t)return e.error(t);var r=n(o.refreshInstalledApps.bind(o),2e3),i=n(o.refreshConfig.bind(o),5e3);e.$on("$destroy",function(){n.cancel(r),n.cancel(i)}),o.setReady(),e.config=o.getConfig(),e.initialized=!0}))}))}):e.login())}),o.onConfig(function(e){e.progress.update&&(window.location.href="/update.html")})}]),angular.module("Application").controller("AccountController",["$scope","$location","Client",function(e,t,n){e.user=n.getUserInfo(),e.config=n.getConfig(),e.changePassword=function(){t.path("/userpassword")}}]),angular.module("Application").controller("AppConfigureController",["$scope","$routeParams","$location","Client",function(e,t,n,o){o.getUserInfo().admin||n.path("/"),e.app=null,e.password="",e.location="",e.accessRestriction="",e.disabled=!1,e.error={},e.domain="",e.portBindings={},e.configureApp=function(){e.error.name=null,e.error.password=null;var n={};for(var r in e.portBindings)n[r]=e.portBindings[r].hostPort;o.configureApp(t.appId,e.password,{location:e.location,portBindings:n,accessRestriction:e.accessRestriction},function(n){return n?(403===n.statusCode?(e.error.password="Wrong password provided.",e.password=""):e.error.name="App with the name "+e.app.name+" cannot be configured.",void(e.disabled=!1)):void window.location.replace("#/app/"+t.appId+"/details")})},e.cancel=function(){window.history.back()},o.onReady(function(){e.domain=o.getConfig().fqdn,o.getApp(t.appId,function(t,n){if(e.error=t||{},!t){e.app=n,e.location=n.location,e.portBindings=n.manifest.tcpPorts,e.accessRestriction=n.accessRestriction;for(var o in e.portBindings)e.portBindings[o].hostPort=n.portBindings[o]}})}),document.getElementById("inputLocation").focus()}]),angular.module("Application").controller("AppDetailsController",["$scope","$http","$routeParams","$location","Client",function(e,t,n,o,r){function i(e,t){var n=[];t&&t.datapoints&&(n=t.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var o=new Rickshaw.Graph({element:document.querySelector("#"+e+"CpuChart"),renderer:"area",width:580,height:250,min:0,max:100,series:[{color:"steelblue",data:n||[],name:"cpu"}]});new Rickshaw.Graph.Axis.Time({graph:o}),new Rickshaw.Graph.Axis.Y({graph:o,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"CpuYAxis")}),new Rickshaw.Graph.HoverDetail({graph:o,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n).toFixed(2)+"%
";return r}})}o.render()}function a(e,t){var n=[];t&&t.datapoints&&(n=t.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var o=new Rickshaw.Graph({element:document.querySelector("#"+e+"MemoryChart"),renderer:"area",width:580,height:250,min:0,max:2147483648,series:[{color:"steelblue",data:n||[],name:"memory"}]});new Rickshaw.Graph.Axis.Time({graph:o}),new Rickshaw.Graph.Axis.Y({graph:o,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"MemoryYAxis")}),new Rickshaw.Graph.HoverDetail({graph:o,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n/1048576).toFixed(2)+"MB
";return r}})}o.render()}function s(e,t){var n=[];t&&t.datapoints&&(n=t.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var o=new Rickshaw.Graph({element:document.querySelector("#"+e+"DiskChart"),renderer:"area",width:580,height:250,min:0,max:32212254720,series:[{color:"steelblue",data:n||[],name:"apps"}]});new Rickshaw.Graph.Axis.Time({graph:o}),new Rickshaw.Graph.Axis.Y({graph:o,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"DiskYAxis")}),new Rickshaw.Graph.HoverDetail({graph:o,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n/1048576).toFixed(2)+"MB
";return r}}),new Rickshaw.Graph.Legend({graph:o,element:document.getElementById(e+"DiskLegend")})}o.render()}r.getUserInfo().admin||o.path("/"),e.app={},e.initialized=!1,e.updateAvailable=!1,e.activeTab="day",e.updateVersion=null,e.password="",e.passwordWrong=!1,e.startApp=function(){r.startApp(n.appId,function(e){e&&console.error(e)})},e.stopApp=function(){r.stopApp(n.appId,function(e){e&&console.error(e)})},e.updateApp=function(){e.passwordWrong=!1,r.updateApp(n.appId,e.updateVersion,e.password,function(t){t&&403===t.statusCode?(e.password="",e.passwordWrong=!0,$("#inputPasswordUpdate").focus()):t?console.error(t):($("#updateAppModal").modal("hide"),e.updateAvailable=!1,e.updateVersion=null,e.password="")})},e.uninstallApp=function(){e.passwordWrong=!1,r.uninstallApp(n.appId,e.password,function(t){t&&403===t.statusCode?(e.password="",e.passwordWrong=!0,$("#inputPasswordUninstall").focus()):t?console.error(t):($("#uninstallAppModal").modal("hide"),e.password="",window.location.href="#/")})},e.updateGraphs=function(){var t="nonNegativeDerivative(sumSeries(collectd.localhost.table-"+e.app.id+"-cpu.gauge-user,collectd.localhost.table-"+e.app.id+"-cpu.gauge-system))",n="collectd.localhost.table-"+e.app.id+"-memory.gauge-max_usage_in_bytes",o="collectd.localhost.filecount-"+e.app.id+"-appdata.bytes",l=e.activeTab,c="-24hours";switch(l){case"day":c="-24hours";break;case"month":c="-1month";break;case"year":c="-1year";break;default:console.log("internal errror")}r.graphs([t,n,o],c,function(e,t){return e?console.log(e):(i(l,t[0]),a(l,t[1]),void s(l,t[2]))})},r.onReady(function(){r.getApp(n.appId,function(t,n){if(t)return console.error(t),void(window.location.href="#/");if(e.app=n,e.appLogUrl=r.getAppLogUrl(n.id),r.getConfig().update&&r.getConfig().update.apps)for(var o=r.getConfig().update.apps,i=0;i',r=o+e.name+": "+new Number(n).toFixed(2)+"%
";return r}})}o.render()}function r(e,t,n){var o=[],r=[];t&&t.datapoints&&(o=t.datapoints.map(function(e){return{y:e[0],x:e[1]}})),n&&n.datapoints&&(r=n.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var i=new Rickshaw.Graph({element:document.querySelector("#"+e+"NetworkChart"),renderer:"area",width:580,height:250,series:[{color:"steelblue",data:o,name:"tx"},{color:"green",data:r,name:"rx"}]});new Rickshaw.Graph.Axis.Time({graph:i}),new Rickshaw.Graph.Axis.Y({graph:i,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"NetworkYAxis")}),new Rickshaw.Graph.HoverDetail({graph:i,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n/1024).toFixed(2)+"KB
";return r}})}i.render()}function i(e,t,n){var o=[],r=[];t&&t.datapoints&&(o=t.datapoints.map(function(e){return{y:e[0],x:e[1]}})),n&&n.datapoints&&(r=n.datapoints.map(function(e){return{y:e[0],x:e[1]}}));{var i=new Rickshaw.Graph({element:document.querySelector("#"+e+"DiskChart"),renderer:"area",width:580,height:250,min:0,max:32212254720,series:[{color:"steelblue",data:o,name:"apps"},{color:"green",data:r,name:"data"}]});new Rickshaw.Graph.Axis.Time({graph:i}),new Rickshaw.Graph.Axis.Y({graph:i,orientation:"left",tickFormat:Rickshaw.Fixtures.Number.formatKMBT,element:document.getElementById(e+"DiskYAxis")}),new Rickshaw.Graph.HoverDetail({graph:i,formatter:function(e,t,n){var o='',r=o+e.name+": "+new Number(n/1073741824).toFixed(2)+"GB
";return r}}),new Rickshaw.Graph.Legend({graph:i,element:document.getElementById(e+"DiskLegend")})}i.render()}n.getUserInfo().admin||t.path("/"),e.activeTab="day";var a="transformNull(scale(divideSeries(sumSeries(collectd.localhost.cpu-0.cpu-system,collectd.localhost.cpu-0.cpu-nice,collectd.localhost.cpu-0.cpu-user),sumSeries(collectd.localhost.cpu-0.cpu-idle,collectd.localhost.cpu-0.cpu-system,collectd.localhost.cpu-0.cpu-nice,collectd.localhost.cpu-0.cpu-user,collectd.localhost.cpu-0.cpu-wait)), 100), 0)",s="transformNull(collectd.localhost.interface-eth0.if_octets.tx, 0)",l="transformNull(collectd.localhost.interface-eth0.if_octets.rx, 0)",c="transformNull(collectd.localhost.df-loop0.df_complex-used, 0)",p="transformNull(collectd.localhost.df-loop1.df_complex-used, 0)";e.updateGraphs=function(){var t=e.activeTab,u="-24hours";switch(t){case"day":u="-24hours";break;case"month":u="-1month";break;case"year":u="-1year";break;default:console.log("internal errror")}n.graphs([a,s,l,c,p],u,function(e,n){return e?console.log(e):(o(t,n[0]),r(t,n[1],n[2]),void i(t,n[3],n[4]))})},n.onReady(e.updateGraphs)}]),angular.module("Application").controller("SecurityController",["$scope","Client",function(e,t){e.activeClients=[],e.tokenInUse=null,e.removeAccessTokens=function(e,n){e._busy=!0,t.delTokensByClientId(e.id,function(t){return t?console.error(t):($(n.target).addClass("disabled"),void(e._busy=!1))})},t.onReady(function(){e.tokenInUse=t._token,t.getOAuthClients(function(t,n){return t?console.error(t):void(e.activeClients=n)})})}]),angular.module("Application").controller("SettingsController",["$scope","$location","Client",function(e,t,n){n.getUserInfo().admin||t.path("/"),e.user=n.getUserInfo(),e.config=n.getConfig(),e.nakedDomainApp=null,e.certificateFile=null,e.certificateFileName="",e.keyFile=null,e.keyFileName="",e.setNakedDomain=function(){var t=e.nakedDomainApp?e.nakedDomainApp.id:"admin";n.setNakedDomain(t,function(e){return e?console.error("Error setting naked domain",e):void 0})},e.backup=function(){$("#backupProgressModal").modal("show"),e.$parent.initialized=!1,n.backup(function(t){function o(){n.version(function(t){return t?window.setTimeout(o,1e3):($("#backupProgressModal").modal("hide"),void(e.$parent.initialized=!0))})}t&&console.error(t),window.setTimeout(o,5e3)})},e.update=function(){$("#updateModal").modal("hide"),e.$parent.initialized=!1,n.update(function(e){e&&console.error(e),window.location.href="/update.html"})},document.getElementById("idCertificate").onchange=function(t){e.$apply(function(){e.certificateFile=t.target.files[0],e.certificateFileName=t.target.files[0].name})},document.getElementById("idKey").onchange=function(t){e.$apply(function(){e.keyFile=t.target.files[0],e.keyFileName=t.target.files[0].name})},e.setCertificate=function(){return console.log("Will set the certificate"),e.certificateFile?e.keyFile?void n.setCertificate(e.certificateFile,e.keyFile,function(e){return e?console.log(e):void window.setTimeout(window.location.reload.bind(window.location,!0),3e3)}):console.log("Key not set"):console.log("Certificate not set")},n.onConfig(function(){e.tokenInUse=n._token,n.getApps(function(t,o){t&&console.error("Error loading app list"),e.apps=o,n.getNakedDomain(function(t,n){if(t)return console.error(t);e.nakedDomainApp=null;for(var o=0;o +

Loading

-
-
-

Error reaching the Store

-
-
- -
-
+
+

No Apps available

-
+
diff --git a/webadmin/src/views/appstore.html b/webadmin/src/views/appstore.html index 3050657ad..9a6eccf46 100644 --- a/webadmin/src/views/appstore.html +++ b/webadmin/src/views/appstore.html @@ -1,22 +1,16 @@ -
+

Loading

-
-
-

Error reaching the Store

-
-
- -
-
+
+

No Apps available

-
+
diff --git a/webadmin/src/views/appstore.js b/webadmin/src/views/appstore.js index 552008400..b2815cb45 100644 --- a/webadmin/src/views/appstore.js +++ b/webadmin/src/views/appstore.js @@ -3,13 +3,7 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$location', '$timeout', 'Client', 'AppStore', function ($scope, $location, $timeout, Client, AppStore) { if (!Client.getUserInfo().admin) $location.path('/'); - $scope.LOADING = 1; - $scope.ERROR = 2; - $scope.LOADED = 3; - - $scope.loadStatus = $scope.LOADING; - $scope.loadError = ''; - + $scope.ready = false; $scope.apps = []; $scope.installApp = function (app) { @@ -26,40 +20,16 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca }; function refresh() { + $scope.ready = false; + AppStore.getApps(function (error, apps) { - if (error && error.statusCode === 420) return $timeout(refresh, 500); if (error) { - $scope.loadStatus = $scope.ERROR; - $scope.loadError = error.message; - return; + console.error(error); + return $timeout(refresh, 1000); } - Client.refreshInstalledApps(function (error) { - if (error) { - $scope.loadStatus = $scope.ERROR; - $scope.loadError = error.message; - return; - } - - for (var app in apps) { - var found = false; - for (var i = 0; i < $scope.apps.length; ++i) { - if (apps[app].id === $scope.apps[i].id) { - found = true; - break; - } - } - - if (!found) $scope.apps.push(apps[app]); - } - - $scope.apps.forEach(function (app, index) { - if (Client._installedApps) app.installed = Client._installedApps.some(function (a) { return a.appStoreId === app.id; }); - if (!apps[app.id]) $scope.apps.splice(index, 1); - }); - - $scope.loadStatus = $scope.LOADED; - }); + $scope.apps = apps; + $scope.ready = true; }); }