Add ufw detection and setup
This commit is contained in:
@@ -16,6 +16,7 @@ add_executable(wivrn-dashboard
|
||||
rectangle_partitionner.cpp
|
||||
adb.cpp
|
||||
apk_installer.cpp
|
||||
firewall.cpp
|
||||
vulkan_info.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "firewall.h"
|
||||
|
||||
#include "escape_sandbox.h"
|
||||
#include "utils/flatpak.h"
|
||||
#include "wivrn_config.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
firewall::type_t firewall::detect_type()
|
||||
{
|
||||
if (wivrn::is_flatpak())
|
||||
{
|
||||
if (not QStandardPaths::findExecutable(
|
||||
"ufw",
|
||||
QStringList({"/run/host/usr/sbin", "/run/host/usr/bin"}))
|
||||
.isEmpty())
|
||||
return type_t::ufw;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (not QStandardPaths::findExecutable("ufw").isEmpty())
|
||||
return type_t::ufw;
|
||||
}
|
||||
|
||||
return type_t::none;
|
||||
}
|
||||
|
||||
firewall::firewall() :
|
||||
type(detect_type())
|
||||
{
|
||||
}
|
||||
|
||||
const std::filesystem::path ufw_conf = "etc/ufw/applications.d/wivrn";
|
||||
|
||||
static bool need_setup_ufw()
|
||||
{
|
||||
return not std::filesystem::exists(
|
||||
(wivrn::is_flatpak() ? "/run/host" : "/") / ufw_conf);
|
||||
}
|
||||
|
||||
bool firewall::needSetup()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case type_t::none:
|
||||
return false;
|
||||
case type_t::ufw:
|
||||
return need_setup_ufw();
|
||||
}
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void firewall::doSetup()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case type_t::none:
|
||||
return;
|
||||
case type_t::ufw: {
|
||||
pkexec = escape_sandbox("pkexec",
|
||||
"sh",
|
||||
"-c",
|
||||
"printf '[WiVRn]\\ntitle=WiVRn server\ndescription=WiVRn OpenXR streaming server\nports=" + std::to_string(wivrn::default_port) + "' > /" + ufw_conf.string() + " && ufw allow wivrn");
|
||||
pkexec->setProcessChannelMode(QProcess::MergedChannels);
|
||||
pkexec->start();
|
||||
|
||||
QObject::connect(pkexec.get(), &QProcess::finished, this, [this](int exit_code, QProcess::ExitStatus exit_status) {
|
||||
if (exit_status != QProcess::NormalExit or exit_code)
|
||||
qWarning() << "ufw configuration exitec with status" << exit_status << "and code" << exit_code;
|
||||
needSetupChanged(needSetup());
|
||||
pkexec.release()->deleteLater();
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
|
||||
class firewall : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(Firewall)
|
||||
QML_SINGLETON
|
||||
|
||||
Q_PROPERTY(bool needSetup READ needSetup NOTIFY needSetupChanged)
|
||||
|
||||
enum class type_t
|
||||
{
|
||||
none,
|
||||
ufw,
|
||||
};
|
||||
|
||||
type_t type;
|
||||
std::unique_ptr<QProcess> pkexec;
|
||||
|
||||
static type_t detect_type();
|
||||
|
||||
public:
|
||||
firewall();
|
||||
bool needSetup();
|
||||
Q_INVOKABLE void doSetup();
|
||||
|
||||
Q_SIGNALS:
|
||||
void needSetupChanged(bool);
|
||||
};
|
||||
@@ -117,6 +117,20 @@ Kirigami.ApplicationWindow {
|
||||
]
|
||||
}
|
||||
|
||||
Kirigami.InlineMessage {
|
||||
Layout.fillWidth: true
|
||||
text: i18n("Firewall may not allow port 9757.")
|
||||
type: Kirigami.MessageType.Warning
|
||||
showCloseButton: true
|
||||
visible: Firewall.needSetup
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
text: i18n("Fix it")
|
||||
onTriggered: Firewall.doSetup()
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Kirigami.InlineMessage {
|
||||
id: restart_capsysnice
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -38,6 +38,8 @@ finish-args:
|
||||
# Let outside application access the WiVRn socket
|
||||
- --filesystem=xdg-run/wivrn:create
|
||||
- --own-name=io.github.wivrn.Server
|
||||
# Check firewall configuration
|
||||
- --filesystem=host-etc
|
||||
# QSystemTrayIcon
|
||||
- --talk-name=org.kde.StatusNotifierWatcher
|
||||
# Run processes outside of sandbox
|
||||
|
||||
Reference in New Issue
Block a user