feat: add static phonebook

This commit is contained in:
Jan-Henrik 2026-04-19 11:04:23 +02:00
parent 6bb30f8227
commit 85d54363f2
4 changed files with 75 additions and 0 deletions

View file

@ -146,6 +146,11 @@ in {
# };
};
phonebook = [
{ name = "Oma"; numbers = { Mobil = "+49151..."; Zuhause = "+494..."; }; }
{ name = "Opa"; numbers = { Zuhause = "+494..."; }; }
];
extensions = {
"*99" = { mode = "page"; displayName = "Durchsage an alle"; };
"*100" = { mode = "all"; displayName = "Alle rufen"; };

View file

@ -90,6 +90,13 @@ in {
"= /intercom.xml" = { alias = "${directory.intercomFile}"; extraConfig = "default_type text/xml;"; };
"= /contacts.json" = { alias = "${directoryJson}"; extraConfig = ''default_type application/json; add_header Access-Control-Allow-Origin "*";''; };
"= /auth" = { extraConfig = ''default_type text/plain; return 200 "AUTHORIZED";''; };
} // lib.optionalAttrs (cfg.phonebook != []) (
{ "= /phonebook.xml" = { alias = "${directory.phonebookMenuFile}"; extraConfig = "default_type text/xml;"; }; }
// lib.listToAttrs (lib.imap0 (i: _: {
name = "= /phonebook-${toString i}.xml";
value = { alias = "${lib.elemAt directory.phonebookDetailFiles i}"; extraConfig = "default_type text/xml;"; };
}) cfg.phonebook)
) // {
"/" = {
root = "${diagram.webRoot}";
extraConfig = lib.optionalString (!hasRuntimeSecrets) "index index.html;";

View file

@ -306,6 +306,29 @@ in {
});
};
phonebook = lib.mkOption {
default = [];
description = ''
External contacts shown in the phone directory. Example:
[
{ name = "Oma"; numbers = { Mobil = "+49151..."; Zuhause = "+494..."; }; }
{ name = "Opa"; numbers = { Zuhause = "+494..."; }; }
]
'';
type = lib.types.listOf (lib.types.submodule {
options = {
name = lib.mkOption {
type = lib.types.str;
description = "Contact name shown in the directory listing.";
};
numbers = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
description = ''Labelled phone numbers, e.g. { Mobil = "+49..."; Zuhause = "+49..."; }.'';
};
};
});
};
voicemailCheckExtension = lib.mkOption {
type = lib.types.str;
default = "*97";

View file

@ -4,6 +4,7 @@ let
baseUrl = "http://${cfg.serverAddress}:${toString cfg.directoryPort}";
hasPageExtensions = lib.any (e: e.mode == "page") (lib.attrValues cfg.extensions);
hasPhonebook = cfg.phonebook != [];
# Deduplicated directory entries: one per extension, using the displayName from
# allPhones (all phones sharing an extension have the same displayName).
@ -27,6 +28,11 @@ let
<Name>Intercom / Durchsage</Name>
<URL>${baseUrl}/intercom.xml</URL>
</MenuItem>
'' + lib.optionalString hasPhonebook ''
<MenuItem>
<Name>Externes Telefonbuch</Name>
<URL>${baseUrl}/phonebook.xml</URL>
</MenuItem>
'' + ''
</CiscoIPPhoneMenu>
'';
@ -68,8 +74,42 @@ let
</CiscoIPPhoneDirectory>
'';
phonebookMenuXml = ''
<?xml version="1.0" encoding="UTF-8"?>
<CiscoIPPhoneMenu>
<Title>Externes Telefonbuch</Title>
<Prompt>Bitte wählen</Prompt>
'' + lib.concatStringsSep "\n" (lib.imap0 (i: contact: ''
<MenuItem>
<Name>${contact.name}</Name>
<URL>${baseUrl}/phonebook-${toString i}.xml</URL>
</MenuItem>
'') cfg.phonebook)
+ ''
</CiscoIPPhoneMenu>
'';
mkContactXml = contact: ''
<?xml version="1.0" encoding="UTF-8"?>
<CiscoIPPhoneDirectory>
<Title>${contact.name}</Title>
<Prompt>Bitte wählen</Prompt>
'' + lib.concatStringsSep "\n" (lib.mapAttrsToList (label: number: ''
<DirectoryEntry>
<Name>${label}</Name>
<Telephone>${number}</Telephone>
</DirectoryEntry>
'') contact.numbers)
+ ''
</CiscoIPPhoneDirectory>
'';
in {
menuFile = pkgs.writeText "directory.xml" menuXml;
listFile = pkgs.writeText "directory-list.xml" listXml;
intercomFile = pkgs.writeText "intercom.xml" intercomXml;
phonebookMenuFile = pkgs.writeText "phonebook.xml" phonebookMenuXml;
phonebookDetailFiles = lib.imap0 (i: contact:
pkgs.writeText "phonebook-${toString i}.xml" (mkContactXml contact)
) cfg.phonebook;
}