Browse Source

add admin page to show enterprise license status

Dan Cech 7 years ago
parent
commit
a4f90fd10d

+ 14 - 7
pkg/api/index.go

@@ -316,6 +316,19 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
 		}
 
 		if c.IsGrafanaAdmin {
+			children := []*dtos.NavLink{
+				{Text: "Users", Id: "global-users", Url: setting.AppSubUrl + "/admin/users", Icon: "gicon gicon-user"},
+				{Text: "Orgs", Id: "global-orgs", Url: setting.AppSubUrl + "/admin/orgs", Icon: "gicon gicon-org"},
+				{Text: "Settings", Id: "server-settings", Url: setting.AppSubUrl + "/admin/settings", Icon: "gicon gicon-preferences"},
+				{Text: "Stats", Id: "server-stats", Url: setting.AppSubUrl + "/admin/stats", Icon: "fa fa-fw fa-bar-chart"},
+			}
+
+			if setting.IsEnterprise {
+				children = append(children, &dtos.NavLink{Text: "Licensing", Id: "licensing", Url: setting.AppSubUrl + "/admin/licensing", Icon: "fa fa-fw fa-unlock-alt"})
+			}
+
+			children = append(children, &dtos.NavLink{Text: "Style Guide", Id: "styleguide", Url: setting.AppSubUrl + "/styleguide", Icon: "fa fa-fw fa-eyedropper"})
+
 			cfgNode.Children = append(cfgNode.Children, &dtos.NavLink{
 				Text:         "Server Admin",
 				HideFromTabs: true,
@@ -323,13 +336,7 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
 				Id:           "admin",
 				Icon:         "gicon gicon-shield",
 				Url:          setting.AppSubUrl + "/admin/users",
-				Children: []*dtos.NavLink{
-					{Text: "Users", Id: "global-users", Url: setting.AppSubUrl + "/admin/users", Icon: "gicon gicon-user"},
-					{Text: "Orgs", Id: "global-orgs", Url: setting.AppSubUrl + "/admin/orgs", Icon: "gicon gicon-org"},
-					{Text: "Settings", Id: "server-settings", Url: setting.AppSubUrl + "/admin/settings", Icon: "gicon gicon-preferences"},
-					{Text: "Stats", Id: "server-stats", Url: setting.AppSubUrl + "/admin/stats", Icon: "fa fa-fw fa-bar-chart"},
-					{Text: "Style Guide", Id: "styleguide", Url: setting.AppSubUrl + "/styleguide", Icon: "fa fa-fw fa-eyedropper"},
-				},
+				Children:     children,
 			})
 		}
 

+ 19 - 0
public/app/features/admin/index.ts

@@ -4,6 +4,7 @@ import AdminListOrgsCtrl from './AdminListOrgsCtrl';
 import AdminEditOrgCtrl from './AdminEditOrgCtrl';
 import StyleGuideCtrl from './StyleGuideCtrl';
 
+import config from 'app/core/config';
 import coreModule from 'app/core/core_module';
 
 class AdminSettingsCtrl {
@@ -35,3 +36,21 @@ coreModule.controller('AdminEditOrgCtrl', AdminEditOrgCtrl);
 coreModule.controller('AdminSettingsCtrl', AdminSettingsCtrl);
 coreModule.controller('AdminHomeCtrl', AdminHomeCtrl);
 coreModule.controller('StyleGuideCtrl', StyleGuideCtrl);
+
+if (config.buildInfo.isEnterprise) {
+  class AdminLicensingCtrl {
+    navModel: any;
+
+    /** @ngInject */
+    constructor($scope, backendSrv, navModelSrv) {
+      this.navModel = navModelSrv.getNav('cfg', 'admin', 'licensing', 1);
+
+      backendSrv.get('/api/licensing/token').then(token => {
+        token.maxUsers = token.max_users >= 0 ? token.max_users : 'Unlimited';
+        $scope.token = token;
+      });
+    }
+  }
+
+  coreModule.controller('AdminLicensingCtrl', AdminLicensingCtrl);
+}

+ 56 - 0
public/app/features/admin/partials/licensing.html

@@ -0,0 +1,56 @@
+<page-header model="ctrl.navModel"></page-header>
+
+<div class="page-container page-body">
+	<table class="filter-table form-inline">
+		<tbody>
+			<tr>
+				<td colspan="2" class="admin-settings-section">License Details</td>
+			</tr>
+			<tr>
+				<td>License ID</td>
+				<td>{{token.lid}} (<a href="{{token.iss}}/licenses/{{token.lid}}" target="_blank" rel="noopener noreferer">View Details</a>)</td>
+			</tr>
+			<tr>
+				<td>Licensed URL</td>
+				<td><a href="{{token.sub}}" target="_blank" rel="noopener noreferer">{{token.sub}}</a></td>
+			</tr>
+			<tr>
+				<td>Company</td>
+				<td>{{token.company}}</td>
+			</tr>
+			<tr>
+				<td>Products</td>
+				<td>
+					<div ng-repeat="product in token.prod">{{product}}</div>
+				</td>
+			</tr>
+			<tr>
+				<td>Max Users</td>
+				<td>{{token.maxUsers}}</td>
+			</tr>
+			<tr>
+				<td>License Issued</td>
+				<td>{{token.nbf*1000 | date:'medium'}}</td>
+			</tr>
+			<tr>
+				<td>License Expires</td>
+				<td>{{token.lexp*1000 | date:'medium'}}</td>
+			</tr>
+			<tr>
+				<td colspan="2" class="admin-settings-section">Token Details</td>
+			</tr>
+			<tr>
+				<td>Token ID</td>
+				<td>{{token.jti}}</td>
+			</tr>
+			<tr>
+				<td>Token Issued</td>
+				<td>{{token.iat*1000 | date:'medium'}}</td>
+			</tr>
+			<tr>
+				<td>Token Expires</td>
+				<td>{{token.exp*1000 | date:'medium'}}</td>
+			</tr>
+		</tbody>
+	</table>
+</div>

+ 5 - 0
public/app/routes/routes.ts

@@ -225,6 +225,11 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
         component: () => ServerStats,
       },
     })
+    .when('/admin/licensing', {
+      templateUrl: 'public/app/features/admin/partials/licensing.html',
+      controller: 'AdminLicensingCtrl',
+      controllerAs: 'ctrl',
+    })
     // LOGIN / SIGNUP
     .when('/login', {
       templateUrl: 'public/app/partials/login.html',