This repository has been archived on 2024-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-03/src/bitmessageqt/support.py

180 lines
5.5 KiB
Python
Raw Normal View History

"""Composing support request message functions."""
import ctypes
import os
import ssl
import sys
2015-12-21 15:38:45 +01:00
import time
2024-05-26 03:18:08 +02:00
from unqstr import ustr, unic
from dbcompat import dbstr
from bitmessageqt import account
import defaults
import network.stats
import paths
2017-08-15 18:14:36 +02:00
import proofofwork
import queues
import state
from bmconfigparser import config
from .foldertree import AccountMixin
from helper_sql import sqlExecute, sqlQuery
from l10n import getTranslationLanguage
from openclpow import openclEnabled
from pyelliptic.openssl import OpenSSL
from .settings import getSOCKSProxyType
from version import softwareVersion
from tr import _translate
# this is BM support address going to Peter Surda
OLD_SUPPORT_ADDRESS = 'BM-2cTkCtMYkrSPwFTpgcBrMrf5d8oZwvMZWK'
SUPPORT_ADDRESS = 'BM-2cUdgkDDAahwPAU6oD2A7DnjqZz3hgY832'
SUPPORT_LABEL = _translate("Support", "PyBitmessage support")
SUPPORT_MY_LABEL = _translate("Support", "My new address")
SUPPORT_SUBJECT = _translate("Support", "Support request")
SUPPORT_MESSAGE = _translate("Support", '''
You can use this message to send a report to one of the PyBitmessage core \
developers regarding PyBitmessage or the mailchuck.com email service. \
If you are using PyBitmessage involuntarily, for example because \
your computer was infected with ransomware, this is not an appropriate venue \
for resolving such issues.
Please describe what you are trying to do:
Please describe what you expect to happen:
Please describe what happens instead:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Please write above this line and if possible, keep the information about your \
environment below intact.
2016-11-05 00:46:07 +01:00
PyBitmessage version: {}
Operating system: {}
Architecture: {}bit
Python Version: {}
OpenSSL Version: {}
Qt API: {}
Frozen: {}
Portable mode: {}
C PoW: {}
OpenCL PoW: {}
Locale: {}
SOCKS: {}
UPnP: {}
Connected hosts: {}
''')
def checkAddressBook(myapp):
"""
Add "PyBitmessage support" address to address book, remove old one if found.
"""
sqlExecute('DELETE from addressbook WHERE address=?', dbstr(OLD_SUPPORT_ADDRESS))
queryreturn = sqlQuery(
2024-05-29 14:39:16 +02:00
'SELECT * FROM addressbook WHERE address=?', dbstr(SUPPORT_ADDRESS))
if queryreturn == []:
sqlExecute(
'INSERT INTO addressbook VALUES (?,?)',
2024-05-28 01:40:40 +02:00
dbstr(SUPPORT_LABEL), dbstr(SUPPORT_ADDRESS))
myapp.rerenderAddressBook()
def checkHasNormalAddress():
"""Returns first enabled normal address or False if not found."""
2024-05-21 16:49:12 +02:00
for address in config.addresses(True):
acct = account.accountClass(address)
2024-05-21 16:49:12 +02:00
if acct.type == AccountMixin.NORMAL and config.safeGetBoolean(
address, 'enabled'):
return address
return False
def createAddressIfNeeded(myapp):
"""Checks if user has any anabled normal address, creates new one if no."""
if not checkHasNormalAddress():
queues.addressGeneratorQueue.put((
'createRandomAddress', 4, 1,
2024-05-23 06:28:40 +02:00
ustr(SUPPORT_MY_LABEL),
1, "", False,
defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
defaults.networkDefaultPayloadLengthExtraBytes
))
while state.shutdown == 0 and not checkHasNormalAddress():
time.sleep(.2)
myapp.rerenderComboBoxSendFrom()
return checkHasNormalAddress()
def createSupportMessage(myapp):
"""
Prepare the support request message and switch to tab "Send"
"""
checkAddressBook(myapp)
address = createAddressIfNeeded(myapp)
if state.shutdown:
return
myapp.ui.lineEditSubject.setText(SUPPORT_SUBJECT)
# addrIndex = myapp.ui.comboBoxSendFrom.findData(
# address, QtCore.Qt.UserRole,
# QtCore.Qt.MatchFixedString | QtCore.Qt.MatchCaseSensitive
# )
addrIndex = myapp.ui.comboBoxSendFrom.findData(address)
if addrIndex == -1: # something is very wrong
return
myapp.ui.comboBoxSendFrom.setCurrentIndex(addrIndex)
myapp.ui.lineEditTo.setText(SUPPORT_ADDRESS)
version = softwareVersion
commit = paths.lastCommit().get('commit')
if commit:
version += " GIT " + commit
if sys.platform.startswith("win"):
# pylint: disable=no-member
osname = "Windows %s.%s" % sys.getwindowsversion()[:2]
else:
try:
unixversion = os.uname()
osname = unixversion[0] + " " + unixversion[2]
except:
pass
architecture = "32" if ctypes.sizeof(ctypes.c_voidp) == 4 else "64"
pythonversion = sys.version
opensslversion = "%s (Python internal), %s (external for PyElliptic)" % (
ssl.OPENSSL_VERSION, OpenSSL._version)
2019-02-11 17:48:57 +01:00
qtapi = os.environ.get('QT_API', 'fallback')
frozen = "N/A"
if paths.frozen:
frozen = paths.frozen
portablemode = str(state.appdata == paths.lookupExeFolder())
2017-08-15 18:14:36 +02:00
cpow = "True" if proofofwork.bmpow else "False"
2024-05-23 06:28:40 +02:00
openclpow = ustr(
config.safeGet('bitmessagesettings', 'opencl')
) if openclEnabled() else "None"
locale = getTranslationLanguage()
2024-05-21 16:49:12 +02:00
socks = getSOCKSProxyType(config) or 'N/A'
upnp = config.safeGet('bitmessagesettings', 'upnp', 'N/A')
connectedhosts = len(network.stats.connectedHostsList())
2024-05-23 06:28:40 +02:00
myapp.ui.textEditMessage.setText(unic(ustr(SUPPORT_MESSAGE).format(
version, osname, architecture, pythonversion, opensslversion, qtapi,
frozen, portablemode, cpow, openclpow, locale, socks, upnp,
connectedhosts
2024-05-29 14:39:16 +02:00
)))
# single msg tab
myapp.ui.tabWidgetSend.setCurrentIndex(
myapp.ui.tabWidgetSend.indexOf(myapp.ui.sendDirect)
)
# send tab
myapp.ui.tabWidget.setCurrentIndex(
myapp.ui.tabWidget.indexOf(myapp.ui.send)
)