-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): ✨ create a secret sharing cli on piping servers
- Loading branch information
0 parents
commit 2beb16b
Showing
5 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## Secret Sharing | ||
|
||
[README in Portuguese](README_pt.md) | ||
|
||
# Piping Server Secret Sharing Script | ||
|
||
This script is a utility for creating and sharing secrets through Piping Server. The created secret is temporary and can be only accessed once. | ||
|
||
You can know more about Piping Server [here](https://github.com/nwtgck/piping-server/tree/develop) | ||
|
||
### Prerequisites | ||
|
||
Make sure you have installed the following dependencies: | ||
|
||
- `curl` | ||
- `yq` | ||
- `uuidgen` | ||
|
||
If not install them by using your package manager (Pacman, APT, Yum, etc). | ||
|
||
You will need a Piping Server, you can use ours: | ||
|
||
- `https://ping.enderson.dev` | ||
|
||
### Usage | ||
|
||
After installation, run the script by executing it in the terminal using: | ||
|
||
```bash | ||
bash main.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## Compartilhamento de Segredos | ||
|
||
[README em Inglês](README.md) | ||
|
||
# Script de Compartilhamento de Segredos do Piping Server | ||
|
||
Este script é uma utilidade para criar e compartilhar segredos através do Piping Server. O segredo criado é temporário e só pode ser acessado uma vez. | ||
|
||
Você pode saber mais sobre Piping Server [aqui](https://github.com/nwtgck/piping-server/tree/develop) | ||
|
||
### Pré-requisitos | ||
|
||
Certifique-se de ter instalado as seguintes dependências: | ||
|
||
- `curl` | ||
- `yq` | ||
- `uuidgen` | ||
|
||
Caso contrário, instale-os usando o gerenciador de pacotes (Pacman, APT, Yum, etc). | ||
|
||
Você irá precisar de um Piping Server, você pode usar o nosso: | ||
|
||
- `https://ping.enderson.dev` | ||
|
||
### Uso | ||
|
||
Após a instalação, execute o script no terminal usando: | ||
|
||
```bash | ||
bash main.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/bin/bash | ||
|
||
## | ||
# https://github.com/nwtgck/piping-server/tree/develop | ||
# Secret Sharing for Piping Server | ||
## | ||
|
||
## Setup | ||
set -euo pipefail | ||
|
||
## Functions | ||
function log(){ | ||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $1" | ||
} | ||
|
||
function log_success(){ | ||
log "✅ $1" | ||
} | ||
|
||
function log_error(){ | ||
log "❌ $1" | ||
} | ||
|
||
function setup() { | ||
# Create config.yaml | ||
log "Create config.yaml" | ||
log "Whats is your piping server URL? (Press enter to use default)" | ||
log "Default: https://ping.enderson.dev" | ||
read piping_server_url | ||
if [ -z "$piping_server_url" ]; then | ||
piping_server_url="https://ping.enderson.dev" | ||
fi | ||
echo "piping_server_url: $piping_server_url" > config.yaml | ||
log_success "config.yaml created" | ||
} | ||
|
||
function test_is_a_piping_server(){ | ||
server_to_test=$1 | ||
# Check if the server is a piping server | ||
log "Check if the server is a piping server" | ||
RANDOM_UUID=$(uuidgen) | ||
RANDOM_TEXT="Hello, World! $RANDOM_UUID" | ||
# Execute a POST with timeout 10 seconds in background | ||
# The GET response should be the same as the POST | ||
curl -s -X POST -d "$RANDOM_TEXT" -m 10 "$server_to_test/$RANDOM_UUID" > /dev/null 2>&1 & \ | ||
if curl -s -m 10 "$server_to_test/$RANDOM_UUID" | grep "$RANDOM_TEXT" > /dev/null 2>&1; then | ||
log_success "The server is a piping server" | ||
else | ||
log_error "The server is not a piping server" | ||
exit 1 | ||
fi | ||
} | ||
|
||
|
||
## Verify Dependencies | ||
|
||
# Check if "curl" exists | ||
if ! type curl > /dev/null 2>&1; then | ||
log_error "curl command is required. Please install curl." | ||
exit 1 | ||
fi | ||
|
||
# Check if "yq" exists | ||
if ! type yq > /dev/null 2>&1; then | ||
log_error "yq command is required. Please install yq." | ||
exit 1 | ||
fi | ||
|
||
# Check if "uuidgen" exists | ||
if ! type uuidgen > /dev/null 2>&1; then | ||
log_error "uuidgen command is required. Please install uuidgen." | ||
exit 1 | ||
fi | ||
|
||
# Check if config.yaml exists | ||
if [ ! -e config.yaml ]; then | ||
setup | ||
fi | ||
|
||
# Begin | ||
VERSION=$(cat version) | ||
log "Starting a Secret Sharing for Piping Server v$VERSION" | ||
|
||
# Read config.yaml | ||
log "Reading config.yaml" | ||
piping_server_url=$(yq '.piping_server_url' config.yaml) | ||
log_success "piping_server_url: $piping_server_url" | ||
|
||
# Test if the server is a piping server | ||
test_is_a_piping_server $piping_server_url | ||
|
||
# Create a Menu | ||
log "Select an option:" | ||
log "1) Create a Secret" | ||
log "2) Put this script in your path" | ||
log "0) Exit" | ||
read option | ||
|
||
# Create a Secret | ||
if [ "$option" = "1" ]; then | ||
RANDOM_UUID=$(uuidgen) | ||
log "What is the secret? (Press enter to use default)" | ||
log "Default: Hello, World!" | ||
read secret | ||
if [ -z "$secret" ]; then | ||
secret="Hello, World!" | ||
fi | ||
# Make a post with the secret and a timeout of 60 seconds in background | ||
log "Making a secret" | ||
curl -s -X POST -d "$secret" -m 60 "$piping_server_url/$RANDOM_UUID" > /dev/null 2>&1 & \ | ||
log_success "Secret created successfully" | ||
log "Your secret is: $piping_server_url/$RANDOM_UUID" | ||
log "You can access with curl too:" | ||
log "curl -s $piping_server_url/$RANDOM_UUID" | ||
log "You can share this link with anyone, the person have 60 seconds to see the secret" | ||
exit 0 | ||
else | ||
log "Bye!" | ||
exit 0 | ||
fi | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 |