Allow internet connections checkbox
This commit is contained in:
@@ -106,18 +106,25 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
restoreSavedStates();
|
||||
|
||||
if (AppDataServer::getInstance()->isAppConnected()) {
|
||||
createWebsocket();
|
||||
auto ads = AppDataServer::getInstance();
|
||||
|
||||
QString wormholecode = "";
|
||||
if (ads->getAllowInternetConnection())
|
||||
wormholecode = ads->getWormholeCode(ads->getSecretHex());
|
||||
|
||||
createWebsocket(wormholecode);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::createWebsocket() {
|
||||
void MainWindow::createWebsocket(QString wormholecode) {
|
||||
qDebug() << "Listening for app connections on port 8237";
|
||||
// Create the websocket server, for listening to direct connections
|
||||
wsserver = new WSServer(8237, false, this);
|
||||
|
||||
// Connect to the wormhole service
|
||||
wormhole = new WormholeClient(this, AppDataServer::getInstance()->getWormholeCode(
|
||||
AppDataServer::getInstance()->getSecretHex()));
|
||||
if (!wormholecode.isEmpty()) {
|
||||
// Connect to the wormhole service
|
||||
wormhole = new WormholeClient(this, wormholecode);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::stopWebsocket() {
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
void replaceWormholeClient(WormholeClient* newClient);
|
||||
bool isWebsocketListening();
|
||||
void createWebsocket();
|
||||
void createWebsocket(QString wormholecode);
|
||||
void stopWebsocket();
|
||||
|
||||
Ui::MainWindow* ui;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>532</width>
|
||||
<height>400</height>
|
||||
<width>800</width>
|
||||
<height>530</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -43,6 +43,25 @@
|
||||
<string>QR Code</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Connection String</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLineEdit" name="txtConnStr">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QRCodeLabel" name="qrcode">
|
||||
<property name="sizePolicy">
|
||||
@@ -59,17 +78,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="chkInternetConn">
|
||||
<property name="text">
|
||||
<string>Connection String</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLineEdit" name="txtConnStr">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
<string>Allow connections over the internet</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -117,12 +117,6 @@ void WormholeClient::onTextMessageReceived(QString message)
|
||||
// ==============================
|
||||
AppDataServer* AppDataServer::instance = nullptr;
|
||||
|
||||
QString AppDataServer::getSecretHex() {
|
||||
QSettings s;
|
||||
|
||||
return s.value("mobileapp/secret", "").toString();
|
||||
}
|
||||
|
||||
QString AppDataServer::getWormholeCode(QString secretHex) {
|
||||
unsigned char* secret = new unsigned char[crypto_secretbox_KEYBYTES];
|
||||
sodium_hex2bin(secret, crypto_secretbox_KEYBYTES, secretHex.toStdString().c_str(), crypto_secretbox_KEYBYTES*2,
|
||||
@@ -147,11 +141,25 @@ QString AppDataServer::getWormholeCode(QString secretHex) {
|
||||
return wmcodehex;
|
||||
}
|
||||
|
||||
void AppDataServer::saveNewSecret(QString secretHex) {
|
||||
QString AppDataServer::getSecretHex() {
|
||||
QSettings s;
|
||||
s.setValue("mobileapp/secret", secretHex);
|
||||
|
||||
s.sync();
|
||||
return s.value("mobileapp/secret", "").toString();
|
||||
}
|
||||
|
||||
void AppDataServer::saveNewSecret(QString secretHex) {
|
||||
QSettings().setValue("mobileapp/secret", secretHex);
|
||||
|
||||
if (secretHex.isEmpty())
|
||||
setAllowInternetConnection(false);
|
||||
}
|
||||
|
||||
bool AppDataServer::getAllowInternetConnection() {
|
||||
return QSettings().value("mobileapp/allowinternet", false).toBool();
|
||||
}
|
||||
|
||||
void AppDataServer::setAllowInternetConnection(bool allow) {
|
||||
QSettings().setValue("mobileapp/allowinternet", allow);
|
||||
}
|
||||
|
||||
void AppDataServer::saveLastConnectedOver(AppConnectionType type) {
|
||||
@@ -203,9 +211,20 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
|
||||
ui->txtConnStr->selectAll();
|
||||
});
|
||||
|
||||
QObject::connect(ui->chkInternetConn, &QCheckBox::stateChanged, [=] (int state) {
|
||||
if (state == Qt::Checked) {
|
||||
|
||||
}
|
||||
updateUIWithNewQRCode(parent);
|
||||
});
|
||||
|
||||
// If we're not listening for the app, then start the websockets
|
||||
if (!parent->isWebsocketListening()) {
|
||||
parent->createWebsocket();
|
||||
QString wormholecode = "";
|
||||
if (getAllowInternetConnection())
|
||||
wormholecode = AppDataServer::getInstance()->getWormholeCode(AppDataServer::getInstance()->getSecretHex());
|
||||
|
||||
parent->createWebsocket(wormholecode);
|
||||
}
|
||||
|
||||
d.exec();
|
||||
@@ -217,7 +236,10 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
|
||||
|
||||
// Cleanup
|
||||
tempSecret = "";
|
||||
|
||||
delete tempWormholeClient;
|
||||
tempWormholeClient = nullptr;
|
||||
|
||||
delete ui;
|
||||
ui = nullptr;
|
||||
}
|
||||
@@ -248,18 +270,26 @@ void AppDataServer::updateUIWithNewQRCode(MainWindow* mainwindow) {
|
||||
sodium_bin2hex(secretHex, crypto_secretbox_KEYBYTES*2+1, secretBin, crypto_secretbox_KEYBYTES);
|
||||
|
||||
QString secretStr(secretHex);
|
||||
registerNewTempSecret(secretStr, mainwindow);
|
||||
|
||||
QString codeStr = uri + "," + secretStr;
|
||||
|
||||
if (ui->chkInternetConn->isChecked()) {
|
||||
codeStr = codeStr + ",1";
|
||||
}
|
||||
|
||||
registerNewTempSecret(secretStr, ui->chkInternetConn->isChecked(), mainwindow);
|
||||
|
||||
ui->qrcode->setQrcodeString(codeStr);
|
||||
ui->txtConnStr->setText(codeStr);
|
||||
}
|
||||
|
||||
void AppDataServer::registerNewTempSecret(QString tmpSecretHex, MainWindow* main) {
|
||||
void AppDataServer::registerNewTempSecret(QString tmpSecretHex, bool allowInternet, MainWindow* main) {
|
||||
tempSecret = tmpSecretHex;
|
||||
|
||||
tempWormholeClient = new WormholeClient(main, getWormholeCode(tempSecret));
|
||||
delete tempWormholeClient;
|
||||
tempWormholeClient = nullptr;
|
||||
|
||||
if (allowInternet)
|
||||
tempWormholeClient = new WormholeClient(main, getWormholeCode(tempSecret));
|
||||
}
|
||||
|
||||
QString AppDataServer::connDesc(AppConnectionType t) {
|
||||
@@ -473,6 +503,7 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
||||
// This is a new connection. So, update the the secret. Note the last seen remote nonce has already been updated by
|
||||
// decryptMessage()
|
||||
saveNewSecret(tempSecret);
|
||||
setAllowInternetConnection(tempWormholeClient != nullptr);
|
||||
|
||||
// Swap out the wormhole connection
|
||||
mainWindow->replaceWormholeClient(tempWormholeClient);
|
||||
|
||||
@@ -91,11 +91,14 @@ public:
|
||||
QString getSecretHex();
|
||||
void saveNewSecret(QString secretHex);
|
||||
|
||||
void registerNewTempSecret(QString tmpSecretHex, MainWindow* main);
|
||||
void registerNewTempSecret(QString tmpSecretHex, bool allowInternet, MainWindow* main);
|
||||
|
||||
QString getNonceHex(NonceType nt);
|
||||
void saveNonceHex(NonceType nt, QString noncehex);
|
||||
|
||||
bool getAllowInternetConnection();
|
||||
void setAllowInternetConnection(bool allow);
|
||||
|
||||
void saveLastSeenTime();
|
||||
QDateTime getLastSeenTime();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user