-
Notifications
You must be signed in to change notification settings - Fork 3
/
pwpush
executable file
·50 lines (42 loc) · 1.58 KB
/
pwpush
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
__author__ = 'Adam Kierstein'
__copyright__ = ''
__credits__ = []
__license__ = ''
__version__ = '1.1'
__maintainer__ = '[email protected]'
__email__ = '[email protected]'
__status__ = 'published'
'''
import argparse
import requests
import secrets
import string
import json
def autogen_pw():
alphabet = string.ascii_letters + string.digits + string.punctuation
password = ''.join(secrets.choice(alphabet)
for i in range(20)) # for a 20-character password
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())
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()
payload = {
'password[payload]': args.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'URL: {args.url}/p/{r_response}')