Adds API commands for blacklist manipulation.
This commit is contained in:
parent
b02a5d3109
commit
afb21ca307
49
src/api.py
49
src/api.py
|
@ -735,6 +735,55 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
shared.UISignalQueue.put(('rerenderSubscriptions', ''))
|
shared.UISignalQueue.put(('rerenderSubscriptions', ''))
|
||||||
return 'Added subscription.'
|
return 'Added subscription.'
|
||||||
|
|
||||||
|
elif method == 'addAddressToBlackWhiteList':
|
||||||
|
if len(params) == 0:
|
||||||
|
raise APIError(0, 'I need parameters!')
|
||||||
|
if len(params) == 1:
|
||||||
|
address, = params
|
||||||
|
label = ''
|
||||||
|
if len(params) == 2:
|
||||||
|
address, label = params
|
||||||
|
label = self._decode(label, "base64")
|
||||||
|
try:
|
||||||
|
unicode(label, 'utf-8')
|
||||||
|
except:
|
||||||
|
raise APIError(17, 'Label is not valid UTF-8 data.')
|
||||||
|
if len(params) > 2:
|
||||||
|
raise APIError(0, 'I need either 1 or 2 parameters!')
|
||||||
|
address = addBMIfNotPresent(address)
|
||||||
|
self._verifyAddress(address)
|
||||||
|
|
||||||
|
table = ''
|
||||||
|
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
|
||||||
|
table = 'blacklist'
|
||||||
|
else:
|
||||||
|
table = 'whitelist'
|
||||||
|
|
||||||
|
# First we must check to see if the address is already in the
|
||||||
|
# black-/white-list.
|
||||||
|
queryreturn = sqlQuery('''select * from '''+table+''' where address=?''', address)
|
||||||
|
if queryreturn != []:
|
||||||
|
raise APIError(16, 'You have already black-/white-listed that address.')
|
||||||
|
sqlExecute('''INSERT INTO '''+table+''' VALUES (?,?,?)''',label, address, True)
|
||||||
|
shared.UISignalQueue.put(('rerenderBlacklist', ''))
|
||||||
|
return 'Added black-/white-list entry.'
|
||||||
|
|
||||||
|
elif method == 'removeAddressFromBlackWhiteList':
|
||||||
|
if len(params) != 1:
|
||||||
|
raise APIError(0, 'I need 1 parameter!')
|
||||||
|
address, = params
|
||||||
|
address = addBMIfNotPresent(address)
|
||||||
|
|
||||||
|
table = ''
|
||||||
|
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
|
||||||
|
table = 'blacklist'
|
||||||
|
else:
|
||||||
|
table = 'whitelist'
|
||||||
|
|
||||||
|
sqlExecute('''DELETE FROM blacklist WHERE address=?''', address)
|
||||||
|
shared.UISignalQueue.put(('rerenderBlacklist', ''))
|
||||||
|
return 'Deleted black-/white-list entry if it existed.'
|
||||||
|
|
||||||
elif method == 'deleteSubscription':
|
elif method == 'deleteSubscription':
|
||||||
if len(params) != 1:
|
if len(params) != 1:
|
||||||
raise APIError(0, 'I need 1 parameter!')
|
raise APIError(0, 'I need 1 parameter!')
|
||||||
|
|
|
@ -557,6 +557,7 @@ class MyForm(QtGui.QMainWindow):
|
||||||
self.ui.tabWidget.setTabText(6, 'Whitelist')
|
self.ui.tabWidget.setTabText(6, 'Whitelist')
|
||||||
self.ui.radioButtonWhitelist.click()
|
self.ui.radioButtonWhitelist.click()
|
||||||
self.loadBlackWhiteList()
|
self.loadBlackWhiteList()
|
||||||
|
self.rerenderBlacklist()
|
||||||
|
|
||||||
QtCore.QObject.connect(self.ui.tableWidgetYourIdentities, QtCore.SIGNAL(
|
QtCore.QObject.connect(self.ui.tableWidgetYourIdentities, QtCore.SIGNAL(
|
||||||
"itemChanged(QTableWidgetItem *)"), self.tableWidgetYourIdentitiesItemChanged)
|
"itemChanged(QTableWidgetItem *)"), self.tableWidgetYourIdentitiesItemChanged)
|
||||||
|
@ -621,6 +622,8 @@ class MyForm(QtGui.QMainWindow):
|
||||||
"rerenderAddressBook()"), self.rerenderAddressBook)
|
"rerenderAddressBook()"), self.rerenderAddressBook)
|
||||||
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
"rerenderSubscriptions()"), self.rerenderSubscriptions)
|
"rerenderSubscriptions()"), self.rerenderSubscriptions)
|
||||||
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
|
"rerenderBlacklist()"), self.rerenderBlacklist)
|
||||||
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
"removeInboxRowByMsgid(PyQt_PyObject)"), self.removeInboxRowByMsgid)
|
"removeInboxRowByMsgid(PyQt_PyObject)"), self.removeInboxRowByMsgid)
|
||||||
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
|
@ -1832,6 +1835,24 @@ class MyForm(QtGui.QMainWindow):
|
||||||
newItem.setTextColor(QtGui.QColor(128, 128, 128))
|
newItem.setTextColor(QtGui.QColor(128, 128, 128))
|
||||||
self.ui.tableWidgetSubscriptions.setItem(0, 1, newItem)
|
self.ui.tableWidgetSubscriptions.setItem(0, 1, newItem)
|
||||||
|
|
||||||
|
def rerenderBlacklist(self):
|
||||||
|
self.ui.tableWidgetBlacklist.setRowCount(0)
|
||||||
|
queryreturn = sqlQuery('SELECT label, address, enabled FROM blacklist')
|
||||||
|
for row in queryreturn:
|
||||||
|
label, address, enabled = row
|
||||||
|
self.ui.tableWidgetBlacklist.insertRow(0)
|
||||||
|
newItem = QtGui.QTableWidgetItem(unicode(label, 'utf-8'))
|
||||||
|
if not enabled:
|
||||||
|
newItem.setTextColor(QtGui.QColor(128, 128, 128))
|
||||||
|
newItem.setIcon(avatarize(address))
|
||||||
|
self.ui.tableWidgetBlacklist.setItem(0, 0, newItem)
|
||||||
|
newItem = QtGui.QTableWidgetItem(address)
|
||||||
|
newItem.setFlags(
|
||||||
|
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||||
|
if not enabled:
|
||||||
|
newItem.setTextColor(QtGui.QColor(128, 128, 128))
|
||||||
|
self.ui.tableWidgetBlacklist.setItem(0, 1, newItem)
|
||||||
|
|
||||||
def click_pushButtonSend(self):
|
def click_pushButtonSend(self):
|
||||||
self.statusBar().showMessage('')
|
self.statusBar().showMessage('')
|
||||||
toAddresses = str(self.ui.lineEditTo.text())
|
toAddresses = str(self.ui.lineEditTo.text())
|
||||||
|
@ -3183,6 +3204,7 @@ class MyForm(QtGui.QMainWindow):
|
||||||
self.rerenderInboxToLabels()
|
self.rerenderInboxToLabels()
|
||||||
self.rerenderSentFromLabels()
|
self.rerenderSentFromLabels()
|
||||||
self.rerenderSentToLabels()
|
self.rerenderSentToLabels()
|
||||||
|
self.rerenderBlacklist()
|
||||||
|
|
||||||
def on_context_menuYourIdentities(self, point):
|
def on_context_menuYourIdentities(self, point):
|
||||||
self.popMenu.exec_(
|
self.popMenu.exec_(
|
||||||
|
@ -3838,6 +3860,8 @@ class UISignaler(QThread):
|
||||||
self.emit(SIGNAL("rerenderAddressBook()"))
|
self.emit(SIGNAL("rerenderAddressBook()"))
|
||||||
elif command == 'rerenderSubscriptions':
|
elif command == 'rerenderSubscriptions':
|
||||||
self.emit(SIGNAL("rerenderSubscriptions()"))
|
self.emit(SIGNAL("rerenderSubscriptions()"))
|
||||||
|
elif command == 'rerenderBlacklist':
|
||||||
|
self.emit(SIGNAL("rerenderBlacklist()"))
|
||||||
elif command == 'removeInboxRowByMsgid':
|
elif command == 'removeInboxRowByMsgid':
|
||||||
self.emit(SIGNAL("removeInboxRowByMsgid(PyQt_PyObject)"), data)
|
self.emit(SIGNAL("removeInboxRowByMsgid(PyQt_PyObject)"), data)
|
||||||
elif command == 'alert':
|
elif command == 'alert':
|
||||||
|
|
Reference in New Issue
Block a user