tcs: part 1
This commit is contained in:
parent
e004838013
commit
7c2a2f16df
@ -12,7 +12,7 @@ from callbacks import init_callbacks
|
|||||||
from util import curr_directory, program_version
|
from util import curr_directory, program_version
|
||||||
import styles.style
|
import styles.style
|
||||||
import toxencryptsave
|
import toxencryptsave
|
||||||
from passwordscreen import PasswordScreen, UnlockAppScreen
|
from passwordscreen import PasswordScreen, UnlockAppScreen, SetProfilePasswordScreen
|
||||||
from plugin_support import PluginLoader
|
from plugin_support import PluginLoader
|
||||||
|
|
||||||
|
|
||||||
@ -97,6 +97,19 @@ class Toxygen:
|
|||||||
self.tox = profile.tox_factory()
|
self.tox = profile.tox_factory()
|
||||||
self.tox.self_set_name(bytes(_login.name, 'utf-8') if _login.name else b'Toxygen User')
|
self.tox.self_set_name(bytes(_login.name, 'utf-8') if _login.name else b'Toxygen User')
|
||||||
self.tox.self_set_status_message(b'Toxing on Toxygen')
|
self.tox.self_set_status_message(b'Toxing on Toxygen')
|
||||||
|
reply = QtGui.QMessageBox.question(None,
|
||||||
|
'Profile {}'.format(name),
|
||||||
|
QtGui.QApplication.translate("login",
|
||||||
|
'Do you want to set profile password?',
|
||||||
|
None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8),
|
||||||
|
QtGui.QMessageBox.Yes,
|
||||||
|
QtGui.QMessageBox.No)
|
||||||
|
if reply == QtGui.QMessageBox.Yes:
|
||||||
|
set_pass = SetProfilePasswordScreen(encrypt_save)
|
||||||
|
set_pass.show()
|
||||||
|
self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()"))
|
||||||
|
self.app.exec_()
|
||||||
ProfileHelper(Settings.get_default_path(), name).save_profile(self.tox.get_savedata())
|
ProfileHelper(Settings.get_default_path(), name).save_profile(self.tox.get_savedata())
|
||||||
path = Settings.get_default_path()
|
path = Settings.get_default_path()
|
||||||
settings = Settings(name)
|
settings = Settings(name)
|
||||||
@ -292,6 +305,7 @@ class Toxygen:
|
|||||||
if self.stop:
|
if self.stop:
|
||||||
return
|
return
|
||||||
self.tox.bootstrap(*data)
|
self.tox.bootstrap(*data)
|
||||||
|
self.tox.add_tcp_relay(*data)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
@ -304,6 +318,7 @@ class Toxygen:
|
|||||||
if self.stop:
|
if self.stop:
|
||||||
return
|
return
|
||||||
self.tox.bootstrap(*data)
|
self.tox.bootstrap(*data)
|
||||||
|
self.tox.add_tcp_relay(*data)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
@ -405,4 +420,3 @@ def main():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ class AddContact(CenteredWidget):
|
|||||||
def __init__(self, tox_id=''):
|
def __init__(self, tox_id=''):
|
||||||
super(AddContact, self).__init__()
|
super(AddContact, self).__init__()
|
||||||
self.initUI(tox_id)
|
self.initUI(tox_id)
|
||||||
|
self._adding = False
|
||||||
|
|
||||||
def initUI(self, tox_id):
|
def initUI(self, tox_id):
|
||||||
self.setObjectName('AddContact')
|
self.setObjectName('AddContact')
|
||||||
@ -58,8 +59,12 @@ class AddContact(CenteredWidget):
|
|||||||
QtCore.QMetaObject.connectSlotsByName(self)
|
QtCore.QMetaObject.connectSlotsByName(self)
|
||||||
|
|
||||||
def add_friend(self):
|
def add_friend(self):
|
||||||
|
if self._adding:
|
||||||
|
return
|
||||||
|
self._adding = True
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
send = profile.send_friend_request(self.tox_id.text(), self.message_edit.toPlainText())
|
send = profile.send_friend_request(self.tox_id.text(), self.message_edit.toPlainText())
|
||||||
|
self._adding = False
|
||||||
if send is True:
|
if send is True:
|
||||||
# request was successful
|
# request was successful
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -100,3 +100,65 @@ class UnlockAppScreen(PasswordScreenBase):
|
|||||||
else:
|
else:
|
||||||
self.warning.setVisible(True)
|
self.warning.setVisible(True)
|
||||||
print('Wrong password!')
|
print('Wrong password!')
|
||||||
|
|
||||||
|
|
||||||
|
class SetProfilePasswordScreen(CenteredWidget):
|
||||||
|
|
||||||
|
def __init__(self, encrypt):
|
||||||
|
super(SetProfilePasswordScreen, self).__init__()
|
||||||
|
self._encrypt = encrypt
|
||||||
|
self.initUI()
|
||||||
|
self.retranslateUi()
|
||||||
|
self.center()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
self.setMinimumSize(QtCore.QSize(700, 200))
|
||||||
|
self.setMaximumSize(QtCore.QSize(700, 200))
|
||||||
|
self.password = LineEdit(self)
|
||||||
|
self.password.setGeometry(QtCore.QRect(40, 10, 300, 30))
|
||||||
|
self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
|
||||||
|
self.confirm_password = LineEdit(self)
|
||||||
|
self.confirm_password.setGeometry(QtCore.QRect(40, 50, 300, 30))
|
||||||
|
self.confirm_password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
|
||||||
|
self.set_password = QtGui.QPushButton(self)
|
||||||
|
self.set_password.setGeometry(QtCore.QRect(40, 100, 300, 30))
|
||||||
|
self.set_password.clicked.connect(self.new_password)
|
||||||
|
self.not_match = QtGui.QLabel(self)
|
||||||
|
self.not_match.setGeometry(QtCore.QRect(350, 50, 300, 30))
|
||||||
|
self.not_match.setVisible(False)
|
||||||
|
self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }')
|
||||||
|
self.warning = QtGui.QLabel(self)
|
||||||
|
self.warning.setGeometry(QtCore.QRect(40, 160, 500, 30))
|
||||||
|
self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
|
||||||
|
|
||||||
|
def retranslateUi(self):
|
||||||
|
self.setWindowTitle(QtGui.QApplication.translate("PasswordScreen", "Profile password", None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.password.setPlaceholderText(
|
||||||
|
QtGui.QApplication.translate("PasswordScreen", "Password (at least 8 symbols)", None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.confirm_password.setPlaceholderText(
|
||||||
|
QtGui.QApplication.translate("PasswordScreen", "Confirm password", None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.set_password.setText(
|
||||||
|
QtGui.QApplication.translate("PasswordScreen", "Set password", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.not_match.setText(QtGui.QApplication.translate("PasswordScreen", "Passwords do not match", None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.warning.setText(
|
||||||
|
QtGui.QApplication.translate("PasswordScreen", "There is no way to recover lost passwords", None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
|
def new_password(self):
|
||||||
|
if self.password.text() == self.confirm_password.text():
|
||||||
|
if len(self.password.text()) >= 8:
|
||||||
|
self._encrypt.set_password(self.password.text())
|
||||||
|
self.close()
|
||||||
|
else:
|
||||||
|
self.not_match.setText(
|
||||||
|
QtGui.QApplication.translate("PasswordScreen", "Password must be at least 8 symbols", None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.not_match.setVisible(True)
|
||||||
|
else:
|
||||||
|
self.not_match.setText(QtGui.QApplication.translate("PasswordScreen", "Passwords do not match", None,
|
||||||
|
QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.not_match.setVisible(True)
|
||||||
|
@ -152,5 +152,6 @@ class PluginLoader(util.Singleton):
|
|||||||
App is closing, stop all plugins
|
App is closing, stop all plugins
|
||||||
"""
|
"""
|
||||||
for key in list(self._plugins.keys()):
|
for key in list(self._plugins.keys()):
|
||||||
|
if self._plugins[key][1]:
|
||||||
self._plugins[key][0].close()
|
self._plugins[key][0].close()
|
||||||
del self._plugins[key]
|
del self._plugins[key]
|
||||||
|
@ -820,22 +820,12 @@ class Profile(contact.Contact, Singleton):
|
|||||||
|
|
||||||
elif auto:
|
elif auto:
|
||||||
path = settings['auto_accept_path'] or curr_directory()
|
path = settings['auto_accept_path'] or curr_directory()
|
||||||
if not os.path.isdir(path):
|
self.accept_transfer(None, path + '/' + file_name, friend_number, file_number, size)
|
||||||
path = curr_directory()
|
|
||||||
new_file_name, i = file_name, 1
|
|
||||||
while os.path.isfile(path + '/' + new_file_name): # file with same name already exists
|
|
||||||
if '.' in file_name: # has extension
|
|
||||||
d = file_name.rindex('.')
|
|
||||||
else: # no extension
|
|
||||||
d = len(file_name)
|
|
||||||
new_file_name = file_name[:d] + ' ({})'.format(i) + file_name[d:]
|
|
||||||
i += 1
|
|
||||||
self.accept_transfer(None, path + '/' + new_file_name, friend_number, file_number, size)
|
|
||||||
tm = TransferMessage(MESSAGE_OWNER['FRIEND'],
|
tm = TransferMessage(MESSAGE_OWNER['FRIEND'],
|
||||||
time.time(),
|
time.time(),
|
||||||
TOX_FILE_TRANSFER_STATE['RUNNING'],
|
TOX_FILE_TRANSFER_STATE['RUNNING'],
|
||||||
size,
|
size,
|
||||||
new_file_name,
|
file_name,
|
||||||
friend_number,
|
friend_number,
|
||||||
file_number)
|
file_number)
|
||||||
else:
|
else:
|
||||||
@ -922,6 +912,16 @@ class Profile(contact.Contact, Singleton):
|
|||||||
:param size: file size
|
:param size: file size
|
||||||
:param inline: is inline image
|
:param inline: is inline image
|
||||||
"""
|
"""
|
||||||
|
path, file_name = os.path.split(path)
|
||||||
|
new_file_name, i = file_name, 1
|
||||||
|
while os.path.isfile(path + '/' + new_file_name): # file with same name already exists
|
||||||
|
if '.' in file_name: # has extension
|
||||||
|
d = file_name.rindex('.')
|
||||||
|
else: # no extension
|
||||||
|
d = len(file_name)
|
||||||
|
new_file_name = file_name[:d] + ' ({})'.format(i) + file_name[d:]
|
||||||
|
i += 1
|
||||||
|
path = os.path.join(path, new_file_name)
|
||||||
if not inline:
|
if not inline:
|
||||||
rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number)
|
rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number)
|
||||||
else:
|
else:
|
||||||
|
@ -2,6 +2,10 @@ import json
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
from util import log
|
from util import log
|
||||||
import settings
|
import settings
|
||||||
|
try:
|
||||||
|
from PySide import QtNetwork, QtCore
|
||||||
|
except:
|
||||||
|
from PyQt4 import QtNetwork, QtCore
|
||||||
|
|
||||||
|
|
||||||
def tox_dns(email):
|
def tox_dns(email):
|
||||||
@ -14,40 +18,40 @@ def tox_dns(email):
|
|||||||
data = {"action": 3, "name": "{}".format(email)}
|
data = {"action": 3, "name": "{}".format(email)}
|
||||||
urls = ('https://{}/api'.format(site), 'http://{}/api'.format(site))
|
urls = ('https://{}/api'.format(site), 'http://{}/api'.format(site))
|
||||||
s = settings.Settings.get_instance()
|
s = settings.Settings.get_instance()
|
||||||
if s['proxy_type'] != 2: # no proxy or http proxy
|
if not s['proxy_type']: # no proxy
|
||||||
proxy = s['proxy_host'] + ':' + s['proxy_port'] if s['proxy_type'] else None
|
|
||||||
for url in urls:
|
for url in urls:
|
||||||
try:
|
try:
|
||||||
return send_request(url, data, proxy)
|
return send_request(url, data)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log('TOX DNS ERROR: ' + str(ex))
|
log('TOX DNS ERROR: ' + str(ex))
|
||||||
else: # SOCKS5 proxy
|
else: # proxy
|
||||||
|
netman = QtNetwork.QNetworkAccessManager()
|
||||||
|
proxy = QtNetwork.QNetworkProxy()
|
||||||
|
proxy.setType(QtNetwork.QNetworkProxy.Socks5Proxy if s['proxy_type'] == 2 else QtNetwork.QNetworkProxy.HttpProxy)
|
||||||
|
proxy.setHostName(s['proxy_host'])
|
||||||
|
proxy.setPort(s['proxy_port'])
|
||||||
|
netman.setProxy(proxy)
|
||||||
|
for url in urls:
|
||||||
try:
|
try:
|
||||||
import socks
|
request = QtNetwork.QNetworkRequest(url)
|
||||||
import socket
|
request.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader, "application/json")
|
||||||
import requests
|
reply = netman.post(request, bytes(json.dumps(data), 'utf-8'))
|
||||||
|
|
||||||
socks.set_default_proxy(socks.SOCKS5, s['proxy_host'], s['proxy_port'])
|
while not reply.isFinished():
|
||||||
socket.socket = socks.socksocket
|
QtCore.QThread.msleep(1)
|
||||||
for url in urls:
|
QtCore.QCoreApplication.processEvents()
|
||||||
try:
|
data = bytes(reply.readAll().data())
|
||||||
r = requests.get(url)
|
result = json.loads(str(data, 'utf-8'))
|
||||||
res = json.loads(r.text)
|
if not result['c']:
|
||||||
if not res['c']:
|
return result['tox_id']
|
||||||
return res['tox_id']
|
|
||||||
else:
|
|
||||||
raise LookupError()
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log('TOX DNS ERROR: ' + str(ex))
|
log('TOX DNS ERROR: ' + str(ex))
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return None # error
|
return None # error
|
||||||
|
|
||||||
|
|
||||||
def send_request(url, data, proxy):
|
def send_request(url, data):
|
||||||
req = urllib.request.Request(url)
|
req = urllib.request.Request(url)
|
||||||
if proxy is not None:
|
|
||||||
req.set_proxy(proxy, 'http')
|
|
||||||
req.add_header('Content-Type', 'application/json')
|
req.add_header('Content-Type', 'application/json')
|
||||||
response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8'))
|
response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8'))
|
||||||
res = json.loads(str(response.read(), 'utf-8'))
|
res = json.loads(str(response.read(), 'utf-8'))
|
||||||
|
Loading…
Reference in New Issue
Block a user