From 460e31260e492838e7e98b75f09c2c40043bf63f Mon Sep 17 00:00:00 2001 From: Den Piligrim <89912505+vasiljevdenis@users.noreply.github.com> Date: Fri, 6 Feb 2026 12:42:25 +0300 Subject: [PATCH] fix: hardcode credentials --- install.sh | 8 ++++++-- server/.env.example | 7 +++++++ server/src/auth/auth.service.ts | 10 +++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 server/.env.example diff --git a/install.sh b/install.sh index 18860fa..183788e 100644 --- a/install.sh +++ b/install.sh @@ -175,6 +175,8 @@ FINAL_PORT=$(get_random_port) # --- 4. Генерация паролей --- DB_PASS=$(openssl rand -base64 12) JWT_SECRET=$(openssl rand -base64 32) +ADMIN_USER=$(openssl rand -base64 12) +ADMIN_PASS=$(openssl rand -base64 12) log "Сгенерированы секретные ключи для БД и JWT." ################################# @@ -186,6 +188,8 @@ DB_PORT=5432 DB_USERNAME=admin DB_PASSWORD=${DB_PASS} DB_NAME=3dp_manager +ADMIN_LOGIN=${ADMIN_USER} +ADMIN_PASSWORD=${ADMIN_PASS} EOF if [[ "$USE_SSL" == "true" ]]; then @@ -412,8 +416,8 @@ if [[ "$USE_SSL" == "true" ]]; then else echo -e "${GREEN}✔ Установка завершена! Доступно по адресу: http://${UI_HOST}:${FINAL_PORT}${NC}" fi -echo "Логин: admin" -echo "Пароль: admin" +echo "${GREEN}Логин: $ADMIN_USER" +echo "${GREEN}Пароль: $ADMIN_PASS" echo "" echo "Немедленно измените пароль в Настройках утилиты!" echo "===================================================" \ No newline at end of file diff --git a/server/.env.example b/server/.env.example new file mode 100644 index 0000000..b00d553 --- /dev/null +++ b/server/.env.example @@ -0,0 +1,7 @@ +DB_HOST=localhost +DB_PORT=5432 +DB_USERNAME=admin +DB_PASSWORD= +DB_NAME=3dp_manager +ADMIN_LOGIN=admin +ADMIN_PASSWORD= \ No newline at end of file diff --git a/server/src/auth/auth.service.ts b/server/src/auth/auth.service.ts index 2c293d2..9a30247 100644 --- a/server/src/auth/auth.service.ts +++ b/server/src/auth/auth.service.ts @@ -4,6 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import * as bcrypt from 'bcrypt'; import { Setting } from '../settings/entities/setting.entity'; +import { ConfigService } from '@nestjs/config'; @Injectable() export class AuthService { @@ -13,6 +14,7 @@ export class AuthService { @InjectRepository(Setting) private settingsRepo: Repository, private jwtService: JwtService, + private configService: ConfigService, ) {} async validateUser(login: string, pass: string): Promise { @@ -85,12 +87,14 @@ export class AuthService { const login = await this.settingsRepo.findOne({ where: { key: 'admin_login' } }); if (!login) { - this.logger.log('Инициализация администратора (admin / admin)...'); + this.logger.log('Инициализация администратора...'); + const envLogin = this.configService.get('ADMIN_LOGIN') || 'admin'; + const envPass = this.configService.get('ADMIN_PASSWORD') || 'admin'; - const loginSetting = this.settingsRepo.create({ key: 'admin_login', value: 'admin' }); + const loginSetting = this.settingsRepo.create({ key: 'admin_login', value: envLogin }); await this.settingsRepo.save(loginSetting); - const hash = await bcrypt.hash('admin', 10); + const hash = await bcrypt.hash(envPass, 10); const passSetting = this.settingsRepo.create({ key: 'admin_password', value: hash }); await this.settingsRepo.save(passSetting);