Serenity Operating System
1/*
2 * Copyright (c) 2022, Maciej <sppmacd@pm.me>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include "NetworkSettingsWidget.h"
8#include <LibCore/ArgsParser.h>
9#include <LibGUI/MessageBox.h>
10#include <unistd.h>
11
12#include <LibCore/System.h>
13#include <LibGUI/Application.h>
14#include <LibGUI/Icon.h>
15#include <LibGUI/SettingsWindow.h>
16#include <LibMain/Main.h>
17
18ErrorOr<int> serenity_main(Main::Arguments args)
19{
20 TRY(Core::System::pledge("stdio rpath wpath cpath recvfd sendfd unix proc exec"));
21
22 TRY(Core::System::unveil("/bin/NetworkServer", "x"));
23 TRY(Core::System::unveil("/etc/Network.ini", "rwc"));
24 TRY(Core::System::unveil("/sys/kernel/net/adapters", "r"));
25 TRY(Core::System::unveil("/res", "r"));
26 TRY(Core::System::unveil("/tmp/session/%sid/portal/clipboard", "rw"));
27 TRY(Core::System::unveil("/tmp/portal/window", "rw"));
28 TRY(Core::System::unveil(nullptr, nullptr));
29
30 DeprecatedString adapter;
31
32 Core::ArgsParser parser;
33 parser.add_positional_argument(adapter, "Adapter to display settings for", "adapter", Core::ArgsParser::Required::No);
34 parser.parse(args);
35
36 auto app = TRY(GUI::Application::try_create(args));
37
38 if (getuid() != 0) {
39 GUI::MessageBox::show_error(nullptr, "You need to be root to run Network Settings!"sv);
40 return 1;
41 }
42
43 TRY(Core::System::pledge("stdio rpath wpath cpath recvfd sendfd proc exec"));
44
45 auto app_icon = GUI::Icon::default_icon("network"sv);
46 auto window = TRY(GUI::SettingsWindow::create("Network Settings", GUI::SettingsWindow::ShowDefaultsButton::No));
47 auto network_settings_widget = TRY(window->add_tab<NetworkSettings::NetworkSettingsWidget>("Network"sv, "network"sv));
48 if (!adapter.is_null()) {
49 network_settings_widget->switch_adapter(adapter);
50 }
51 window->set_icon(app_icon.bitmap_for_size(16));
52
53 window->show();
54 return app->exec();
55}