mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-05 20:54:14 +00:00
feat: add API token to install output
Add -getApiToken flag to the setting subcommand so shell scripts can retrieve the panel API token. Include the token in the install.sh completion banner for automation/deployment use.
This commit is contained in:
parent
07bc74a521
commit
8f4579215e
2 changed files with 22 additions and 0 deletions
|
|
@ -763,6 +763,9 @@ config_after_install() {
|
|||
|
||||
prompt_and_setup_ssl "${config_port}" "${config_webBasePath}" "${server_ip}"
|
||||
|
||||
# Retrieve the API token for display
|
||||
local config_apiToken=$(${xui_folder}/x-ui setting -getApiToken true | grep -Eo 'apiToken: .+' | awk '{print $2}')
|
||||
|
||||
# Display final credentials and access information
|
||||
echo ""
|
||||
echo -e "${green}═══════════════════════════════════════════${plain}"
|
||||
|
|
@ -773,6 +776,7 @@ config_after_install() {
|
|||
echo -e "${green}Port: ${config_port}${plain}"
|
||||
echo -e "${green}WebBasePath: ${config_webBasePath}${plain}"
|
||||
echo -e "${green}Access URL: ${SSL_SCHEME}://${SSL_HOST}:${config_port}/${config_webBasePath}${plain}"
|
||||
echo -e "${green}API Token: ${config_apiToken}${plain}"
|
||||
echo -e "${green}═══════════════════════════════════════════${plain}"
|
||||
echo -e "${yellow}⚠ IMPORTANT: Save these credentials securely!${plain}"
|
||||
if [[ "$SSL_SCHEME" == "https" ]]; then
|
||||
|
|
|
|||
18
main.go
18
main.go
|
|
@ -391,6 +391,19 @@ func GetListenIP(getListen bool) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetApiToken displays the current API token if getApiToken is true.
|
||||
func GetApiToken(getApiToken bool) {
|
||||
if getApiToken {
|
||||
settingService := service.SettingService{}
|
||||
apiToken, err := settingService.GetApiToken()
|
||||
if err != nil {
|
||||
fmt.Println("get apiToken failed, error info:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println("apiToken:", apiToken)
|
||||
}
|
||||
}
|
||||
|
||||
// migrateDb performs database migration operations for the 3x-ui panel.
|
||||
func migrateDb() {
|
||||
inboundService := service.InboundService{}
|
||||
|
|
@ -433,6 +446,7 @@ func main() {
|
|||
var reset bool
|
||||
var show bool
|
||||
var getCert bool
|
||||
var getApiToken bool
|
||||
var resetTwoFactor bool
|
||||
settingCmd.BoolVar(&reset, "reset", false, "Reset all settings")
|
||||
settingCmd.BoolVar(&show, "show", false, "Display current settings")
|
||||
|
|
@ -444,6 +458,7 @@ func main() {
|
|||
settingCmd.BoolVar(&resetTwoFactor, "resetTwoFactor", false, "Reset two-factor authentication settings")
|
||||
settingCmd.BoolVar(&getListen, "getListen", false, "Display current panel listenIP IP")
|
||||
settingCmd.BoolVar(&getCert, "getCert", false, "Display current certificate settings")
|
||||
settingCmd.BoolVar(&getApiToken, "getApiToken", false, "Display current API token")
|
||||
settingCmd.StringVar(&webCertFile, "webCert", "", "Set path to public key file for panel")
|
||||
settingCmd.StringVar(&webKeyFile, "webCertKey", "", "Set path to private key file for panel")
|
||||
settingCmd.StringVar(&tgbottoken, "tgbottoken", "", "Set token for Telegram bot")
|
||||
|
|
@ -501,6 +516,9 @@ func main() {
|
|||
if getCert {
|
||||
GetCertificate(getCert)
|
||||
}
|
||||
if getApiToken {
|
||||
GetApiToken(getApiToken)
|
||||
}
|
||||
if (tgbottoken != "") || (tgbotchatid != "") || (tgbotRuntime != "") {
|
||||
updateTgbotSetting(tgbottoken, tgbotchatid, tgbotRuntime)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue