Skip to content

Commit

Permalink
feat: add node maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
trenutoo committed Oct 21, 2023
1 parent 483f729 commit 3b2c3db
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/api/models/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class Node extends BaseModel {
public id = -1;
public name = '';
public description = '';
public maintenanceMode = false;
public connection = {
fqdn: '',
display: '',
Expand All @@ -17,7 +18,6 @@ export class Node extends BaseModel {

// Admin only props
public public = false;
public maintenanceMode = false;
public serversCount?: number;
public limits = {
cpu: -1,
Expand Down
2 changes: 1 addition & 1 deletion src/api/services/admin/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface UpdateNodeRequest {
description?: string;
public: boolean;
display_fqdn?: string;
maintenance_node: boolean;
maintenance_mode: boolean;
location_id: number;

cpu: number;
Expand Down
22 changes: 22 additions & 0 deletions src/api/services/client/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,30 @@ interface WebsocketResponse {
interface UpdateDetailsRequest {
server_name: string;
}
interface ServerResponse {
attributes: {
relationships: {
node: {
attributes: {
maintenance_mode: boolean;
};
};
};
};
}


class ServerService {

getNodeMaintenanceMode(): Promise<boolean> {
return RequestService.get('/servers/:server', { include: ['node'] })
.then((response: ServerResponse) => response.attributes.relationships.node.attributes.maintenance_mode)
.catch(error => {
console.error('Error getting node maintenance mode:', error);
throw error;
});
}

getWebsocket(): Promise<WebsocketResponse> {
return RequestService.get('/servers/:server/websocket');
}
Expand Down
5 changes: 5 additions & 0 deletions src/locales/en/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"description": "Couldn't find the page you were looking for."
},

"maintenance": {
"title": "Maintenance",
"description": "The Node hosting this server is currently in Maintenance Mode. Please try again later or contact support for more information."
},

"login": {
"index": {
"title": "Login",
Expand Down
1 change: 1 addition & 0 deletions src/middlewares/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { default as Permission } from './permission';
export { default as Feature } from './feature';
export { default as Require2FA } from './require_2fa';
export { ModelBindings } from './model_bindings';
export { default as MaintenanceMode } from './maintenance_mode';
20 changes: 20 additions & 0 deletions src/middlewares/maintenance_mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { RouteLocationNormalized } from 'vue-router';
import ServerService from '~/api/services/client/server';

class MaintenanceMode implements Middleware {
name() {
return 'maintenance_node';
}

async run(to: RouteLocationNormalized) {
const maintenance = await ServerService.getNodeMaintenanceMode();

if (to.name !== 'MaintenanceView' && maintenance) {
return {
name: 'MaintenanceView',
};
}
}
}

export default new MaintenanceMode();
17 changes: 11 additions & 6 deletions src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RouteRecordRaw } from 'vue-router';
import { Router, state } from '~/core';
import { Admin, Authenticated, Guest, Permission, Feature, Require2FA, ModelBindings, MFAInProgress } from '~/middlewares';
import { Admin, Authenticated, Guest, Permission, Feature, Require2FA, ModelBindings, MFAInProgress, MaintenanceMode } from '~/middlewares';
import { GenericLayout, PopupLayout, Passthrough, TabberPassthrough } from '~/views';
import { NotFoundView } from '~/views/errors';
import { NotFoundView, MaintenanceView } from '~/views/errors';

declare module 'vue-router' {
interface RouteMeta {
Expand Down Expand Up @@ -65,7 +65,7 @@ export const routes: RouteRecordRaw[] = [
},
],
},
{ // Backwards compatability with v1
{ // Backwards compatibility with v1
name: 'login.sso',
path: '/auth/login/sso',
meta: {
Expand Down Expand Up @@ -118,7 +118,7 @@ export const routes: RouteRecordRaw[] = [
}
],
},
{ // Redirect for backwards compatability with v1
{ // Redirect for backwards compatibility with v1
name: 'account.sso',
path: 'account/sso',
meta: {
Expand All @@ -145,7 +145,7 @@ export const routes: RouteRecordRaw[] = [
path: '/server/:server',
component: GenericLayout,
meta: {
middlewares: [Authenticated, Require2FA, new ModelBindings('client')],
middlewares: [Authenticated, Require2FA, MaintenanceMode, new ModelBindings('client')],
showChildrenInNavbar: true
},
children: [
Expand Down Expand Up @@ -825,7 +825,7 @@ export const routes: RouteRecordRaw[] = [
]
},

{ // Backwards compatibility with WHMCS's go go Service button
{ // Backwards compatibility with WHMCS's go to Service button
name: 'admin.management.servers.view',
path: 'view/:id',
meta: {
Expand Down Expand Up @@ -1092,6 +1092,11 @@ export const routes: RouteRecordRaw[] = [
path: '/:catchAll(.*)',
component: NotFoundView,
},
{
name: 'maintenance',
path: '/maintenance',
component: MaintenanceView,
}
];

routes.forEach(Router.addRoute);
38 changes: 38 additions & 0 deletions src/views/errors/Maintenance.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<div class="flex flex-col justify-center items-center flex-grow">
<div class="text-center">
<h1 class="text-warning font-bold text-5xl">
<t path="navigation.maintenance.title" />
</h1>
<p class="py-2">
<t path="navigation.maintenance.description" />
</p>
<div class="py-5">
<v-button color="warning" class="p-4 mr-1" @click="$router.go(-1)">
← <t path="navigation.errors.go_back" />
</v-button>
<v-button :to="{name: 'index'}" color="primary" class="p-4">
<t path="navigation.errors.go_home" />
</v-button>
</div>
</div>
</div>

<v-footer />
</template>

<style scoped>
button {
line-height: revert;
}
</style>

<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
setup() {
return {};
}
});
</script>
3 changes: 2 additions & 1 deletion src/views/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as NotFoundView } from './404.vue';
export { default as NotFoundView } from './404.vue';
export { default as MaintenanceView } from './Maintenance.vue';

0 comments on commit 3b2c3db

Please sign in to comment.