Commit a064ccd0 authored by Dan Pascu's avatar Dan Pascu

Removed obsolete code

parent d5c13f1c
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import os import os
import sys import sys
import sip import sip
import cjson
sip.setapi('QString', 2) sip.setapi('QString', 2)
sip.setapi('QVariant', 2) sip.setapi('QVariant', 2)
...@@ -15,11 +14,8 @@ QApplication.setAttribute(Qt.AA_X11InitThreads, True) ...@@ -15,11 +14,8 @@ QApplication.setAttribute(Qt.AA_X11InitThreads, True)
from application import log from application import log
from application.notification import IObserver, NotificationCenter, NotificationData from application.notification import IObserver, NotificationCenter, NotificationData
from application.python import Null from application.python import Null
from application.system import host, makedirs, unlink from application.system import host, makedirs
from collections import defaultdict
from eventlib import api from eventlib import api
from gnutls.crypto import X509Certificate, X509PrivateKey
from gnutls.errors import GNUTLSError
from zope.interface import implements from zope.interface import implements
from sipsimple.account import Account, AccountManager, BonjourAccount from sipsimple.account import Account, AccountManager, BonjourAccount
...@@ -176,82 +172,6 @@ class Blink(QApplication): ...@@ -176,82 +172,6 @@ class Blink(QApplication):
self.main_window.close() self.main_window.close()
super(Blink, self).quit() super(Blink, self).quit()
def fetch_account(self):
filename = os.path.expanduser('~/.blink_account')
if not os.path.exists(filename):
return
try:
data = open(filename).read()
data = cjson.decode(data.replace(r'\/', '/'))
except (OSError, IOError), e:
print "Failed to read json data from ~/.blink_account: %s" % e
return
except cjson.DecodeError, e:
print "Failed to decode json data from ~/.blink_account: %s" % e
return
finally:
unlink(filename)
data = defaultdict(lambda: None, data)
account_id = data['sip_address']
if account_id is None:
return
account_manager = AccountManager()
try:
account = account_manager.get_account(account_id)
except KeyError:
account = Account(account_id)
account.display_name = data['display_name'] or None
default_account = account
else:
default_account = account_manager.default_account
account.auth.username = data['auth_username']
account.auth.password = data['password'] or ''
account.sip.outbound_proxy = data['outbound_proxy']
account.xcap.xcap_root = data['xcap_root']
account.nat_traversal.msrp_relay = data['msrp_relay']
account.server.conference_server = data['conference_server']
account.server.settings_url = data['settings_url']
if data['passport'] is not None:
try:
passport = data['passport']
certificate_path = self.save_certificates(account_id, passport['crt'], passport['key'], passport['ca'])
account.tls.certificate = certificate_path
except (GNUTLSError, IOError, OSError):
pass
account.enabled = True
account.save()
account_manager.default_account = default_account
def save_certificates(self, sip_address, crt, key, ca):
crt = crt.strip() + os.linesep
key = key.strip() + os.linesep
ca = ca.strip() + os.linesep
X509Certificate(crt)
X509PrivateKey(key)
X509Certificate(ca)
makedirs(ApplicationData.get('tls'))
certificate_path = ApplicationData.get(os.path.join('tls', sip_address+'.crt'))
file = open(certificate_path, 'w')
os.chmod(certificate_path, 0600)
file.write(crt+key)
file.close()
ca_path = ApplicationData.get(os.path.join('tls', 'ca.crt'))
try:
existing_cas = open(ca_path).read().strip() + os.linesep
except:
file = open(ca_path, 'w')
file.write(ca)
file.close()
else:
if ca not in existing_cas:
file = open(ca_path, 'w')
file.write(existing_cas+ca)
file.close()
settings = SIPSimpleSettings()
settings.tls.ca_list = ca_path
settings.save()
return certificate_path
def eventFilter(self, watched, event): def eventFilter(self, watched, event):
if watched in (self.main_window, self.chat_window): if watched in (self.main_window, self.chat_window):
if event.type() == QEvent.Show: if event.type() == QEvent.Show:
...@@ -286,9 +206,7 @@ class Blink(QApplication): ...@@ -286,9 +206,7 @@ class Blink(QApplication):
@run_in_gui_thread @run_in_gui_thread
def _NH_SIPApplicationDidStart(self, notification): def _NH_SIPApplicationDidStart(self, notification):
self.ip_address_monitor.start() self.ip_address_monitor.start()
self.fetch_account()
self.main_window.show() self.main_window.show()
settings = SIPSimpleSettings()
accounts = AccountManager().get_accounts() accounts = AccountManager().get_accounts()
if not accounts or (self.first_run and accounts == [BonjourAccount()]): if not accounts or (self.first_run and accounts == [BonjourAccount()]):
self.main_window.preferences_window.show_create_account_dialog() self.main_window.preferences_window.show_create_account_dialog()
......
...@@ -15,6 +15,8 @@ from PyQt4.QtWebKit import QWebView ...@@ -15,6 +15,8 @@ from PyQt4.QtWebKit import QWebView
import cjson import cjson
from application.notification import IObserver, NotificationCenter from application.notification import IObserver, NotificationCenter
from application.python import Null from application.python import Null
from application.system import makedirs
from gnutls.crypto import X509Certificate, X509PrivateKey
from gnutls.errors import GNUTLSError from gnutls.errors import GNUTLSError
from zope.interface import implements from zope.interface import implements
...@@ -24,7 +26,7 @@ from sipsimple.configuration.settings import SIPSimpleSettings ...@@ -24,7 +26,7 @@ from sipsimple.configuration.settings import SIPSimpleSettings
from sipsimple.threading import run_in_thread from sipsimple.threading import run_in_thread
from sipsimple.util import user_info from sipsimple.util import user_info
from blink.resources import Resources from blink.resources import ApplicationData, Resources
from blink.widgets.labels import Status from blink.widgets.labels import Status
from blink.util import QSingleton, call_in_gui_thread, run_in_gui_thread from blink.util import QSingleton, call_in_gui_thread, run_in_gui_thread
...@@ -421,14 +423,14 @@ class AddAccountDialog(base_class, ui_class): ...@@ -421,14 +423,14 @@ class AddAccountDialog(base_class, ui_class):
response_data = cjson.decode(response.read().replace(r'\/', '/')) response_data = cjson.decode(response.read().replace(r'\/', '/'))
response_data = defaultdict(lambda: None, response_data) response_data = defaultdict(lambda: None, response_data)
if response_data['success']: if response_data['success']:
from blink import Blink
try: try:
certificate_path = None
passport = response_data['passport'] passport = response_data['passport']
if passport is not None: if passport is not None:
certificate_path = Blink().save_certificates(response_data['sip_address'], passport['crt'], passport['key'], passport['ca']) certificate_path = self._save_certificates(response_data['sip_address'], passport['crt'], passport['key'], passport['ca'])
else:
certificate_path = None
except (GNUTLSError, IOError, OSError): except (GNUTLSError, IOError, OSError):
pass certificate_path = None
account_manager = AccountManager() account_manager = AccountManager()
try: try:
account = Account(response_data['sip_address']) account = Account(response_data['sip_address'])
...@@ -457,6 +459,37 @@ class AddAccountDialog(base_class, ui_class): ...@@ -457,6 +459,37 @@ class AddAccountDialog(base_class, ui_class):
finally: finally:
call_in_gui_thread(self.setEnabled, True) call_in_gui_thread(self.setEnabled, True)
@staticmethod
def _save_certificates(sip_address, crt, key, ca):
crt = crt.strip() + os.linesep
key = key.strip() + os.linesep
ca = ca.strip() + os.linesep
X509Certificate(crt)
X509PrivateKey(key)
X509Certificate(ca)
makedirs(ApplicationData.get('tls'))
certificate_path = ApplicationData.get(os.path.join('tls', sip_address+'.crt'))
certificate_file = open(certificate_path, 'w')
os.chmod(certificate_path, 0600)
certificate_file.write(crt+key)
certificate_file.close()
ca_path = ApplicationData.get(os.path.join('tls', 'ca.crt'))
try:
existing_cas = open(ca_path).read().strip() + os.linesep
except:
certificate_file = open(ca_path, 'w')
certificate_file.write(ca)
certificate_file.close()
else:
if ca not in existing_cas:
certificate_file = open(ca_path, 'w')
certificate_file.write(existing_cas+ca)
certificate_file.close()
settings = SIPSimpleSettings()
settings.tls.ca_list = ca_path
settings.save()
return certificate_path
@run_in_gui_thread @run_in_gui_thread
def handle_notification(self, notification): def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null) handler = getattr(self, '_NH_%s' % notification.name, Null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment