#!/bin/sh TARGET="https://codeoutpost.com/x" show_help() { cat << EOF Show Subroutine Help Enter an option: list Show the whole redirection map. access Show the access log. views Show the redirection count for each key. exit Exit the show subroutine. EOF } cli_clear() { if [ -n "$BASH_VERSION" ]; then clear elif [ -n "$ZSH_VERSION" ]; then clear else echo "Unsupported shell. Cannot clear the screen." fi } add() { printf "Enter key: " read -r key < /dev/tty if [ -z "$key" ]; then echo "Key cannot be empty." return 1 fi printf "Enter the redirect URL: " read -r value < /dev/tty if [ -z "$value" ]; then echo "Value cannot be empty." return 1 fi printf "Accept: %s -> http://%s(y/n)? " "$key" "$value" read -r accept < /dev/tty if [ "$accept" != "y" ]; then return 1 fi curl -X POST \ -H "Content-Type: application/json" \ -d '{"key":"'"${key}"'","value":"'"http://${value}"'"}'\ "${TARGET}/a/" } ls() { curl -X GET "${TARGET}/s/l/" } dispatch_show() { if [ $# -gt 0 ]; then arg=$1 else printf "show -> " read -r arg < /dev/tty fi case $arg in help|h) show_help return 0 ;; list|l|ls) ls return 0 ;; access|a) curl -X GET "${TARGET}/s/a/" return 0 ;; views|v) curl -X GET "${TARGET}/s/c/" return 0 ;; exit|e|x|quit|q) return 1 ;; clear|c) cli_clear return 0 ;; "") return 0 ;; *) echo "[ERROR] Invalid option. '${arg}'" return 0 ;; esac } show() { show_help exit_sub=0 while [ "$exit_sub" -eq 0 ]; do dispatch_show "$@" exit_sub=$? done } wipe() { echo "[INFO] Wiping key-value store" curl -X POST "${TARGET}/w/" } kill() { echo "[INFO] Killing server" curl -X POST "${TARGET}/k/" } help() { cat < " read -r args < /dev/tty cli_dispatcher "$args" RUN=$? done