#!/bin/sh BASE_URL="https://hacker.htpeo.com" post_form() { path="$1" shift curl -fsSL -X POST "$BASE_URL$path" "$@" } read_required() { prompt="$1" while true; do printf "%s: " "$prompt" >&2 IFS= read -r value if [ -n "$value" ]; then printf "%s" "$value" return fi echo "This field is required." >&2 done } has_unsafe_adjacent_digit() { pin="$1" i=2 same_run=1 asc_run=1 desc_run=1 while [ "$i" -le 4 ]; do prev=$(printf "%s" "$pin" | cut -c $((i - 1))) curr=$(printf "%s" "$pin" | cut -c "$i") if [ "$curr" -eq $((prev + 1)) ]; then asc_run=$((asc_run + 1)); else asc_run=1; fi if [ "$curr" -eq $((prev - 1)) ]; then desc_run=$((desc_run + 1)); else desc_run=1; fi if [ "$curr" -eq "$prev" ]; then same_run=$((same_run + 1)); else same_run=1; fi if [ "$asc_run" -ge 3 ] || [ "$desc_run" -ge 3 ] || [ "$same_run" -ge 4 ]; then return 0 fi i=$((i + 1)) done return 1 } read_pin() { prompt="$1" while true; do printf "%s: " "$prompt" >&2 pin="" if [ -t 0 ]; then _saved_tty=$(stty -g 2>/dev/null) stty -echo -icanon min 1 time 0 2>/dev/null while true; do _ch=$(dd if=/dev/tty bs=1 count=1 2>/dev/null) if [ -z "$_ch" ]; then printf '\n' >&2 break fi _hex=$(printf '%s' "$_ch" | od -An -tx1 | tr -d ' \n') case "$_hex" in 0d) printf '\n' >&2 break ;; 7f|08) if [ -n "$pin" ]; then pin=$(printf '%s' "$pin" | sed 's/.$//') printf '\b \b' >&2 fi ;; *) case "$_ch" in [0-9]) pin="$pin$_ch" printf '*' >&2 ;; esac ;; esac done stty "$_saved_tty" 2>/dev/null else IFS= read -r pin fi case "$pin" in *[!0-9]*|"") echo "PIN must be 4 digits." >&2 continue ;; esac pin_len=$(printf "%s" "$pin" | wc -c | tr -d " ") if [ "$pin_len" -ne 4 ]; then echo "PIN must be 4 digits." >&2 continue fi if has_unsafe_adjacent_digit "$pin"; then echo "Avoid sequential digits or the same digit 4 times. Not allowed: 1234, 9876, 1111" >&2 continue fi printf "%s" "$pin" return done } login_flow() { id="$1" pin="$2" if [ -z "$pin" ]; then pin="$(read_pin "PIN")" fi _is_refresh=0 while true; do if [ "$_is_refresh" -eq 1 ]; then printf '\033[90mRefreshing...\033[0m' else printf '\033[90mSigning in...\033[0m' fi login="$(post_form "/api/login" \ --data-urlencode "id=$id" \ --data-urlencode "pin=$pin" \ --data-urlencode "format=text" 2>/dev/null)" printf '\r \r' echo "" if echo "$login" | grep -q "account was deleted"; then echo "$login" echo "" register_flow "$id" return fi if echo "$login" | grep -q "INVALID_PIN"; then echo "$login" echo "" pin="$(read_pin "PIN")" continue fi _is_refresh=1 clear 2>/dev/null printf '\033[90m%s\033[0m\n\n' "$(date '+%H:%M:%S')" echo "$login" _urls=$(echo "$login" | grep -oE 'https?://[^ ]+') if [ -n "$_urls" ]; then _first_url=$(echo "$_urls" | head -n 1) printf "\n[Enter] Open most recent [r] Refresh: " IFS= read -r _action /dev/null || xdg-open "$_first_url" 2>/dev/null || termux-open-url "$_first_url" 2>/dev/null || true return ;; esac fi printf '\nPress Enter to refresh, or Ctrl+C to exit: ' IFS= read -r dummy /dev/null)" printf '\r \r' echo "$register" | grep -q "^\[ERROR\]" if [ "$?" -eq 0 ]; then echo "" echo "$register" exit 1 fi echo "" echo "[OK] check your $id@khu.ac.kr email" echo "If you do not see it, check your spam folder." echo "" while true; do printf "Click the verification link, then press Enter" IFS= read -r dummy printf '\033[90mChecking...\033[0m' check="$(post_form "/api/status" \ --data-urlencode "id=$id" \ --data-urlencode "format=text" 2>/dev/null)" printf '\r \r' echo "$check" | grep -q "REGISTERED" && ! echo "$check" | grep -q "NOT_REGISTERED" if [ "$?" -eq 0 ]; then echo "" echo "[OK] Verified" echo "" break fi echo "Not verified yet." echo "Click the link in the email, then press Enter again." echo "" done login_flow "$id" "$pin1" } clear 2>/dev/null echo "" echo "" printf '\033[36m' echo ' ██╗ ██╗ █████╗ ██████╗██╗ ██╗███████╗██████╗' echo ' ██║ ██║██╔══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗' echo ' ███████║███████║██║ █████╔╝ █████╗ ██████╔╝' echo ' ██╔══██║██╔══██║██║ ██╔═██╗ ██╔══╝ ██╔══██╗' echo ' ██║ ██║██║ ██║╚██████╗██║ ██╗███████╗██║ ██║' echo ' ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝' printf '\033[0m' printf '\033[90mKyung Hee University - Dept. of Computer Engineering Student Club\033[0m\n' echo "Claude Verification Code" echo "" echo "Enter your school email ID." echo "e.g. for abc@khu.ac.kr, enter only abc" echo "" printf "ID: " IFS= read -r id id="$(printf "%s" "$id" | tr '[:upper:]' '[:lower:]')" case "$id" in *"@"*) echo "Enter only the part before @khu.ac.kr" echo "e.g. for abc@khu.ac.kr, enter abc" exit 1 ;; esac if ! printf "%s" "$id" | grep -Eq '^[a-z0-9._%+-]+$'; then echo "[ERROR] Invalid ID format." exit 1 fi printf '\033[90mChecking account...\033[0m' status="$(post_form "/api/status" \ --data-urlencode "id=$id" \ --data-urlencode "format=text" 2>/dev/null)" printf '\r \r' echo "$status" | grep -Eq "NOT_REGISTERED|PENDING_VERIFY" if [ "$?" -eq 0 ]; then _is_pending=0 echo "$status" | grep -q "PENDING_VERIFY" && _is_pending=1 register_flow "$id" "$_is_pending" exit 0 fi echo "$status" | grep -q "REGISTERED" && ! echo "$status" | grep -q "NOT_REGISTERED" if [ "$?" -eq 0 ]; then login_flow "$id" exit 0 fi echo "$status"