Update custom command help and protect against double quote in project name

This commit is contained in:
grossmj
2023-10-31 14:43:50 +10:00
parent 82e7c151c4
commit 932083be88
6 changed files with 21 additions and 19 deletions

View File

@@ -150,7 +150,7 @@ class PacketCapture:
# Add project name
command = command.replace("%P", link.project().name())
command = command.replace("{project}", link.project().name())
command = command.replace("{project}", link.project().name().replace('"', '\\"'))
# Add link description
description = "{}[{}]->{}[{}]".format(link.sourceNode().name(),
@@ -214,7 +214,7 @@ class PacketCapture:
# Add project name
command = command.replace("%P", link.project().name())
command = command.replace("{project}", link.project().name())
command = command.replace("{project}", link.project().name().replace('"', '\\"'))
# Add link description
description = "{} {} to {} {}".format(link.sourceNode().name(),

View File

@@ -54,8 +54,8 @@ def spiceConsole(node, port, command):
command = command.replace("%h", host)
command = command.replace("%p", str(port))
command = command.replace("%d", name.replace('"', '\\"'))
command = command.replace("%P", node.project().name().replace('"', '\\"'))
command = command.replace("%i", node.project().id())
command = command.replace("%P", node.project().name())
command = command.replace("%n", str(node.id()))
command = command.replace("%c", Controller.instance().httpClient().fullUrl())

View File

@@ -113,15 +113,15 @@ class ConsoleThread(QtCore.QThread):
command = self._command.replace("%h", host)
command = command.replace("%p", str(port))
command = command.replace("%d", self._name.replace('"', '\\"'))
command = command.replace("%P", self._node.project().name().replace('"', '\\"'))
command = command.replace("%i", self._node.project().id())
command = command.replace("%P", self._node.project().name())
command = command.replace("%n", str(self._node.id()))
command = command.replace("%c", Controller.instance().httpClient().fullUrl())
command = self._command.replace("{host}", host)
command = command.replace("{host}", host)
command = command.replace("{port}", str(port))
command = command.replace("{name}", self._name.replace('"', '\\"'))
command = command.replace("{project}", self._node.project().name())
command = command.replace("{project}", self._node.project().name().replace('"', '\\"'))
command = command.replace("{project_id}", self._node.project().id())
command = command.replace("{node_id}", str(self._node.id()))
command = command.replace("{url}", Controller.instance().httpClient().fullUrl())

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>965</width>
<height>547</height>
<width>576</width>
<height>346</height>
</rect>
</property>
<property name="sizePolicy">
@@ -70,7 +70,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Or customize the command in the next input field. &lt;br/&gt;The following variables are replaced by GNS3: &lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%h: console IP or hostname&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%p: console port&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%P: VNC display&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%s: path of the serial connection&lt;/li&gt;&lt;/ul&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%d: title of the console&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%i: Project UUID&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%c: server URL (&lt;span style=&quot; font-style:italic;&quot;&gt;http://user:password@server:port&lt;/span&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Or customize the command in the next input field. &lt;br/&gt;The following variables are replaced by GNS3: &lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%h or {host}: console IP or hostname&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%p or {port}: console port&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%D or {display}: VNC display&lt;/li&gt;&lt;/ul&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%d or {name}: title of the console&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%P or {project}: project name&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%i or {project_id}: project UUID&lt;/li&gt;&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;%c or {url}: server URL (&lt;span style=&quot; font-style:italic;&quot;&gt;http://user:password@server:port&lt;/span&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>

View File

@@ -2,16 +2,19 @@
# Form implementation generated from reading ui file '/home/grossmj/PycharmProjects/gns3-gui/gns3/ui/console_command_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.5.1
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING! All changes made in this file will be lost!
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_uiConsoleCommandDialog(object):
def setupUi(self, uiConsoleCommandDialog):
uiConsoleCommandDialog.setObjectName("uiConsoleCommandDialog")
uiConsoleCommandDialog.resize(965, 547)
uiConsoleCommandDialog.resize(576, 346)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
@@ -57,8 +60,8 @@ class Ui_uiConsoleCommandDialog(object):
self.verticalLayout.addWidget(self.uiButtonBox)
self.retranslateUi(uiConsoleCommandDialog)
self.uiButtonBox.accepted.connect(uiConsoleCommandDialog.accept)
self.uiButtonBox.rejected.connect(uiConsoleCommandDialog.reject)
self.uiButtonBox.accepted.connect(uiConsoleCommandDialog.accept) # type: ignore
self.uiButtonBox.rejected.connect(uiConsoleCommandDialog.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(uiConsoleCommandDialog)
def retranslateUi(self, uiConsoleCommandDialog):
@@ -67,5 +70,4 @@ class Ui_uiConsoleCommandDialog(object):
self.label_2.setText(_translate("uiConsoleCommandDialog", "Choose a predefined command:"))
self.uiRemovePushButton.setText(_translate("uiConsoleCommandDialog", "Remove"))
self.uiSavePushButton.setText(_translate("uiConsoleCommandDialog", "Save"))
self.label.setText(_translate("uiConsoleCommandDialog", "<html><head/><body><p>Or customize the command in the next input field. <br/>The following variables are replaced by GNS3: </p><ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%h: console IP or hostname</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%p: console port</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%P: VNC display</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%s: path of the serial connection</li></ul><ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%d: title of the console</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%i: Project UUID</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%c: server URL (<span style=\" font-style:italic;\">http://user:password@server:port</span>)</li></ul></body></html>"))
self.label.setText(_translate("uiConsoleCommandDialog", "<html><head/><body><p>Or customize the command in the next input field. <br/>The following variables are replaced by GNS3: </p><ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%h or {host}: console IP or hostname</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%p or {port}: console port</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%D or {display}: VNC display</li></ul><ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%d or {name}: title of the console</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%P or {project}: project name</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%i or {project_id}: project UUID</li><li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">%c or {url}: server URL (<span style=\" font-style:italic;\">http://user:password@server:port</span>)</li></ul></body></html>"))

View File

@@ -48,17 +48,17 @@ def vncConsole(node, port, command):
# replace the place-holders by the actual values
command = command.replace("%h", host)
command = command.replace("%p", str(port))
command = command.replace("%P", str(port - 5900))
command = command.replace("%D", str(port - 5900))
command = command.replace("%d", name.replace('"', '\\"'))
command = command.replace("%P", node.project().name().replace('"', '\\"'))
command = command.replace("%i", node.project().id())
command = command.replace("%T", node.project().name())
command = command.replace("%n", str(node.id()))
command = command.replace("{host}", host)
command = command.replace("{port}", str(port))
command = command.replace("{display}", str(port - 5900))
command = command.replace("{name}", name.replace('"', '\\"'))
command = command.replace("{project}", node.project().name())
command = command.replace("{project}", node.project().name().replace('"', '\\"'))
command = command.replace("{project_id}", node.project().id())
command = command.replace("{node_id}", str(node.id()))
command = command.replace("{url}", Controller.instance().httpClient().fullUrl())