-
Notifications
You must be signed in to change notification settings - Fork 0
/
DKAPinit.py
38 lines (34 loc) · 2.25 KB
/
DKAPinit.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
import os
import sys
import subprocess
def initCheck():
user_profile = os.environ["USERPROFILE"]
if os.path.isdir(os.environ["USERPROFILE"] + "\\.ssh\\DKAP"): # create folder to house DKAP managed data
print("DKAP folder exists.")
else:
try:
print("Creating DKAP folder at " + os.environ["USERPROFILE"] + "\\.ssh\\DKAP")
cmd = "mkdir \"" + os.environ["USERPROFILE"] + "\\.ssh\\DKAP\"" # HOME variable, really
subprocess.run(cmd, shell=True, check=True) # stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL for silent error, silent run
except subprocess.CalledProcessError:
print("DKAP folder creation failed. Insufficient permissions? Application will now exit.")
sys.exit(1)
if os.path.isdir(os.environ["USERPROFILE"] + "\\.ssh\\authorized_keys"): # create folder to house authorised pubkeys (people who can ssh to this machine)
print("authorized_keys folder exists.") # SSH standard folder (https://security.stackexchange.com/questions/20706/what-is-the-difference-between-authorized-keys-and-known-hosts-file-for-ssh)
else:
try:
print("Creating authorized_keys folder at " + os.environ["USERPROFILE"] + "\\.ssh\\authorized_keys")
cmd = "mkdir \"" + os.environ["USERPROFILE"] + "\\.ssh\\authorized_keys\"" # HOME variable, really
subprocess.run(cmd, shell=True, check=True) # stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL for silent error, silent run
except subprocess.CalledProcessError:
print("authorized_keys folder creation failed. Insufficient permissions? Application will now exit.")
sys.exit(1)
if os.path.isfile("\"" + os.environ["USERPROFILE"] + "\\.ssh\\DKAP\\register.txt\""): # create file to track which pubkeys are managed by DKAP, there may be sshkeys that are not DKAP's business
print("DKAP register exists.")
else:
try:
cmd = "type NUL > \"" + os.environ["USERPROFILE"] + "\\.ssh\\DKAP\\register.txt\""
subprocess.run(cmd, shell=True, check=True)
except subprocess.CalledProcessError:
print("DKAP register creation failed. Insufficient permissions? Application will now exit.")
sys.exit(1)