-
Notifications
You must be signed in to change notification settings - Fork 1
/
refmon_client.py
111 lines (95 loc) · 3.24 KB
/
refmon_client.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import client_side_connection
import peer_ip
import filetable
def add_authorization(peer_name):
print('Who would you like to give authorization to?')
grantee = input()
print('What file would you like to give them access to?')
filename = input()
print('What operation would you like to allow them to do (get, put, or del)?')
operation = input()
# Look up which host has the file
file_host = filetable.getFiletable(peer_name)[filename]
# Use the peer_map to figure out the address of that host
file_location = peer_ip.peer_map[file_host]
# Connect to the appropriate host
net = client_side_connection.ClientSideConnection(
peer_name = peer_name, ip = file_location[0], portno = int(file_location[1]))
net.send('Add_Authorization')
net.send(grantee)
net.send(operation)
net.send(filename)
# print the response
print(net.recv())
net.done()
def delete_authorization(peer_name):
print('Who would you like to remove authorization from?')
grantee = input()
print('What file would you like to remove access to?')
filename = input()
print('What operation would you like to restrict them from (get, put, or del)?')
operation = input()
# Look up which host has the file
file_host = filetable.getFiletable(peer_name)[filename]
# Use the peer_map to figure out the address of that host
file_location = peer_ip.peer_map[file_host]
# Connect to the appropriate host
net = client_side_connection.ClientSideConnection(
peer_name = peer_name, ip = file_location[0], portno = int(file_location[1]))
net.send('Delete_Authorization')
net.send(grantee)
net.send(operation)
net.send(filename)
# print the response
print(net.recv())
net.done()
def add_group_member(peer_name):
print('What host would you like to modify groups for?')
host_input = input()
host_location = None
# Request a list of files we can access from every host
for hostname, host in peer_ip.peer_map.items():
name = str(eval(hostname)[4][0][1])
if(host_input == name):
host_location = host
if(host_location == None):
print("Host not found")
return
print('Who would you like to add to a group?')
grantee = input()
print('What group would you like to add them to?')
group = input()
# Connect to the appropriate host
net = client_side_connection.ClientSideConnection(
peer_name = peer_name, ip = host_location[0], portno = int(host_location[1]))
net.send('Add_Group_Member')
net.send(grantee)
net.send(group)
# print the response
print(net.recv())
net.done()
def delete_group_member(peer_name):
print('What host would you like to modify groups for?')
host_input = input()
host_location = None
# Request a list of files we can access from every host
for hostname, host in peer_ip.peer_map.items():
name = str(eval(hostname)[4][0][1])
if(host_input == name):
host_location = host
if(host_location == None):
print("Host not found")
return
print('Who would you like to remove from a group?')
grantee = input()
print('What group would you like to remove them from?')
group = input()
# Connect to the appropriate host
net = client_side_connection.ClientSideConnection(
peer_name = peer_name, ip = host_location[0], portno = int(host_location[1]))
net.send('Delete_Group_Member')
net.send(grantee)
net.send(group)
# print the response
print(net.recv())
net.done()