Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
price: add XMR<->Cryptocurrency section, use more API data
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Sep 9, 2022
1 parent 01fb219 commit 86e56b3
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 50 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# v1.9.1
## Updates
* **HTTP Spoofing:** Added `TOR_BROWSER_MIMIC` option that mimics the HTTP headers sent/used by [Tor browser.](https://github.com/hinto-janaiyo/monero-bash/blob/main/docs/fake_http_headers/tor_browser) Tor proxying must be enabled for this option to work
* **HTTP Spoofing:** Added `ONLY_WGET_CURL` option to only use randomly selected 2016-2022 versions of `wget/curl` as the [User-Agent.](https://github.com/hinto-janaiyo/monero-bash/blob/main/docs/fake_http_headers/wget_curl) This option and `ONLY_USER_AGENT` will always enabled when sending a non-local RPC call
* **HTTP Spoofing:** Added `TOR_BROWSER_MIMIC` option that mimics the HTTP headers used by [Tor browser](https://github.com/hinto-janaiyo/monero-bash/blob/main/docs/fake_http_headers/tor_browser)
* **HTTP Spoofing:** Added `ONLY_WGET_CURL` option to only use random [`wget/curl` versions](https://github.com/hinto-janaiyo/monero-bash/blob/main/docs/fake_http_headers/wget_curl) as the User-Agent
* **HTTP Spoofing:** More language permutations [[230] -> [4105],](https://github.com/hinto-janaiyo/monero-bash/blob/main/docs/fake_http_headers/language) more referers [[5] -> [10]](https://github.com/hinto-janaiyo/monero-bash/blob/main/docs/fake_http_headers/referer)
* **Price:** Added `XMR<->Cryptocurrency`, `Day High`, `Day Low`, and `Day Change %` to `monero-bash price`
* **Watch:** Spacing is auto-adjusted on terminal size changes
* **Status:** P2Pool stat calculation is slightly faster

## Fixes
* **Package manager:** The GitHub API returns 1-line JSON (sometimes) which causes parsing errors. This long standing issue was the cause of most update/upgrade failures, it is now fixed
* **HTTP Spoofing:** If `Accept-Encoding: gzip` is set, the data is now decompressed properly. This was also the cause of many update/upgrade errors when using fake headers
* **HTTP Spoofing:** Compressed data when using `Accept-Encoding: gzip` is now decompressed properly
* **HTTP Spoofing:** Only set once when upgrading multiple packages
* **Status:** Fixed P2Pool `x/hour, x/day` math

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ TOR_QUIET Silence Tor set-up messages
monero-bash has options to spoof the HTTP headers sent during connections such that you blend in with web-browsers. Options in [`monero-bash.conf`](https://github.com/hinto-janaiyo/monero-bash/blob/main/config/monero-bash.conf):
```
FAKE_HTTP_HEADERS Send random (weighted) browser-like HTTP headers instead of [Wget/VERSION]
TOR_BROWSER_MIMIC Mimic the HTTP headers that [Tor browser] uses/sends
TOR_BROWSER_MIMIC Mimic the HTTP headers that [Tor browser] uses
ONLY_USER_AGENT Only send a random [User-Agent] instead of all the normal HTTP headers
ONLY_WGET_CURL Only use random [2016-2022] versions of Wget/Curl as the User-Agent
HTTP_HEADERS_VERBOSE Print the HTTP headers selected before making a connection
Expand All @@ -341,11 +341,11 @@ For transparency and ease-of-mind, here's all the connections `monero-bash` make
| Domain | Why | When | Where |
|--------------------------|-------------------------------------------------------------------------------------------|------|-------|
| https://github.com | Fetching metadata information on packages + Tar/hash/signature/key download | `monero-bash update`, `monero-bash upgrade` | [`download.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/download.sh) [`eol.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/eol.sh) [`gpg.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/gpg.sh) [`verify.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/verify.sh) [`version.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/version.sh)
| https://getmonero.org | Tar/hash/signature/key download specifically for Monero (not hosted on GitHub) | When `upgrading` Monero | Same as above
| https://cryptocompare.com | XMR fiat price data | `monero-bash price` | [`price.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/price.sh)
| https://getmonero.org | Tar/hash/signature/key download specifically for Monero (not hosted on GitHub) | When upgrading Monero | Same as above
| https://cryptocompare.com | XMR price data | `monero-bash price` | [`price.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/price.sh)
| https://torproject.com | Test Tor connection + Get exit IP | `monero-bash tor` or when using any internet-related command with `TEST_TOR` enabled | [`torsocks.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/torsocks.sh)
| RPC | Monero RPC calls, the IP given in `DAEMON_RPC_IP` will be contacted | `monero-bash rpc` | [`rpc.sh`](https://github.com/hinto-janaiyo/monero-bash/blob/main/src/func/rpc.sh)
| DNS | DNS connections will usually be handled by your OS (or whatever custom DNS setup you have). If using Tor, the `torsocks` wrapper will route all DNS requests through the Tor network automatically | Any internet-related command when DNS isn't already cached | All of the above files
| DNS | DNS connections will usually be handled by your OS (or whatever custom DNS setup you have). If using Tor, the `torsocks` wrapper will route all DNS requests through the Tor network automatically | Any internet-related command when DNS isn't already cached | All of the above

## FAQ
<details>
Expand Down Expand Up @@ -546,7 +546,7 @@ The full list monero-bash uses (including more than just User-Agents) can be fou
</details>

<details>
<summary>Where are the 'monero-bash seed' mnemonics sourced from?</summary>
<summary>Where are the [monero-bash seed] mnemonics sourced from?</summary>

---

Expand Down
3 changes: 2 additions & 1 deletion config/monero-bash.conf
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ WATCH_REFRESH_RATE=1
#ONLY_USER_AGENT=true

## Rather than browser-like User-Agents, use randomly selected [2016-2022]
## versions of Wget/Curl. This is always enabled when using [monero-bash rpc].
## versions of Wget/Curl. This and [ONLY_USER_AGENT] are always enabled when
## sending a non-local Monero RPC call with [monero-bash rpc].
## USAGE: [true|false]
#ONLY_WGET_CURL=true

Expand Down
19 changes: 14 additions & 5 deletions src/func/gpg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@ gpg_import_Template()
{
local LOCAL="$(cat "$installDirectory/gpg/${GPG_OWNER}.asc")"
if [[ $USE_TOR = true ]]; then
local ONLINE="$(torsocks_func wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -qO- "$GPG_PUB_KEY")"
if [[ $WGET_GZIP = true ]]; then
local ONLINE="$(torsocks_func wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -qO- "$GPG_PUB_KEY" | gzip -d)"
else
local ONLINE="$(torsocks_func wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -qO- "$GPG_PUB_KEY")"
fi
else
local ONLINE="$(wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -qO- "$GPG_PUB_KEY")"
if [[ $WGET_GZIP = true ]]; then
local ONLINE="$(wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -qO- "$GPG_PUB_KEY" | gzip -d)"
else
local ONLINE="$(wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -qO- "$GPG_PUB_KEY")"
fi
fi
if [[ "$LOCAL" = "$ONLINE" ]]; then
code_Wget
if [[ $LOCAL = "$ONLINE" ]]; then
gpg --import "$installDirectory/gpg/${GPG_OWNER}.asc"
else
gpg_Diff
Expand Down Expand Up @@ -134,13 +143,13 @@ gpg_Overwrite()
trap "trap_Hash" 1 2 3 6 15
if [[ $USE_TOR = true ]]; then
if [[ $WGET_GZIP = true ]]; then
torsocks_func wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -q -O "$installDirectory/gpg/${GPG_OWNER}.asc" "$GPG_PUB_KEY"
torsocks_func wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -q -O "$installDirectory/gpg/${GPG_OWNER}.asc" "$GPG_PUB_KEY" | gzip -d
else
torsocks_func wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -q -O "$installDirectory/gpg/${GPG_OWNER}.asc" "$GPG_PUB_KEY"
fi
else
if [[ $WGET_GZIP = true ]]; then
wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -q -O "$installDirectory/gpg/${GPG_OWNER}.asc" "$GPG_PUB_KEY"
wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -q -O "$installDirectory/gpg/${GPG_OWNER}.asc" "$GPG_PUB_KEY" | gzip -d
else
wget "${WGET_HTTP_HEADERS[@]}" -e robots=off -q -O "$installDirectory/gpg/${GPG_OWNER}.asc" "$GPG_PUB_KEY"
fi
Expand Down
81 changes: 74 additions & 7 deletions src/func/price.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,88 @@ price_Check()
{
[[ $USE_TOR = true ]] && torsocks_init || prompt_PriceAPI_IP
[[ $FAKE_HTTP_HEADERS = true ]] && header_Random
BRED; echo "--- XMR fiat price ---" ;OFF
local PRICE LINK="https://min-api.cryptocompare.com/data/pricemultifull?fsyms=XMR&tsyms=USD,EUR,JPY,GBP,CHF,CAD,AUD,ZAR,BTC,ETH,BCH,ZEC,BNB,XRP,ADA,SOL,DOT,DOGE,TRX,ETC,LTC,LINK,XLM,ALGO"
# use TOR if enabled
if [[ $USE_TOR = true ]]; then
if [[ $WGET_GZIP = true ]]; then
local PRICE=$(torsocks_func wget -qO- "${WGET_HTTP_HEADERS[@]}" -e robots=off "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD,EUR,JPY,GBP,CHF,CAD,AUD,ZAR" | gzip -d)
PRICE=$(torsocks_func wget -qO- "${WGET_HTTP_HEADERS[@]}" -e robots=off "$LINK" | gzip -d)
code_Wget
else
local PRICE=$(torsocks_func wget -qO- "${WGET_HTTP_HEADERS[@]}" -e robots=off "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD,EUR,JPY,GBP,CHF,CAD,AUD,ZAR" | gzip -d)
PRICE=$(torsocks_func wget -qO- "${WGET_HTTP_HEADERS[@]}" -e robots=off "$LINK")
code_Wget
fi
else
if [[ $WGET_GZIP = true ]]; then
local PRICE=$(wget -qO- "${WGET_HTTP_HEADERS[@]}" -e robots=off "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD,EUR,JPY,GBP,CHF,CAD,AUD,ZAR" | gzip -d)
PRICE=$(wget -qO- "${WGET_HTTP_HEADERS[@]}" -e robots=off "$LINK" | gzip -d)
code_Wget
else
local PRICE=$(wget -qO- "${WGET_HTTP_HEADERS[@]}" -e robots=off "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD,EUR,JPY,GBP,CHF,CAD,AUD,ZAR")
PRICE=$(wget -qO- "${WGET_HTTP_HEADERS[@]}" -e robots=off "$LINK")
code_Wget
fi
fi
# filter
echo $PRICE | tr -d "{\"}" | tr "," "\n" | sed 's/:/ | /g'
# declare JSON values into variables
local $(echo "$PRICE" | json::var | grep "RAW.*PRICE\|RAW.*HIGHDAY\|RAW.*LOWDAY\|RAW.*CHANGEPCTDAY\|RAW_XMR_USD_LASTUPDATE\|RAW_XMR_BTC_LASTUPDATE")
# timestamp conversion
RAW_XMR_USD_LASTUPDATE=$(printf "%(%F %T)T" "$RAW_XMR_USD_LASTUPDATE")
RAW_XMR_BTC_LASTUPDATE=$(printf "%(%F %T)T" "$RAW_XMR_BTC_LASTUPDATE")
# fiat
local FIAT=$(\
printf "%s${BWHITE}${UWHITE}%s${OFF}%s\n" \
"| " "Fiat Currency | Symbol | Price | Day High | Day Low | Day Change %" " |"
printf "%s\n" \
"| United States Dollar | USD | ${RAW_XMR_USD_PRICE:0:7} | ${RAW_XMR_USD_HIGHDAY:0:7} | ${RAW_XMR_USD_LOWDAY:0:7} | ${RAW_XMR_USD_CHANGEPCTDAY:0:5}% |" \
"| Great British Pound | GBP | ${RAW_XMR_GBP_PRICE:0:7} | ${RAW_XMR_GBP_HIGHDAY:0:7} | ${RAW_XMR_GBP_LOWDAY:0:7} | ${RAW_XMR_GBP_CHANGEPCTDAY:0:5}% |" \
"| European Euro | EUR | ${RAW_XMR_EUR_PRICE:0:7} | ${RAW_XMR_EUR_HIGHDAY:0:7} | ${RAW_XMR_EUR_LOWDAY:0:7} | ${RAW_XMR_EUR_CHANGEPCTDAY:0:5}% |" \
"| Japanese Yen | JPY | ${RAW_XMR_JPY_PRICE:0:7} | ${RAW_XMR_JPY_HIGHDAY:0:7} | ${RAW_XMR_JPY_LOWDAY:0:7} | ${RAW_XMR_JPY_CHANGEPCTDAY:0:5}% |" \
"| Swiss Franc | CHF | ${RAW_XMR_CHF_PRICE:0:7} | ${RAW_XMR_CHF_HIGHDAY:0:7} | ${RAW_XMR_CHF_LOWDAY:0:7} | ${RAW_XMR_CHF_CHANGEPCTDAY:0:5}% |" \
"| Canadian Dollar | CAD | ${RAW_XMR_CAD_PRICE:0:7} | ${RAW_XMR_CAD_HIGHDAY:0:7} | ${RAW_XMR_CAD_LOWDAY:0:7} | ${RAW_XMR_CAD_CHANGEPCTDAY:0:5}% |" \
"| Australian Dollar | AUD | ${RAW_XMR_AUD_PRICE:0:7} | ${RAW_XMR_AUD_HIGHDAY:0:7} | ${RAW_XMR_AUD_LOWDAY:0:7} | ${RAW_XMR_AUD_CHANGEPCTDAY:0:5}% |" \
"| South African Rand | ZAR | ${RAW_XMR_ZAR_PRICE:0:7} | ${RAW_XMR_ZAR_HIGHDAY:0:7} | ${RAW_XMR_ZAR_LOWDAY:0:7} | ${RAW_XMR_ZAR_CHANGEPCTDAY:0:5}% |")
# cryptocurrency
CRYPTO=$(\
printf "%s${BWHITE}${UWHITE}%s${OFF}%s\n" \
"| " "Cryptocurrency | Symbol | Price | Day High | Day Low | Day Change %" " |"
printf "%s\n" \
"| Bitcoin | BTC | ${RAW_XMR_BTC_PRICE:0:7} | ${RAW_XMR_BTC_HIGHDAY:0:7} | ${RAW_XMR_BTC_LOWDAY:0:7} | ${RAW_XMR_BTC_CHANGEPCTDAY:0:5}% |" \
"| Ethereum | ETH | ${RAW_XMR_ETH_PRICE:0:7} | ${RAW_XMR_ETH_HIGHDAY:0:7} | ${RAW_XMR_ETH_LOWDAY:0:7} | ${RAW_XMR_ETH_CHANGEPCTDAY:0:5}% |" \
"| BNB | BNB | ${RAW_XMR_BNB_PRICE:0:7} | ${RAW_XMR_BNB_HIGHDAY:0:7} | ${RAW_XMR_BNB_LOWDAY:0:7} | ${RAW_XMR_BNB_CHANGEPCTDAY:0:5}% |" \
"| Ripple | XRP | ${RAW_XMR_XRP_PRICE:0:7} | ${RAW_XMR_XRP_HIGHDAY:0:7} | ${RAW_XMR_XRP_LOWDAY:0:7} | ${RAW_XMR_XRP_CHANGEPCTDAY:0:5}% |" \
"| Cardano | ADA | ${RAW_XMR_ADA_PRICE:0:7} | ${RAW_XMR_ADA_HIGHDAY:0:7} | ${RAW_XMR_ADA_LOWDAY:0:7} | ${RAW_XMR_ADA_CHANGEPCTDAY:0:5}% |" \
"| Solana | SOL | ${RAW_XMR_SOL_PRICE:0:7} | ${RAW_XMR_SOL_HIGHDAY:0:7} | ${RAW_XMR_SOL_LOWDAY:0:7} | ${RAW_XMR_SOL_CHANGEPCTDAY:0:5}% |" \
"| Polkadot | DOT | ${RAW_XMR_DOT_PRICE:0:7} | ${RAW_XMR_DOT_HIGHDAY:0:7} | ${RAW_XMR_DOT_LOWDAY:0:7} | ${RAW_XMR_DOT_CHANGEPCTDAY:0:5}% |" \
"| Dogecoin | DOGE | ${RAW_XMR_DOGE_PRICE:0:7} | ${RAW_XMR_DOGE_HIGHDAY:0:7} | ${RAW_XMR_DOGE_LOWDAY:0:7} | ${RAW_XMR_DOGE_CHANGEPCTDAY:0:5}% |" \
"| TRON | TRX | ${RAW_XMR_TRX_PRICE:0:7} | ${RAW_XMR_TRX_HIGHDAY:0:7} | ${RAW_XMR_TRX_LOWDAY:0:7} | ${RAW_XMR_TRX_CHANGEPCTDAY:0:5}% |" \
"| Ethereum Classic | ETC | ${RAW_XMR_ETC_PRICE:0:7} | ${RAW_XMR_ETC_HIGHDAY:0:7} | ${RAW_XMR_ETC_LOWDAY:0:7} | ${RAW_XMR_ETC_CHANGEPCTDAY:0:5}% |" \
"| Litecoin | LTC | ${RAW_XMR_LTC_PRICE:0:7} | ${RAW_XMR_LTC_HIGHDAY:0:7} | ${RAW_XMR_LTC_LOWDAY:0:7} | ${RAW_XMR_LTC_CHANGEPCTDAY:0:5}% |" \
"| Chainlink | LINK | ${RAW_XMR_LINK_PRICE:0:7} | ${RAW_XMR_LINK_HIGHDAY:0:7} | ${RAW_XMR_LINK_LOWDAY:0:7} | ${RAW_XMR_LINK_CHANGEPCTDAY:0:5}% |" \
"| Stellar | XLM | ${RAW_XMR_XLM_PRICE:0:7} | ${RAW_XMR_XLM_HIGHDAY:0:7} | ${RAW_XMR_XLM_LOWDAY:0:7} | ${RAW_XMR_XLM_CHANGEPCTDAY:0:5}% |" \
"| Bitcoin Cash | BCH | ${RAW_XMR_BCH_PRICE:0:7} | ${RAW_XMR_BCH_HIGHDAY:0:7} | ${RAW_XMR_BCH_LOWDAY:0:7} | ${RAW_XMR_BCH_CHANGEPCTDAY:0:5}% |" \
"| Algorand | ALGO | ${RAW_XMR_ALGO_PRICE:0:7} | ${RAW_XMR_ALGO_HIGHDAY:0:7} | ${RAW_XMR_ALGO_LOWDAY:0:7} | ${RAW_XMR_ALGO_CHANGEPCTDAY:0:5}% |" \
"| ZCash | ZEC | ${RAW_XMR_ZEC_PRICE:0:7} | ${RAW_XMR_ZEC_HIGHDAY:0:7} | ${RAW_XMR_ZEC_LOWDAY:0:7} | ${RAW_XMR_ZEC_CHANGEPCTDAY:0:5}% |")
# Stupid stupid stupid Ubuntu comes with BSD's [column]
# so [-o] doesn't work. This doesn't even make sense,
# Ubuntu is mostly GNU/util-linux userspace but for certain
# programs it has the BSD versions? I thought this was maybe
# inherited from Debian but even Debian has [util-linux's] version.
# Why why why why why Ubuntu.

# Instead of specifically testing for [x] distro,
# just test to see if the [column -o] option works.
if echo "Why Ubuntu" | column -o -t &>/dev/null; then
printf "${BRED}%s${OFF}\n" "[XMR <-> Fiat] <$RAW_XMR_USD_LASTUPDATE>"
printf "%s\n" "|-----------------------------------------------------------------------------|"
echo -e "$FIAT" | column -t -s '|' -o '|'
printf "%s\n" "|-----------------------------------------------------------------------------|"
echo
printf "${BRED}%s${OFF}\n" "[XMR <-> Cryptocurrency] <$RAW_XMR_BTC_LASTUPDATE>"
printf "%s\n" "|---------------------------------------------------------------------------|"
echo -e "$CRYPTO" | column -t -s '|' -o '|'
printf "%s\n" "|---------------------------------------------------------------------------|"
else
printf "${BRED}%s${OFF}\n" "[XMR <-> Fiat] <$RAW_XMR_USD_LASTUPDATE>"
echo -e "$FIAT" | column -t -s '|'
echo
printf "${BRED}%s${OFF}\n" "[XMR <-> Cryptocurrency] <$RAW_XMR_BTC_LASTUPDATE>"
echo -e "$CRYPTO" | column -t -s '|'
fi
}
4 changes: 2 additions & 2 deletions src/func/status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ status_Template()
BGREEN; echo "ONLINE" ;OFF

# ps stats
ps -o "| %C | %t |" -p $PROCESS_ID
echo "----------------------"
ps -o "| %C | %t | %p" -p $PROCESS_ID
echo "--------------------------------"
# process specific stats
EXTRA_STATS
printf "\n"
Expand Down
Loading

0 comments on commit 86e56b3

Please sign in to comment.