Add connection password support (+ PASS)
This commit is contained in:
parent
34dacaea70
commit
14935a23ce
4 changed files with 64 additions and 10 deletions
15
irc.py
15
irc.py
|
@ -61,13 +61,22 @@ SERVICES = [
|
||||||
class PesterIRC(QtCore.QThread):
|
class PesterIRC(QtCore.QThread):
|
||||||
"""Class for making a thread that manages the connection to server."""
|
"""Class for making a thread that manages the connection to server."""
|
||||||
|
|
||||||
def __init__(self, window, server: str, port: int, ssl: bool, verify_hostname=True):
|
def __init__(
|
||||||
|
self,
|
||||||
|
window,
|
||||||
|
server: str,
|
||||||
|
port: int,
|
||||||
|
ssl: bool,
|
||||||
|
password="",
|
||||||
|
verify_hostname=True,
|
||||||
|
):
|
||||||
QtCore.QThread.__init__(self)
|
QtCore.QThread.__init__(self)
|
||||||
self.mainwindow = window
|
self.mainwindow = window
|
||||||
|
|
||||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.server = server # Server to connect to.
|
self.server = server # Server to connect to.
|
||||||
self.port = port # Port on server to connect to.
|
self.port = port # Port on server to connect to.
|
||||||
|
self.password = password # Optional password for PASS.
|
||||||
self.ssl = ssl # Whether to connect over SSL/TLS.
|
self.ssl = ssl # Whether to connect over SSL/TLS.
|
||||||
self.verify_hostname = (
|
self.verify_hostname = (
|
||||||
verify_hostname # Whether to verify server hostname. (SSL-only)
|
verify_hostname # Whether to verify server hostname. (SSL-only)
|
||||||
|
@ -179,6 +188,8 @@ class PesterIRC(QtCore.QThread):
|
||||||
self.socket.settimeout(90)
|
self.socket.settimeout(90)
|
||||||
self._send_irc.socket = self.socket
|
self._send_irc.socket = self.socket
|
||||||
|
|
||||||
|
if self.password:
|
||||||
|
self._send_irc.pass_(self.password)
|
||||||
self._send_irc.nick(self.mainwindow.profile().handle)
|
self._send_irc.nick(self.mainwindow.profile().handle)
|
||||||
self._send_irc.user("pcc31", "pcc31")
|
self._send_irc.user("pcc31", "pcc31")
|
||||||
|
|
||||||
|
@ -404,7 +415,7 @@ class PesterIRC(QtCore.QThread):
|
||||||
self.mainwindow.doAutoIdentify()
|
self.mainwindow.doAutoIdentify()
|
||||||
self.mainwindow.autoJoinDone = False
|
self.mainwindow.autoJoinDone = False
|
||||||
self.mainwindow.doAutoJoins()
|
self.mainwindow.doAutoJoins()
|
||||||
self.updateMood()
|
self.update_mood()
|
||||||
|
|
||||||
@QtCore.pyqtSlot()
|
@QtCore.pyqtSlot()
|
||||||
def update_mood(self):
|
def update_mood(self):
|
||||||
|
|
|
@ -3805,9 +3805,10 @@ class PesterWindow(MovingWindow):
|
||||||
"port": int(
|
"port": int(
|
||||||
server_and_port[1]
|
server_and_port[1]
|
||||||
), # to make sure port is a valid integer, and raise an exception if it cannot be converted.
|
), # to make sure port is a valid integer, and raise an exception if it cannot be converted.
|
||||||
|
"pass": self.auth_pass_qline.text(),
|
||||||
"TLS": self.TLS_checkbox.isChecked(),
|
"TLS": self.TLS_checkbox.isChecked(),
|
||||||
}
|
}
|
||||||
PchumLog.info("server: " + str(server))
|
PchumLog.info("server: %s", server)
|
||||||
except:
|
except:
|
||||||
msgbox = QtWidgets.QMessageBox()
|
msgbox = QtWidgets.QMessageBox()
|
||||||
msgbox.setStyleSheet(
|
msgbox.setStyleSheet(
|
||||||
|
@ -3950,12 +3951,24 @@ class PesterWindow(MovingWindow):
|
||||||
layout.addWidget(cancel)
|
layout.addWidget(cancel)
|
||||||
layout.addWidget(ok)
|
layout.addWidget(ok)
|
||||||
main_layout = QtWidgets.QVBoxLayout()
|
main_layout = QtWidgets.QVBoxLayout()
|
||||||
|
|
||||||
nep_prompt = QtWidgets.QLabel(
|
nep_prompt = QtWidgets.QLabel(
|
||||||
":33 < Please put in the server's address in the format HOSTNAME:PORT\n:33 < Fur example, irc.pesterchum.xyz:6697"
|
":33 < Please put in the server's address in the format HOSTNAME:PORT\n:33 < Fur example, irc.pesterchum.xyz:6697"
|
||||||
)
|
)
|
||||||
nep_prompt.setStyleSheet("QLabel { color: #416600; font-weight: bold;}")
|
nep_prompt.setStyleSheet("QLabel { color: #416600; font-weight: bold;}")
|
||||||
|
|
||||||
|
auth_pass_prompt = QtWidgets.QLabel(":33 < type the password!! (optional)")
|
||||||
|
auth_pass_prompt.setStyleSheet(
|
||||||
|
"QLabel { color: #416600; font-weight: bold;}"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.auth_pass_qline = QtWidgets.QLineEdit(self)
|
||||||
|
self.auth_pass_qline.setMinimumWidth(200)
|
||||||
|
|
||||||
main_layout.addWidget(nep_prompt)
|
main_layout.addWidget(nep_prompt)
|
||||||
main_layout.addWidget(self.customServerPrompt_qline)
|
main_layout.addWidget(self.customServerPrompt_qline)
|
||||||
|
main_layout.addWidget(auth_pass_prompt)
|
||||||
|
main_layout.addWidget(self.auth_pass_qline)
|
||||||
main_layout.addLayout(TLS_layout)
|
main_layout.addLayout(TLS_layout)
|
||||||
main_layout.addLayout(layout)
|
main_layout.addLayout(layout)
|
||||||
|
|
||||||
|
@ -4048,6 +4061,11 @@ class PesterWindow(MovingWindow):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
selected_entry = self.serverBox.currentIndex()
|
selected_entry = self.serverBox.currentIndex()
|
||||||
|
PchumLog.debug(
|
||||||
|
"'%s' == '%s'",
|
||||||
|
server_obj[selected_entry]["server"],
|
||||||
|
self.serverBox.currentText(),
|
||||||
|
)
|
||||||
assert (
|
assert (
|
||||||
server_obj[selected_entry]["server"] == self.serverBox.currentText()
|
server_obj[selected_entry]["server"] == self.serverBox.currentText()
|
||||||
)
|
)
|
||||||
|
@ -4060,9 +4078,13 @@ class PesterWindow(MovingWindow):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(_datadir + "server.json", "w") as server_file:
|
with open(_datadir + "server.json", "w") as server_file:
|
||||||
|
password = ""
|
||||||
|
if "pass" in server_obj[selected_entry]:
|
||||||
|
password = server_obj[selected_entry]["pass"]
|
||||||
json_server_file = {
|
json_server_file = {
|
||||||
"server": server_obj[selected_entry]["server"],
|
"server": server_obj[selected_entry]["server"],
|
||||||
"port": server_obj[selected_entry]["port"],
|
"port": server_obj[selected_entry]["port"],
|
||||||
|
"pass": password,
|
||||||
"TLS": server_obj[selected_entry]["TLS"],
|
"TLS": server_obj[selected_entry]["TLS"],
|
||||||
}
|
}
|
||||||
server_file.write(json.dumps(json_server_file, indent=4))
|
server_file.write(json.dumps(json_server_file, indent=4))
|
||||||
|
@ -4089,12 +4111,13 @@ class PesterWindow(MovingWindow):
|
||||||
for i in range(len(server_obj)):
|
for i in range(len(server_obj)):
|
||||||
server_list_items.append(server_obj[i]["server"])
|
server_list_items.append(server_obj[i]["server"])
|
||||||
except:
|
except:
|
||||||
|
PchumLog.exception("")
|
||||||
if not self.chooseServerAskedToReset:
|
if not self.chooseServerAskedToReset:
|
||||||
self.chooseServerAskedToReset = True
|
self.chooseServerAskedToReset = True
|
||||||
self.resetServerlist()
|
self.resetServerlist()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
PchumLog.info("server_list_items: " + str(server_list_items))
|
PchumLog.info("server_list_items: %s", server_list_items)
|
||||||
|
|
||||||
# Widget 1
|
# Widget 1
|
||||||
self.chooseServerWidged = QtWidgets.QDialog()
|
self.chooseServerWidged = QtWidgets.QDialog()
|
||||||
|
@ -4326,6 +4349,7 @@ class MainProgram(QtCore.QObject):
|
||||||
self.widget.config.server(),
|
self.widget.config.server(),
|
||||||
self.widget.config.port(),
|
self.widget.config.port(),
|
||||||
self.widget.config.ssl(),
|
self.widget.config.ssl(),
|
||||||
|
password=self.widget.config.password(),
|
||||||
)
|
)
|
||||||
self.connectWidgets(self.irc, self.widget)
|
self.connectWidgets(self.irc, self.widget)
|
||||||
|
|
||||||
|
@ -4503,6 +4527,7 @@ class MainProgram(QtCore.QObject):
|
||||||
self.widget.config.server(),
|
self.widget.config.server(),
|
||||||
self.widget.config.port(),
|
self.widget.config.port(),
|
||||||
self.widget.config.ssl(),
|
self.widget.config.ssl(),
|
||||||
|
password=self.widget.config.password(),
|
||||||
verify_hostname=verify_hostname,
|
verify_hostname=verify_hostname,
|
||||||
)
|
)
|
||||||
self.connectWidgets(self.irc, self.widget)
|
self.connectWidgets(self.irc, self.widget)
|
||||||
|
|
24
profile.py
24
profile.py
|
@ -446,10 +446,10 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
|
||||||
try:
|
try:
|
||||||
with open(_datadir + "server.json") as server_file:
|
with open(_datadir + "server.json") as server_file:
|
||||||
read_file = server_file.read()
|
read_file = server_file.read()
|
||||||
server_file.close()
|
|
||||||
server_obj = json.loads(read_file)
|
server_obj = json.loads(read_file)
|
||||||
return server_obj["server"]
|
return server_obj["server"]
|
||||||
except:
|
except:
|
||||||
|
PchumLog.exception("Failed to load server, falling back to default.")
|
||||||
try:
|
try:
|
||||||
with open(_datadir + "server.json", "w") as server_file:
|
with open(_datadir + "server.json", "w") as server_file:
|
||||||
json_server_file = {
|
json_server_file = {
|
||||||
|
@ -458,7 +458,6 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
|
||||||
"TLS": True,
|
"TLS": True,
|
||||||
}
|
}
|
||||||
server_file.write(json.dumps(json_server_file, indent=4))
|
server_file.write(json.dumps(json_server_file, indent=4))
|
||||||
server_file.close()
|
|
||||||
server = "irc.pesterchum.xyz"
|
server = "irc.pesterchum.xyz"
|
||||||
except:
|
except:
|
||||||
return self.config.get("server", "irc.pesterchum.xyz")
|
return self.config.get("server", "irc.pesterchum.xyz")
|
||||||
|
@ -469,11 +468,11 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
|
||||||
try:
|
try:
|
||||||
with open(_datadir + "server.json") as server_file:
|
with open(_datadir + "server.json") as server_file:
|
||||||
read_file = server_file.read()
|
read_file = server_file.read()
|
||||||
server_file.close()
|
server_obj = json.loads(read_file)
|
||||||
server_obj = json.loads(read_file)
|
|
||||||
port = server_obj["port"]
|
port = server_obj["port"]
|
||||||
return port
|
return port
|
||||||
except:
|
except:
|
||||||
|
PchumLog.exception("Failed to load port, falling back to default.")
|
||||||
return self.config.get("port", "6697")
|
return self.config.get("port", "6697")
|
||||||
|
|
||||||
def ssl(self):
|
def ssl(self):
|
||||||
|
@ -482,10 +481,23 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
|
||||||
try:
|
try:
|
||||||
with open(_datadir + "server.json") as server_file:
|
with open(_datadir + "server.json") as server_file:
|
||||||
read_file = server_file.read()
|
read_file = server_file.read()
|
||||||
server_file.close()
|
server_obj = json.loads(read_file)
|
||||||
server_obj = json.loads(read_file)
|
|
||||||
return server_obj["TLS"]
|
return server_obj["TLS"]
|
||||||
except:
|
except:
|
||||||
|
PchumLog.exception("Failed to load TLS setting, falling back to default.")
|
||||||
|
return self.config.get("TLS", True)
|
||||||
|
|
||||||
|
def password(self):
|
||||||
|
try:
|
||||||
|
with open(_datadir + "server.json") as server_file:
|
||||||
|
read_file = server_file.read()
|
||||||
|
server_obj = json.loads(read_file)
|
||||||
|
password = ""
|
||||||
|
if "pass" in server_obj:
|
||||||
|
password = server_obj["pass"]
|
||||||
|
return password
|
||||||
|
except:
|
||||||
|
PchumLog.exception("Failed to load TLS setting, falling back to default.")
|
||||||
return self.config.get("TLS", True)
|
return self.config.get("TLS", True)
|
||||||
|
|
||||||
def soundOn(self):
|
def soundOn(self):
|
||||||
|
|
|
@ -54,6 +54,12 @@ class SendIRC:
|
||||||
"""Send PONG command to reply to server PING."""
|
"""Send PONG command to reply to server PING."""
|
||||||
self._send("PONG", token)
|
self._send("PONG", token)
|
||||||
|
|
||||||
|
def pass_(self, password):
|
||||||
|
"""Send a 'connection password' to the server.
|
||||||
|
|
||||||
|
Function is 'pass_' because 'pass' is reserved."""
|
||||||
|
self._send("PASS", text=password)
|
||||||
|
|
||||||
def nick(self, nick):
|
def nick(self, nick):
|
||||||
"""Send USER command to communicate nick to server."""
|
"""Send USER command to communicate nick to server."""
|
||||||
self._send("NICK", nick)
|
self._send("NICK", nick)
|
||||||
|
|
Loading…
Reference in a new issue