-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
39 lines (33 loc) · 1.04 KB
/
build.py
File metadata and controls
39 lines (33 loc) · 1.04 KB
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
import os
import sys
import hashlib
keys = {}
root = "./data/keys/"
usernames = os.listdir(root)
os.makedirs("api/names/")
for username in usernames:
f = open(root + username, "r")
sshkey = f.read()
sshkey = sshkey.split(' ')[0] + " " + sshkey.split(' ')[1]
keys[username] = hashlib.sha256(sshkey.encode()).hexdigest()
f = open("api/names/{}".format(keys[username]), "w")
f.write(username)
f.close()
def make_route(host, ruser, keyhash):
if os.path.exists("api/access/{}/{}".format(host, ruser)) == False:
os.makedirs("api/access/{}/{}".format(host, ruser))
f = open("api/access/{}/{}/{}".format(host, ruser, keyhash), "w")
f.write("1")
f.close()
for username in os.listdir("data/hosts"):
fp = open("data/hosts/{}".format(username))
lines = fp.readlines()
for l in lines:
if l == '\n':
continue
l = l.strip()
idx = l.index('|')
hostname = l[:idx]
ruser = l[idx+1:]
keyhash = keys[username]
make_route(hostname, ruser, keyhash)