feat: json directory
This commit is contained in:
parent
bf60fcce98
commit
ac4dc82594
2 changed files with 53 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ let
|
||||||
confFiles = import ./asterisk/default.nix { inherit lib cfg models allPhones intercomEntries mohDirs greetingDirs; };
|
confFiles = import ./asterisk/default.nix { inherit lib cfg models allPhones intercomEntries mohDirs greetingDirs; };
|
||||||
|
|
||||||
directory = import ./provisioning/directory.nix { inherit lib pkgs cfg allPhones intercomEntries; };
|
directory = import ./provisioning/directory.nix { inherit lib pkgs cfg allPhones intercomEntries; };
|
||||||
|
directoryJson = import ./provisioning/directory-json.nix { inherit lib pkgs cfg models allPhones; };
|
||||||
provisioningRoot = import ./provisioning/default.nix { inherit lib pkgs cfg models allPhones; };
|
provisioningRoot = import ./provisioning/default.nix { inherit lib pkgs cfg models allPhones; };
|
||||||
|
|
||||||
diagram = import ./dashboard.nix { inherit lib pkgs cfg models allPhones intercomEntries; };
|
diagram = import ./dashboard.nix { inherit lib pkgs cfg models allPhones intercomEntries; };
|
||||||
|
|
@ -87,6 +88,7 @@ in {
|
||||||
"= /directory.xml" = { alias = "${directory.menuFile}"; extraConfig = "default_type text/xml;"; };
|
"= /directory.xml" = { alias = "${directory.menuFile}"; extraConfig = "default_type text/xml;"; };
|
||||||
"= /directory-list.xml" = { alias = "${directory.listFile}"; extraConfig = "default_type text/xml;"; };
|
"= /directory-list.xml" = { alias = "${directory.listFile}"; extraConfig = "default_type text/xml;"; };
|
||||||
"= /intercom.xml" = { alias = "${directory.intercomFile}"; extraConfig = "default_type text/xml;"; };
|
"= /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 "*";''; };
|
||||||
"/" = {
|
"/" = {
|
||||||
root = "${diagram.webRoot}";
|
root = "${diagram.webRoot}";
|
||||||
extraConfig = lib.optionalString (!hasRuntimeSecrets) "index index.html;";
|
extraConfig = lib.optionalString (!hasRuntimeSecrets) "index index.html;";
|
||||||
|
|
|
||||||
50
modules/voip/provisioning/directory-json.nix
Normal file
50
modules/voip/provisioning/directory-json.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
{ lib, pkgs, cfg, models, allPhones }:
|
||||||
|
|
||||||
|
let
|
||||||
|
# Does any provisioned phone on this extension support intercom?
|
||||||
|
extensionHasIntercom = ext:
|
||||||
|
lib.any (phone: phone.extension == ext && models.${phone.model}.hasIntercom)
|
||||||
|
(lib.attrValues allPhones);
|
||||||
|
|
||||||
|
personContacts = lib.mapAttrsToList (_key: person:
|
||||||
|
lib.filterAttrs (_: v: v != null) {
|
||||||
|
displayName = person.displayName;
|
||||||
|
extension = person.extension;
|
||||||
|
intercomExtension =
|
||||||
|
if cfg.intercomPrefix != null && extensionHasIntercom person.extension
|
||||||
|
then "${cfg.intercomPrefix}${person.extension}"
|
||||||
|
else null;
|
||||||
|
mailboxCheckExtension =
|
||||||
|
if person.mailbox then "*97" else null;
|
||||||
|
}
|
||||||
|
) cfg.persons;
|
||||||
|
|
||||||
|
sharedPhoneContacts = lib.mapAttrsToList (_key: phone:
|
||||||
|
lib.filterAttrs (_: v: v != null) {
|
||||||
|
displayName = phone.displayName;
|
||||||
|
extension = phone.extension;
|
||||||
|
intercomExtension =
|
||||||
|
if cfg.intercomPrefix != null && models.${phone.model}.hasIntercom
|
||||||
|
then "${cfg.intercomPrefix}${phone.extension}"
|
||||||
|
else null;
|
||||||
|
}
|
||||||
|
) cfg.sharedPhones;
|
||||||
|
|
||||||
|
specialExtensions = lib.mapAttrsToList (ext: extCfg: {
|
||||||
|
displayName = extCfg.displayName;
|
||||||
|
extension = ext;
|
||||||
|
mode = extCfg.mode;
|
||||||
|
}) cfg.extensions;
|
||||||
|
|
||||||
|
directory = {
|
||||||
|
version = 1;
|
||||||
|
contacts = personContacts ++ sharedPhoneContacts;
|
||||||
|
specialExtensions = specialExtensions;
|
||||||
|
} // lib.optionalAttrs (cfg.sharedMailbox != null) {
|
||||||
|
sharedMailbox = {
|
||||||
|
inherit (cfg.sharedMailbox) displayName checkExtension;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
pkgs.writeText "contacts.json" (builtins.toJSON directory)
|
||||||
Loading…
Reference in a new issue