diff options
| -rw-r--r-- | README.md | 1 | ||||
| -rwxr-xr-x | bot.zsh | 2 | ||||
| -rw-r--r-- | units/ib_auth.zsh | 114 | ||||
| -rw-r--r-- | units/ib_authconfig.zsh | 9 | ||||
| -rw-r--r-- | units/ib_config.zsh | 2 | ||||
| -rw-r--r-- | units/ib_file.zsh | 3 | ||||
| -rw-r--r-- | units/ib_token.zsh | 5 |
7 files changed, 133 insertions, 3 deletions
@@ -34,6 +34,7 @@ BusyBox is a hard-coded dependency and cannot be replaced with alternatives! * curl * jq * recode +* xq For distribution specific installation commands follow [command-not-found](https://command-not-found.com/). @@ -151,7 +151,7 @@ then exit 1 fi -for required in busybox curl jq recode +for required in busybox curl jq recode xq do if ! command -v ${required} > /dev/null then diff --git a/units/ib_auth.zsh b/units/ib_auth.zsh index 6b8c891..b7c0fa0 100644 --- a/units/ib_auth.zsh +++ b/units/ib_auth.zsh @@ -93,6 +93,120 @@ case "${ib_board}" in "ib_dfield5" "user_id=${ib_login}" \ "ib_dfield6" "api_key=${ib_key}" > "${user_config}/${ib_config}/legacy" ;; + (i) + ib_cookies="${user_config}/${ib_config}/cookies.txt" + 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 process request" + 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 process request" + 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 process request" + 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="Failed to process request" + 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 process request" + 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}" | htmlescape)" + + if [[ -n "${ib_notice}" && "${ib_notice}" != "You are now logged in" ]] + then + output_text="${ib_notice}" + elif [[ -z "${ib_notice}" ]] + then + output_text="Failed to process request" + log_text="ib_auth (${update_id}): ${output_text}" + + . "${units}/log.zsh" + . "${units}/dump.zsh" + + return 0 + fi + + strftime %s > "${user_config}/${ib_config}/timestamp" + ;; (s) ib_login_data="$(jq --null-input --compact-output \ --arg login "${ib_login}" \ diff --git a/units/ib_authconfig.zsh b/units/ib_authconfig.zsh index 01c7939..64fb71c 100644 --- a/units/ib_authconfig.zsh +++ b/units/ib_authconfig.zsh @@ -20,6 +20,15 @@ case "${ib_board}" in ib_login_word="user ID" ib_key_word="API key" ;; + (i) + ib_auth="https://idol.sankakucomplex.com" + ib_config="idol" + ib_expire=86400 + ib_login_file="username" + ib_key_file="password" + ib_login_word="email or username" + ib_key_word="password" + ;; (s) ib_auth="https://sankakuapi.com/auth/token" ib_config="sankaku" diff --git a/units/ib_config.zsh b/units/ib_config.zsh index af4218d..0bcb71c 100644 --- a/units/ib_config.zsh +++ b/units/ib_config.zsh @@ -157,7 +157,7 @@ case "${ib_board}" in ;; (i) ib_name="Idol Complex" - ib_api="https://iapi.sankakucomplex.com" + ib_api="https://idol.sankakucomplex.com" ib_url="https://idol.sankakucomplex.com" ib_ratings=( diff --git a/units/ib_file.zsh b/units/ib_file.zsh index a0b3780..42af4e0 100644 --- a/units/ib_file.zsh +++ b/units/ib_file.zsh @@ -50,7 +50,8 @@ fi rm -f "${ib_file}" -if ! curl --data-urlencode "${ib_dfield1}" \ +if ! curl --cookie "${ib_cookies}" \ + --data-urlencode "${ib_dfield1}" \ --data-urlencode "${ib_dfield2}" \ --data-urlencode "${ib_dfield3}" \ --data-urlencode "${ib_dfield4}" \ diff --git a/units/ib_token.zsh b/units/ib_token.zsh index f243dac..f1794a9 100644 --- a/units/ib_token.zsh +++ b/units/ib_token.zsh @@ -32,6 +32,11 @@ then fi fi +if [[ -f "${user_config}/${ib_config}/cookies.txt" ]] +then + ib_cookies="${user_config}/${ib_config}/cookies.txt" +fi + if [[ -f "${user_config}/${ib_config}/token" ]] then ib_header="${ib_authorization} $(< "${user_config}/${ib_config}/token")" |
