Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions center/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
iDB_image_version=v0.0.1
iDB_admin_pass=admin123
iDB_service_name=idb
iDB_service_host_ip=127.0.0.1
iDB_service_port=9918 #默认端口9918
Expand Down
9 changes: 6 additions & 3 deletions center/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (

// Config定义
type CenterConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Latest string `json:"latest"`
Host string `json:"host"`
Port int `json:"port"`
Latest string `json:"latest"`
AdminPass string `json:"admin_pass"`
}

// Manager定义
Expand Down Expand Up @@ -74,6 +75,8 @@ func (m *Manager) loadConfig() error {
config.Port = portValue
case "latest":
config.Latest = strings.TrimSpace(value)
case "admin_pass":
config.AdminPass = strings.TrimSpace(value)
default:
return fmt.Errorf("unknown config key: %s", key)
}
Expand Down
8 changes: 6 additions & 2 deletions center/db/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import (
//go:embed timezones.json
var timezonesData []byte

func Init() {
var adminPass string

func Init(password string) {
adminPass = password

global.LOG.Info("db init begin")
m := gormigrate.New(global.DB, gormigrate.DefaultOptions, []*gormigrate.Migration{
AddTableRole,
Expand Down Expand Up @@ -114,7 +118,7 @@ var AddTableUser = &gormigrate.Migration{
return err
}

password := "admin123"
password := adminPass
salt := utils.GenerateNonce(8)
passwordHash := utils.HashPassword(password, salt)
adminUser := model.User{
Expand Down
1 change: 1 addition & 0 deletions center/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
environment:
- PORT=${iDB_service_container_port:-9918} # 容器内部的 PORT 变量
- HOST=${iDB_service_host_ip:-127.0.0.1} # 宿主机ip
- PASSWORD=${iDB_admin_pass:-admin123} # admin密码
network_mode: ${iDB_service_network_mode}
ports:
- "${iDB_service_port:-9918}:${iDB_service_container_port:-9918}"
Expand Down
4 changes: 4 additions & 0 deletions center/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ set -e

DEFAULT_HOST=127.0.0.1
DEFAULT_PORT=9918
DEFAULT_ADMIN_PASS=admin123
HOST=${HOST:-$DEFAULT_HOST}
PORT=${PORT:-$DEFAULT_PORT}
ADMIN_PASS=${PASSWORD:-$DEFAULT_ADMIN_PASS}

LATEST=https://static.sensdata.com/idb/release/latest
CONFIG_FILE=/etc/idb/idb.conf
LOG_FILE=/var/log/idb/idb.log
Expand Down Expand Up @@ -76,6 +79,7 @@ main() {
update_config "host" "$HOST"
update_config "port" "$PORT"
update_config "latest" "$LATEST"
update_config "admin_pass" "$ADMIN_PASS"

log "配置文件内容:"
cat "$CONFIG_FILE" || {
Expand Down
3 changes: 2 additions & 1 deletion center/idb.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
host=127.0.0.1
port=9918
latest=https://static.sensdata.com/idb/release/latest
latest=https://static.sensdata.com/idb/release/latest
admin_pass=admin123
2 changes: 1 addition & 1 deletion center/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func StartServices() error {
// 初始化数据库
global.LOG.Info("Init db")
db.Init(filepath.Join(constant.CenterDataDir, constant.CenterDb))
migration.Init()
migration.Init(manager.GetConfig().AdminPass)
// 初始化设置
err = db.InitSettings(conn.CONFMAN.GetConfig())
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,15 @@ function Install_IDB() {

log ".env 和 docker-compose.yaml 文件下载成功。"

# 修改 .env 文件中的端口配置
# 生成随机8位密码
ADMIN_PASS=$(cat /dev/urandom | tr -dc 'a-z0-9' | head -c 8)

# 修改 .env 文件中的配置
log "正在修改 .env 文件中的配置..."
sed -i "s/^iDB_service_host_ip=.*/iDB_service_host_ip=${PUBLIC_IP}/" "${PANEL_DIR}/.env"
sed -i "s/^iDB_service_port=.*/iDB_service_port=${PANEL_PORT}/" "${PANEL_DIR}/.env"
sed -i "s/^iDB_service_container_port=.*/iDB_service_container_port=${CONTAINER_PORT}/" "${PANEL_DIR}/.env"
sed -i "s/^iDB_admin_pass=.*/iDB_admin_pass=${ADMIN_PASS}/" "${PANEL_DIR}/.env"

log ".env 文件内容已更新为:\n$(cat ${PANEL_DIR}/.env)"

Expand Down Expand Up @@ -530,7 +534,7 @@ function Show_Result(){
log "外网地址: http://${PUBLIC_IP}:${PANEL_PORT}/idb"
log "内网地址: http://${LOCAL_IP}:${PANEL_PORT}/idb"
log "初始用户: admin"
log "初始密码: admin123"
log "初始密码: ${ADMIN_PASS}"
log ""
log "项目官网: https://idb.sensdata.com"
log "项目文档: https://idb.sensdata.com/docs"
Expand Down