Skip to content

Commit

Permalink
Add ipv6 support to server
Browse files Browse the repository at this point in the history
  • Loading branch information
sgourdas committed Oct 12, 2024
1 parent b2c7e94 commit ec73b5a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 3 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
"open-in-browser":"Open in browser",
"start-kiwix-server":"Start Kiwix Server",
"stop-kiwix-server":"Stop Kiwix Server",
"all":"All",
"all":"All - Dual Stack Mode",
"ipv4":"IPv4 Only Mode",
"ipv6":"IPv6 Only Mode",
"fulltext-search":"Fulltext search",
"pictures":"Pictures",
"videos":"Videos",
Expand Down
2 changes: 2 additions & 0 deletions resources/i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
"start-kiwix-server": "Represents the action of starting the kiwix server.",
"stop-kiwix-server": "Represents the action of stopping the running kiwix server.",
"all": "{{Identical|All}}",
"ipv4": "Indicates IPv4 mode on local server.",
"ipv6": "Indicates IPv6 mode on local server",
"fulltext-search": "Represents the action of searching the text appearances in all the articles in a ZIM file.",
"pictures": "{{identical|Picture}}",
"videos": "{{identical|Video}}",
Expand Down
26 changes: 20 additions & 6 deletions src/localkiwixserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ LocalKiwixServer::LocalKiwixServer(QWidget *parent) :
QVector<QString> interfaces;
interfaces.reserve(interfacesMap.size() + 1);
for (const auto &interfacePair : interfacesMap) {
QString ip = QString::fromStdString(interfacePair.second.addr);
interfaces.push_back(ip);
QString ipv4 = QString::fromStdString(interfacePair.second.addr);
if (!ipv4.isEmpty()) interfaces.push_back(ipv4);
QString ipv6 = QString::fromStdString(interfacePair.second.addr6);
if (!ipv6.isEmpty()) interfaces.push_back(ipv6);
}
std::sort(interfaces.begin(), interfaces.end());
interfaces.push_front(QString(gt("ipv6")));
interfaces.push_front(QString(gt("ipv4")));
interfaces.push_front(QString(gt("all")));
for (const auto &interface : interfaces) {
ui->IpChooser->addItem(interface);
Expand Down Expand Up @@ -84,11 +88,21 @@ void LocalKiwixServer::runOrStopServer()
auto settingsManager = KiwixApp::instance()->getSettingsManager();
m_port = ui->PortChooser->text().toInt();
mp_server->setPort(m_port);
m_ipAddress = (ui->IpChooser->currentText() != gt("all")) ? ui->IpChooser->currentText() : "0.0.0.0";
settingsManager->setKiwixServerPort(m_port);
settingsManager->setKiwixServerIpAddress(m_ipAddress);
mp_server->setAddress(m_ipAddress.toStdString());
m_ipAddress = (m_ipAddress != "0.0.0.0") ? m_ipAddress : QString::fromStdString(kiwix::getBestPublicIp());
if (ui->IpChooser->currentText() == gt("all")) {
m_ipAddress = QString::fromStdString(kiwix::getBestPublicIp());
} else if (ui->IpChooser->currentText() == gt("ipv4")) {
mp_server->setIpMode(kiwix::IpMode::IPV4);
m_ipAddress = QString::fromStdString(kiwix::getBestPublicIps().addr);
} else if (ui->IpChooser->currentText() == gt("ipv6")) {
mp_server->setIpMode(kiwix::IpMode::IPV6);
m_ipAddress = QString::fromStdString(kiwix::getBestPublicIps().addr6);
} else {
m_ipAddress = ui->IpChooser->currentText();
mp_server->setAddress(m_ipAddress.toStdString());
}
if (m_ipAddress.contains(':')) m_ipAddress = "[" + m_ipAddress + "]";
settingsManager->setKiwixServerIpAddress(ui->IpChooser->currentText());
ui->IpAddress->setText("http://" + m_ipAddress + ":" + QString::number(m_port));
ui->IpAddress->setReadOnly(true);
if (!mp_server->start()) {
Expand Down

0 comments on commit ec73b5a

Please sign in to comment.