Skip to content

Commit 0109179

Browse files
authored
Merge pull request #467 from devforth/feature/AdminForth/1193/i-think-we-had-some-feature-wh
feat: add default user detection and private IP check to AdminForthRe…
2 parents 2269d81 + 2a2547a commit 0109179

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

adminforth/modules/restApi.ts

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

379+
let defaultUserExists = false;
380+
if (username === 'adminforth') {
381+
defaultUserExists = true;
382+
}
383+
const clientIp = this.adminforth.auth.getClientIp(response.getHeaders?.() || {});
384+
const isPrivateIP = clientIp === null ? true : false;
385+
379386
const publicPart = {
380387
brandName: this.adminforth.config.customization.brandName,
381388
usernameFieldName: usernameColumn.label,
@@ -404,6 +411,7 @@ export default class AdminForthRestAPI implements IAdminForthRestAPI {
404411
globalInjections: this.adminforth.config.customization.globalInjections,
405412
userFullnameField: this.adminforth.config.auth.userFullNameField,
406413
settingPages: settingPages,
414+
hasDefaultUserOnPublicNetwork: defaultUserExists && !isPrivateIP
407415
}
408416

409417
// 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.hasDefaultUserOnPublicNetwork" 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
@@ -1117,6 +1117,7 @@ export interface AdminForthConfigForFrontend {
11171117
loginBackgroundImage: string,
11181118
loginBackgroundPosition: string,
11191119
removeBackgroundBlendMode: boolean,
1120+
defaultUserExists?: boolean;
11201121
title?: string,
11211122
demoCredentials?: string,
11221123
loginPromptHTML?: string | (() => string | Promise<string> | void | Promise<void> | Promise<undefined>) | undefined

0 commit comments

Comments
 (0)