to post requests

master
quadrismegistus 4 years ago
parent 97deca9c71
commit b163c3ac18

@ -963,8 +963,8 @@ class MainApp(MDApp, Logger):
with open(path_avatar,'rb') as f:
other_data['img_avatar']=f.read()
extra_msg = await self.get_input(f'Include a short message to {meet_name}? (optional)')
other_data['extra_msg']=extra_msg.strip()
# extra_msg = await self.get_input(f'Include a short message to {meet_name}? (optional)')
# other_data['extra_msg']=extra_msg.strip()
await self.stat('Sending the invitation...')
self.open_map()
res = await self.comrad.meet_async(

@ -24,31 +24,48 @@ class TheSwitchboard(FlaskView, Logger):
self._op=OPERATOR=TheOperator()
return OPERATOR
def get(self,data_b64_str_esc):
def post(self):
clear_screen()
from comrad.cli.artcode import ART_OLDPHONE4
# self.log(f'Incoming call!: {data_b64_str_esc}')
if not data_b64_str_esc:
data_b=requests.data
self.log(f'Incoming call! {ART_OLDPHONE4}: {data_b}')
if not data_b:
self.log('empty request!')
return OPERATOR_INTERCEPT_MESSAGE
# unenescape
data_b64_str = data_b64_str_esc.replace('_','/')
# encode to binary
data_b64 = data_b64_str.encode()
data_b = b64decode(data_b64)
# ask operator to answer phone and request
resp_data_b = self.op.answer_phone(data_b)
# decode to str
resp_data_b64 = b64encode(resp_data_b)
resp_data_b64_str = resp_data_b64.decode()
self.log('about to send back -->',resp_data_b)
return resp_data_b
# def get(self,data_b64_str_esc):
# clear_screen()
# from comrad.cli.artcode import ART_OLDPHONE4
# # self.log(f'Incoming call!: {data_b64_str_esc}')
# if not data_b64_str_esc:
# self.log('empty request!')
# return OPERATOR_INTERCEPT_MESSAGE
# # unenescape
# data_b64_str = data_b64_str_esc.replace('_','/')
# # encode to binary
# data_b64 = data_b64_str.encode()
# data_b = b64decode(data_b64)
# # ask operator to answer phone and request
# resp_data_b = self.op.answer_phone(data_b)
# # decode to str
# resp_data_b64 = b64encode(resp_data_b)
# resp_data_b64_str = resp_data_b64.decode()
# return as str
return resp_data_b64_str
# # return as str
# return resp_data_b64_str
def run_forever(port='8080'):
# global OP_PASS

@ -54,12 +54,13 @@ class TheTelephone(Operator):
# self.log('but going to send just msg?',msg_b)
msg_b=msg_d["msg"]
msg_b64 = b64encode(msg_b)
msg_b64_str = msg_b64.decode()
self.log(f'''Sending the encrypted content package:\n\n{msg_b64_str}''')
# msg_b64 = b64encode(msg_b)
# msg_b64_str = msg_b64.decode()
# self.log(f'''Sending the encrypted content package:\n\n{msg_b64_str}''')
self.log(f'''Sending the encrypted content package:\n\n{msg_b}''')
# seal for transport
msg_b64_str_esc = msg_b64_str.replace('/','_')
# msg_b64_str_esc = msg_b64_str.replace('/','_')
# dial the operator
@ -78,23 +79,34 @@ class TheTelephone(Operator):
self.log('making first attempt to connect via Tor')
try:
# phonecall=self.comrad_request(URL)
phonecall = await texec(self.comrad_request, URL)
# phonecall = await texec(self.comrad_request, URL)
phonecall = await texec(
self.comrad_request_post,
self.api_url,
msg_b64_str_esc
)
break
except (TorSocketConnectError,ConnectionError) as e:
self.log(f'!! {e} trying again?')
pass
if phonecall.status_code!=200:
self.log('!! error in request',phonecall.status_code,phonecall.text)
self.log('!! error in request',phonecall.status_code,phonecall)
return
# response back from Operator!
resp_msg_b64_str = phonecall.text
self.log(f'{self}: Received response from Operator! We got back:\n\n',resp_msg_b64_str)
# resp_msg_b64_str = phonecall.text
# self.log(f'{self}: Received response from Operator! We got back:\n\n',resp_msg_b64_str)
resp_msg_b64 = resp_msg_b64_str.encode()
resp_msg_b = b64decode(resp_msg_b64)
# resp_msg_b64 = resp_msg_b64_str.encode()
# resp_msg_b = b64decode(resp_msg_b64)
# self.log('resp_msg_b:',resp_msg_b)
resp_msg_b = phonecall.data
self.log(f'{self}: Received response from Operator! We got back:\n\n',resp_msg_b)
resp_msg_d = pickle.loads(resp_msg_b)
# self.log('unpickled:',resp_msg_d)
@ -137,6 +149,10 @@ class TheTelephone(Operator):
return self.tor_request_in_python(url)
# return tor_request_in_proxy(url)
def tor_request_post(self,url,data=''):
return self.tor_request_in_python_post(url,data=data)
# return tor_request_in_proxy_post(url,data=data)
async def tor_request_async(self,url):
return await self.tor_request_in_python_async(url)
@ -159,6 +175,11 @@ class TheTelephone(Operator):
self.log('<-- r',r)
return r
def comrad_request_post(self,url,data='',allow_clearnet = ALLOW_CLEARNET):
if '.onion' in url or not allow_clearnet:
return self.tor_request_post(url)
return requests.post(url,data=data,timeout=60)
def tor_request_in_python(self,url):
tor = TorClient()
@ -171,6 +192,18 @@ class TheTelephone(Operator):
s.mount('https://', adapter)
r = s.get(url, timeout=600)
return r
def tor_request_in_python_post(self,url,data=''):
tor = TorClient()
with tor.get_guard() as guard:
adapter = TorHttpAdapter(guard, 3, retries=RETRIES)
with requests.Session() as s:
s.headers.update({'User-Agent': 'Mozilla/5.0'})
s.mount('http://', adapter)
s.mount('https://', adapter)
r = s.post(url, data=data, timeout=600)
return r
def get_tor_proxy_session(self):
session = requests.session()

Loading…
Cancel
Save