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
|
||||
import styles.style
|
||||
import toxencryptsave
|
||||
from passwordscreen import PasswordScreen, UnlockAppScreen
|
||||
from passwordscreen import PasswordScreen, UnlockAppScreen, SetProfilePasswordScreen
|
||||
from plugin_support import PluginLoader
|
||||
|
||||
|
||||
@ -97,6 +97,19 @@ class Toxygen:
|
||||
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_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())
|
||||
path = Settings.get_default_path()
|
||||
settings = Settings(name)
|
||||
@ -292,6 +305,7 @@ class Toxygen:
|
||||
if self.stop:
|
||||
return
|
||||
self.tox.bootstrap(*data)
|
||||
self.tox.add_tcp_relay(*data)
|
||||
except:
|
||||
pass
|
||||
for _ in range(10):
|
||||
@ -304,6 +318,7 @@ class Toxygen:
|
||||
if self.stop:
|
||||
return
|
||||
self.tox.bootstrap(*data)
|
||||
self.tox.add_tcp_relay(*data)
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
@ -405,4 +420,3 @@ def main():
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
@ -17,6 +17,7 @@ class AddContact(CenteredWidget):
|
||||
def __init__(self, tox_id=''):
|
||||
super(AddContact, self).__init__()
|
||||
self.initUI(tox_id)
|
||||
self._adding = False
|
||||
|
||||
def initUI(self, tox_id):
|
||||
self.setObjectName('AddContact')
|
||||
@ -58,8 +59,12 @@ class AddContact(CenteredWidget):
|
||||
QtCore.QMetaObject.connectSlotsByName(self)
|
||||
|
||||
def add_friend(self):
|
||||
if self._adding:
|
||||
return
|
||||
self._adding = True
|
||||
profile = Profile.get_instance()
|
||||
send = profile.send_friend_request(self.tox_id.text(), self.message_edit.toPlainText())
|
||||
self._adding = False
|
||||
if send is True:
|
||||
# request was successful
|
||||
self.close()
|
||||
|
@ -100,3 +100,65 @@ class UnlockAppScreen(PasswordScreenBase):
|
||||
else:
|
||||
self.warning.setVisible(True)
|
||||
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
|
||||
"""
|
||||
for key in list(self._plugins.keys()):
|
||||
if self._plugins[key][1]:
|
||||
self._plugins[key][0].close()
|
||||
del self._plugins[key]
|
||||
|
@ -820,22 +820,12 @@ class Profile(contact.Contact, Singleton):
|
||||
|
||||
elif auto:
|
||||
path = settings['auto_accept_path'] or curr_directory()
|
||||
if not os.path.isdir(path):
|
||||
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)
|
||||
self.accept_transfer(None, path + '/' + file_name, friend_number, file_number, size)
|
||||
tm = TransferMessage(MESSAGE_OWNER['FRIEND'],
|
||||
time.time(),
|
||||
TOX_FILE_TRANSFER_STATE['RUNNING'],
|
||||
size,
|
||||
new_file_name,
|
||||
file_name,
|
||||
friend_number,
|
||||
file_number)
|
||||
else:
|
||||
@ -922,6 +912,16 @@ class Profile(contact.Contact, Singleton):
|
||||
:param size: file size
|
||||
: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:
|
||||
rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number)
|
||||
else:
|
||||
|
@ -2,6 +2,10 @@ import json
|
||||
import urllib.request
|
||||
from util import log
|
||||
import settings
|
||||
try:
|
||||
from PySide import QtNetwork, QtCore
|
||||
except:
|
||||
from PyQt4 import QtNetwork, QtCore
|
||||
|
||||
|
||||
def tox_dns(email):
|
||||
@ -14,40 +18,40 @@ def tox_dns(email):
|
||||
data = {"action": 3, "name": "{}".format(email)}
|
||||
urls = ('https://{}/api'.format(site), 'http://{}/api'.format(site))
|
||||
s = settings.Settings.get_instance()
|
||||
if s['proxy_type'] != 2: # no proxy or http proxy
|
||||
proxy = s['proxy_host'] + ':' + s['proxy_port'] if s['proxy_type'] else None
|
||||
if not s['proxy_type']: # no proxy
|
||||
for url in urls:
|
||||
try:
|
||||
return send_request(url, data, proxy)
|
||||
return send_request(url, data)
|
||||
except Exception as 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:
|
||||
import socks
|
||||
import socket
|
||||
import requests
|
||||
request = QtNetwork.QNetworkRequest(url)
|
||||
request.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader, "application/json")
|
||||
reply = netman.post(request, bytes(json.dumps(data), 'utf-8'))
|
||||
|
||||
socks.set_default_proxy(socks.SOCKS5, s['proxy_host'], s['proxy_port'])
|
||||
socket.socket = socks.socksocket
|
||||
for url in urls:
|
||||
try:
|
||||
r = requests.get(url)
|
||||
res = json.loads(r.text)
|
||||
if not res['c']:
|
||||
return res['tox_id']
|
||||
else:
|
||||
raise LookupError()
|
||||
while not reply.isFinished():
|
||||
QtCore.QThread.msleep(1)
|
||||
QtCore.QCoreApplication.processEvents()
|
||||
data = bytes(reply.readAll().data())
|
||||
result = json.loads(str(data, 'utf-8'))
|
||||
if not result['c']:
|
||||
return result['tox_id']
|
||||
except Exception as ex:
|
||||
log('TOX DNS ERROR: ' + str(ex))
|
||||
except:
|
||||
pass
|
||||
|
||||
return None # error
|
||||
|
||||
|
||||
def send_request(url, data, proxy):
|
||||
def send_request(url, data):
|
||||
req = urllib.request.Request(url)
|
||||
if proxy is not None:
|
||||
req.set_proxy(proxy, 'http')
|
||||
req.add_header('Content-Type', 'application/json')
|
||||
response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8'))
|
||||
res = json.loads(str(response.read(), 'utf-8'))
|
||||
|
Loading…
Reference in New Issue
Block a user