(tags string, settingRepo repo.ISettingRepo)
| 33 | } |
| 34 | |
| 35 | func handleUserInfo(tags string, settingRepo repo.ISettingRepo) { |
| 36 | if len(tags) == 0 { |
| 37 | return |
| 38 | } |
| 39 | settingMap := make(map[string]string) |
| 40 | if tags == "use_existing" { |
| 41 | settingMap["ServerPort"] = ctl_conf.Load("ORIGINAL_PORT") |
| 42 | global.CONF.Conn.Port = settingMap["ServerPort"] |
| 43 | settingMap["UserName"] = global.CONF.Base.Username |
| 44 | settingMap["Password"] = global.CONF.Base.Password |
| 45 | settingMap["SecurityEntrance"] = global.CONF.Conn.Entrance |
| 46 | settingMap["SystemVersion"] = ctl_conf.Load("ORIGINAL_VERSION") |
| 47 | global.CONF.Base.Version = settingMap["SystemVersion"] |
| 48 | settingMap["Language"] = global.CONF.Base.Language |
| 49 | } |
| 50 | if tags == "all" { |
| 51 | settingMap["UserName"] = common.RandStrAndNum(10) |
| 52 | settingMap["Password"] = common.RandStrAndNum(10) |
| 53 | settingMap["SecurityEntrance"] = common.RandStrAndNum(10) |
| 54 | } |
| 55 | if strings.Contains(global.CONF.Base.ChangeUserInfo, "username") { |
| 56 | settingMap["UserName"] = common.RandStrAndNum(10) |
| 57 | } |
| 58 | if strings.Contains(global.CONF.Base.ChangeUserInfo, "password") { |
| 59 | settingMap["Password"] = common.RandStrAndNum(10) |
| 60 | } |
| 61 | if strings.Contains(global.CONF.Base.ChangeUserInfo, "entrance") { |
| 62 | settingMap["SecurityEntrance"] = common.RandStrAndNum(10) |
| 63 | } |
| 64 | if global.CONF.Base.IsEnterprise { |
| 65 | if len(settingMap["UserName"]) != 0 || len(settingMap["Password"]) != 0 { |
| 66 | if err := xpack.AuthProvider.ResetSuperAdminUser(settingMap["UserName"], settingMap["Password"]); err != nil { |
| 67 | global.LOG.Fatalf("reset enterprise super admin failed, err: %v", err) |
| 68 | return |
| 69 | } |
| 70 | } |
| 71 | } else { |
| 72 | for key, val := range settingMap { |
| 73 | if len(val) == 0 { |
| 74 | continue |
| 75 | } |
| 76 | if key == "Password" { |
| 77 | val, _ = encrypt.StringEncrypt(val) |
| 78 | } |
| 79 | if err := settingRepo.Update(key, val); err != nil { |
| 80 | global.LOG.Errorf("update %s before start failed, err: %v", key, err) |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | _ = ctl_conf.RemoveValueFromFile("/usr/local/bin/1pctl", "CHANGE_USER_INFO", global.CONF.Base.ChangeUserInfo) |
| 86 | _ = ctl_conf.UpdateInFile("/usr/local/bin/1pctl", "ORIGINAL_PASSWORD", "**********") |
| 87 | } |
| 88 | |
| 89 | func generateKey() { |
| 90 | if err := service.NewISettingService().GenerateRSAKey(); err != nil { |
no test coverage detected