diff options
| author | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2025-06-02 06:08:21 +0500 |
|---|---|---|
| committer | Maria Lisina <sekoohaka.sarisan@gmail.com> | 2025-06-02 06:08:21 +0500 |
| commit | a3474e2b7ef1005675bede0494c31b9a8b809f39 (patch) | |
| tree | de95470e53b12bf186663ef047e481752a92fdc5 /auth | |
| parent | 98e3f4749f319be42dc2c519ada73fa3ef751ada (diff) | |
bot: Move Image Board configuration and authorization out
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
Diffstat (limited to 'auth')
| -rw-r--r-- | auth/donmai.zsh | 59 | ||||
| -rw-r--r-- | auth/gelbooru.zsh | 7 | ||||
| -rw-r--r-- | auth/idolcomplex.zsh | 124 | ||||
| -rw-r--r-- | auth/moebooru.zsh | 40 | ||||
| -rw-r--r-- | auth/sankakuchannel.zsh | 55 |
5 files changed, 285 insertions, 0 deletions
diff --git a/auth/donmai.zsh b/auth/donmai.zsh new file mode 100644 index 0000000..8bc04a8 --- /dev/null +++ b/auth/donmai.zsh @@ -0,0 +1,59 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_auth_file="${cache}/${update_id}_profile.json" +dump+=(${ib_auth_file##*/}) + +if ! curl --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request GET \ + --silent \ + --user "${ib_login}:${ib_key}" \ + --user-agent "${useragent}" \ + "${ib_auth}/profile.json" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if ! jq -e '.' "${ib_auth_file}" > /dev/null +then + output_text="An unknown error occurred" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ "$(jq -r '.success' "${ib_auth_file}")" = "false" ]] +then + output_text="Error: <code>$(jq -r '.message' "${ib_auth_file}" | htmlescape)</code>" + log_text="ib_auth (${update_id}): Error: $(jq -r '.message' "${ib_auth_file}")" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ "$(jq -r '.name' "${ib_auth_file}")" != "${ib_login}" ]] +then + output_text="Failed to verify user authorization" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +printf "%s" "${ib_login}:${ib_key}" | base64 > "${token_file}" diff --git a/auth/gelbooru.zsh b/auth/gelbooru.zsh new file mode 100644 index 0000000..8adb436 --- /dev/null +++ b/auth/gelbooru.zsh @@ -0,0 +1,7 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +printf '%s="%s"\n%s="%s"\n' \ + "ib_dfield5" "user_id=${ib_login}" \ + "ib_dfield6" "api_key=${ib_key}" > "${legacy_file}" diff --git a/auth/idolcomplex.zsh b/auth/idolcomplex.zsh new file mode 100644 index 0000000..3112514 --- /dev/null +++ b/auth/idolcomplex.zsh @@ -0,0 +1,124 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_cookies="${cookies_file}" +ib_auth_file="${cache}/${update_id}_login.html" +dump+=(${ib_auth_file##*/}) + +if ! curl --cookie-jar "${ib_cookies}" \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request GET \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/users/login" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +ib_action="$(xq -a "action" -q "form" "${ib_auth_file}")" +ib_token="$(xq -a "value" -q "form>input[name=authenticity_token]" "${ib_auth_file}")" + +if [[ -z "${ib_action}" || -z "${ib_token}" ]] +then + output_text="Failed to get authorization data" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +ib_auth_file="${cache}/${update_id}_authenticate.html" +dump+=(${ib_auth_file##*/}) + +if ! curl --cookie "${ib_cookies}" \ + --cookie-jar "${ib_cookies}" \ + --data-urlencode "authenticity_token=${ib_token}" \ + --data-urlencode "user[name]=${ib_login}" \ + --data-urlencode "user[password]=${ib_key}" \ + --data-urlencode "commit=Login" \ + --header "Referer: ${ib_auth}/users/login" \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request POST \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}${ib_action}" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ -s "${ib_auth_file}" ]] +then + output_text="An unknown error occurred" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +ib_auth_file="${cache}/${update_id}_home.html" +dump+=(${ib_auth_file##*/}) + +if ! curl --cookie "${ib_cookies}" \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request GET \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/users/home" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +ib_notice="$(xq -q "div[id=notice]" "${ib_auth_file}")" + +if [[ -n "${ib_notice}" && "${ib_notice}" != "You are now logged in" ]] +then + output_text="$(printf "%s" "${ib_notice}" | htmlescape)" + log_text="ib_auth (${update_id}): ${ib_notice}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ -z "${ib_notice}" ]] +then + output_text="Failed to verify user authorization" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +strftime %s > "${timestamp_file}" diff --git a/auth/moebooru.zsh b/auth/moebooru.zsh new file mode 100644 index 0000000..c3a893d --- /dev/null +++ b/auth/moebooru.zsh @@ -0,0 +1,40 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_auth_file="${cache}/${update_id}_user.json" +dump+=(${ib_auth_file##*/}) + +if ! curl --data-urlencode "username=${ib_login}" \ + --data-urlencode "api_key=${ib_key}" \ + --get \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/user.json" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if ! jq -e '.' "${ib_auth_file}" > /dev/null +then + output_text="Invalid username or API key" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +printf '%s="%s"\n%s="%s"\n' \ + "ib_dfield5" "username=${ib_login}" \ + "ib_dfield6" "api_key=${ib_key}" > "${legacy_file}" diff --git a/auth/sankakuchannel.zsh b/auth/sankakuchannel.zsh new file mode 100644 index 0000000..86f076a --- /dev/null +++ b/auth/sankakuchannel.zsh @@ -0,0 +1,55 @@ +# Copyright (C) 2024-2025 Maria Lisina +# Copyright (C) 2024-2025 Danil Lisin +# SPDX-License-Identifier: Apache-2.0 + +ib_login_data="$(jq --null-input --compact-output \ + --arg login "${ib_login}" \ + --arg password "${ib_key}" \ + '{"login": $login, "password": $password}')" + +ib_auth_file="${cache}/${update_id}_token.json" +dump+=(${ib_auth_file##*/}) + +if ! curl --data "${ib_login_data}" \ + --header "Content-Type: application/json" \ + --max-time ${external_timeout} \ + --output "${ib_auth_file}" \ + --proxy "${external_proxy}" \ + --request POST \ + --silent \ + --user-agent "${useragent}" \ + "${ib_auth}/auth/token" +then + output_text="Failed to access ${ib_name} API" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if ! jq -e '.' "${ib_auth_file}" > /dev/null +then + output_text="An unknown error occurred" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +if [[ "$(jq -r '.success' "${ib_auth_file}")" != "true" ]] +then + output_text="Error: <code>$(jq -r '.error' "${ib_auth_file}" | htmlescape)</code>" + log_text="ib_auth (${update_id}): Error: $(jq -r '.error' "${ib_auth_file}")" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 +fi + +jq -r '.access_token' "${ib_auth_file}" > "${token_file}" +strftime %s > "${timestamp_file}" |
