0
|
1 #!/usr/bin/env python3
|
|
2 import os
|
|
3 import glob
|
|
4 import time
|
|
5 import base64
|
|
6 import argparse
|
|
7
|
|
8 originalApiServer = 'app.pritunl.com'
|
|
9 originalAuthServer = 'auth.pritunl.com'
|
|
10 defaultApiServer = 'pritunl-api.simonmicro.de'
|
|
11 searchIn = [*glob.glob('/usr/lib/python3*'), '/usr/lib/pritunl/', '/usr/share/pritunl/www/', '/usr/lib/pritunl/', '/usr/share/pritunl/www/']
|
|
12
|
|
13 print(" ____ _ _ _ _____ _ _ ____ ___ ")
|
|
14 print(" | _ \ _ __(_) |_ _ _ _ __ | | | ___|_ _| | _____ / \ | _ \_ _|")
|
|
15 print(" | |_) | '__| | __| | | | '_ \| | | |_ / _` | |/ / _ \ / _ \ | |_) | | ")
|
|
16 print(" | __/| | | | |_| |_| | | | | | | _| (_| | < __/ / ___ \| __/| | ")
|
|
17 print(" |_| |_| |_|\__|\__,_|_| |_|_| |_| \__,_|_|\_\___| /_/ \_\_| |___|")
|
|
18 print(" ")
|
|
19
|
|
20 sel = None
|
|
21 interactive = True
|
|
22 parser = argparse.ArgumentParser()
|
|
23 parser.add_argument('--install', type=str, default='DEFAULT', nargs='?', help='Do not ask and install new API endpoint.')
|
|
24 parser.add_argument('--reset', type=str, default='DEFAULT', nargs='?', help='Do not ask and remove new API endpoint.')
|
|
25 parser.add_argument('--api-server', type=str, default=defaultApiServer, help='Set new API server.')
|
|
26 args = parser.parse_args()
|
|
27
|
|
28 newApiServer = args.api_server if args.api_server.strip() != '' else defaultApiServer
|
|
29 if args.install != 'DEFAULT':
|
|
30 interactive = False
|
|
31 newApiServer = args.install if args.install is not None else newApiServer
|
|
32 sel = 'I'
|
|
33 if args.reset != 'DEFAULT':
|
|
34 interactive = False
|
|
35 newApiServer = args.reset if args.reset is not None else newApiServer
|
|
36 sel = 'R'
|
|
37
|
|
38 if interactive:
|
|
39 while sel not in ['I', 'R', 'B', 'Q']:
|
|
40 sel = input('[I]nstall, [R]eset, [B]uy Pritunl, [Q]uit? ').upper()
|
|
41 print()
|
|
42
|
|
43 def doTheReplace(fromApiStr, toApiStr, fromAuthStr, toAuthStr):
|
|
44 print(f'Okay. We will change "{fromApiStr}" to "{toApiStr}" and "{fromAuthStr}" to "{toAuthStr}" now...')
|
|
45 numFiles = 0
|
|
46 for i in range(len(searchIn)):
|
|
47 print(f'[{i+1}/{len(searchIn)}] Replacing in {searchIn[i]}...')
|
|
48 for p, d, f in os.walk(searchIn[i]):
|
|
49 for ff in f:
|
|
50 try:
|
|
51 fh = open(os.path.join(p, ff), 'r')
|
|
52 lines = fh.read()
|
|
53 fh.close()
|
|
54 newLines = lines.replace(fromApiStr, toApiStr)
|
|
55 newLines = newLines.replace(fromAuthStr, toAuthStr)
|
|
56 # Special case for changes from c1772d9b3268f91de409ad552e3d4d54d5ae1125
|
|
57 newLines = newLines.replace(base64.b64encode(f'https://{fromApiStr}/subscription'.encode()).decode(), base64.b64encode(f'https://{toApiStr}/subscription'.encode()).decode())
|
|
58 if newLines != lines:
|
|
59 numFiles += 1
|
|
60 fh = open(os.path.join(p, ff), 'w')
|
|
61 fh.writelines(newLines)
|
|
62 fh.close()
|
|
63 except UnicodeDecodeError:
|
|
64 # Brrr - binary files...
|
|
65 pass
|
|
66 print(f'Modified {numFiles} files in {len(searchIn)} paths.')
|
|
67
|
|
68 if sel == 'I':
|
|
69 if interactive:
|
|
70 print(f'By default, the Pritunl API endpoint is hosted at "{originalApiServer}".')
|
|
71 print(f'In case you want to use your own instance, you also have to support HTTPS!')
|
|
72 print(f'Note, that the SSO implementation of Pritunl is hosted at their servers (closed source) and will just be "disabled".')
|
|
73 ownApiServer = input(f'Please enter the new API endpoint [{newApiServer}]: ')
|
|
74 if ownApiServer == '':
|
|
75 ownApiServer = newApiServer
|
|
76 else:
|
|
77 ownApiServer = newApiServer
|
|
78 doTheReplace(originalApiServer, ownApiServer, originalAuthServer, ownApiServer + '/auth/')
|
|
79 print('Please make sure to restart the Pritunl daemon now and please support the developer.')
|
|
80 elif sel == 'R':
|
|
81 if interactive:
|
|
82 print(f'To properly revert any changes to your Pritunl server, this script must exactly know what (custom) API endpoint you have choosen.')
|
|
83 ownApiServer = input(f'Please enter the current API endpoint [{newApiServer}]: ')
|
|
84 if ownApiServer == '':
|
|
85 ownApiServer = newApiServer
|
|
86 print('Make sure to REMOVE ANY FAKED SUBSCRIPTION KEY (by not entering an other command - just remove them). You have now 30 seconds time to hit CTRL+C and do this.')
|
|
87 time.sleep(30)
|
|
88 else:
|
|
89 ownApiServer = newApiServer
|
|
90 doTheReplace(ownApiServer, originalApiServer, ownApiServer + '/auth/', originalAuthServer)
|
|
91 print('Please make sure to restart the Pritunl daemon now.')
|
|
92 elif sel == 'B':
|
|
93 print('Sure thing, buddy... Why did you try to use this?')
|
|
94 print('Visit https://pritunl.com/ for you own license!')
|
|
95 try:
|
|
96 import webbrowser
|
|
97 webbrowser.open('https://pritunl.com/')
|
|
98 print('Let me help you...')
|
|
99 except:
|
|
100 pass
|
|
101 elif sel == 'Q':
|
|
102 print('Bye!')
|