Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ If no password argument is given, a 20 character password comprised of letters,
### Usage:

```
usage: pwpush [-h] [-u URL] [-p PASSWORD] [-d DAYS] [-v VIEWS]
usage: pwpush [-h] [-u URL] [-p PASSWORD] [-l LENGTH] [-d DAYS] [-v VIEWS]

Accept a password from stdin.

optional arguments:
options:
-h, --help show this help message and exit
-u URL, --url URL Optional: Specify the URL of a local pwpush instance. ex: pwpush -u https://foobar.com
-p PASSWORD, --password PASSWORD
Optional: User defined password.
-l LENGTH, --length LENGTH
Optional: Length of auto-generated password. Ignored if password argument already provided.
-d DAYS, --days DAYS Optional: Specify the amount of days after which the password should expire.
-v VIEWS, --views VIEWS
Optional: Specify the amount of views after which the password should expire.
Expand All @@ -29,4 +31,13 @@ URL: https://pwpush.com/p/tkfrluql1hi0f6qt
> ./pwpush -p foobar -u http://localhost:5100 -v 5
Pass is: foobar
URL: http://localhost:5100/p/630thim25imnm2x1

# -l is ignored since -p takes precedence
> ./pwpush -l 10 -p africanswallow
Pass is: africanswallow
URL: https://pwpush.com/p/zynqhemqkyvxi4q

> ./pwpush -l 10
Pass is: 0ezR.)cwg,
URL: https://pwpush.com/p/9ylhw57z4_qywugmqw
```
14 changes: 9 additions & 5 deletions pwpush
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,36 @@ import string
import json


def autogen_pw():
def autogen_pw(length):
alphabet = string.ascii_letters + string.digits + string.punctuation
password = ''.join(secrets.choice(alphabet)
for i in range(20)) # for a 20-character password
for _ in range(length))
return password


parser = argparse.ArgumentParser(description='Accept a password from stdin.')
parser.add_argument('-u', '--url', type=str,
help="Optional: Specify the URL of a local pwpush instance. ex: pwpush -u https://foobar.com", default="https://pwpush.com")
parser.add_argument('-p', '--password', type=str,
help="Optional: User defined password.", default=autogen_pw())
help="Optional: User defined password.")
parser.add_argument('-l', '--length', type=int, default=20,
help="Optional: Length of auto-generated password. Ignored if password argument already provided.")
parser.add_argument('-d', '--days', type=int,
help="Optional: Specify the amount of days after which the password should expire.", default=2)
parser.add_argument('-v', '--views', type=int,
help="Optional: Specify the amount of views after which the password should expire.", default=10)
args = parser.parse_args()

password = args.password or autogen_pw(args.length)

payload = {
'password[payload]': args.password,
'password[payload]': password,
'password[expire_after_days]': args.days,
'password[expire_after_views]': args.views
}
r = requests.post(f"{args.url}/p.json", data=payload)
r_response = json.loads(r.content)['url_token']

# Console output
print(f'Pass is: {args.password}')
print(f'Pass is: {password}')
print(f'URL: {args.url}/p/{r_response}')