1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

docs(usermanual): Add information about commandline options

This commit is contained in:
jenli669 2019-08-29 14:38:33 +02:00 committed by Anthony Bilinski
parent 31fec7488f
commit bd034e130d
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
4 changed files with 174 additions and 189 deletions

View File

@ -10,6 +10,7 @@
* [Quotes](#quotes) * [Quotes](#quotes)
* [Multi Window Mode](#multi-window-mode) * [Multi Window Mode](#multi-window-mode)
* [Keyboard Shortcuts](#keyboard-shortcuts) * [Keyboard Shortcuts](#keyboard-shortcuts)
* [Commandline Options](#commandline-options)
* [Emoji Packs](#emoji-packs) * [Emoji Packs](#emoji-packs)
@ -429,6 +430,25 @@ The following shortcuts are currently supported:
In audio group chat microphone mute state will be changed while `Ctrl` + In audio group chat microphone mute state will be changed while `Ctrl` +
`p` pressed and reverted on release. `p` pressed and reverted on release.
## Commandline Options
| Option | Action |
|------------------------------------|----------------------------------------------------|
| `-p` `<profile>` | Use specified unencrypted profile |
| `-l` | Start with loginscreen |
| `-I` `<on/off>` | Sets IPv6 toggle [Default: ON] |
| `-U` `<on/off>` | Sets UDP toggle [Default: ON] |
| `-L` `<on/off>` | Sets LAN toggle [Default: ON] |
| `-P` `<protocol>:<address>:<port>` | Applies [proxy options](#commandline-proxy-options) [Default: NONE]|
### Commandline Proxy Options
Protocol: NONE, HTTP or SOCKS5 <br>
Address: Proxy address <br>
Port: Proxy port number (0-65535) <br>
Example input: <br>
`qtox -P SOCKS5:192.168.0.1:2121` <br>
`qtox -P none`
## Emoji Packs ## Emoji Packs
qTox provides support for custom emoji packs. To install a new emoji pack qTox provides support for custom emoji packs. To install a new emoji pack

View File

@ -58,96 +58,6 @@ static QList<QByteArray>* logBuffer =
QMutex* logBufferMutex = new QMutex(); QMutex* logBufferMutex = new QMutex();
#endif #endif
/**
* Verifies that commandline proxy settings are at least reasonable. Does not verify provided IP
* or hostname addresses are valid. Code duplication with Settings::applyCommandLineOptions, which
* also verifies arguments, should be removed in a future refactor.
* @param parser QCommandLineParser instance
*/
bool verifyProxySettings(QCommandLineParser& parser)
{
QString IPv6Setting = parser.value("I");
QString LANSetting = parser.value("L");
QString UDPSetting = parser.value("U");
QString proxySettingString = parser.value("proxy");
QStringList proxySettings = proxySettingString.split(":");
// Check for incompatible settings
bool activeProxyType = false;
if (parser.isSet("P")) {
activeProxyType = proxySettings[0].compare(QString("SOCKS5"), Qt::CaseInsensitive) == 0
|| proxySettings[0].compare(QString("HTTP"), Qt::CaseInsensitive) == 0;
}
if (activeProxyType && (UDPSetting.compare(QString("on"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Cannot set UDP on with proxy.";
return false;
}
if (activeProxyType && (LANSetting.compare(QString("on"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Cannot set LAN discovery on with proxy.";
return false;
}
if ((LANSetting.compare(QString("on"), Qt::CaseInsensitive) == 0)
&& (UDPSetting.compare(QString("off"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Incompatible UDP/LAN settings.";
return false;
}
if (parser.isSet("I")) {
if (!(IPv6Setting.compare(QString("on"), Qt::CaseInsensitive) == 0
|| IPv6Setting.compare(QString("off"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Unable to parse IPv6 setting.";
return false;
}
}
if (parser.isSet("U")) {
if (!(UDPSetting.compare(QString("on"), Qt::CaseInsensitive) == 0
|| UDPSetting.compare(QString("off"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Unable to parse UDP setting.";
return false;
}
}
if (parser.isSet("L")) {
if (!(LANSetting.compare(QString("on"), Qt::CaseInsensitive) == 0
|| LANSetting.compare(QString("off"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Unable to parse LAN setting.";
return false;
}
}
if (parser.isSet("P")) {
if (proxySettings[0].compare(QString("NONE"), Qt::CaseInsensitive) == 0) {
return true;
// slightly lazy check here, accepting 'NONE[:.*]' is fine since no other
// arguments will be investigated when proxy settings are applied.
}
// Since the first argument isn't 'none', verify format of remaining arguments
if (proxySettings.size() != 3) {
qCritical() << "Invalid number of proxy arguments.";
return false;
}
if (!(proxySettings[0].compare(QString("SOCKS5"), Qt::CaseInsensitive) == 0
|| proxySettings[0].compare(QString("HTTP"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Unable to parse proxy type.";
return false;
}
// Kriby: Sanity checking IPv4+IPv6/hostnames sure is a lot of work!
int portNumber = proxySettings[2].toInt();
if (!(portNumber > 0 && portNumber < 65536)) {
qCritical() << "Invalid port number range.";
}
}
return true;
}
void cleanup() void cleanup()
{ {
// force save early even though destruction saves, because Windows OS will // force save early even though destruction saves, because Windows OS will
@ -307,18 +217,21 @@ int main(int argc, char* argv[])
QObject::tr("Starts new instance and opens the login screen."))); QObject::tr("Starts new instance and opens the login screen.")));
parser.addOption(QCommandLineOption(QStringList() << "I" parser.addOption(QCommandLineOption(QStringList() << "I"
<< "IPv6", << "IPv6",
QObject::tr("Sets IPv6 <on>/<off>"), QObject::tr("on/off"))); QObject::tr("Sets IPv6 <on>/<off>. Default is ON."),
QObject::tr("on/off")));
parser.addOption(QCommandLineOption(QStringList() << "U" parser.addOption(QCommandLineOption(QStringList() << "U"
<< "UDP", << "UDP",
QObject::tr("Sets UDP <on>/<off>"), QObject::tr("on/off"))); QObject::tr("Sets UDP <on>/<off>. Default is ON."),
QObject::tr("on/off")));
parser.addOption( parser.addOption(
QCommandLineOption(QStringList() << "L" QCommandLineOption(QStringList() << "L"
<< "LAN", << "LAN",
QObject::tr("Sets LAN discovery <on>/<off>. UDP off overrides."), QObject::tr(
"Sets LAN discovery <on>/<off>. UDP off overrides. Default is ON."),
QObject::tr("on/off"))); QObject::tr("on/off")));
parser.addOption(QCommandLineOption(QStringList() << "P" parser.addOption(QCommandLineOption(QStringList() << "P"
<< "proxy", << "proxy",
QObject::tr("Sets proxy settings."), QObject::tr("Sets proxy settings. Default is NONE."),
QObject::tr("(SOCKS5/HTTP/NONE):(ADDRESS):(PORT)"))); QObject::tr("(SOCKS5/HTTP/NONE):(ADDRESS):(PORT)")));
parser.process(*a); parser.process(*a);
@ -435,7 +348,7 @@ int main(int argc, char* argv[])
} }
} }
if (!verifyProxySettings(parser)) { if (!Settings::verifyProxySettings(parser)) {
return -1; return -1;
} }

View File

@ -292,142 +292,193 @@ void Settings::updateProfileData(Profile* profile, const QCommandLineParser* par
saveGlobal(); saveGlobal();
loadPersonal(profile->getName(), profile->getPasskey()); loadPersonal(profile->getName(), profile->getPasskey());
if (parser) { if (parser) {
applyCommandLineOptions(parser); applyCommandLineOptions(*parser);
} }
} }
/** /**
* Applies command line options on top of loaded settings. Fails without changes if attempting to * Verifies that commandline proxy settings are at least reasonable. Does not verify provided IP
* apply contradicting settings. * or hostname addresses are valid. Code duplication with Settings::applyCommandLineOptions, which
* @param parser * also verifies arguments, should be removed in a future refactor.
* @return Success indicator (success = true) * @param parser QCommandLineParser instance
*/ */
bool Settings::applyCommandLineOptions(const QCommandLineParser* parser) bool Settings::verifyProxySettings(const QCommandLineParser& parser)
{ {
QString IPv6Setting = parser->value("I"); QString IPv6SettingString = parser.value("I").toLower();
QString LANSetting = parser->value("L"); QString LANSettingString = parser.value("L").toLower();
QString UDPSetting = parser->value("U"); QString UDPSettingString = parser.value("U").toLower();
QString proxySettingString = parser->value("proxy"); QString proxySettingString = parser.value("proxy").toLower();
QStringList proxySettings = proxySettingString.split(":"); QStringList proxySettingStrings = proxySettingString.split(":");
const QString SOCKS5 = QStringLiteral("socks5");
const QString HTTP = QStringLiteral("http");
const QString NONE = QStringLiteral("none");
const QString ON = QStringLiteral("on");
const QString OFF = QStringLiteral("off");
// Check for incompatible settings // Check for incompatible settings
bool activeProxyType = false; bool activeProxyType = false;
if (parser->isSet("P")) { if (parser.isSet("P")) {
activeProxyType = proxySettings[0].compare(QString("SOCKS5"), Qt::CaseInsensitive) == 0 activeProxyType = proxySettingStrings[0] == SOCKS5 || proxySettingStrings[0] == HTTP;
|| proxySettings[0].compare(QString("HTTP"), Qt::CaseInsensitive) == 0;
} }
if (parser.isSet("I")) {
if (activeProxyType && (UDPSetting.compare(QString("on"), Qt::CaseInsensitive) == 0)) { if (!(IPv6SettingString == ON || IPv6SettingString == OFF)) {
qCritical() << "Cannot set UDP on with proxy.";
return false;
}
if (activeProxyType && (LANSetting.compare(QString("on"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Cannot set LAN discovery on with proxy.";
return false;
}
if ((LANSetting.compare(QString("on"), Qt::CaseInsensitive) == 0)
&& (UDPSetting.compare(QString("off"), Qt::CaseInsensitive) == 0)) {
qCritical() << "Incompatible UDP/LAN settings.";
return false;
}
if (parser->isSet("I")) {
if (IPv6Setting.compare(QString("on"), Qt::CaseInsensitive) == 0) {
enableIPv6 = true;
qDebug() << "Setting IPv6 ON.";
} else if (IPv6Setting.compare(QString("off"), Qt::CaseInsensitive) == 0) {
enableIPv6 = false;
qDebug() << "Setting IPv6 OFF.";
} else {
qCritical() << "Unable to parse IPv6 setting."; qCritical() << "Unable to parse IPv6 setting.";
return false; return false;
} }
} }
if (parser->isSet("U")) { if (parser.isSet("U")) {
if (UDPSetting.compare(QString("on"), Qt::CaseInsensitive) == 0) { if (!(UDPSettingString == ON || UDPSettingString == OFF)) {
forceTCP = false;
qDebug() << "Setting UDP ON.";
if (proxyType != ICoreSettings::ProxyType::ptNone) {
qDebug() << "Cannot use UDP with proxy; disabling proxy settings.";
proxyType = ICoreSettings::ProxyType::ptNone;
}
} else if (UDPSetting.compare(QString("off"), Qt::CaseInsensitive) == 0) {
forceTCP = true;
qDebug() << "Setting UDP OFF.";
} else {
qCritical() << "Unable to parse UDP setting."; qCritical() << "Unable to parse UDP setting.";
return false; return false;
} }
} }
if (parser->isSet("L")) { if (parser.isSet("L")) {
if (LANSetting.compare(QString("on"), Qt::CaseInsensitive) == 0) { if (!(LANSettingString == ON || LANSettingString == OFF)) {
qDebug() << "Setting LAN Discovery ON.";
enableLanDiscovery = true;
if (forceTCP) {
qDebug() << "Cannot use LAN discovery without UDP; enabling UDP.";
proxyType = ICoreSettings::ProxyType::ptNone;
}
if (proxyType != ICoreSettings::ProxyType::ptNone) {
qDebug() << "Cannot use LAN discovery with proxy; disabling proxy settings.";
proxyType = ICoreSettings::ProxyType::ptNone;
}
} else if (LANSetting.compare(QString("off"), Qt::CaseInsensitive) == 0) {
enableLanDiscovery = false;
qDebug() << "Setting LAN Discovery OFF.";
} else {
qCritical() << "Unable to parse LAN setting."; qCritical() << "Unable to parse LAN setting.";
return false; return false;
} }
} }
if (activeProxyType && UDPSettingString == ON) {
qCritical() << "Cannot set UDP on with proxy.";
return false;
}
if (parser->isSet("P")) { if (activeProxyType && LANSettingString == ON) {
if (proxySettings[0].compare(QString("NONE"), Qt::CaseInsensitive) == 0) { qCritical() << "Cannot set LAN discovery on with proxy.";
proxyType = ICoreSettings::ProxyType::ptNone; return false;
proxyAddr = ""; }
proxyPort = 0;
qDebug() << "Setting proxy type to NONE."; if (LANSettingString == ON && UDPSettingString == OFF) {
qCritical() << "Incompatible UDP/LAN settings.";
return false;
}
if (parser.isSet("P")) {
if (proxySettingStrings[0] == NONE) {
// slightly lazy check here, accepting 'NONE[:.*]' is fine since no other
// arguments will be investigated when proxy settings are applied.
return true; return true;
} }
// Since the first argument isn't 'none', verify format of remaining arguments // Since the first argument isn't 'none', verify format of remaining arguments
if (proxySettings.size() != 3) { if (proxySettingStrings.size() != 3) {
qCritical() << "Invalid number of proxy arguments."; qCritical() << "Invalid number of proxy arguments.";
return false; return false;
} }
if (proxySettings[0].compare(QString("SOCKS5"), Qt::CaseInsensitive) == 0) { if (!(proxySettingStrings[0] == SOCKS5 || proxySettingStrings[0] == HTTP)) {
proxyType = ICoreSettings::ProxyType::ptSOCKS5;
forceTCP = true;
enableLanDiscovery = false;
qDebug() << "Setting proxy type to SOCKS5.";
} else if (proxySettings[0].compare(QString("HTTP"), Qt::CaseInsensitive) == 0) {
proxyType = ICoreSettings::ProxyType::ptHTTP;
forceTCP = true;
enableLanDiscovery = false;
qDebug() << "Setting proxy type to HTTP.";
} else {
qCritical() << "Unable to parse proxy type."; qCritical() << "Unable to parse proxy type.";
return false; return false;
} }
// Kriby: Sanity checking IPv4+IPv6/hostnames sure is a lot of work! // TODO(Kriby): Sanity check IPv4/IPv6 addresses/hostnames?
proxyAddr = proxySettings[1];
qDebug() << QString("Setting proxy address to %1.").arg(proxySettings[1]);
int portNumber = proxySettings[2].toInt(); int portNumber = proxySettingStrings[2].toInt();
if (portNumber > 0 && portNumber < 65536) { if (!(portNumber > 0 && portNumber < 65536)) {
proxyPort = portNumber;
qDebug() << QString("Setting port number to %1.").arg(portNumber);
} else {
qCritical() << "Invalid port number range."; qCritical() << "Invalid port number range.";
} }
} }
return true; return true;
} }
/**
* Applies command line options on top of loaded settings. Fails without changes if attempting to
* apply contradicting settings.
* @param parser QCommandLineParser instance
* @return Success indicator (success = true)
*/
bool Settings::applyCommandLineOptions(const QCommandLineParser& parser)
{
if (!verifyProxySettings(parser)) {
return false;
};
QString IPv6Setting = parser.value("I").toUpper();
QString LANSetting = parser.value("L").toUpper();
QString UDPSetting = parser.value("U").toUpper();
QString proxySettingString = parser.value("proxy").toUpper();
QStringList proxySettings = proxySettingString.split(":");
const QString SOCKS5 = QStringLiteral("SOCKS5");
const QString HTTP = QStringLiteral("HTTP");
const QString NONE = QStringLiteral("NONE");
const QString ON = QStringLiteral("ON");
const QString OFF = QStringLiteral("OFF");
if (parser.isSet("I")) {
enableIPv6 = IPv6Setting == ON;
qDebug() << QString("Setting IPv6 %1.").arg(IPv6Setting);
}
if (parser.isSet("P")) {
qDebug() << QString("Setting proxy type to %1.").arg(proxySettings[0]);
quint16 portNumber = 0;
QString address = "";
if (proxySettings[0] == NONE) {
proxyType = ICoreSettings::ProxyType::ptNone;
} else {
if (proxySettings[0] == SOCKS5) {
proxyType = ICoreSettings::ProxyType::ptSOCKS5;
} else if (proxySettings[0] == HTTP) {
proxyType = ICoreSettings::ProxyType::ptHTTP;
} else {
qCritical() << "Failed to set valid proxy type";
assert(false); // verifyProxySettings should've made this impossible
}
forceTCP = true;
enableLanDiscovery = false;
address = proxySettings[1];
portNumber = static_cast<quint16>(proxySettings[2].toInt());
}
proxyAddr = address;
qDebug() << QString("Setting proxy address to %1.").arg(address);
proxyPort = portNumber;
qDebug() << QString("Setting port number to %1.").arg(portNumber);
}
if (parser.isSet("U")) {
bool shouldForceTCP = UDPSetting == OFF;
if (!shouldForceTCP && proxyType != ICoreSettings::ProxyType::ptNone) {
qDebug() << "Cannot use UDP with proxy; disable proxy explicitly with '-P none'.";
} else {
forceTCP = shouldForceTCP;
qDebug() << QString("Setting UDP %1.").arg(UDPSetting);
}
// LANSetting == ON is caught by verifyProxySettings, the OFF check removes needless debug
if (shouldForceTCP && !(LANSetting == OFF) && enableLanDiscovery) {
qDebug() << "Cannot perform LAN discovery without UDP; disabling LAN discovery.";
enableLanDiscovery = false;
}
}
if (parser.isSet("L")) {
bool shouldEnableLAN = LANSetting == ON;
if (shouldEnableLAN && proxyType != ICoreSettings::ProxyType::ptNone) {
qDebug()
<< "Cannot use LAN discovery with proxy; disable proxy explicitly with '-P none'.";
} else if (shouldEnableLAN && forceTCP) {
qDebug() << "Cannot use LAN discovery without UDP; enable UDP explicitly with '-U on'.";
} else {
enableLanDiscovery = shouldEnableLAN;
qDebug() << QString("Setting LAN Discovery %1.").arg(LANSetting);
}
}
return true;
}
void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey) void Settings::loadPersonal(QString profileName, const ToxEncrypt* passKey)
{ {
QMutexLocker locker{&bigLock}; QMutexLocker locker{&bigLock};

View File

@ -239,7 +239,8 @@ signals:
void blackListChanged(QStringList& blist); void blackListChanged(QStringList& blist);
public: public:
bool applyCommandLineOptions(const QCommandLineParser* parser); bool applyCommandLineOptions(const QCommandLineParser& parser);
static bool verifyProxySettings(const QCommandLineParser& parser);
bool getMakeToxPortable() const; bool getMakeToxPortable() const;
void setMakeToxPortable(bool newValue); void setMakeToxPortable(bool newValue);