xref: /openbmc/webui-vue/src/router/index.js (revision 75100469)
1import Vue from 'vue';
2import VueRouter from 'vue-router';
3import store from '../store/index';
4import AppLayout from '../layouts/AppLayout.vue';
5import LoginLayout from '@/layouts/LoginLayout';
6import ConsoleLayout from '@/layouts/ConsoleLayout.vue';
7import Overview from '@/views/Overview';
8import ProfileSettings from '@/views/ProfileSettings';
9import EventLogs from '@/views/Health/EventLogs';
10import HardwareStatus from '@/views/Health/HardwareStatus';
11import Sensors from '@/views/Health/Sensors';
12import Ldap from '@/views/AccessControl/Ldap';
13import LocalUserManagement from '@/views/AccessControl/LocalUserManagement';
14import SslCertificates from '@/views/AccessControl/SslCertificates';
15import DateTimeSettings from '@/views/Configuration/DateTimeSettings';
16import Firmware from '@/views/Configuration/Firmware';
17import Kvm from '@/views/Control/Kvm';
18import ManagePowerUsage from '@/views/Control/ManagePowerUsage';
19import NetworkSettings from '@/views/Configuration/NetworkSettings';
20import RebootBmc from '@/views/Control/RebootBmc';
21import ServerLed from '@/views/Control/ServerLed';
22import SerialOverLan from '@/views/Control/SerialOverLan';
23import ServerPowerOperations from '@/views/Control/ServerPowerOperations';
24import Unauthorized from '@/views/Unauthorized';
25import Login from '@/views/Login';
26import ChangePassword from '@/views/ChangePassword';
27import SerialOverLanConsole from '@/views/Control/SerialOverLan/SerialOverLanConsole';
28import KvmConsole from '@/views/Control/Kvm/KvmConsole';
29
30Vue.use(VueRouter);
31
32// Meta title is translated using i18n in App.vue and PageTitle.Vue
33// Example meta: {title: 'appPageTitle.overview'}
34const routes = [
35  {
36    path: '/',
37    meta: {
38      requiresAuth: true
39    },
40    component: AppLayout,
41    children: [
42      {
43        path: '',
44        name: 'overview',
45        component: Overview,
46        meta: {
47          title: 'appPageTitle.overview'
48        }
49      },
50      {
51        path: '/profile-settings',
52        name: 'profile-settings',
53        component: ProfileSettings,
54        meta: {
55          title: 'appPageTitle.profileSettings'
56        }
57      },
58      {
59        path: '/health/event-logs',
60        name: 'event-logs',
61        component: EventLogs,
62        meta: {
63          title: 'appPageTitle.eventLogs'
64        }
65      },
66      {
67        path: '/health/hardware-status',
68        name: 'hardware-status',
69        component: HardwareStatus,
70        meta: {
71          title: 'appPageTitle.hardwareStatus'
72        }
73      },
74      {
75        path: '/health/sensors',
76        name: 'sensors',
77        component: Sensors,
78        meta: {
79          title: 'appPageTitle.sensors'
80        }
81      },
82      {
83        path: '/access-control/ldap',
84        name: 'ldap',
85        component: Ldap,
86        meta: {
87          title: 'appPageTitle.ldap'
88        }
89      },
90      {
91        path: '/access-control/local-user-management',
92        name: 'local-users',
93        component: LocalUserManagement,
94        meta: {
95          title: 'appPageTitle.localUserManagement'
96        }
97      },
98      {
99        path: '/access-control/ssl-certificates',
100        name: 'ssl-certificates',
101        component: SslCertificates,
102        meta: {
103          title: 'appPageTitle.sslCertificates'
104        }
105      },
106      {
107        path: '/configuration/date-time-settings',
108        name: 'date-time-settings',
109        component: DateTimeSettings,
110        meta: {
111          title: 'appPageTitle.dateTimeSettings'
112        }
113      },
114      {
115        path: '/configuration/firmware',
116        name: 'firmware',
117        component: Firmware,
118        meta: {
119          title: 'appPageTitle.firmware'
120        }
121      },
122      {
123        path: '/control/kvm',
124        name: 'kvm',
125        component: Kvm,
126        meta: {
127          title: 'appPageTitle.kvm'
128        }
129      },
130      {
131        path: '/control/manage-power-usage',
132        name: 'manage-power-usage',
133        component: ManagePowerUsage,
134        meta: {
135          title: 'appPageTitle.managePowerUsage'
136        }
137      },
138      {
139        path: '/configuration/network-settings',
140        name: 'network-settings',
141        component: NetworkSettings,
142        meta: {
143          title: 'appPageTitle.networkSettings'
144        }
145      },
146      {
147        path: '/control/reboot-bmc',
148        name: 'reboot-bmc',
149        component: RebootBmc,
150        meta: {
151          title: 'appPageTitle.rebootBmc'
152        }
153      },
154      {
155        path: '/control/server-led',
156        name: 'server-led',
157        component: ServerLed,
158        meta: {
159          title: 'appPageTitle.serverLed'
160        }
161      },
162      {
163        path: '/control/serial-over-lan',
164        name: 'serial-over-lan',
165        component: SerialOverLan,
166        meta: {
167          title: 'appPageTitle.serialOverLan'
168        }
169      },
170      {
171        path: '/control/server-power-operations',
172        name: 'server-power-operations',
173        component: ServerPowerOperations,
174        meta: {
175          title: 'appPageTitle.serverPowerOperations'
176        }
177      },
178      {
179        path: '/control/virtual-media',
180        name: 'virtual-media',
181        component: () => import('@/views/Control/VirtualMedia'),
182        meta: {
183          title: 'appPageTitle.virtualMedia'
184        }
185      },
186      {
187        path: '/unauthorized',
188        name: 'unauthorized',
189        component: Unauthorized,
190        meta: {
191          title: 'appPageTitle.unauthorized'
192        }
193      }
194    ]
195  },
196  {
197    path: '/login',
198    component: LoginLayout,
199    children: [
200      {
201        path: '',
202        name: 'login',
203        component: Login,
204        meta: {
205          title: 'appPageTitle.login'
206        }
207      },
208      {
209        path: '/change-password',
210        name: 'change-password',
211        component: ChangePassword,
212        meta: {
213          title: 'appPageTitle.changePassword',
214          requiresAuth: true
215        }
216      }
217    ]
218  },
219  {
220    path: '/console',
221    component: ConsoleLayout,
222    meta: {
223      requiresAuth: true
224    },
225    children: [
226      {
227        path: 'serial-over-lan-console',
228        name: 'serial-over-lan-console',
229        component: SerialOverLanConsole,
230        meta: {
231          title: 'appPageTitle.serialOverLan'
232        }
233      },
234      {
235        path: 'kvm',
236        name: 'kvm-console',
237        component: KvmConsole,
238        meta: {
239          title: 'appPageTitle.kvm'
240        }
241      }
242    ]
243  }
244];
245
246const router = new VueRouter({
247  base: process.env.BASE_URL,
248  routes,
249  linkExactActiveClass: 'nav-link--current'
250});
251
252router.beforeEach((to, from, next) => {
253  if (to.matched.some(record => record.meta.requiresAuth)) {
254    if (store.getters['authentication/isLoggedIn']) {
255      next();
256      return;
257    }
258    next('/login');
259  } else {
260    next();
261  }
262});
263
264export default router;
265