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