-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Update dns_beget.sh #6509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Update dns_beget.sh #6509
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,270 +12,119 @@ Author: ARNik <[email protected]> | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Beget_Api="https://api.beget.com/api" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| #################### Public functions #################### | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" | ||||||||||||||||||||||||||||||||||||||||||
| # Used to add txt record | ||||||||||||||||||||||||||||||||||||||||||
| dns_beget_add() { | ||||||||||||||||||||||||||||||||||||||||||
| fulldomain=$1 | ||||||||||||||||||||||||||||||||||||||||||
| txtvalue=$2 | ||||||||||||||||||||||||||||||||||||||||||
| _debug "dns_beget_add() $fulldomain $txtvalue" | ||||||||||||||||||||||||||||||||||||||||||
| fulldomain=$(echo "$fulldomain" | _lower_case) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Beget_Username="${Beget_Username:-$(_readaccountconf_mutable Beget_Username)}" | ||||||||||||||||||||||||||||||||||||||||||
| Beget_Password="${Beget_Password:-$(_readaccountconf_mutable Beget_Password)}" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if [ -z "$Beget_Username" ] || [ -z "$Beget_Password" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| Beget_Username="" | ||||||||||||||||||||||||||||||||||||||||||
| Beget_Password="" | ||||||||||||||||||||||||||||||||||||||||||
| _err "You must export variables: Beget_Username, and Beget_Password" | ||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| #save the credentials to the account conf file. | ||||||||||||||||||||||||||||||||||||||||||
| _saveaccountconf_mutable Beget_Username "$Beget_Username" | ||||||||||||||||||||||||||||||||||||||||||
| _saveaccountconf_mutable Beget_Password "$Beget_Password" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _info "Prepare subdomain." | ||||||||||||||||||||||||||||||||||||||||||
| if ! _prepare_subdomain "$fulldomain"; then | ||||||||||||||||||||||||||||||||||||||||||
| _err "Can't prepare subdomain." | ||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _info "Get domain records" | ||||||||||||||||||||||||||||||||||||||||||
| data="{\"fqdn\":\"$fulldomain\"}" | ||||||||||||||||||||||||||||||||||||||||||
| res=$(_api_call "$Beget_Api/dns/getData" "$data") | ||||||||||||||||||||||||||||||||||||||||||
| if ! _is_api_reply_ok "$res"; then | ||||||||||||||||||||||||||||||||||||||||||
| _err "Can't get domain records." | ||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _info "Add new TXT record" | ||||||||||||||||||||||||||||||||||||||||||
| data="{\"fqdn\":\"$fulldomain\",\"records\":{" | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "A") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "AAAA") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "CAA") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "MX") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "SRV") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "TXT") | ||||||||||||||||||||||||||||||||||||||||||
| data=$(echo "$data" | sed 's/,$//') | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}'}}' | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| str=$(_txt_to_dns_json "$txtvalue") | ||||||||||||||||||||||||||||||||||||||||||
| data=$(_add_record "$data" "TXT" "$str") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| res=$(_api_call "$Beget_Api/dns/changeRecords" "$data") | ||||||||||||||||||||||||||||||||||||||||||
| if ! _is_api_reply_ok "$res"; then | ||||||||||||||||||||||||||||||||||||||||||
| _err "Can't change domain records." | ||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| # API call function | ||||||||||||||||||||||||||||||||||||||||||
| _api_call() { | ||||||||||||||||||||||||||||||||||||||||||
| api_url="$1" | ||||||||||||||||||||||||||||||||||||||||||
| input_data="$2" | ||||||||||||||||||||||||||||||||||||||||||
| url="$api_url?login=$Beget_Username&passwd=$Beget_Password&input_format=json&output_format=json" | ||||||||||||||||||||||||||||||||||||||||||
| [ -n "$input_data" ] && url="${url}&input_data=$(echo -n "$input_data" | jq -s -R -r @uri)" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||
| echo "[DEBUG] _api_call url=$url" | ||||||||||||||||||||||||||||||||||||||||||
| curl -s "$url" | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Usage: fulldomain txtvalue | ||||||||||||||||||||||||||||||||||||||||||
| # Used to remove the txt record after validation | ||||||||||||||||||||||||||||||||||||||||||
| dns_beget_rm() { | ||||||||||||||||||||||||||||||||||||||||||
| # Add TXT record (supports multiple additions without overwriting) | ||||||||||||||||||||||||||||||||||||||||||
| dns_beget_add() { | ||||||||||||||||||||||||||||||||||||||||||
| fulldomain=$1 | ||||||||||||||||||||||||||||||||||||||||||
| txtvalue=$2 | ||||||||||||||||||||||||||||||||||||||||||
| _debug "dns_beget_rm() $fulldomain $txtvalue" | ||||||||||||||||||||||||||||||||||||||||||
| fulldomain=$(echo "$fulldomain" | _lower_case) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Beget_Username="${Beget_Username:-$(_readaccountconf_mutable Beget_Username)}" | ||||||||||||||||||||||||||||||||||||||||||
| Beget_Password="${Beget_Password:-$(_readaccountconf_mutable Beget_Password)}" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _info "Get current domain records" | ||||||||||||||||||||||||||||||||||||||||||
| data="{\"fqdn\":\"$fulldomain\"}" | ||||||||||||||||||||||||||||||||||||||||||
| res=$(_api_call "$Beget_Api/dns/getData" "$data") | ||||||||||||||||||||||||||||||||||||||||||
| if ! _is_api_reply_ok "$res"; then | ||||||||||||||||||||||||||||||||||||||||||
| _err "Can't get domain records." | ||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _info "Remove TXT record" | ||||||||||||||||||||||||||||||||||||||||||
| data="{\"fqdn\":\"$fulldomain\",\"records\":{" | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "A") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "AAAA") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "CAA") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "MX") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "SRV") | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}$(_parce_records "$res" "TXT") | ||||||||||||||||||||||||||||||||||||||||||
| data=$(echo "$data" | sed 's/,$//') | ||||||||||||||||||||||||||||||||||||||||||
| data=${data}'}}' | ||||||||||||||||||||||||||||||||||||||||||
| echo "[DEBUG] Starting dns_beget_add" | ||||||||||||||||||||||||||||||||||||||||||
| echo "[DEBUG] fulldomain=$fulldomain" | ||||||||||||||||||||||||||||||||||||||||||
| echo "[DEBUG] txtvalue=$txtvalue" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| str=$(_txt_to_dns_json "$txtvalue") | ||||||||||||||||||||||||||||||||||||||||||
| data=$(_rm_record "$data" "$str") | ||||||||||||||||||||||||||||||||||||||||||
| Beget_Username="${Beget_Username:?Please set Beget_Username}" | ||||||||||||||||||||||||||||||||||||||||||
| Beget_Password="${Beget_Password:?Please set Beget_Password}" | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+36
|
||||||||||||||||||||||||||||||||||||||||||
| Beget_Username="${Beget_Username:?Please set Beget_Username}" | |
| Beget_Password="${Beget_Password:?Please set Beget_Password}" | |
| # Credential management: read from account config if not set | |
| if [ -z "$Beget_Username" ]; then | |
| Beget_Username="$(_readaccountconf_mutable BEGET_User)" | |
| fi | |
| if [ -z "$Beget_Password" ]; then | |
| Beget_Password="$(_readaccountconf_mutable BEGET_Password)" | |
| fi | |
| if [ -z "$Beget_Username" ]; then | |
| _err "Please set BEGET_User." | |
| return 1 | |
| fi | |
| if [ -z "$Beget_Password" ]; then | |
| _err "Please set BEGET_Password." | |
| return 1 | |
| fi | |
| # Save credentials to account config for future use | |
| _saveaccountconf_mutable BEGET_User "$Beget_Username" | |
| _saveaccountconf_mutable BEGET_Password "$Beget_Password" |
Copilot
AI
Sep 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The || operator will trigger on any non-zero exit code from _api_call, but _api_call uses curl -s which returns the response regardless of HTTP status. This condition may incorrectly trigger when the API returns a valid response with an error status.
Copilot
AI
Sep 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment contains text in Russian (Cyrillic characters). Comments should be in English for consistency with the codebase.
| while [ $i -le 6 ]; do # 6 раз по 20 секунд = максимум 120 | |
| while [ $i -le 6 ]; do # 6 times 20 seconds = maximum 120 seconds |
Copilot
AI
Sep 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as above - the || operator will trigger on any non-zero exit code from _api_call, but the function doesn't validate HTTP status codes or API response status, potentially masking actual API errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug output exposes sensitive credentials (username and password) in the URL. This could leak credentials to logs. Consider masking credentials in debug output or using a different logging approach.