-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJellyguard.py
83 lines (74 loc) · 5.13 KB
/
Jellyguard.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from genericpath import exists
from time import sleep
import subprocess
import os
import glob
# Prerequisites: Wireguard installation on the systemdrive with the Windows install, imported tunnel in Wireguard, config file correctly pointed to the Jellyfin Media Player's executable, if it's not installed on the systemdrive or D: drive.
# Must be executed as admin, or Wireguard will lack the proper permissions.
# To install a jellyfin tunnel, preferably install the tunnel with the name 'Jellyfin' or 'jellyfin'.
# If the tunnel is not aptly named, it will grab and activate the first tunnel it finds.
# Which may or may not be the correct tunnel if several tunnels are installed.
#
# It will check for the systemdrive, which may or may not be C:
# And will then check to see if wireguard is installed under Program Files or Program Files (x86)
# If wireguard is not found, but installed in a different directory, reinstall it on the systemdrive first.
# If wireguard is not found, and is not installed yet, install wireguard on the systemdrive first.
#
# A config file will be placed in the userprofile's documents folder, when the app is first run, it will open the file for you to edit.
# Make sure to edit the Jellyfin Media Player's full .exe location in the file to be the correct location, as such, eg: C:\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe
# Save and exit the file, run Jellyguard again.
# If all conditions are met, it will launch successfully
if (exists(os.getenv("SystemDrive") + "\Program Files\WireGuard\wireguard.exe")):
wireguard = os.getenv("SystemDrive") + "\Program Files\WireGuard\\"
elif (exists(os.getenv("SystemDrive") + "\Program Files (x86)\WireGuard\wireguard.exe")):
wireguard = os.getenv("SystemDrive") + "\Program Files (x86)\WireGuard\\"
else:
exit(0)
if (glob.glob(wireguard + "Data\Configurations\*.conf.dpapi")):
if (glob.glob(wireguard + "Data\Configurations\*ellyfin.conf.dpapi")):
peer = str(glob.glob(wireguard + "Data\Configurations\*ellyfin.conf.dpapi")).split("\\")[-1].split(".")[0]
else:
peer = str(glob.glob(wireguard + "Data\Configurations\*.conf.dpapi")).split("\\")[-1].split(".")[0]
else:
exit(0)
if (exists(os.getenv("USERPROFILE") + "\Jellyguard\jg.conf")):
with open(os.getenv("USERPROFILE") + "\Jellyguard\jg.conf", "r") as config:
jellyfin = config.readline().strip()
config.close()
if not (exists(jellyfin)):
exit(0)
else:
if not (exists(os.getenv("USERPROFILE") + "\Jellyguard")):
os.makedirs(os.getenv("USERPROFILE") + "\Jellyguard")
if (exists(os.getenv("SystemDrive") + "\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe")):
with open(os.getenv("USERPROFILE") + "\Jellyguard\jg.conf", "w") as config:
config.write(os.getenv("SystemDrive") + "\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe")
config.close()
jellyfin = os.getenv("SystemDrive") + "\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe"
elif (exists(os.getenv("SystemDrive") + "\Program Files (x86)\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe")):
with open(os.getenv("USERPROFILE") + "\Jellyguard\jg.conf", "w") as config:
config.write(os.getenv("SystemDrive") + "\Program Files (x86)\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe")
config.close()
jellyfin = os.getenv("SystemDrive") + "\Program Files (x86)\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe"
elif (exists("D:\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe")):
with open(os.getenv("USERPROFILE") + "\Jellyguard\jg.conf", "w") as config:
config.write("D:\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe")
config.close()
jellyfin = "D:\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe"
elif (exists("D:\Program Files (x86)\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe")):
with open(os.getenv("USERPROFILE") + "\Jellyguard\jg.conf", "w") as config:
config.write("D:\Program Files (x86)\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe")
config.close()
jellyfin = "D:\Program Files (x86)\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe"
else:
with open(os.getenv("USERPROFILE") + "\Jellyguard\jg.conf", "w") as config:
config.write("C:\Program Files\Jellyfin\Jellyfin Media Player\JellyfinMediaPlayer.exe\n# The above filepath is an example filepath, please edit the filepath to the correct path of JellyfinMediaPlayer.exe\n# Then save this file, close notepad, and run Jellyguard again")
config.close()
sleep(2)
os.system("notepad.exe " + os.getenv("USERPROFILE") + "\Jellyguard\jg.conf")
exit(0)
subprocess.run([wireguard + "wireguard.exe", "/installtunnelservice", wireguard + "Data\Configurations\\" + peer + ".conf.dpapi"])
sleep(5)
subprocess.run([jellyfin])
sleep(2)
subprocess.run([wireguard+"wireguard.exe", "/uninstalltunnelservice", peer])