Skip to content

Commit

Permalink
Merge pull request #1 from codaqui/feat/improve-and-create
Browse files Browse the repository at this point in the history
docs(README): 📝 try use only one README.md
  • Loading branch information
endersonmenezes authored Oct 24, 2023
2 parents 3bf00cf + 0f230bb commit 3f13d19
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 51 deletions.
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
## 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.
🇺🇸 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)

🇧🇷 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 o Piping Server [aqui](https://github.com/nwtgck/piping-server/tree/develop)

### Prerequisites

Make sure you have installed the following dependencies:
🇺🇸 Make sure you have installed the following dependencies:

🇧🇷 Certifique-se de ter instalado as seguintes dependências:

- `curl`
- `yq`
- `uuidgen`
- `curl`
- `yq`
- `uuidgen`
- `pbcopy`

If not install them by using your package manager (Pacman, APT, Yum, etc).
🇺🇸 If not install them by using your package manager (Pacman, APT, Yum, etc).

You will need a Piping Server, you can use ours:

🇧🇷 Se não, instale-os usando seu gerenciador de pacotes (Pacman, APT, Yum, etc).

Você precisará de um Piping Server, você pode usar o nosso:

- `https://ping.enderson.dev`


### Usage

After installation, run the script by executing it in the terminal using:
🇺🇸 After installation, run the script by executing it in the terminal using:

🇧🇷 Após a instalação, execute o script executando-o no terminal usando:

```bash
bash main.sh
Expand Down
33 changes: 0 additions & 33 deletions README_pt.md

This file was deleted.

92 changes: 83 additions & 9 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,43 @@ function test_is_a_piping_server(){
fi
}

function generate_secret(){
secret_length=$1
secret_type=$2
char_set=""
if [[ $secret_type == *"l"* ]]; then
char_set="${char_set}abcdefghijklmnopqrstuvwxyz"
fi
if [[ $secret_type == *"u"* ]]; then
char_set="${char_set}ABCDEFGHIJKLMNOPQRSTUVWXYZ"
fi
if [[ $secret_type == *"n"* ]]; then
char_set="${char_set}0123456789"
fi
if [[ $secret_type == *"s"* ]]; then
char_set="${char_set}!@#$%^&*_-+="
fi
secret=""
for i in $(seq 1 $secret_length)
do
secret+=${char_set:RANDOM%${#char_set}:1}
done
echo $secret
}

function generate_secret_on_server(){
piping_server_url=$1
secret=$2
RANDOM_UUID=$(uuidgen)
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"
log "The secret will be available on your local clipboard"
echo $secret | pbcopy
}

## Verify Dependencies

Expand All @@ -72,6 +109,12 @@ if ! type uuidgen > /dev/null 2>&1; then
exit 1
fi

# Check if "pbcopy" exists
if ! type pbcopy > /dev/null 2>&1; then
log_error "pbcopy command is required. Please install pbcopy."
exit 1
fi

# Check if config.yaml exists
if [ ! -e config.yaml ]; then
setup
Expand All @@ -91,29 +134,60 @@ 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 "1) Share a Secret"
log "2) Generate and Share a Secret"
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
# Check if secret is empty
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"
generate_secret_on_server $piping_server_url $secret
exit 0
elif [ "$option" = "2" ]; then
RANDOM_UUID=$(uuidgen)
log "How many characters do you want in the secret? (Press enter to use default)"
log "Default: 16"
read secret_length

# Check if secret_length is empty
if [ -z "$secret_length" ]; then
secret_length=16
fi

log "What type of characters do you want in the secret? (Press enter to use default)"
log "Default: luns"
log "l: lowercase"
log "u: uppercase"
log "n: numbers"
log "s: symbols"
read secret_type

# Check if secret_type is empty
if [ -z "$secret_type" ]; then
secret_type="luns"
fi

# Check if secret_type is valid
if [[ ! $secret_type =~ ^[luns]+$ ]]; then
log_error "Invalid secret type"
exit 1
fi

# Generate a secret
log "Generating a secret"
secret=$(generate_secret $secret_length $secret_type)

# Generate a secret on server
generate_secret_on_server $piping_server_url $secret
else
log "Bye!"
exit 0
Expand Down

0 comments on commit 3f13d19

Please sign in to comment.