-
Notifications
You must be signed in to change notification settings - Fork 0
/
octane.py
executable file
·147 lines (124 loc) · 4.23 KB
/
octane.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python3
from hmac import digest
import requests, sys, subprocess, os
from datetime import datetime
import time
from hashlib import blake2b
endpoint = "http://127.0.0.1:3000/api/v1/"
config_path = os.getenv('HOME') + '/.octane/'
def newroom():
obj = {'name': 'string'}
x = requests.post(endpoint+"room/", json=obj)
with open(config_path+'id', "w") as f: # .octane.d/id
f.write(str(x.json()["id"]))
return x
def connect(verbose=True):
url = endpoint + "room/" + roomid
obj = {"name": "string", "request": "connect"}
x = requests.post(url, json=obj)
if verbose: print("Connecting: ", x.status_code)
def disconnect(verbose=True):
url = endpoint + "room/" + roomid
obj = {"name": "string", "request": "disconnect"}
x = requests.post(url, json=obj)
if verbose: print("Disconnecting: ", x.status_code)
# if x.status_code != 200: print(x.text)
def send_metadata():
url = endpoint + "room/" + roomid + "/status"
data = subprocess.run(['xclip', '-o'], stdout=subprocess.PIPE).stdout
hashval = blake2b(data, digest_size=32).hexdigest()
print(hashval)
obj = {"device": "string",
"hash": hashval,
"mime": "text/plain",
"name": "string",
"timestamp": int(time.time()),
"type": "string"}
x = requests.put(url, json=obj)
print("Sending metadata: ", x.status_code)
def send_content():
url = endpoint + "room/" + roomid + "/content"
headers = {"Content-Type": "text/plain"}
data = subprocess.run(['xclip', '-o', '-selection'], stdout=subprocess.PIPE).stdout.decode('utf-8')
x = requests.put(url, headers=headers, data=data)
print("Copying to server: ", x.status_code)
print(x.text)
def copy_to_server():
disconnect()
connect()
send_metadata()
send_content()
disconnect()
def paste_from_server():
disconnect(verbose=False)
connect(verbose=False)
url = endpoint + "room/" + roomid + "/content"
x = requests.get(url)
# print("Pasting: ", x.status_code)
disconnect(verbose=False)
print(x.text)
return x.text
try:
with open(config_path+'id', "r") as f:
roomid = f.read()
# print("Existing ID mounted and loaded: ", roomid)
except:
# print("No existing ID detected. Generating.")
x = newroom()
if sys.argv[1] == "copy":
copy_to_server()
elif sys.argv[1] == "paste":
paste_from_server()
elif sys.argv[1] == "health":
x = requests.get(url + "health")
elif sys.argv[1] == "room":
url = endpoint + "room/"
if sys.argv[2] == "new":
x = newroom()
elif sys.argv[2] == "delete":
url += roomid
x = requests.delete(url)
elif sys.argv[2] == "status":
url += roomid
x = requests.get(url)
elif sys.argv[2] == "connect":
connect()
elif sys.argv[2] == "disconnect":
disconnect()
elif sys.argv[1] == "content":
url = endpoint + "room/" + roomid + "/content"
if sys.argv[2] == "delete":
x = requests.delete(url)
elif sys.argv[2] == "get":
x = requests.get(url)
elif sys.argv[2] == "put":
# data = "mockup"
data = subprocess.run(['xclip', '-o', '-selection'], stdout=subprocess.PIPE).stdout.decode('utf-8')
x = requests.put(url, data=data)
print("Copying to server: ", x.status_code)
elif sys.argv[1] == "status":
url = endpoint + "room/" + roomid + "/status"
if sys.argv[2] == "delete":
x = requests.delete(url)
elif sys.argv[2] == "get":
x = requests.get(url)
elif sys.argv[2] == "put":
# data = b"mockup"
data = subprocess.run(['xclip', '-o', '-selection'], stdout=subprocess.PIPE).stdout.decode('utf-8')
hashval = blake2b(data, digest_size=32).hexdigest()
print(hashval)
obj = {"device": "string",
"hash": hashval,
"mime": "text/plain",
"name": "string",
"timestamp": int(time.time()),
"type": "string"}
x = requests.put(url, json=obj)
print("Sending metadata: ", x.status_code)
'''
url = endpoint + "room/" + roomid
obj = {"name": "string", "request": "disconnect"}
x = requests.post(url, json=obj)
print("Disonnecting: ", x.status_code)
'''
# print(x.text)