Skip to content

Commit 4c67998

Browse files
author
Pavlo Kulyk
committed
feat: add default user detection and private IP check to AdminForthRestAPI
1 parent f48a6ca commit 4c67998

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

adminforth/modules/restApi.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,14 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
376376
}
377377
}
378378

379+
let defaultUserExists = false;
380+
if (username === 'adminforth') {
381+
defaultUserExists = true;
382+
}
383+
const headers = response.getHeaders?.() || {};
384+
const clientIp = this.adminforth.auth.getClientIp(headers);
385+
const isPrivateIP = clientIp === null ? true :false;
386+
379387
const publicPart = {
380388
brandName: this.adminforth.config.customization.brandName,
381389
usernameFieldName: usernameColumn.label,
@@ -404,6 +412,8 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
404412
globalInjections: this.adminforth.config.customization.globalInjections,
405413
userFullnameField: this.adminforth.config.auth.userFullNameField,
406414
settingPages: settingPages,
415+
defaultUserExists: defaultUserExists,
416+
isPrivateIP: isPrivateIP,
407417
}
408418

409419
// translate menu labels

adminforth/spa/src/components/Sidebar.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
</div>
5252
</div>
5353

54+
<div v-if="coreStore.config.defaultUserExists&&!coreStore.config.isPrivateIP" class="p-4 mb-4 text-white rounded-lg bg-red-700/80 fill-white text-sm">
55+
<IconExclamationCircleOutline class="inline-block align-text-bottom mr-0,5 w-5 h-5" />
56+
Default user <strong>"adminforth"</strong> detected. Delete it and create your own account.
57+
</div>
58+
5459
<ul class="af-sidebar-container space-y-2 font-medium" >
5560
<template v-if="!iconOnlySidebarEnabled || !isSidebarIconOnly" v-for="(item, i) in coreStore.menu" :key="`menu-${i}`">
5661
<div v-if="item.type === 'divider'" class="border-t border-lightSidebarDevider dark:border-darkSidebarDevider"></div>
@@ -300,6 +305,7 @@ import { getIcon, verySimpleHash, loadFile, getCustomComponent } from '@/utils';
300305
import { Tooltip } from '@/afcl';
301306
import type { AnnouncementBadgeResponse } from '@/types/Common';
302307
import { useAdminforth } from '@/adminforth';
308+
import { IconExclamationCircleOutline} from '@iconify-prerendered/vue-flowbite';
303309
304310
const { menu } = useAdminforth();
305311

adminforth/types/Common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ export interface AdminForthConfigForFrontend {
11101110
loginBackgroundImage: string,
11111111
loginBackgroundPosition: string,
11121112
removeBackgroundBlendMode: boolean,
1113+
defaultUserExists?: boolean;
11131114
title?: string,
11141115
demoCredentials?: string,
11151116
loginPromptHTML?: string | (() => string | Promise<string> | void | Promise<void> | Promise<undefined>) | undefined

0 commit comments

Comments
 (0)