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: '/unauthorized', 180 name: 'unauthorized', 181 component: Unauthorized, 182 meta: { 183 title: 'appPageTitle.unauthorized' 184 } 185 } 186 ] 187 }, 188 { 189 path: '/login', 190 component: LoginLayout, 191 children: [ 192 { 193 path: '', 194 name: 'login', 195 component: Login, 196 meta: { 197 title: 'appPageTitle.login' 198 } 199 }, 200 { 201 path: '/change-password', 202 name: 'change-password', 203 component: ChangePassword, 204 meta: { 205 title: 'appPageTitle.changePassword', 206 requiresAuth: true 207 } 208 } 209 ] 210 }, 211 { 212 path: '/console', 213 component: ConsoleLayout, 214 meta: { 215 requiresAuth: true 216 }, 217 children: [ 218 { 219 path: 'serial-over-lan-console', 220 name: 'serial-over-lan-console', 221 component: SerialOverLanConsole, 222 meta: { 223 title: 'appPageTitle.serialOverLan' 224 } 225 }, 226 { 227 path: 'kvm', 228 name: 'kvm-console', 229 component: KvmConsole, 230 meta: { 231 title: 'appPageTitle.kvm' 232 } 233 } 234 ] 235 } 236]; 237 238const router = new VueRouter({ 239 base: process.env.BASE_URL, 240 routes, 241 linkExactActiveClass: 'nav-link--current' 242}); 243 244router.beforeEach((to, from, next) => { 245 if (to.matched.some(record => record.meta.requiresAuth)) { 246 if (store.getters['authentication/isLoggedIn']) { 247 next(); 248 return; 249 } 250 next('/login'); 251 } else { 252 next(); 253 } 254}); 255 256export default router; 257