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 /units/ib_auth.zsh | |
| parent | 98e3f4749f319be42dc2c519ada73fa3ef751ada (diff) | |
bot: Move Image Board configuration and authorization out
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
Diffstat (limited to 'units/ib_auth.zsh')
| -rw-r--r-- | units/ib_auth.zsh | 277 |
1 files changed, 11 insertions, 266 deletions
diff --git a/units/ib_auth.zsh b/units/ib_auth.zsh index 6a70167..4c81a93 100644 --- a/units/ib_auth.zsh +++ b/units/ib_auth.zsh @@ -34,282 +34,27 @@ then fi case "${ib_board}" in - (d) - 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}" + (a|d) + . "${auth}/donmai.zsh" ;; (g) - printf '%s="%s"\n%s="%s"\n' \ - "ib_dfield5" "user_id=${ib_login}" \ - "ib_dfield6" "api_key=${ib_key}" > "${legacy_file}" + . "${auth}/gelbooru.zsh" ;; (i) - 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}" + . "${auth}/idolcomplex.zsh" ;; (s) - 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}" + . "${auth}/sankakuchannel.zsh" ;; (k|y) - 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}" + . "${auth}/moebooru.zsh" ;; esac +if [[ -n "${output_text}" ]] +then + return 0 +fi + printf "%s\n" "${ib_login}" > "${login_file}" printf "%s\n" "${ib_key}" > "${key_file}" |
