Software / code / prosody
Comparison
util/prosodyctl/check.lua @ 13717:4f173a44370b 13.0
prosodyctl: check features: check for mod_muc_mam on MUC components
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 16 Feb 2025 13:17:00 +0000 |
| parent | 13710:f7de36fed53c |
| child | 13722:8bf5d07e3796 |
comparison
equal
deleted
inserted
replaced
| 13715:edd006093533 | 13717:4f173a44370b |
|---|---|
| 1484 local common_subdomains = { | 1484 local common_subdomains = { |
| 1485 http_file_share = "share"; | 1485 http_file_share = "share"; |
| 1486 muc = "groups"; | 1486 muc = "groups"; |
| 1487 }; | 1487 }; |
| 1488 | 1488 |
| 1489 local recommended_component_modules = { | |
| 1490 muc = { "muc_mam" }; | |
| 1491 }; | |
| 1492 | |
| 1489 local function print_feature_status(feature, host) | 1493 local function print_feature_status(feature, host) |
| 1490 if quiet then return; end | 1494 if quiet then return; end |
| 1491 print("", feature.ok and "OK" or "(!)", feature.name); | 1495 print("", feature.ok and "OK" or "(!)", feature.name); |
| 1492 if not feature.ok then | 1496 if not feature.ok then |
| 1493 if feature.lacking_modules then | 1497 if feature.lacking_modules then |
| 1499 end | 1503 end |
| 1500 if feature.lacking_components then | 1504 if feature.lacking_components then |
| 1501 table.sort(feature.lacking_components); | 1505 table.sort(feature.lacking_components); |
| 1502 for _, component_module in ipairs(feature.lacking_components) do | 1506 for _, component_module in ipairs(feature.lacking_components) do |
| 1503 local subdomain = common_subdomains[component_module]; | 1507 local subdomain = common_subdomains[component_module]; |
| 1508 local recommended_mods = recommended_component_modules[component_module]; | |
| 1504 if subdomain then | 1509 if subdomain then |
| 1505 print("", "", "Suggested component:"); | 1510 print("", "", "Suggested component:"); |
| 1506 print(""); | 1511 print(""); |
| 1512 print("", "", "", ("-- Documentation: https://prosody.im/doc/modules/mod_%s"):format(component_module)); | |
| 1507 print("", "", "", ("Component %q %q"):format(subdomain.."."..host, component_module)); | 1513 print("", "", "", ("Component %q %q"):format(subdomain.."."..host, component_module)); |
| 1508 print("", "", "", ("-- Documentation: https://prosody.im/doc/modules/mod_%s"):format(component_module)); | 1514 if recommended_mods then |
| 1515 print("", "", "", " modules_enabled = {"); | |
| 1516 table.sort(recommended_mods); | |
| 1517 for _, mod in ipairs(recommended_mods) do | |
| 1518 print("", "", "", (" %q;"):format(mod)); | |
| 1519 end | |
| 1520 print("", "", "", " }"); | |
| 1521 end | |
| 1509 else | 1522 else |
| 1510 print("", "", ("Suggested component: %s"):format(component_module)); | 1523 print("", "", ("Suggested component: %s"):format(component_module)); |
| 1511 end | 1524 end |
| 1512 end | 1525 end |
| 1513 print(""); | 1526 print(""); |
| 1514 print("", "", "If you have already configured any these components, they may not be"); | 1527 print("", "", "If you have already configured any these components, they may not be"); |
| 1515 print("", "", "linked correctly to "..host..". For more info see https://prosody.im/doc/components"); | 1528 print("", "", "linked correctly to "..host..". For more info see https://prosody.im/doc/components"); |
| 1529 end | |
| 1530 if feature.lacking_component_modules then | |
| 1531 table.sort(feature.lacking_component_modules, function (a, b) | |
| 1532 return a.host < b.host; | |
| 1533 end); | |
| 1534 for _, problem in ipairs(feature.lacking_component_modules) do | |
| 1535 local hostapi = api(problem.host); | |
| 1536 local current_modules_enabled = hostapi:get_option_array("modules_enabled", {}); | |
| 1537 print("", "", ("Component %q is missing the following modules: %s"):format(problem.host, table.concat(problem.missing_mods))); | |
| 1538 print(""); | |
| 1539 print("","", "Add the missing modules to your modules_enabled under the Component, like this:"); | |
| 1540 print(""); | |
| 1541 print(""); | |
| 1542 print("", "", "", ("-- Documentation: https://prosody.im/doc/modules/mod_%s"):format(problem.component_module)); | |
| 1543 print("", "", "", ("Component %q %q"):format(problem.host, problem.component_module)); | |
| 1544 print("", "", "", (" modules_enabled = {")); | |
| 1545 for _, mod in ipairs(current_modules_enabled) do | |
| 1546 print("", "", "", (" %q;"):format(mod)); | |
| 1547 end | |
| 1548 for _, mod in ipairs(problem.missing_mods) do | |
| 1549 print("", "", "", (" %q; -- Add this!"):format(mod)); | |
| 1550 end | |
| 1551 print("", "", "", (" }")); | |
| 1552 end | |
| 1516 end | 1553 end |
| 1517 end | 1554 end |
| 1518 print(""); | 1555 print(""); |
| 1519 end | 1556 end |
| 1520 | 1557 |
| 1570 end | 1607 end |
| 1571 | 1608 |
| 1572 local function check_component(suggested, alternate, ...) | 1609 local function check_component(suggested, alternate, ...) |
| 1573 local found; | 1610 local found; |
| 1574 for _, component_module in ipairs({ suggested, alternate, ... }) do | 1611 for _, component_module in ipairs({ suggested, alternate, ... }) do |
| 1575 found = #host_components[component_module] > 0; | 1612 found = host_components[component_module][1]; |
| 1576 if found then break; end | 1613 if found then |
| 1614 local enabled_component_modules = api(found):get_option_inherited_set("modules_enabled"); | |
| 1615 local recommended_mods = recommended_component_modules[component_module]; | |
| 1616 local missing_mods = {}; | |
| 1617 for _, mod in ipairs(recommended_mods) do | |
| 1618 if not enabled_component_modules:contains(mod) then | |
| 1619 table.insert(missing_mods, mod); | |
| 1620 end | |
| 1621 end | |
| 1622 if #missing_mods > 0 then | |
| 1623 if not current_feature.lacking_component_modules then | |
| 1624 current_feature.lacking_component_modules = {}; | |
| 1625 end | |
| 1626 table.insert(current_feature.lacking_component_modules, { | |
| 1627 host = found; | |
| 1628 component_module = component_module; | |
| 1629 missing_mods = missing_mods; | |
| 1630 }); | |
| 1631 end | |
| 1632 end | |
| 1577 end | 1633 end |
| 1578 if not found then | 1634 if not found then |
| 1579 current_feature.lacking_components = current_feature.lacking_components or {}; | 1635 current_feature.lacking_components = current_feature.lacking_components or {}; |
| 1580 table.insert(current_feature.lacking_components, suggested); | 1636 table.insert(current_feature.lacking_components, suggested); |
| 1581 end | 1637 end |
| 1662 end | 1718 end |
| 1663 | 1719 |
| 1664 for _, feature in ipairs(features) do | 1720 for _, feature in ipairs(features) do |
| 1665 current_feature = feature; | 1721 current_feature = feature; |
| 1666 feature.check(); | 1722 feature.check(); |
| 1667 feature.ok = not feature.lacking_modules and not feature.lacking_components; | 1723 feature.ok = ( |
| 1724 not feature.lacking_modules and | |
| 1725 not feature.lacking_components and | |
| 1726 not feature.lacking_component_modules | |
| 1727 ); | |
| 1668 -- For improved presentation, we group the (ok) and (not ok) features | 1728 -- For improved presentation, we group the (ok) and (not ok) features |
| 1669 if feature.ok then | 1729 if feature.ok then |
| 1670 print_feature_status(feature, host); | 1730 print_feature_status(feature, host); |
| 1671 end | 1731 end |
| 1672 end | 1732 end |