1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2025-01-04 05:36:04 +00:00

clean up netpage, randomize lan-play ip addresses

This commit is contained in:
flb 2021-09-11 14:43:14 +02:00
parent 3b982eecab
commit 32736c443f

View file

@ -11,11 +11,12 @@
namespace i18n = brls::i18n; namespace i18n = brls::i18n;
using namespace i18n::literals; using namespace i18n::literals;
using json = nlohmann::json; using json = nlohmann::ordered_json;
NetPage::NetPage() : AppletFrame(true, true) NetPage::NetPage() : AppletFrame(true, true)
{ {
this->setTitle("menus/net/title"_i18n); this->setTitle("menus/net/title"_i18n);
list = new brls::List();
nifmInitialize(NifmServiceType_User); nifmInitialize(NifmServiceType_User);
NifmNetworkProfileData profile; NifmNetworkProfileData profile;
@ -24,33 +25,42 @@ NetPage::NetPage() : AppletFrame(true, true)
int uuid = std::accumulate(profile.uuid.uuid, profile.uuid.uuid + 16, 0); int uuid = std::accumulate(profile.uuid.uuid, profile.uuid.uuid + 16, 0);
std::string labelText = ""; std::string labelText;
if(uuid){
if(profile.ip_setting_data.ip_address_setting.is_automatic){ if(!uuid || !profile.ip_setting_data.mtu){
labelText += "IP Adress: Automatic"; labelText = "Please connect to internet to use this feature.";
label = new brls::Label(brls::LabelStyle::DESCRIPTION, labelText, true);
list->addView(label);
cancel = new brls::ListItem("menus/common/go_back"_i18n);
cancel->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new MainFrame());
});
list->addView(cancel);
} }
else{ else{
labelText = "IP Adress: " + ipToString(profile.ip_setting_data.ip_address_setting.current_addr.addr) if(profile.ip_setting_data.ip_address_setting.is_automatic){
+"\nSubnet Mask: " + ipToString(profile.ip_setting_data.ip_address_setting.subnet_mask.addr) labelText = "IP Adress: Automatic";
+"\nGateway: " + ipToString(profile.ip_setting_data.ip_address_setting.gateway.addr);
} }
struct in_addr addr = {(in_addr_t) gethostid()}; else{
labelText += "\nLocal IP addr" + std::string(inet_ntoa(addr)); labelText = fmt::format("IP Adress: {}\nSubnet Mask: {}\nGateway: {}",
labelText += "\nMTU: " + std::to_string(unsigned(profile.ip_setting_data.mtu)); ipToString(profile.ip_setting_data.ip_address_setting.current_addr.addr),
ipToString(profile.ip_setting_data.ip_address_setting.subnet_mask.addr),
ipToString(profile.ip_setting_data.ip_address_setting.gateway.addr)
);
}
labelText = fmt::format("{}\nLocal IP addr: {}\nMTU: {}", labelText, std::string(inet_ntoa({(in_addr_t) gethostid()})), std::to_string(unsigned(profile.ip_setting_data.mtu)));
if(profile.ip_setting_data.dns_setting.is_automatic){ if(profile.ip_setting_data.dns_setting.is_automatic){
labelText += "\nDNS: Automatic"; labelText = fmt::format("{}\nDNS: Automatic", labelText);
} }
else{ else{
labelText += "\nPrimary DNS: " + ipToString(profile.ip_setting_data.dns_setting.primary_dns_server.addr) labelText = fmt::format("{}\nPrimary DNS: {}\nSecondary DNS: {}",
+"\nSecondary DNS: "+ ipToString(profile.ip_setting_data.dns_setting.secondary_dns_server.addr); labelText,
} ipToString(profile.ip_setting_data.dns_setting.primary_dns_server.addr),
} ipToString(profile.ip_setting_data.dns_setting.secondary_dns_server.addr)
else{ );
labelText = "Please connect to internet to use this feature.";
} }
list = new brls::List();
label = new brls::Label(brls::LabelStyle::DESCRIPTION, labelText, true); label = new brls::Label(brls::LabelStyle::DESCRIPTION, labelText, true);
list->addView(label); list->addView(label);
@ -63,12 +73,28 @@ NetPage::NetPage() : AppletFrame(true, true)
//ip_auto //ip_auto
//dns_auto //dns_auto
if(uuid){
json profiles = fs::parseJsonFile(INTERNET_JSON); json profiles = fs::parseJsonFile(INTERNET_JSON);
if(profiles.empty()) { if(profiles.empty()) {
profiles = json::array(); profiles = json::array();
} }
profiles.push_back(json::object({
{"name", "lan-play"},
{"ip_addr", fmt::format("10.13.{}.{}", std::rand() % 256, std::rand() % 253 + 2)},
{"subnet_mask", "255.255.0.0"},
{"gateway", "10.13.37.1"}
}));
profiles.push_back(json::object({
{"name", "Automatic IP Address"},
{"ip_auto", true}
}));
profiles.push_back(json::object({
{"name", "Automatic DNS"},
{"dns_auto", true}
}));
profiles.push_back(json::object({ profiles.push_back(json::object({
{"name", "90DNS (Europe)"}, {"name", "90DNS (Europe)"},
{"dns1", "163.172.141.219"}, {"dns1", "163.172.141.219"},
@ -88,24 +114,10 @@ NetPage::NetPage() : AppletFrame(true, true)
})); }));
profiles.push_back(json::object({ profiles.push_back(json::object({
{"name", "Automatic IP Address"}, {"name", "ACNH mtu"},
{"ip_auto", true} {"mtu", 1500}
})); }));
profiles.push_back(json::object({
{"name", "Automatic DNS"},
{"dns_auto", true}
}));
profiles.push_back(json::object({
{"ip_addr", "10.13.111.111"},
{"subnet_mask", "255.255.0.0"},
{"gateway", "10.13.37.1"},
{"mtu", 1500},
{"name", "ACNH lan-play"}
}));
int iter = 0;
for (const auto& p : profiles.items()){ for (const auto& p : profiles.items()){
json values = p.value(); json values = p.value();
if(values.find("name") != values.end()) listItem = new brls::ListItem(values["name"]); if(values.find("name") != values.end()) listItem = new brls::ListItem(values["name"]);
@ -170,16 +182,8 @@ NetPage::NetPage() : AppletFrame(true, true)
dialog->open(); dialog->open();
}); });
list->addView(listItem); list->addView(listItem);
iter++;
} }
} }
else{
cancel = new brls::ListItem("menus/common/go_back"_i18n);
cancel->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new MainFrame());
});
list->addView(cancel);
}
this->setContentView(list); this->setContentView(list);
} }